OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """A module to execute a subclass of MediaTastBase class. | 7 """A module to execute a subclass of MediaTastBase class. |
8 | 8 |
9 This executes a media test class (a subclass of MediaTastBase class) with | 9 This executes a media test class (a subclass of MediaTastBase class) with |
10 different configuration (parameters) which are passed in the form of | 10 different configuration (parameters) which are passed in the form of |
(...skipping 18 matching lines...) Expand all Loading... |
29 from media_test_env_names import MediaTestEnvNames | 29 from media_test_env_names import MediaTestEnvNames |
30 from media_test_matrix import MediaTestMatrix | 30 from media_test_matrix import MediaTestMatrix |
31 | 31 |
32 | 32 |
33 def main(): | 33 def main(): |
34 EXTRA_NICKNAMES = ['nocache', 'cache'] | 34 EXTRA_NICKNAMES = ['nocache', 'cache'] |
35 # Disable/enable media_cache. | 35 # Disable/enable media_cache. |
36 CHROME_FLAGS = ['--chrome-flags=\'--media-cache-size=1\'', ''] | 36 CHROME_FLAGS = ['--chrome-flags=\'--media-cache-size=1\'', ''] |
37 # The 't' parameter is passed to player.html to disable/enable the media | 37 # The 't' parameter is passed to player.html to disable/enable the media |
38 # cache (refer to data/media/html/player.js). | 38 # cache (refer to data/media/html/player.js). |
39 ADD_T_PARAMETERS = ['Y', 'N'] | 39 ADD_T_PARAMETERS = [False, True] |
40 # Player.html should contain all the HTML and Javascript that is | 40 # Player.html should contain all the HTML and Javascript that is |
41 # necessary to run these tests. | 41 # necessary to run these tests. |
42 DEFAULT_PLAYER_HTML_URL = 'DEFAULT' | 42 DEFAULT_PLAYER_HTML_URL = 'DEFAULT' |
43 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' | 43 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' |
44 # Default base url nickname used to display the result in case it is not | 44 # Default base url nickname used to display the result in case it is not |
45 # specified by the environment variable. | 45 # specified by the environment variable. |
46 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' | 46 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' |
47 PRINT_ONLY_TIME = 'Y' | 47 REMOVE_FIRST_RESULT = True |
48 REMOVE_FIRST_RESULT = 'Y' | |
49 # The number of runs for each test. This is used to compute average values | 48 # The number of runs for each test. This is used to compute average values |
50 # from among all runs. | 49 # from among all runs. |
51 DEFAULT_NUMBER_OF_RUNS = 3 | 50 DEFAULT_NUMBER_OF_RUNS = 3 |
52 # The interval between measurement calls. | 51 # The interval between measurement calls. |
53 DEFAULT_MEASURE_INTERVALS = 3 | 52 DEFAULT_MEASURE_INTERVALS = 3 |
54 DEFAULT_SUITE_NAME = 'MEDIA_TESTS' | 53 DEFAULT_SUITE_NAME = 'MEDIA_TESTS' |
55 # This script is used to run the PYAUTO suite. | 54 # This script is used to run the PYAUTO suite. |
56 pyauto_functional_script_name = os.path.join(os.path.dirname(__file__), | 55 pyauto_functional_script_name = os.path.join(os.path.dirname(__file__), |
57 'pyauto_media.py') | 56 'pyauto_media.py') |
58 # This defines default file name for CSV file. | 57 # This defines default file name for CSV file. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 parser.add_option( | 104 parser.add_option( |
106 '-c', '--test_scenario', dest='test_scenario', | 105 '-c', '--test_scenario', dest='test_scenario', |
107 default='', help='Test scenario (action triples delimited by \'|\')') | 106 default='', help='Test scenario (action triples delimited by \'|\')') |
108 parser.add_option('-s', '--suite', dest='suite', | 107 parser.add_option('-s', '--suite', dest='suite', |
109 help='Suite file') | 108 help='Suite file') |
110 parser.add_option('-e', '--media_file', dest='media_file', | 109 parser.add_option('-e', '--media_file', dest='media_file', |
111 default='', | 110 default='', |
112 help=('Media file to be played using player.html. ' | 111 help=('Media file to be played using player.html. ' |
113 'The relative path needs to be specified starting ' | 112 'The relative path needs to be specified starting ' |
114 'from data/html/ directory.')) | 113 'from data/html/ directory.')) |
| 114 parser.add_option('-a', '--reference_build', dest='reference_build', |
| 115 help='Include reference build run', default=False, |
| 116 action='store_true') |
| 117 parser.add_option('-k', '--reference_build_dir', dest='reference_build_dir', |
| 118 help=('A absolute path to the directory that contains', |
| 119 'binaries of reference build.')) |
| 120 parser.add_option('-v', '--verbose', dest='verbose', help='Verbose mode.', |
| 121 default=False, action='store_true') |
115 | 122 |
116 options, args = parser.parse_args() | 123 options, args = parser.parse_args() |
117 if args: | 124 if args: |
118 parser.print_help() | 125 parser.print_help() |
119 sys.exit(1) | 126 sys.exit(1) |
120 | 127 |
121 test_data_list = [] | 128 test_data_list = [] |
122 if options.media_file: | 129 if options.media_file: |
123 test_data_list.append(['video', options.media_file, options.media_file]) | 130 test_data_list.append(['video', options.media_file, options.media_file]) |
124 elif options.input_matrix_filename is None: | 131 elif options.input_matrix_filename is None: |
(...skipping 11 matching lines...) Expand all Loading... |
136 True, options.video_matrix_home_url) | 143 True, options.video_matrix_home_url) |
137 if options.input_matrix_testcase_name is None: | 144 if options.input_matrix_testcase_name is None: |
138 # Use all test cases. | 145 # Use all test cases. |
139 test_data_list = all_data_list | 146 test_data_list = all_data_list |
140 else: | 147 else: |
141 # Choose particular video. | 148 # Choose particular video. |
142 media_info = MediaTestMatrix.LookForMediaInfoInCompactFormByNickName( | 149 media_info = MediaTestMatrix.LookForMediaInfoInCompactFormByNickName( |
143 all_data_list, options.input_matrix_testcase_name) | 150 all_data_list, options.input_matrix_testcase_name) |
144 if media_info is not None: | 151 if media_info is not None: |
145 test_data_list.append(media_info) | 152 test_data_list.append(media_info) |
| 153 |
| 154 # Determine whether we need to repeat a test using a reference build. |
| 155 # The default is not to include a test using a reference build. |
| 156 if options.reference_build: |
| 157 reference_build_list = [False, True] |
| 158 else: |
| 159 reference_build_list = [False] |
146 # This is a loop for iterating through all videos defined above (list | 160 # This is a loop for iterating through all videos defined above (list |
147 # or matrix). Each video has associated tag and nickname for display | 161 # or matrix). Each video has associated tag and nickname for display |
148 # purpose. | 162 # purpose. |
149 for tag, filename, nickname in test_data_list: | 163 for tag, filename, nickname in test_data_list: |
150 # This inner loop iterates twice. The first iteration of the loop | 164 # This inner loop iterates twice. The first iteration of the loop |
151 # disables the media cache, and the second iteration enables the media | 165 # disables the media cache, and the second iteration enables the media |
152 # cache. Other parameters remain the same on both loop iterations. | 166 # cache. Other parameters remain the same on both loop iterations. |
153 # There are two ways to disable the media cache: setting Chrome option | 167 # There are two ways to disable the media cache: setting Chrome option |
154 # to --media-cache-size=1 or adding t parameter in query parameter of | 168 # to --media-cache-size=1 or adding t parameter in query parameter of |
155 # URL in which player.js (data/media/html/player.js) disables the | 169 # URL in which player.js (data/media/html/player.js) disables the |
156 # media cache). We are doing both here. Please note the length of | 170 # media cache). We are doing both here. Please note the length of |
157 # CHROME_FLAGS and ADD_T_PARAMETERS should be the same. | 171 # CHROME_FLAGS and ADD_T_PARAMETERS should be the same. |
158 for j in range(len(CHROME_FLAGS)): | 172 for j in range(len(CHROME_FLAGS)): |
159 parent_envs = copy.deepcopy(os.environ) | 173 for reference_build in reference_build_list: |
160 if options.input_matrix_filename is None: | 174 parent_envs = copy.deepcopy(os.environ) |
161 filename = os.path.join(os.pardir, filename) | 175 if options.input_matrix_filename is None: |
162 envs = { | 176 par_filename = os.path.join(os.pardir, filename) |
163 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, | 177 envs = { |
164 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: filename, | 178 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, |
165 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, | 179 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, |
166 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: | 180 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, |
167 options.player_html_url, | 181 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: |
168 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: | 182 options.player_html_url, |
169 options.player_html_url_nickname, | 183 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: |
170 MediaTestEnvNames.EXTRA_NICKNAME_ENV_NAME: | 184 options.player_html_url_nickname, |
171 EXTRA_NICKNAMES[j], | 185 MediaTestEnvNames.EXTRA_NICKNAME_ENV_NAME: |
172 # Enables or disables the media cache. | 186 EXTRA_NICKNAMES[j], |
173 # (refer to data/media/html/player.js) | 187 # Enables or disables the media cache. |
174 MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME: ADD_T_PARAMETERS[j], | 188 # (refer to data/media/html/player.js) |
175 MediaTestEnvNames.PRINT_ONLY_TIME_ENV_NAME: PRINT_ONLY_TIME, | 189 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), |
176 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), | 190 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: |
177 MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME: | 191 str(options.measure_intervals), |
178 REMOVE_FIRST_RESULT, | 192 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: |
179 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: | 193 options.test_scenario_input_filename, |
180 str(options.measure_intervals), | 194 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: |
181 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: | 195 options.test_scenario, |
182 options.test_scenario_input_filename, | 196 } |
183 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: | 197 # Boolean variables and their related variables. |
184 options.test_scenario, | 198 if ADD_T_PARAMETERS[j]: |
185 } | 199 envs[MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME] = str( |
186 envs.update(parent_envs) | 200 ADD_T_PARAMETERS[j]) |
187 if options.suite is None and options.test_prog_name is not None: | 201 if reference_build: |
188 # Suite is not used - run test program directly. | 202 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( |
189 test_prog_name = options.test_prog_name | 203 reference_build) |
190 suite_string = '' | 204 if REMOVE_FIRST_RESULT: |
191 else: | 205 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( |
192 # Suite is used. | 206 REMOVE_FIRST_RESULT) |
193 # The test script names are in the PYAUTO_TEST file. | 207 if options.reference_build_dir: |
194 test_prog_name = pyauto_functional_script_name | 208 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( |
195 if options.suite is None: | 209 options.reference_build_dir) |
196 suite_name = DEFAULT_SUITE_NAME | 210 envs.update(parent_envs) |
| 211 if options.suite is None and options.test_prog_name is not None: |
| 212 # Suite is not used - run test program directly. |
| 213 test_prog_name = options.test_prog_name |
| 214 suite_string = '' |
197 else: | 215 else: |
198 suite_name = options.suite | 216 # Suite is used. |
199 suite_string = ' --suite=%s' % suite_name | 217 # The test script names are in the PYAUTO_TEST file. |
200 test_prog_name = sys.executable + ' ' + test_prog_name | 218 test_prog_name = pyauto_functional_script_name |
201 cmd = test_prog_name + suite_string + ' ' + CHROME_FLAGS[j] | 219 if options.suite is None: |
202 proc = Popen(cmd, env=envs, shell=True) | 220 suite_name = DEFAULT_SUITE_NAME |
203 proc.communicate() | 221 else: |
| 222 suite_name = options.suite |
| 223 suite_string = ' --suite=%s' % suite_name |
| 224 test_prog_name = sys.executable + ' ' + test_prog_name |
| 225 cmd = test_prog_name + suite_string + ' ' + CHROME_FLAGS[j] |
| 226 if options.verbose: |
| 227 cmd += ' -v' |
| 228 proc = Popen(cmd, env=envs, shell=True) |
| 229 proc.communicate() |
204 if options.one_combination: | 230 if options.one_combination: |
205 sys.exit(0) | 231 sys.exit(0) |
206 | 232 |
207 | 233 |
208 if __name__ == '__main__': | 234 if __name__ == '__main__': |
209 main() | 235 main() |
OLD | NEW |