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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 from optparse import OptionParser | 23 from optparse import OptionParser |
24 import shlex | 24 import shlex |
25 import sys | 25 import sys |
26 from subprocess import Popen | 26 from subprocess import Popen |
27 | 27 |
28 from media_test_env_names import MediaTestEnvNames | 28 from media_test_env_names import MediaTestEnvNames |
29 from media_test_matrix import MediaTestMatrix | 29 from media_test_matrix import MediaTestMatrix |
30 | 30 |
31 | 31 |
32 def main(): | 32 def main(): |
33 EXTRA_NICKNAMES = ['nocache', 'cache'] | 33 CHROME_FLAGS = {'disable_cache': '--media-cache-size=1', |
34 # Disable/enable media_cache. | 34 # Please note track (caption) option is not implemented yet |
35 CHROME_FLAGS = ['--chrome-flags=\'--media-cache-size=1\'', ''] | 35 # as of 6/8/2011. |
36 # The 't' parameter is passed to player.html to disable/enable the media | 36 'track': '--enable-video-track'} |
37 # cache (refer to data/media/html/player.js). | |
38 ADD_T_PARAMETERS = [False, True] | |
39 # Player.html should contain all the HTML and Javascript that is | 37 # Player.html should contain all the HTML and Javascript that is |
40 # necessary to run these tests. | 38 # necessary to run these tests. |
41 DEFAULT_PLAYER_HTML_URL = 'DEFAULT' | 39 DEFAULT_PLAYER_HTML_URL = 'DEFAULT' |
42 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' | 40 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' |
43 # Default base url nickname used to display the result in case it is not | 41 # Default base url nickname used to display the result in case it is not |
44 # specified by the environment variable. | 42 # specified by the environment variable. |
45 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' | 43 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' |
46 REMOVE_FIRST_RESULT = True | 44 REMOVE_FIRST_RESULT = True |
47 # The number of runs for each test. This is used to compute average values | 45 # The number of runs for each test. This is used to compute average values |
48 # from among all runs. | 46 # from among all runs. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 help='Player.html Nickname [defaults to "%s"]' % | 83 help='Player.html Nickname [defaults to "%s"]' % |
86 DEFAULT_PLAYER_HTML_URL_NICKNAME) | 84 DEFAULT_PLAYER_HTML_URL_NICKNAME) |
87 parser.add_option('-n', '--number_of_runs', dest='number_of_runs', | 85 parser.add_option('-n', '--number_of_runs', dest='number_of_runs', |
88 default=DEFAULT_NUMBER_OF_RUNS, | 86 default=DEFAULT_NUMBER_OF_RUNS, |
89 help='The number of runs [defaults to "%d"]' % | 87 help='The number of runs [defaults to "%d"]' % |
90 DEFAULT_NUMBER_OF_RUNS) | 88 DEFAULT_NUMBER_OF_RUNS) |
91 parser.add_option('-m', '--measure_intervals', dest='measure_intervals', | 89 parser.add_option('-m', '--measure_intervals', dest='measure_intervals', |
92 default=DEFAULT_MEASURE_INTERVALS, | 90 default=DEFAULT_MEASURE_INTERVALS, |
93 help='Interval for measurement data [defaults to "%d"]' % | 91 help='Interval for measurement data [defaults to "%d"]' % |
94 DEFAULT_MEASURE_INTERVALS) | 92 DEFAULT_MEASURE_INTERVALS) |
95 parser.add_option('-c', '--cache_test', dest='cache_test', | 93 parser.add_option('-c', '--disable_media_cache', dest='disable_media_cache', |
96 default=False, help='Include cache test', | 94 default=False, help='Disable media cache', |
97 action='store_true') | 95 action='store_true') |
98 parser.add_option('-z', '--test-one-video', dest='one_video', | 96 parser.add_option('-z', '--test-one-video', dest='one_video', |
99 default=False, help='Run only one video', | 97 default=False, help='Run only one video', |
100 action='store_true') | 98 action='store_true') |
101 parser.add_option( | 99 parser.add_option( |
102 '-w', '--test_scenario_input_filename', | 100 '-w', '--test_scenario_input_filename', |
103 dest='test_scenario_input_filename', | 101 dest='test_scenario_input_filename', |
104 default='', help='Test scenario file (CSV form)', metavar='FILE') | 102 default='', help='Test scenario file (CSV form)', metavar='FILE') |
105 parser.add_option( | 103 parser.add_option( |
106 '-q', '--test_scenario', dest='test_scenario', | 104 '-q', '--test_scenario', dest='test_scenario', |
107 default='', help='Test scenario (action triples delimited by \'|\')') | 105 default='', help='Test scenario (action triples delimited by \'|\')') |
108 parser.add_option('-s', '--suite', dest='suite', | 106 parser.add_option('-s', '--suite', dest='suite', |
109 help='Suite file') | 107 help='Suite file') |
110 parser.add_option('-e', '--media_file', dest='media_file', | 108 parser.add_option('-e', '--media_file', dest='media_file', |
111 default='', | 109 default='', |
112 help=('Media file to be played using player.html. ' | 110 help=('Media file to be played using player.html. ' |
113 'The relative path needs to be specified starting ' | 111 'The relative path needs to be specified starting ' |
114 'from data/html/ directory.')) | 112 'from data/html/ directory.')) |
115 parser.add_option('-a', '--reference_build', dest='reference_build', | 113 parser.add_option('-a', '--reference_build', dest='reference_build', |
116 help='Include reference build run', default=False, | 114 help='Include reference build run', default=False, |
117 action='store_true') | 115 action='store_true') |
118 parser.add_option('-k', '--reference_build_dir', dest='reference_build_dir', | 116 parser.add_option('-k', '--reference_build_dir', dest='reference_build_dir', |
119 help=('A absolute path to the directory that contains' | 117 help=('A absolute path to the directory that contains' |
120 'binaries of reference build.')) | 118 'binaries of reference build.')) |
121 parser.add_option('-v', '--verbose', dest='verbose', help='Verbose mode.', | 119 parser.add_option('-v', '--verbose', dest='verbose', help='Verbose mode.', |
122 default=False, action='store_true') | 120 default=False, action='store_true') |
123 | 121 parser.add_option('-j', '--track', dest='track', |
| 122 help=('Run track test (binary should be downloaded' |
| 123 ' from http://www.annacavender.com/track/' |
| 124 ' and put into reference_build_dir).'), |
| 125 default=False, action='store_true') |
124 options, args = parser.parse_args() | 126 options, args = parser.parse_args() |
125 if args: | 127 if args: |
126 parser.print_help() | 128 parser.print_help() |
127 sys.exit(1) | 129 sys.exit(1) |
128 | 130 |
129 test_data_list = [] | 131 test_data_list = [] |
130 if options.media_file: | 132 if options.media_file: |
131 test_data_list.append(['video', options.media_file, options.media_file]) | 133 test_data_list.append(['video', options.media_file, options.media_file]) |
132 elif options.input_matrix_filename is None: | 134 elif options.input_matrix_filename is None: |
133 file = open(options.input_filename, 'rb') | 135 file = open(options.input_filename, 'rb') |
(...skipping 17 matching lines...) Expand all Loading... |
151 all_data_list, options.input_matrix_testcase_name) | 153 all_data_list, options.input_matrix_testcase_name) |
152 if media_info is not None: | 154 if media_info is not None: |
153 test_data_list.append(media_info) | 155 test_data_list.append(media_info) |
154 | 156 |
155 # Determine whether we need to repeat a test using a reference build. | 157 # Determine whether we need to repeat a test using a reference build. |
156 # The default is not to include a test using a reference build. | 158 # The default is not to include a test using a reference build. |
157 if options.reference_build: | 159 if options.reference_build: |
158 reference_build_list = [False, True] | 160 reference_build_list = [False, True] |
159 else: | 161 else: |
160 reference_build_list = [False] | 162 reference_build_list = [False] |
| 163 if options.track: |
| 164 # TODO(imasaki@chromium.org): change here after track functionality is |
| 165 # available on Chrome. Currently, track patch is still under development. |
| 166 # So, I need to download the binary from |
| 167 # http://www.annacavender.com/track/ and use it for testing. |
| 168 # I temporarily use reference build mechanism. |
| 169 reference_build_list = [True] |
161 # This is a loop for iterating through all videos defined above (list | 170 # This is a loop for iterating through all videos defined above (list |
162 # or matrix). Each video has associated tag and nickname for display | 171 # or matrix). Each video has associated tag and nickname for display |
163 # purpose. | 172 # purpose. |
164 for tag, filename, nickname in test_data_list: | 173 for tag, filename, nickname in test_data_list: |
165 # This inner loop iterates twice. The first iteration of the loop | 174 # This inner loop iterates twice. The first iteration of the loop |
166 # disables the media cache, and the second iteration enables the media | 175 # disables the media cache, and the second iteration enables the media |
167 # cache. Other parameters remain the same on both loop iterations. | 176 # cache. Other parameters remain the same on both loop iterations. |
168 # There are two ways to disable the media cache: setting Chrome option | 177 # There are two ways to disable the media cache: setting Chrome option |
169 # to --media-cache-size=1 or adding t parameter in query parameter of | 178 # to --media-cache-size=1 or adding t parameter in query parameter of |
170 # URL in which player.js (data/media/html/player.js) disables the | 179 # URL in which player.js (data/media/html/player.js) disables the |
171 # media cache). We are doing both here. Please note the length of | 180 # media cache). |
172 # CHROME_FLAGS and ADD_T_PARAMETERS should be the same. | 181 for reference_build in reference_build_list: |
173 for j in range(len(CHROME_FLAGS)): | 182 parent_envs = copy.deepcopy(os.environ) |
174 for reference_build in reference_build_list: | 183 if options.input_matrix_filename is None: |
175 parent_envs = copy.deepcopy(os.environ) | 184 par_filename = os.path.join(os.pardir, filename) |
176 if options.input_matrix_filename is None: | 185 else: |
177 par_filename = os.path.join(os.pardir, filename) | 186 par_filename = filename |
| 187 envs = { |
| 188 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, |
| 189 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, |
| 190 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, |
| 191 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: |
| 192 options.player_html_url, |
| 193 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: |
| 194 options.player_html_url_nickname, |
| 195 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), |
| 196 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: |
| 197 str(options.measure_intervals), |
| 198 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: |
| 199 options.test_scenario_input_filename, |
| 200 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: |
| 201 options.test_scenario, |
| 202 } |
| 203 # Boolean variables and their related variables. |
| 204 if options.disable_media_cache: |
| 205 # The 't' parameter is passed to player.html to disable/enable |
| 206 # the media cache (refer to data/media/html/player.js). |
| 207 envs[MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME] = str( |
| 208 options.disable_media_cache) |
| 209 if reference_build: |
| 210 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( |
| 211 reference_build) |
| 212 if REMOVE_FIRST_RESULT: |
| 213 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( |
| 214 REMOVE_FIRST_RESULT) |
| 215 if options.reference_build_dir: |
| 216 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( |
| 217 options.reference_build_dir) |
| 218 envs.update(parent_envs) |
| 219 if options.suite is None and options.test_prog_name is not None: |
| 220 # Suite is not used - run test program directly. |
| 221 test_prog_name = options.test_prog_name |
| 222 suite_string = '' |
| 223 else: |
| 224 # Suite is used. |
| 225 # The test script names are in the PYAUTO_TESTS file. |
| 226 test_prog_name = pyauto_functional_script_name |
| 227 if options.suite is None: |
| 228 suite_name = DEFAULT_SUITE_NAME |
178 else: | 229 else: |
179 par_filename = filename | 230 suite_name = options.suite |
180 envs = { | 231 suite_string = ' --suite=%s' % suite_name |
181 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, | 232 test_prog_name = sys.executable + ' ' + test_prog_name |
182 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, | 233 chrome_flag = '' |
183 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, | 234 if options.disable_media_cache: |
184 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: | 235 chrome_flag += CHROME_FLAGS['disable_cache'] |
185 options.player_html_url, | 236 if options.track: |
186 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: | 237 if options.disable_media_cache: |
187 options.player_html_url_nickname, | 238 chrome_flag += ' ' |
188 MediaTestEnvNames.EXTRA_NICKNAME_ENV_NAME: | 239 chrome_flag += CHROME_FLAGS['track'] |
189 EXTRA_NICKNAMES[j], | 240 if chrome_flag: |
190 # Enables or disables the media cache. | 241 chrome_flag = '--chrome-flags=\'%s\'' % chrome_flag |
191 # (refer to data/media/html/player.js) | 242 cmd = test_prog_name + suite_string + ' ' + chrome_flag |
192 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), | 243 if options.verbose: |
193 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: | 244 cmd += ' -v' |
194 str(options.measure_intervals), | 245 proc = Popen(cmd, env=envs, shell=True) |
195 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: | 246 proc.communicate() |
196 options.test_scenario_input_filename, | 247 |
197 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: | |
198 options.test_scenario, | |
199 } | |
200 # Boolean variables and their related variables. | |
201 if ADD_T_PARAMETERS[j]: | |
202 envs[MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME] = str( | |
203 ADD_T_PARAMETERS[j]) | |
204 if reference_build: | |
205 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( | |
206 reference_build) | |
207 if REMOVE_FIRST_RESULT: | |
208 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( | |
209 REMOVE_FIRST_RESULT) | |
210 if options.reference_build_dir: | |
211 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( | |
212 options.reference_build_dir) | |
213 envs.update(parent_envs) | |
214 if options.suite is None and options.test_prog_name is not None: | |
215 # Suite is not used - run test program directly. | |
216 test_prog_name = options.test_prog_name | |
217 suite_string = '' | |
218 else: | |
219 # Suite is used. | |
220 # The test script names are in the PYAUTO_TEST file. | |
221 test_prog_name = pyauto_functional_script_name | |
222 if options.suite is None: | |
223 suite_name = DEFAULT_SUITE_NAME | |
224 else: | |
225 suite_name = options.suite | |
226 suite_string = ' --suite=%s' % suite_name | |
227 test_prog_name = sys.executable + ' ' + test_prog_name | |
228 cmd = test_prog_name + suite_string + ' ' + CHROME_FLAGS[j] | |
229 if options.verbose: | |
230 cmd += ' -v' | |
231 proc = Popen(cmd, env=envs, shell=True) | |
232 proc.communicate() | |
233 if not options.cache_test: | |
234 break | |
235 if options.one_video: | 248 if options.one_video: |
236 break | 249 break |
237 | 250 |
238 | 251 |
239 if __name__ == '__main__': | 252 if __name__ == '__main__': |
240 main() | 253 main() |
OLD | NEW |