| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """A module to execute a subclass of MediaTastBase class. | |
| 7 | |
| 8 This executes a media test class (a subclass of MediaTastBase class) with | |
| 9 different configuration (parameters) which are passed in the form of | |
| 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 | |
| 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. | |
| 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 | |
| 16 in data source file (CSV file - its content is list form or its content is | |
| 17 in matrix form), | |
| 18 """ | |
| 19 | |
| 20 import copy | |
| 21 import csv | |
| 22 import glob | |
| 23 import logging | |
| 24 import os | |
| 25 from optparse import OptionParser | |
| 26 import shlex | |
| 27 import sys | |
| 28 from subprocess import Popen | |
| 29 | |
| 30 from media_test_env_names import MediaTestEnvNames | |
| 31 from media_test_matrix import MediaTestMatrix | |
| 32 | |
| 33 | |
| 34 def main(): | |
| 35 CHROME_FLAGS = {'disable_cache': '--media-cache-size=1', | |
| 36 # Please note track (caption) option is not implemented yet | |
| 37 # as of 6/8/2011. | |
| 38 'track': '--enable-video-track'} | |
| 39 # Player.html should contain all the HTML and Javascript that is | |
| 40 # necessary to run these tests. | |
| 41 DEFAULT_PLAYER_HTML_URL = 'DEFAULT' | |
| 42 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' | |
| 43 # Default base url nickname used to display the result in case it is not | |
| 44 # specified by the environment variable. | |
| 45 DEFAULT_PLAYER_HTML_URL_NICKNAME = 'local' | |
| 46 REMOVE_FIRST_RESULT = True | |
| 47 # The number of runs for each test. This is used to compute average values | |
| 48 # from among all runs. | |
| 49 DEFAULT_NUMBER_OF_RUNS = 3 | |
| 50 # The interval between measurement calls. | |
| 51 DEFAULT_MEASURE_INTERVALS = 3 | |
| 52 DEFAULT_SUITE_NAME = 'AV_PERF' | |
| 53 # This script is used to run the PYAUTO suite. | |
| 54 pyauto_functional_script_name = os.path.join(os.path.dirname(__file__), | |
| 55 'pyauto_media.py') | |
| 56 # This defines default file name for CSV file. | |
| 57 default_input_filename = os.path.join(os.pardir, 'data', 'media', 'csv', | |
| 58 'media_list_data.csv') | |
| 59 parser = OptionParser() | |
| 60 # TODO(imasaki@chromium.org): add parameter verification. | |
| 61 parser.add_option( | |
| 62 '-i', '--input', dest='input_filename', default=default_input_filename, | |
| 63 help='Data source file (file contents in list form) [defaults to "%s"]' % | |
| 64 default_input_filename, metavar='FILE') | |
| 65 parser.add_option( | |
| 66 '-x', '--input_matrix', dest='input_matrix_filename', | |
| 67 help='Data source file (file contents in matrix form)', metavar='FILE') | |
| 68 parser.add_option('-t', '--input_matrix_testcase', | |
| 69 dest='input_matrix_testcase_name', | |
| 70 help='Run particular test in matrix') | |
| 71 parser.add_option('-r', '--video_matrix_home_url', | |
| 72 default='', | |
| 73 dest='video_matrix_home_url', | |
| 74 help='Video Matrix home URL') | |
| 75 parser.add_option('-p', '--test_prog_name', dest='test_prog_name', | |
| 76 help='Test main program name (not using suite)', | |
| 77 metavar='FILE') | |
| 78 parser.add_option('-b', '--player_html_url', dest='player_html_url', | |
| 79 default='None', | |
| 80 help='Player.html URL [defaults to "%s"] ' % | |
| 81 DEFAULT_PLAYER_HTML_URL, metavar='FILE') | |
| 82 parser.add_option('-u', '--player_html_url_nickname', | |
| 83 dest='player_html_url_nickname', | |
| 84 default=DEFAULT_PLAYER_HTML_URL_NICKNAME, | |
| 85 help='Player.html Nickname [defaults to "%s"]' % | |
| 86 DEFAULT_PLAYER_HTML_URL_NICKNAME) | |
| 87 parser.add_option('-n', '--number_of_runs', dest='number_of_runs', | |
| 88 default=DEFAULT_NUMBER_OF_RUNS, | |
| 89 help='The number of runs [defaults to "%d"]' % | |
| 90 DEFAULT_NUMBER_OF_RUNS) | |
| 91 parser.add_option('-m', '--measure_intervals', dest='measure_intervals', | |
| 92 default=DEFAULT_MEASURE_INTERVALS, | |
| 93 help='Interval for measurement data [defaults to "%d"]' % | |
| 94 DEFAULT_MEASURE_INTERVALS) | |
| 95 parser.add_option('-c', '--disable_media_cache', dest='disable_media_cache', | |
| 96 default=False, help='Disable media cache', | |
| 97 action='store_true') | |
| 98 parser.add_option('-z', '--test-one-video', dest='one_video', | |
| 99 default=False, help='Run only one video', | |
| 100 action='store_true') | |
| 101 parser.add_option( | |
| 102 '-w', '--test_scenario_input_filename', | |
| 103 dest='test_scenario_input_filename', | |
| 104 default='', help='Test scenario file (CSV form)', metavar='FILE') | |
| 105 parser.add_option( | |
| 106 '-q', '--test_scenario', dest='test_scenario', | |
| 107 default='', help='Test scenario (action triples delimited by \'|\')') | |
| 108 parser.add_option('-s', '--suite', dest='suite', | |
| 109 help='Suite file') | |
| 110 parser.add_option('-e', '--media_file', dest='media_file', | |
| 111 default='', | |
| 112 help=('Media file to be played using player.html. ' | |
| 113 'The relative path needs to be specified starting ' | |
| 114 'from data/html/ directory. ' | |
| 115 'The data should have the following format: ' | |
| 116 'tag(video|audio)|filename|nickname|video_title')) | |
| 117 parser.add_option('-a', '--reference_build', dest='reference_build', | |
| 118 help='Include reference build run', default=False, | |
| 119 action='store_true') | |
| 120 parser.add_option('-k', '--reference_build_dir', dest='reference_build_dir', | |
| 121 help=('A absolute path to the directory that contains' | |
| 122 'binaries of reference build.')) | |
| 123 parser.add_option('-v', '--verbose', dest='verbose', help='Verbose mode.', | |
| 124 default=False, action='store_true') | |
| 125 parser.add_option('-j', '--track', dest='track', | |
| 126 help=('Run track test (binary should be downloaded' | |
| 127 ' from http://www.annacavender.com/track/' | |
| 128 ' and put into reference_build_dir).'), | |
| 129 default=False, action='store_true') | |
| 130 parser.add_option('-g', '--track-file', dest='track_file', | |
| 131 help=('Track file in vtt format (binary should be' | |
| 132 ' downloaded from http://www.annacavender.com/track/' | |
| 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.')) | |
| 136 parser.add_option('-d', '--num-extra-players', | |
| 137 dest='number_of_extra_players', | |
| 138 help=('The number of extra players for ' | |
| 139 'stress testing using the same media file.')) | |
| 140 parser.add_option('-l', '--jerky-tool-location', | |
| 141 dest='jerky_tool_location', | |
| 142 help='The location of the jerky tool binary.') | |
| 143 parser.add_option('--jo', '--jerky-tool-output-directory', | |
| 144 dest='jerky_tool_output_directory', | |
| 145 help='The output directory of the jerky tool.') | |
| 146 parser.add_option('--jb', '--jerky-tool-baseline-directory', | |
| 147 dest='jerky_tool_baseline_directory', | |
| 148 help='The baseline directory of the jerky tool.') | |
| 149 options, args = parser.parse_args() | |
| 150 if args: | |
| 151 parser.print_help() | |
| 152 sys.exit(1) | |
| 153 | |
| 154 test_data_list = [] | |
| 155 if options.media_file: | |
| 156 opts = options.media_file.split('|') | |
| 157 # The media file should have the following format: | |
| 158 # tag(video|audio)|filename|nickname|video_title. | |
| 159 if len(opts) != 4: | |
| 160 logging.error('--media_file option argument does not have correct' | |
| 161 'format. The correct format is tag(video|audio)' | |
| 162 '|filename|nickname|video_title') | |
| 163 sys.exit(1) | |
| 164 test_data_list.append(opts) | |
| 165 elif options.input_matrix_filename is None: | |
| 166 file = open(options.input_filename, 'rb') | |
| 167 test_data_list = csv.reader(file) | |
| 168 # First line contains headers that can be skipped. | |
| 169 test_data_list.next() | |
| 170 else: | |
| 171 # Video_matrix_home_url requires "/" at the end. | |
| 172 if not options.video_matrix_home_url.endswith('/'): | |
| 173 options.video_matrix_home_url += '/' | |
| 174 media_test_matrix = MediaTestMatrix() | |
| 175 media_test_matrix.ReadData(options.input_matrix_filename) | |
| 176 all_data_list = media_test_matrix.GenerateAllMediaInfosInCompactForm( | |
| 177 True, options.video_matrix_home_url) | |
| 178 if options.input_matrix_testcase_name is None: | |
| 179 # Use all test cases. | |
| 180 test_data_list = all_data_list | |
| 181 else: | |
| 182 # Choose particular video. | |
| 183 media_info = MediaTestMatrix.LookForMediaInfoInCompactFormByNickName( | |
| 184 all_data_list, options.input_matrix_testcase_name) | |
| 185 if media_info is not None: | |
| 186 test_data_list.append(media_info) | |
| 187 | |
| 188 # Determine whether we need to repeat a test using a reference build. | |
| 189 # The default is not to include a test using a reference build. | |
| 190 if options.reference_build: | |
| 191 reference_build_list = [False, True] | |
| 192 else: | |
| 193 reference_build_list = [False] | |
| 194 track_files = [''] | |
| 195 if any([options.track_file, options.track, options.track_file_dir]): | |
| 196 # TODO(imasaki@chromium.org): change here after track functionality is | |
| 197 # available on Chrome. Currently, track patch is still under development. | |
| 198 # So, I need to download the binary from | |
| 199 # http://www.annacavender.com/track/ and use it for testing. | |
| 200 # I temporarily use reference build mechanism. | |
| 201 reference_build_list = [True] | |
| 202 if options.track_file_dir: | |
| 203 track_files_orig = ( | |
| 204 glob.glob(os.path.join(options.track_file_dir, '*.vtt'))) | |
| 205 track_files = [] | |
| 206 for tf in track_files_orig: | |
| 207 # The location should be relative path from HTML files. | |
| 208 # So it needs to remove data and media from the path. | |
| 209 track_files.append(tf.replace(os.path.join('data', 'media'), '')) | |
| 210 if not track_files: | |
| 211 logging.warning('No track files in %s', options.track_file_dir) | |
| 212 if options.track_file: | |
| 213 track_files = [options.track_file] | |
| 214 # This is a loop for iterating through all videos defined above (list | |
| 215 # or matrix). Each video has associated tag and nickname for display | |
| 216 # purpose. | |
| 217 for tag, filename, nickname, title in test_data_list: | |
| 218 for track_file in track_files: | |
| 219 for reference_build in reference_build_list: | |
| 220 parent_envs = copy.deepcopy(os.environ) | |
| 221 if options.input_matrix_filename is None: | |
| 222 par_filename = os.path.join(os.pardir, filename) | |
| 223 else: | |
| 224 par_filename = filename | |
| 225 envs = { | |
| 226 MediaTestEnvNames.MEDIA_TAG_ENV_NAME: tag, | |
| 227 MediaTestEnvNames.MEDIA_FILENAME_ENV_NAME: par_filename, | |
| 228 MediaTestEnvNames.MEDIA_FILENAME_NICKNAME_ENV_NAME: nickname, | |
| 229 MediaTestEnvNames.PLAYER_HTML_URL_ENV_NAME: | |
| 230 options.player_html_url, | |
| 231 MediaTestEnvNames.PLAYER_HTML_URL_NICKNAME_ENV_NAME: | |
| 232 options.player_html_url_nickname, | |
| 233 MediaTestEnvNames.N_RUNS_ENV_NAME: str(options.number_of_runs), | |
| 234 MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME: | |
| 235 str(options.measure_intervals), | |
| 236 MediaTestEnvNames.TEST_SCENARIO_FILE_ENV_NAME: | |
| 237 options.test_scenario_input_filename, | |
| 238 MediaTestEnvNames.TEST_SCENARIO_ENV_NAME: | |
| 239 options.test_scenario, | |
| 240 } | |
| 241 # Boolean variables and their related variables. | |
| 242 if options.disable_media_cache: | |
| 243 # The 't' parameter is passed to player.html to disable/enable | |
| 244 # the media cache (refer to data/media/html/player.js). | |
| 245 envs[MediaTestEnvNames.ADD_T_PARAMETER_ENV_NAME] = str( | |
| 246 options.disable_media_cache) | |
| 247 if reference_build: | |
| 248 envs[MediaTestEnvNames.REFERENCE_BUILD_ENV_NAME] = str( | |
| 249 reference_build) | |
| 250 if REMOVE_FIRST_RESULT: | |
| 251 envs[MediaTestEnvNames.REMOVE_FIRST_RESULT_ENV_NAME] = str( | |
| 252 REMOVE_FIRST_RESULT) | |
| 253 if options.reference_build_dir: | |
| 254 envs[MediaTestEnvNames.REFERENCE_BUILD_DIR_ENV_NAME] = ( | |
| 255 options.reference_build_dir) | |
| 256 if track_file: | |
| 257 envs[MediaTestEnvNames.TRACK_FILE_ENV_NAME] = track_file | |
| 258 if options.number_of_extra_players: | |
| 259 envs[MediaTestEnvNames.N_EXTRA_PLAYERS_ENV_NAME] = ( | |
| 260 options.number_of_extra_players) | |
| 261 if options.jerky_tool_location: | |
| 262 envs[MediaTestEnvNames.JERKY_TOOL_BINARY_LOCATION_ENV_NAME] = ( | |
| 263 options.jerky_tool_location) | |
| 264 if options.jerky_tool_output_directory: | |
| 265 envs[MediaTestEnvNames.JERKY_TOOL_OUTPUT_DIR_ENV_NAME] = ( | |
| 266 options.jerky_tool_output_directory) | |
| 267 if options.jerky_tool_baseline_directory: | |
| 268 envs[MediaTestEnvNames.JERKY_TOOL_BASELINE_DIR_ENV_NAME] = ( | |
| 269 options.jerky_tool_baseline_directory) | |
| 270 envs.update(parent_envs) | |
| 271 if options.suite is None and options.test_prog_name is not None: | |
| 272 # Suite is not used - run test program directly. | |
| 273 test_prog_name = options.test_prog_name | |
| 274 suite_string = '' | |
| 275 else: | |
| 276 # Suite is used. | |
| 277 # The test script names are in the PYAUTO_TESTS file. | |
| 278 test_prog_name = pyauto_functional_script_name | |
| 279 if options.suite is None: | |
| 280 suite_name = DEFAULT_SUITE_NAME | |
| 281 else: | |
| 282 suite_name = options.suite | |
| 283 suite_string = ' --suite=%s' % suite_name | |
| 284 test_prog_name = sys.executable + ' ' + test_prog_name | |
| 285 chrome_flag = '' | |
| 286 if options.disable_media_cache: | |
| 287 chrome_flag += CHROME_FLAGS['disable_cache'] | |
| 288 if options.track_file: | |
| 289 if options.disable_media_cache: | |
| 290 chrome_flag += ' ' | |
| 291 chrome_flag += CHROME_FLAGS['track'] | |
| 292 if chrome_flag: | |
| 293 chrome_flag = '--chrome-flags=\'%s\'' % chrome_flag | |
| 294 cmd = test_prog_name + suite_string + ' ' + chrome_flag | |
| 295 if options.verbose: | |
| 296 cmd += ' -v' | |
| 297 proc = Popen(cmd, env=envs, shell=True) | |
| 298 proc.communicate() | |
| 299 | |
| 300 if options.one_video: | |
| 301 break | |
| 302 | |
| 303 | |
| 304 if __name__ == '__main__': | |
| 305 main() | |
| OLD | NEW |