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