Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, android=False, adb_prefix=('adb',)): | |
| 72 out_file_name = os.path.basename(file_path) | 90 out_file_name = os.path.basename(file_path) |
| 73 out_file_path = os.path.join(out_dir, out_file_name) | 91 out_file_path = os.path.join(out_dir, out_file_name) |
| 74 | 92 |
| 75 if android: | 93 if android: |
| 76 # Pull the file from the connected Android device | 94 # Pull the file from the connected Android device |
| 77 adb_command = [adb_path, 'pull', file_path, out_dir] | 95 adb_command = adb_prefix + ('pull', file_path, out_dir) |
| 78 subprocess.check_call(_LogCommand(adb_command)) | 96 subprocess.check_call(_LogCommand(adb_command)) |
|
kjellander_webrtc
2017/04/04 13:10:19
Can you add deletion of the file after a successfu
oprypin_webrtc
2017/04/04 15:47:28
Done.
| |
| 79 elif os.path.abspath(file_path) != os.path.abspath(out_file_path): | 97 elif os.path.abspath(file_path) != os.path.abspath(out_file_path): |
| 80 shutil.copy(file_path, out_file_path) | 98 shutil.copy(file_path, out_file_path) |
| 81 | 99 |
| 82 return out_file_path | 100 return out_file_path |
| 83 | 101 |
| 84 | 102 |
| 85 def main(): | 103 def main(): |
| 86 # pylint: disable=W0101 | 104 # pylint: disable=W0101 |
| 87 logging.basicConfig(level=logging.INFO) | 105 logging.basicConfig(level=logging.INFO) |
| 88 | 106 |
| 89 args = _ParseArgs() | 107 args = _ParseArgs() |
| 90 | 108 |
| 91 pesq_path = _DownloadTools() | 109 pesq_path = _DownloadTools() |
| 92 | 110 |
| 93 out_dir = os.path.join(args.build_dir, '..') | 111 out_dir = os.path.join(args.build_dir, '..') |
| 94 if args.android: | 112 if args.android: |
| 95 test_command = [os.path.join(args.build_dir, 'bin', | 113 test_command = [os.path.join(args.build_dir, 'bin', |
| 96 'run_low_bandwidth_audio_test'), '-v'] | 114 'run_low_bandwidth_audio_test'), '-v'] |
| 97 else: | 115 else: |
| 98 test_command = [os.path.join(args.build_dir, 'low_bandwidth_audio_test')] | 116 test_command = [os.path.join(args.build_dir, 'low_bandwidth_audio_test')] |
| 99 | 117 |
| 100 # Start the test executable that produces audio files. | 118 # Start the test executable that produces audio files. |
| 101 test_process = subprocess.Popen(_LogCommand(test_command), | 119 test_process = subprocess.Popen(_LogCommand(test_command), |
| 102 stdout=subprocess.PIPE) | 120 stdout=subprocess.PIPE) |
| 103 | 121 |
| 104 for line in iter(test_process.stdout.readline, ''): | 122 try: |
| 105 # Echo the output to screen. | 123 lines = iter(test_process.stdout.readline, '') |
| 106 sys.stdout.write(line) | 124 for result in ExtractTestRuns(lines, echo=True): |
| 125 (android_device, test_name, reference_file, degraded_file) = result | |
| 107 | 126 |
| 108 # Extract specific lines that contain information about produced files. | 127 adb_prefix = (args.adb_path,) |
| 109 # Output from Android has a prefix, need to skip it. | 128 if android_device: |
| 110 match = re.search(r'^(?:I\b.+\b)?TEST (\w+) ([^ ]+?) ([^ ]+?)\s*$', line) | 129 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 | 130 |
| 119 # Analyze audio. | 131 reference_file = _GetFile(reference_file, out_dir, |
| 120 pesq_command = [pesq_path, '+16000', | 132 args.android, adb_prefix) |
| 121 os.path.basename(reference_file), | 133 degraded_file = _GetFile(degraded_file, out_dir, |
| 122 os.path.basename(degraded_file)] | 134 args.android, 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 | 135 |
| 129 # Find the scores in stdout of pesq. | 136 # Analyze audio. |
| 130 match = re.search( | 137 pesq_command = [pesq_path, '+16000', |
| 131 r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', | 138 os.path.basename(reference_file), |
| 132 pesq_output) | 139 os.path.basename(degraded_file)] |
| 133 if match: | 140 # Need to provide paths in the current directory due to a bug in PESQ: |
| 134 raw_mos, _ = match.groups() | 141 # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than |
| 142 # 'path/to', PESQ crashes. | |
| 143 pesq_output = subprocess.check_output(_LogCommand(pesq_command), | |
| 144 cwd=out_dir) | |
| 135 | 145 |
| 136 # Output a result for the perf dashboard. | 146 # Find the scores in stdout of pesq. |
| 137 print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) | 147 match = re.search( |
| 138 else: | 148 r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', |
| 139 logging.error('PESQ: %s', pesq_output.splitlines()[-1]) | 149 pesq_output) |
| 150 if match: | |
| 151 raw_mos, _ = match.groups() | |
| 140 | 152 |
| 141 if args.remove: | 153 # Output a result for the perf dashboard. |
| 142 os.remove(reference_file) | 154 print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) |
| 143 os.remove(degraded_file) | 155 else: |
| 156 logging.error('PESQ: %s', pesq_output.splitlines()[-1]) | |
| 157 | |
| 158 if args.remove: | |
| 159 os.remove(reference_file) | |
| 160 os.remove(degraded_file) | |
| 161 finally: | |
| 162 test_process.terminate() | |
| 144 | 163 |
| 145 return test_process.wait() | 164 return test_process.wait() |
| 146 | 165 |
| 147 | 166 |
| 148 if __name__ == '__main__': | 167 if __name__ == '__main__': |
| 149 sys.exit(main()) | 168 sys.exit(main()) |
| OLD | NEW |