Chromium Code Reviews| Index: webrtc/audio/test/low_bandwidth_audio_test.py |
| diff --git a/webrtc/audio/test/low_bandwidth_audio_test.py b/webrtc/audio/test/low_bandwidth_audio_test.py |
| index 58243b1c9804402849ceb89738943178e4b9a9be..49fff13b5c2e6cdafe3cea354a5b6fcda74f4141 100755 |
| --- a/webrtc/audio/test/low_bandwidth_audio_test.py |
| +++ b/webrtc/audio/test/low_bandwidth_audio_test.py |
| @@ -68,13 +68,13 @@ def _DownloadTools(): |
| return pesq_path |
| -def _GetFile(file_path, out_dir, android=False, adb_path=None): |
| +def _GetFile(file_path, out_dir, android=False, adb_prefix=('adb',)): |
| out_file_name = os.path.basename(file_path) |
| out_file_path = os.path.join(out_dir, out_file_name) |
| if android: |
| # Pull the file from the connected Android device |
| - adb_command = [adb_path, 'pull', file_path, out_dir] |
| + adb_command = adb_prefix + ('pull', file_path, out_dir) |
| subprocess.check_call(_LogCommand(adb_command)) |
| elif os.path.abspath(file_path) != os.path.abspath(out_file_path): |
| shutil.copy(file_path, out_file_path) |
| @@ -101,46 +101,58 @@ def main(): |
| test_process = subprocess.Popen(_LogCommand(test_command), |
| stdout=subprocess.PIPE) |
| - for line in iter(test_process.stdout.readline, ''): |
| - # Echo the output to screen. |
| - sys.stdout.write(line) |
| - |
| - # Extract specific lines that contain information about produced files. |
| - # Output from Android has a prefix, need to skip it. |
| - match = re.search(r'^(?:I\b.+\b)?TEST (\w+) ([^ ]+?) ([^ ]+?)\s*$', line) |
| - if not match: |
| - continue |
| - test_name = match.group(1) |
| - reference_file = _GetFile(match.group(2), out_dir, |
| - args.android, args.adb_path) |
| - degraded_file = _GetFile(match.group(3), out_dir, |
| - args.android, args.adb_path) |
| - |
| - # Analyze audio. |
| - pesq_command = [pesq_path, '+16000', |
| - os.path.basename(reference_file), |
| - os.path.basename(degraded_file)] |
| - # Need to provide paths in the current directory due to a bug in PESQ: |
| - # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than |
| - # 'path/to', PESQ crashes. |
| - pesq_output = subprocess.check_output(_LogCommand(pesq_command), |
| - cwd=out_dir) |
| - |
| - # Find the scores in stdout of pesq. |
| - match = re.search( |
| - r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', |
| - pesq_output) |
| - if match: |
| - raw_mos, _ = match.groups() |
| - |
| - # Output a result for the perf dashboard. |
| - print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) |
| - else: |
| - logging.error('PESQ: %s', pesq_output.splitlines()[-1]) |
| - |
| - if args.remove: |
| - os.remove(reference_file) |
| - os.remove(degraded_file) |
| + try: |
| + for line in iter(test_process.stdout.readline, ''): |
| + # Echo the output to screen. |
| + sys.stdout.write(line) |
| + |
| + # Extract specific lines that contain information about produced files. |
| + # Output from Android has a prefix with the device name. |
| + android_prefix_re = r'(?:I\b.+\brun_tests_on_device\((.+?)\)\s*)?' |
| + test_re = r'^' + android_prefix_re + r'TEST (\w+) ([^ ]+?) ([^ ]+?)\s*$' |
|
kjellander_webrtc
2017/04/03 13:07:43
Could you extract the logic here into a function t
oprypin_webrtc
2017/04/04 08:41:50
Thanks for the suggestion. This is now done. I wou
|
| + |
| + match = re.search(test_re, line) |
| + if not match: |
| + continue |
| + test_name = match.group(2) |
| + |
| + android_device = match.group(1) |
| + adb_prefix = (args.adb_path,) |
| + if android_device: |
| + adb_prefix += ('-s', android_device) |
| + |
| + reference_file = _GetFile(match.group(3), out_dir, |
| + args.android, adb_prefix) |
| + degraded_file = _GetFile(match.group(4), out_dir, |
| + args.android, adb_prefix) |
| + |
| + # Analyze audio. |
| + pesq_command = [pesq_path, '+16000', |
| + os.path.basename(reference_file), |
| + os.path.basename(degraded_file)] |
| + # Need to provide paths in the current directory due to a bug in PESQ: |
| + # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than |
| + # 'path/to', PESQ crashes. |
| + pesq_output = subprocess.check_output(_LogCommand(pesq_command), |
| + cwd=out_dir) |
| + |
| + # Find the scores in stdout of pesq. |
| + match = re.search( |
| + r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', |
| + pesq_output) |
| + if match: |
| + raw_mos, _ = match.groups() |
| + |
| + # Output a result for the perf dashboard. |
| + print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) |
| + else: |
| + logging.error('PESQ: %s', pesq_output.splitlines()[-1]) |
| + |
| + if args.remove: |
| + os.remove(reference_file) |
| + os.remove(degraded_file) |
| + finally: |
| + test_process.terminate() |
| return test_process.wait() |