OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A module to execute a subclass of MediaTastBase class. | 6 """A module to execute a subclass of MediaTastBase class. |
7 | 7 |
8 This executes a media test class (a subclass of MediaTastBase class) with | 8 This executes a media test class (a subclass of MediaTastBase class) with |
9 different configuration (parameters) which are passed in the form of | 9 different configuration (parameters) which are passed in the form of |
10 environment variables (e.g., the number of runs). The location of the | 10 environment variables (e.g., the number of runs). The location of the |
11 subclass is passed as one of arguments. An example of invocation is | 11 subclass is passed as one of arguments. An example of invocation is |
12 "./media_test_runner.py -p ./media_perf.py". In this example, | 12 "./media_test_runner.py -p ./media_perf.py". In this example, |
13 media_perf.py will be invoked using the default set of parameters. | 13 media_perf.py will be invoked using the default set of parameters. |
14 The list of possible combinations of parameters are: T parameter | 14 The list of possible combinations of parameters are: T parameter |
15 for media cache is set/non-set, Chrome flag is set/non-set, data element | 15 for media cache is set/non-set, Chrome flag is set/non-set, data element |
16 in data source file (CSV file - its content is list form or its content is | 16 in data source file (CSV file - its content is list form or its content is |
17 in matrix form), | 17 in matrix form), |
18 """ | 18 """ |
19 | 19 |
20 import copy | 20 import copy |
21 import csv | 21 import csv |
| 22 import glob |
22 import logging | 23 import logging |
23 import os | 24 import os |
24 from optparse import OptionParser | 25 from optparse import OptionParser |
25 import shlex | 26 import shlex |
26 import sys | 27 import sys |
27 from subprocess import Popen | 28 from subprocess import Popen |
28 | 29 |
29 from media_test_env_names import MediaTestEnvNames | 30 from media_test_env_names import MediaTestEnvNames |
30 from media_test_matrix import MediaTestMatrix | 31 from media_test_matrix import MediaTestMatrix |
31 | 32 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 default=False, action='store_true') | 124 default=False, action='store_true') |
124 parser.add_option('-j', '--track', dest='track', | 125 parser.add_option('-j', '--track', dest='track', |
125 help=('Run track test (binary should be downloaded' | 126 help=('Run track test (binary should be downloaded' |
126 ' from http://www.annacavender.com/track/' | 127 ' from http://www.annacavender.com/track/' |
127 ' and put into reference_build_dir).'), | 128 ' and put into reference_build_dir).'), |
128 default=False, action='store_true') | 129 default=False, action='store_true') |
129 parser.add_option('-g', '--track-file', dest='track_file', | 130 parser.add_option('-g', '--track-file', dest='track_file', |
130 help=('Track file in vtt format (binary should be' | 131 help=('Track file in vtt format (binary should be' |
131 ' downloaded from http://www.annacavender.com/track/' | 132 ' downloaded from http://www.annacavender.com/track/' |
132 ' and put into reference_build_dir).')) | 133 ' and put into reference_build_dir).')) |
| 134 parser.add_option('-y', '--track-file_dir', dest='track_file_dir', |
| 135 help=('A directory that contains vtt format files')) |
133 | 136 |
134 options, args = parser.parse_args() | 137 options, args = parser.parse_args() |
135 if args: | 138 if args: |
136 parser.print_help() | 139 parser.print_help() |
137 sys.exit(1) | 140 sys.exit(1) |
138 | 141 |
139 test_data_list = [] | 142 test_data_list = [] |
140 if options.media_file: | 143 if options.media_file: |
141 opts = options.media_file.split('|') | 144 opts = options.media_file.split('|') |
142 # The media file should have the following format: | 145 # The media file should have the following format: |
143 # tag(video|audio)|filename|nickname|video_title. | 146 # tag(video|audio)|filename|nickname|video_title. |
144 if len(opts) != 4: | 147 if len(opts) != 4: |
145 logging.error('--media_file option argument does not have correct format.' | 148 logging.error('--media_file option argument does not have correct' |
146 'The correct format is tag(video|audio)|filename|nickname' | 149 'format. The correct format is tag(video|audio)' |
147 '|video_title') | 150 '|filename|nickname|video_title') |
148 sys.exit(1) | 151 sys.exit(1) |
149 test_data_list.append(opts) | 152 test_data_list.append(opts) |
150 elif options.input_matrix_filename is None: | 153 elif options.input_matrix_filename is None: |
151 file = open(options.input_filename, 'rb') | 154 file = open(options.input_filename, 'rb') |
152 test_data_list = csv.reader(file) | 155 test_data_list = csv.reader(file) |
153 # First line contains headers that can be skipped. | 156 # First line contains headers that can be skipped. |
154 test_data_list.next() | 157 test_data_list.next() |
155 else: | 158 else: |
156 # Video_matrix_home_url requires "/" at the end. | 159 # Video_matrix_home_url requires "/" at the end. |
157 if not options.video_matrix_home_url.endswith('/'): | 160 if not options.video_matrix_home_url.endswith('/'): |
(...skipping 11 matching lines...) Expand all Loading... |
169 all_data_list, options.input_matrix_testcase_name) | 172 all_data_list, options.input_matrix_testcase_name) |
170 if media_info is not None: | 173 if media_info is not None: |
171 test_data_list.append(media_info) | 174 test_data_list.append(media_info) |
172 | 175 |
173 # Determine whether we need to repeat a test using a reference build. | 176 # Determine whether we need to repeat a test using a reference build. |
174 # The default is not to include a test using a reference build. | 177 # The default is not to include a test using a reference build. |
175 if options.reference_build: | 178 if options.reference_build: |
176 reference_build_list = [False, True] | 179 reference_build_list = [False, True] |
177 else: | 180 else: |
178 reference_build_list = [False] | 181 reference_build_list = [False] |
179 if options.track_file or options.track: | 182 track_files = [''] |
| 183 if options.track_file or options.track or options.track_file_dir: |
180 # TODO(imasaki@chromium.org): change here after track functionality is | 184 # TODO(imasaki@chromium.org): change here after track functionality is |
181 # available on Chrome. Currently, track patch is still under development. | 185 # available on Chrome. Currently, track patch is still under development. |
182 # So, I need to download the binary from | 186 # So, I need to download the binary from |
183 # http://www.annacavender.com/track/ and use it for testing. | 187 # http://www.annacavender.com/track/ and use it for testing. |
184 # I temporarily use reference build mechanism. | 188 # I temporarily use reference build mechanism. |
185 reference_build_list = [True] | 189 reference_build_list = [True] |
| 190 if options.track_file_dir: |
| 191 track_files_orig = ( |
| 192 glob.glob(os.path.join(options.track_file_dir, '*.vtt'))) |
| 193 track_files = [] |
| 194 for tf in track_files_orig: |
| 195 # The location should be relative path from HTML files. |
| 196 # So it needs to remove data and media from the path. |
| 197 track_files.append(tf.replace(os.path.join('data', 'media'), '')) |
| 198 if options.track_file: |
| 199 track_files = [options.track_file] |
186 # This is a loop for iterating through all videos defined above (list | 200 # This is a loop for iterating through all videos defined above (list |
187 # or matrix). Each video has associated tag and nickname for display | 201 # or matrix). Each video has associated tag and nickname for display |
188 # purpose. | 202 # purpose. |
189 for tag, filename, nickname, title in test_data_list: | 203 for tag, filename, nickname, title in test_data_list: |
190 # This inner loop iterates twice. The first iteration of the loop | 204 for track_file in track_files: |
191 # disables the media cache, and the second iteration enables the media | 205 for reference_build in reference_build_list: |
192 # cache. Other parameters remain the same on both loop iterations. | 206 parent_envs = copy.deepcopy(os.environ) |
193 # There are two ways to disable the media cache: setting Chrome option | 207 if options.input_matrix_filename is None: |
194 # to --media-cache-size=1 or adding t parameter in query parameter of | 208 par_filename = os.path.join(os.pardir, filename) |
195 # URL in which player.js (data/media/html/player.js) disables the | |
196 # media cache). | |
197 # | |
198 # The default name for track vtt file is the name of the video title | |
199 # in the case --track-file is not set. The track file should be in | |
200 # the same directory as video files. For example, bear_en.vtt. | |
201 if options.track and not options.track_file: | |
202 # TODO(imasaki@chromium.org): add more languages. | |
203 lang = 'en' | |
204 options.track_file = os.path.join(os.path.dirname(filename), | |
205 title + '_' + lang + '.vtt') | |
206 for reference_build in reference_build_list: | |
207 parent_envs = copy.deepcopy(os.environ) | |
208 if options.input_matrix_filename is None: | |
209 par_filename = os.path.join(os.pardir, filename) | |
210 else: | |
211 par_filename = filename | |
212 envs = { | |
213 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, | |
214 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, | |
215 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, | |
216 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: | |
217 options.player_html_url, | |
218 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: | |
219 options.player_html_url_nickname, | |
220 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), | |
221 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: | |
222 str(options.measure_intervals), | |
223 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: | |
224 options.test_scenario_input_filename, | |
225 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: | |
226 options.test_scenario, | |
227 } | |
228 # Boolean variables and their related variables. | |
229 if options.disable_media_cache: | |
230 # The 't' parameter is passed to player.html to disable/enable | |
231 # the media cache (refer to data/media/html/player.js). | |
232 envs[MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME] = str( | |
233 options.disable_media_cache) | |
234 if reference_build: | |
235 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( | |
236 reference_build) | |
237 if REMOVE_FIRST_RESULT: | |
238 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( | |
239 REMOVE_FIRST_RESULT) | |
240 if options.reference_build_dir: | |
241 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( | |
242 options.reference_build_dir) | |
243 if options.track_file: | |
244 envs[MediaTestEnvNames.TRACK_FILE_ENV_NAME] = ( | |
245 options.track_file) | |
246 envs.update(parent_envs) | |
247 if options.suite is None and options.test_prog_name is not None: | |
248 # Suite is not used - run test program directly. | |
249 test_prog_name = options.test_prog_name | |
250 suite_string = '' | |
251 else: | |
252 # Suite is used. | |
253 # The test script names are in the PYAUTO_TESTS file. | |
254 test_prog_name = pyauto_functional_script_name | |
255 if options.suite is None: | |
256 suite_name = DEFAULT_SUITE_NAME | |
257 else: | 209 else: |
258 suite_name = options.suite | 210 par_filename = filename |
259 suite_string = ' --suite=%s' % suite_name | 211 envs = { |
260 test_prog_name = sys.executable + ' ' + test_prog_name | 212 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, |
261 chrome_flag = '' | 213 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, |
262 if options.disable_media_cache: | 214 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, |
263 chrome_flag += CHROME_FLAGS['disable_cache'] | 215 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: |
264 if options.track_file: | 216 options.player_html_url, |
| 217 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: |
| 218 options.player_html_url_nickname, |
| 219 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), |
| 220 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: |
| 221 str(options.measure_intervals), |
| 222 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: |
| 223 options.test_scenario_input_filename, |
| 224 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: |
| 225 options.test_scenario, |
| 226 } |
| 227 # Boolean variables and their related variables. |
265 if options.disable_media_cache: | 228 if options.disable_media_cache: |
266 chrome_flag += ' ' | 229 # The 't' parameter is passed to player.html to disable/enable |
267 chrome_flag += CHROME_FLAGS['track'] | 230 # the media cache (refer to data/media/html/player.js). |
268 if chrome_flag: | 231 envs[MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME] = str( |
269 chrome_flag = '--chrome-flags=\'%s\'' % chrome_flag | 232 options.disable_media_cache) |
270 cmd = test_prog_name + suite_string + ' ' + chrome_flag | 233 if reference_build: |
271 if options.verbose: | 234 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( |
272 cmd += ' -v' | 235 reference_build) |
273 proc = Popen(cmd, env=envs, shell=True) | 236 if REMOVE_FIRST_RESULT: |
274 proc.communicate() | 237 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( |
| 238 REMOVE_FIRST_RESULT) |
| 239 if options.reference_build_dir: |
| 240 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( |
| 241 options.reference_build_dir) |
| 242 if track_file: |
| 243 envs[MediaTestEnvNames.TRACK_FILE_ENV_NAME] = track_file |
| 244 envs.update(parent_envs) |
| 245 if options.suite is None and options.test_prog_name is not None: |
| 246 # Suite is not used - run test program directly. |
| 247 test_prog_name = options.test_prog_name |
| 248 suite_string = '' |
| 249 else: |
| 250 # Suite is used. |
| 251 # The test script names are in the PYAUTO_TESTS file. |
| 252 test_prog_name = pyauto_functional_script_name |
| 253 if options.suite is None: |
| 254 suite_name = DEFAULT_SUITE_NAME |
| 255 else: |
| 256 suite_name = options.suite |
| 257 suite_string = ' --suite=%s' % suite_name |
| 258 test_prog_name = sys.executable + ' ' + test_prog_name |
| 259 chrome_flag = '' |
| 260 if options.disable_media_cache: |
| 261 chrome_flag += CHROME_FLAGS['disable_cache'] |
| 262 if options.track_file: |
| 263 if options.disable_media_cache: |
| 264 chrome_flag += ' ' |
| 265 chrome_flag += CHROME_FLAGS['track'] |
| 266 if chrome_flag: |
| 267 chrome_flag = '--chrome-flags=\'%s\'' % chrome_flag |
| 268 cmd = test_prog_name + suite_string + ' ' + chrome_flag |
| 269 if options.verbose: |
| 270 cmd += ' -v' |
| 271 proc = Popen(cmd, env=envs, shell=True) |
| 272 proc.communicate() |
275 | 273 |
276 if options.one_video: | 274 if options.one_video: |
277 break | 275 break |
278 | 276 |
279 | 277 |
280 if __name__ == '__main__': | 278 if __name__ == '__main__': |
281 main() | 279 main() |
OLD | NEW |