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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 default='', help='Test scenario file (CSV form)', metavar='FILE') | 102 default='', help='Test scenario file (CSV form)', metavar='FILE') |
103 parser.add_option( | 103 parser.add_option( |
104 '-q', '--test_scenario', dest='test_scenario', | 104 '-q', '--test_scenario', dest='test_scenario', |
105 default='', help='Test scenario (action triples delimited by \'|\')') | 105 default='', help='Test scenario (action triples delimited by \'|\')') |
106 parser.add_option('-s', '--suite', dest='suite', | 106 parser.add_option('-s', '--suite', dest='suite', |
107 help='Suite file') | 107 help='Suite file') |
108 parser.add_option('-e', '--media_file', dest='media_file', | 108 parser.add_option('-e', '--media_file', dest='media_file', |
109 default='', | 109 default='', |
110 help=('Media file to be played using player.html. ' | 110 help=('Media file to be played using player.html. ' |
111 'The relative path needs to be specified starting ' | 111 'The relative path needs to be specified starting ' |
112 'from data/html/ directory.')) | 112 'from data/html/ directory.' |
dennis_jeffrey
2011/06/13 22:51:49
Nit: put a space right before the closing quote.
imasaki1
2011/06/13 23:43:09
Done.
| |
113 'The data should have the following format:' | |
dennis_jeffrey
2011/06/13 22:51:49
Nit: put a space right before the closing quote.
imasaki1
2011/06/13 23:43:09
Done.
| |
114 'tag(video|audio)|filename|nickname|video_title')) | |
113 parser.add_option('-a', '--reference_build', dest='reference_build', | 115 parser.add_option('-a', '--reference_build', dest='reference_build', |
114 help='Include reference build run', default=False, | 116 help='Include reference build run', default=False, |
115 action='store_true') | 117 action='store_true') |
116 parser.add_option('-k', '--reference_build_dir', dest='reference_build_dir', | 118 parser.add_option('-k', '--reference_build_dir', dest='reference_build_dir', |
117 help=('A absolute path to the directory that contains' | 119 help=('A absolute path to the directory that contains' |
118 'binaries of reference build.')) | 120 'binaries of reference build.')) |
119 parser.add_option('-v', '--verbose', dest='verbose', help='Verbose mode.', | 121 parser.add_option('-v', '--verbose', dest='verbose', help='Verbose mode.', |
120 default=False, action='store_true') | 122 default=False, action='store_true') |
121 parser.add_option('-j', '--track', dest='track', | 123 parser.add_option('-j', '--track', dest='track', |
122 help=('Run track test (binary should be downloaded' | 124 help=('Run track test (binary should be downloaded' |
123 ' from http://www.annacavender.com/track/' | 125 ' from http://www.annacavender.com/track/' |
124 ' and put into reference_build_dir).'), | 126 ' and put into reference_build_dir).'), |
125 default=False, action='store_true') | 127 default=False, action='store_true') |
128 parser.add_option('-g', '--track-file', dest='track_file', | |
129 help=('Track file in vtt format (binary should be' | |
130 ' downloaded from http://www.annacavender.com/track/' | |
131 ' and put into reference_build_dir).')) | |
132 | |
126 options, args = parser.parse_args() | 133 options, args = parser.parse_args() |
127 if args: | 134 if args: |
128 parser.print_help() | 135 parser.print_help() |
129 sys.exit(1) | 136 sys.exit(1) |
130 | 137 |
131 test_data_list = [] | 138 test_data_list = [] |
132 if options.media_file: | 139 if options.media_file: |
133 test_data_list.append(['video', options.media_file, options.media_file]) | 140 opts = options.media_file.split('|') |
141 # media file should have the following format: | |
dennis_jeffrey
2011/06/13 22:51:49
nit: "media file" --> "The media file"
imasaki1
2011/06/13 23:43:09
Done.
| |
142 # tag(video|audio)|filename|nickname|video_title. | |
143 # Otherwise, it exits. | |
Nirnimesh
2011/06/13 22:07:37
remove this line
imasaki1
2011/06/13 23:43:09
Done.
| |
144 if len(opts) != 4: | |
Nirnimesh
2011/06/13 22:07:37
print out some helpful error message
imasaki1
2011/06/13 23:43:09
Done.
| |
145 sys.exit(1) | |
146 test_data_list.append(opts) | |
134 elif options.input_matrix_filename is None: | 147 elif options.input_matrix_filename is None: |
135 file = open(options.input_filename, 'rb') | 148 file = open(options.input_filename, 'rb') |
136 test_data_list = csv.reader(file) | 149 test_data_list = csv.reader(file) |
137 # First line contains headers that can be skipped. | 150 # First line contains headers that can be skipped. |
138 test_data_list.next() | 151 test_data_list.next() |
139 else: | 152 else: |
140 # Video_matrix_home_url requires "/" at the end. | 153 # Video_matrix_home_url requires "/" at the end. |
141 if not options.video_matrix_home_url.endswith('/'): | 154 if not options.video_matrix_home_url.endswith('/'): |
142 options.video_matrix_home_url += '/' | 155 options.video_matrix_home_url += '/' |
143 media_test_matrix = MediaTestMatrix() | 156 media_test_matrix = MediaTestMatrix() |
144 media_test_matrix.ReadData(options.input_matrix_filename) | 157 media_test_matrix.ReadData(options.input_matrix_filename) |
145 all_data_list = media_test_matrix.GenerateAllMediaInfosInCompactForm( | 158 all_data_list = media_test_matrix.GenerateAllMediaInfosInCompactForm( |
146 True, options.video_matrix_home_url) | 159 True, options.video_matrix_home_url) |
147 if options.input_matrix_testcase_name is None: | 160 if options.input_matrix_testcase_name is None: |
148 # Use all test cases. | 161 # Use all test cases. |
149 test_data_list = all_data_list | 162 test_data_list = all_data_list |
150 else: | 163 else: |
151 # Choose particular video. | 164 # Choose particular video. |
152 media_info = MediaTestMatrix.LookForMediaInfoInCompactFormByNickName( | 165 media_info = MediaTestMatrix.LookForMediaInfoInCompactFormByNickName( |
153 all_data_list, options.input_matrix_testcase_name) | 166 all_data_list, options.input_matrix_testcase_name) |
154 if media_info is not None: | 167 if media_info is not None: |
155 test_data_list.append(media_info) | 168 test_data_list.append(media_info) |
156 | 169 |
157 # Determine whether we need to repeat a test using a reference build. | 170 # Determine whether we need to repeat a test using a reference build. |
158 # The default is not to include a test using a reference build. | 171 # The default is not to include a test using a reference build. |
159 if options.reference_build: | 172 if options.reference_build: |
160 reference_build_list = [False, True] | 173 reference_build_list = [False, True] |
161 else: | 174 else: |
162 reference_build_list = [False] | 175 reference_build_list = [False] |
163 if options.track: | 176 if options.track_file or options.track: |
164 # TODO(imasaki@chromium.org): change here after track functionality is | 177 # TODO(imasaki@chromium.org): change here after track functionality is |
165 # available on Chrome. Currently, track patch is still under development. | 178 # available on Chrome. Currently, track patch is still under development. |
166 # So, I need to download the binary from | 179 # So, I need to download the binary from |
167 # http://www.annacavender.com/track/ and use it for testing. | 180 # http://www.annacavender.com/track/ and use it for testing. |
168 # I temporarily use reference build mechanism. | 181 # I temporarily use reference build mechanism. |
169 reference_build_list = [True] | 182 reference_build_list = [True] |
170 # This is a loop for iterating through all videos defined above (list | 183 # This is a loop for iterating through all videos defined above (list |
171 # or matrix). Each video has associated tag and nickname for display | 184 # or matrix). Each video has associated tag and nickname for display |
172 # purpose. | 185 # purpose. |
173 for tag, filename, nickname in test_data_list: | 186 for tag, filename, nickname, title in test_data_list: |
174 # This inner loop iterates twice. The first iteration of the loop | 187 # This inner loop iterates twice. The first iteration of the loop |
175 # disables the media cache, and the second iteration enables the media | 188 # disables the media cache, and the second iteration enables the media |
176 # cache. Other parameters remain the same on both loop iterations. | 189 # cache. Other parameters remain the same on both loop iterations. |
177 # There are two ways to disable the media cache: setting Chrome option | 190 # There are two ways to disable the media cache: setting Chrome option |
178 # to --media-cache-size=1 or adding t parameter in query parameter of | 191 # to --media-cache-size=1 or adding t parameter in query parameter of |
179 # URL in which player.js (data/media/html/player.js) disables the | 192 # URL in which player.js (data/media/html/player.js) disables the |
180 # media cache). | 193 # media cache). |
194 # | |
195 # The default name for track vtt file is the name of the video tile | |
dennis_jeffrey
2011/06/13 22:51:49
"tile" -->
"title"
imasaki1
2011/06/13 23:43:09
Done.
| |
196 # in the case --track-file is not set. The track file should be in | |
197 # the same directory as video files. | |
198 # For example, bear_en.vtt used | |
dennis_jeffrey
2011/06/13 22:51:49
Remove "used"?
imasaki1
2011/06/13 23:43:09
Done.
| |
199 if options.track and not options.track_file: | |
200 # TODO(imasaki@chromium.org): add more languages. | |
201 lang = 'en' | |
202 options.track_file = os.path.join(os.path.dirname(filename), | |
203 title + '_' + lang + '.vtt') | |
181 for reference_build in reference_build_list: | 204 for reference_build in reference_build_list: |
182 parent_envs = copy.deepcopy(os.environ) | 205 parent_envs = copy.deepcopy(os.environ) |
183 if options.input_matrix_filename is None: | 206 if options.input_matrix_filename is None: |
184 par_filename = os.path.join(os.pardir, filename) | 207 par_filename = os.path.join(os.pardir, filename) |
185 else: | 208 else: |
186 par_filename = filename | 209 par_filename = filename |
187 envs = { | 210 envs = { |
188 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, | 211 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, |
189 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, | 212 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, |
190 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, | 213 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, |
(...skipping 17 matching lines...) Expand all Loading... | |
208 options.disable_media_cache) | 231 options.disable_media_cache) |
209 if reference_build: | 232 if reference_build: |
210 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( | 233 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( |
211 reference_build) | 234 reference_build) |
212 if REMOVE_FIRST_RESULT: | 235 if REMOVE_FIRST_RESULT: |
213 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( | 236 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( |
214 REMOVE_FIRST_RESULT) | 237 REMOVE_FIRST_RESULT) |
215 if options.reference_build_dir: | 238 if options.reference_build_dir: |
216 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( | 239 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( |
217 options.reference_build_dir) | 240 options.reference_build_dir) |
241 if options.track_file: | |
242 envs[MediaTestEnvNames.TRACK_FILE_ENV_NAME] = ( | |
243 options.track_file) | |
218 envs.update(parent_envs) | 244 envs.update(parent_envs) |
219 if options.suite is None and options.test_prog_name is not None: | 245 if options.suite is None and options.test_prog_name is not None: |
220 # Suite is not used - run test program directly. | 246 # Suite is not used - run test program directly. |
221 test_prog_name = options.test_prog_name | 247 test_prog_name = options.test_prog_name |
222 suite_string = '' | 248 suite_string = '' |
223 else: | 249 else: |
224 # Suite is used. | 250 # Suite is used. |
225 # The test script names are in the PYAUTO_TESTS file. | 251 # The test script names are in the PYAUTO_TESTS file. |
226 test_prog_name = pyauto_functional_script_name | 252 test_prog_name = pyauto_functional_script_name |
227 if options.suite is None: | 253 if options.suite is None: |
228 suite_name = DEFAULT_SUITE_NAME | 254 suite_name = DEFAULT_SUITE_NAME |
229 else: | 255 else: |
230 suite_name = options.suite | 256 suite_name = options.suite |
231 suite_string = ' --suite=%s' % suite_name | 257 suite_string = ' --suite=%s' % suite_name |
232 test_prog_name = sys.executable + ' ' + test_prog_name | 258 test_prog_name = sys.executable + ' ' + test_prog_name |
233 chrome_flag = '' | 259 chrome_flag = '' |
234 if options.disable_media_cache: | 260 if options.disable_media_cache: |
235 chrome_flag += CHROME_FLAGS['disable_cache'] | 261 chrome_flag += CHROME_FLAGS['disable_cache'] |
236 if options.track: | 262 if options.track_file: |
237 if options.disable_media_cache: | 263 if options.disable_media_cache: |
238 chrome_flag += ' ' | 264 chrome_flag += ' ' |
239 chrome_flag += CHROME_FLAGS['track'] | 265 chrome_flag += CHROME_FLAGS['track'] |
240 if chrome_flag: | 266 if chrome_flag: |
241 chrome_flag = '--chrome-flags=\'%s\'' % chrome_flag | 267 chrome_flag = '--chrome-flags=\'%s\'' % chrome_flag |
242 cmd = test_prog_name + suite_string + ' ' + chrome_flag | 268 cmd = test_prog_name + suite_string + ' ' + chrome_flag |
243 if options.verbose: | 269 if options.verbose: |
244 cmd += ' -v' | 270 cmd += ' -v' |
245 proc = Popen(cmd, env=envs, shell=True) | 271 proc = Popen(cmd, env=envs, shell=True) |
246 proc.communicate() | 272 proc.communicate() |
247 | 273 |
248 if options.one_video: | 274 if options.one_video: |
249 break | 275 break |
250 | 276 |
251 | 277 |
252 if __name__ == '__main__': | 278 if __name__ == '__main__': |
253 main() | 279 main() |
OLD | NEW |