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 6482d3d0209cba828185f771b1299d8c0e355304..768f7c29c2cd36a15bc1b80861a97f2b4e07193a 100755 |
| --- a/webrtc/audio/test/low_bandwidth_audio_test.py |
| +++ b/webrtc/audio/test/low_bandwidth_audio_test.py |
| @@ -18,6 +18,7 @@ import argparse |
| import logging |
| import os |
| import re |
| +import shutil |
| import subprocess |
| import sys |
| @@ -38,6 +39,8 @@ def _ParseArgs(): |
| help='Path to the build directory (e.g. out/Release).') |
| parser.add_argument('--remove', action='store_true', |
| help='Remove output audio files after testing.') |
| + parser.add_argument('--android', action='store_true', |
| + help='Perform the test on a connected Android device instead') |
| args = parser.parse_args() |
| return args |
| @@ -51,13 +54,6 @@ def _GetPlatform(): |
| return 'linux' |
| -def _GetExecutableExtension(): |
| - if sys.platform == 'win32': |
| - return '.exe' |
| - else: |
| - return '' |
| - |
| - |
| def _DownloadTools(): |
| tools_dir = os.path.join(SRC_DIR, 'tools-webrtc') |
| toolchain_dir = os.path.join(tools_dir, 'audio_quality') |
| @@ -67,11 +63,24 @@ def _DownloadTools(): |
| command = [sys.executable, download_script, toolchain_dir] |
| subprocess.check_call(_LogCommand(command)) |
| - pesq_path = os.path.join(toolchain_dir, _GetPlatform(), |
| - 'pesq' + _GetExecutableExtension()) |
| + pesq_path = os.path.join(toolchain_dir, _GetPlatform(), 'pesq') |
|
kjellander_webrtc
2017/03/27 09:05:10
What about .exe on Windows?
oprypin_webrtc
2017/03/27 09:19:07
Works fine (tested), .exe is resolved automaticall
kjellander_webrtc
2017/03/27 09:46:51
Aha, even without shell=True? My mistake then.
|
| return pesq_path |
| +def _GetFile(file_path, out_dir, android=False): |
| + 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', 'pull', file_path, out_dir] |
|
kjellander_webrtc
2017/03/27 09:46:51
adb is not normally in PATH unless you've first so
oprypin_webrtc
2017/03/27 09:59:41
I'm not even sure how we can improve this. I was l
kjellander_webrtc
2017/03/27 12:21:55
Since the bots try hard to keep clean environments
oprypin_webrtc
2017/03/28 07:01:01
Done.
|
| + 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) |
| + |
| + return out_file_path |
| + |
| + |
| def main(): |
| # pylint: disable=W0101 |
| logging.basicConfig(level=logging.INFO) |
| @@ -80,29 +89,39 @@ def main(): |
| pesq_path = _DownloadTools() |
| - test_executable_path = os.path.join(args.build_dir, |
| - 'low_bandwidth_audio_test' + _GetExecutableExtension()) |
| + out_dir = os.path.join(args.build_dir, '..') |
| + if args.android: |
| + test_command = [os.path.join(args.build_dir, 'bin', |
| + 'run_low_bandwidth_audio_test'), '-v'] |
| + else: |
| + test_command = [os.path.join(args.build_dir, 'low_bandwidth_audio_test')] |
| # Start the test executable that produces audio files. |
| - command = [test_executable_path] |
| - test_process = subprocess.Popen(_LogCommand(command), stdout=subprocess.PIPE) |
| + 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. |
| - match = re.search(r'^TEST (\w+) ([^:]+?):([^:]+?)\n?$', line) |
| + # 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, reference_file, degraded_file = match.groups() |
| - |
| - # Analyze audio |
| - command = [pesq_path, '+16000', reference_file, degraded_file] |
| - pesq_output = subprocess.check_output(_LogCommand(command)) |
| - |
| - if args.remove: |
| - os.remove(degraded_file) |
| + test_name = match.group(1) |
| + reference_file = _GetFile(match.group(2), out_dir, args.android) |
| + degraded_file = _GetFile(match.group(3), out_dir, args.android) |
| + |
| + # 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( |
| @@ -116,6 +135,10 @@ def main(): |
| else: |
| logging.error('PESQ: %s', pesq_output.splitlines()[-1]) |
| + if args.remove: |
| + os.remove(reference_file) |
| + os.remove(degraded_file) |
| + |
| return test_process.wait() |