Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: webrtc/audio/test/low_bandwidth_audio_test.py

Issue 2783343003: Support multiple connected Android devices in low bandwidth audio test (Closed)
Patch Set: Rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | webrtc/audio/test/unittests/low_bandwidth_audio_test_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 # 3 #
4 # Use of this source code is governed by a BSD-style license 4 # Use of this source code is governed by a BSD-style license
5 # that can be found in the LICENSE file in the root of the source 5 # that can be found in the LICENSE file in the root of the source
6 # tree. An additional intellectual property rights grant can be found 6 # tree. An additional intellectual property rights grant can be found
7 # in the file PATENTS. All contributing project authors may 7 # in the file PATENTS. All contributing project authors may
8 # be found in the AUTHORS file in the root of the source tree. 8 # be found in the AUTHORS file in the root of the source tree.
9 9
10 """ 10 """
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 # Download pesq. 62 # Download pesq.
63 download_script = os.path.join(tools_dir, 'download_tools.py') 63 download_script = os.path.join(tools_dir, 'download_tools.py')
64 command = [sys.executable, download_script, toolchain_dir] 64 command = [sys.executable, download_script, toolchain_dir]
65 subprocess.check_call(_LogCommand(command)) 65 subprocess.check_call(_LogCommand(command))
66 66
67 pesq_path = os.path.join(toolchain_dir, _GetPlatform(), 'pesq') 67 pesq_path = os.path.join(toolchain_dir, _GetPlatform(), 'pesq')
68 return pesq_path 68 return pesq_path
69 69
70 70
71 def _GetFile(file_path, out_dir, android=False, adb_path=None): 71 def ExtractTestRuns(lines, echo=False):
72 """Extracts information about tests from the output of a test runner.
73
74 Produces tuples (android_device, test_name, reference_file, degraded_file).
75 """
76 for line in lines:
77 if echo:
78 sys.stdout.write(line)
79
80 # Output from Android has a prefix with the device name.
81 android_prefix_re = r'(?:I\b.+\brun_tests_on_device\((.+?)\)\s*)?'
82 test_re = r'^' + android_prefix_re + r'TEST (\w+) ([^ ]+?) ([^ ]+?)\s*$'
83
84 match = re.search(test_re, line)
85 if match:
86 yield match.groups()
87
88
89 def _GetFile(file_path, out_dir, move=False,
90 android=False, adb_prefix=('adb',)):
72 out_file_name = os.path.basename(file_path) 91 out_file_name = os.path.basename(file_path)
73 out_file_path = os.path.join(out_dir, out_file_name) 92 out_file_path = os.path.join(out_dir, out_file_name)
74 93
75 if android: 94 if android:
76 # Pull the file from the connected Android device 95 # Pull the file from the connected Android device.
77 adb_command = [adb_path, 'pull', file_path, out_dir] 96 adb_command = adb_prefix + ('pull', file_path, out_dir)
78 subprocess.check_call(_LogCommand(adb_command)) 97 subprocess.check_call(_LogCommand(adb_command))
98 if move:
99 # Remove that file.
100 adb_command = adb_prefix + ('shell', 'rm', file_path)
101 subprocess.check_call(_LogCommand(adb_command))
79 elif os.path.abspath(file_path) != os.path.abspath(out_file_path): 102 elif os.path.abspath(file_path) != os.path.abspath(out_file_path):
80 shutil.copy(file_path, out_file_path) 103 if move:
104 shutil.move(file_path, out_file_path)
105 else:
106 shutil.copy(file_path, out_file_path)
81 107
82 return out_file_path 108 return out_file_path
83 109
84 110
85 def main(): 111 def main():
86 # pylint: disable=W0101 112 # pylint: disable=W0101
87 logging.basicConfig(level=logging.INFO) 113 logging.basicConfig(level=logging.INFO)
88 114
89 args = _ParseArgs() 115 args = _ParseArgs()
90 116
91 pesq_path = _DownloadTools() 117 pesq_path = _DownloadTools()
92 118
93 out_dir = os.path.join(args.build_dir, '..') 119 out_dir = os.path.join(args.build_dir, '..')
94 if args.android: 120 if args.android:
95 test_command = [os.path.join(args.build_dir, 'bin', 121 test_command = [os.path.join(args.build_dir, 'bin',
96 'run_low_bandwidth_audio_test'), '-v'] 122 'run_low_bandwidth_audio_test'), '-v']
97 else: 123 else:
98 test_command = [os.path.join(args.build_dir, 'low_bandwidth_audio_test')] 124 test_command = [os.path.join(args.build_dir, 'low_bandwidth_audio_test')]
99 125
100 # Start the test executable that produces audio files. 126 # Start the test executable that produces audio files.
101 test_process = subprocess.Popen(_LogCommand(test_command), 127 test_process = subprocess.Popen(_LogCommand(test_command),
102 stdout=subprocess.PIPE) 128 stdout=subprocess.PIPE)
103 129
104 for line in iter(test_process.stdout.readline, ''): 130 try:
105 # Echo the output to screen. 131 lines = iter(test_process.stdout.readline, '')
106 sys.stdout.write(line) 132 for result in ExtractTestRuns(lines, echo=True):
133 (android_device, test_name, reference_file, degraded_file) = result
107 134
108 # Extract specific lines that contain information about produced files. 135 adb_prefix = (args.adb_path,)
109 # Output from Android has a prefix, need to skip it. 136 if android_device:
110 match = re.search(r'^(?:I\b.+\b)?TEST (\w+) ([^ ]+?) ([^ ]+?)\s*$', line) 137 adb_prefix += ('-s', android_device)
111 if not match:
112 continue
113 test_name = match.group(1)
114 reference_file = _GetFile(match.group(2), out_dir,
115 args.android, args.adb_path)
116 degraded_file = _GetFile(match.group(3), out_dir,
117 args.android, args.adb_path)
118 138
119 # Analyze audio. 139 reference_file = _GetFile(reference_file, out_dir,
120 pesq_command = [pesq_path, '+16000', 140 android=args.android, adb_prefix=adb_prefix)
121 os.path.basename(reference_file), 141 degraded_file = _GetFile(degraded_file, out_dir, move=True,
122 os.path.basename(degraded_file)] 142 android=args.android, adb_prefix=adb_prefix)
123 # Need to provide paths in the current directory due to a bug in PESQ:
124 # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than
125 # 'path/to', PESQ crashes.
126 pesq_output = subprocess.check_output(_LogCommand(pesq_command),
127 cwd=out_dir)
128 143
129 # Find the scores in stdout of pesq. 144 # Analyze audio.
130 match = re.search( 145 pesq_command = [pesq_path, '+16000',
131 r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', 146 os.path.basename(reference_file),
132 pesq_output) 147 os.path.basename(degraded_file)]
133 if match: 148 # Need to provide paths in the current directory due to a bug in PESQ:
134 raw_mos, _ = match.groups() 149 # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than
150 # 'path/to', PESQ crashes.
151 pesq_output = subprocess.check_output(_LogCommand(pesq_command),
152 cwd=out_dir)
135 153
136 # Output a result for the perf dashboard. 154 # Find the scores in stdout of pesq.
137 print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) 155 match = re.search(
138 else: 156 r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)',
139 logging.error('PESQ: %s', pesq_output.splitlines()[-1]) 157 pesq_output)
158 if match:
159 raw_mos, _ = match.groups()
140 160
141 if args.remove: 161 # Output a result for the perf dashboard.
142 os.remove(reference_file) 162 print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos)
143 os.remove(degraded_file) 163 else:
164 logging.error('PESQ: %s', pesq_output.splitlines()[-1])
165
166 if args.remove:
167 os.remove(reference_file)
168 os.remove(degraded_file)
169 finally:
170 test_process.terminate()
144 171
145 return test_process.wait() 172 return test_process.wait()
146 173
147 174
148 if __name__ == '__main__': 175 if __name__ == '__main__':
149 sys.exit(main()) 176 sys.exit(main())
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | webrtc/audio/test/unittests/low_bandwidth_audio_test_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698