| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 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 """Runs all types of tests from one unified interface.""" | 7 """Runs all types of tests from one unified interface.""" |
| 8 | 8 |
| 9 import collections | 9 import collections |
| 10 import logging | 10 import logging |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 help=('Address of the server that is hosting the ' | 84 help=('Address of the server that is hosting the ' |
| 85 'Chrome for Android flakiness dashboard.')) | 85 'Chrome for Android flakiness dashboard.')) |
| 86 group.add_option('--enable-platform-mode', action='store_true', | 86 group.add_option('--enable-platform-mode', action='store_true', |
| 87 help=('Run the test scripts in platform mode, which ' | 87 help=('Run the test scripts in platform mode, which ' |
| 88 'conceptually separates the test runner from the ' | 88 'conceptually separates the test runner from the ' |
| 89 '"device" (local or remote, real or emulated) on ' | 89 '"device" (local or remote, real or emulated) on ' |
| 90 'which the tests are running. [experimental]')) | 90 'which the tests are running. [experimental]')) |
| 91 group.add_option('-e', '--environment', default='local', | 91 group.add_option('-e', '--environment', default='local', |
| 92 help=('Test environment to run in. Must be one of: %s' % | 92 help=('Test environment to run in. Must be one of: %s' % |
| 93 ', '.join(constants.VALID_ENVIRONMENTS))) | 93 ', '.join(constants.VALID_ENVIRONMENTS))) |
| 94 group.add_option('--adb-path', |
| 95 help=('Specify the absolute path of the adb binary that ' |
| 96 'should be used.')) |
| 94 option_parser.add_option_group(group) | 97 option_parser.add_option_group(group) |
| 95 | 98 |
| 96 | 99 |
| 97 def ProcessCommonOptions(options, error_func): | 100 def ProcessCommonOptions(options, error_func): |
| 98 """Processes and handles all common options.""" | 101 """Processes and handles all common options.""" |
| 99 run_tests_helper.SetLogLevel(options.verbose_count) | 102 run_tests_helper.SetLogLevel(options.verbose_count) |
| 100 constants.SetBuildType(options.build_type) | 103 constants.SetBuildType(options.build_type) |
| 101 if options.build_directory: | 104 if options.build_directory: |
| 102 constants.SetBuildDirectory(options.build_directory) | 105 constants.SetBuildDirectory(options.build_directory) |
| 103 if options.output_directory: | 106 if options.output_directory: |
| 104 constants.SetOutputDirectort(options.output_directory) | 107 constants.SetOutputDirectort(options.output_directory) |
| 108 if options.adb_path: |
| 109 constants.SetAdbPath(options.adb_path) |
| 110 # Some things such as Forwarder require ADB to be in the environment path. |
| 111 adb_dir = os.path.dirname(constants.GetAdbPath()) |
| 112 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): |
| 113 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH'] |
| 105 if options.environment not in constants.VALID_ENVIRONMENTS: | 114 if options.environment not in constants.VALID_ENVIRONMENTS: |
| 106 error_func('--environment must be one of: %s' % | 115 error_func('--environment must be one of: %s' % |
| 107 ', '.join(constants.VALID_ENVIRONMENTS)) | 116 ', '.join(constants.VALID_ENVIRONMENTS)) |
| 108 | 117 |
| 109 | 118 |
| 110 def AddDeviceOptions(option_parser): | 119 def AddDeviceOptions(option_parser): |
| 111 group = optparse.OptionGroup(option_parser, 'Device Options') | 120 group = optparse.OptionGroup(option_parser, 'Device Options') |
| 112 group.add_option('-c', dest='cleanup_test_files', | 121 group.add_option('-c', dest='cleanup_test_files', |
| 113 help='Cleanup test files on the device after run', | 122 help='Cleanup test files on the device after run', |
| 114 action='store_true') | 123 action='store_true') |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 option_parser.add_option( | 274 option_parser.add_option( |
| 266 '--test-apk', dest='test_apk', | 275 '--test-apk', dest='test_apk', |
| 267 help=('The name of the apk containing the tests ' | 276 help=('The name of the apk containing the tests ' |
| 268 '(without the .apk extension; e.g. "ContentShellTest").')) | 277 '(without the .apk extension; e.g. "ContentShellTest").')) |
| 269 option_parser.add_option('--coverage-dir', | 278 option_parser.add_option('--coverage-dir', |
| 270 help=('Directory in which to place all generated ' | 279 help=('Directory in which to place all generated ' |
| 271 'EMMA coverage files.')) | 280 'EMMA coverage files.')) |
| 272 option_parser.add_option('--device-flags', dest='device_flags', default='', | 281 option_parser.add_option('--device-flags', dest='device_flags', default='', |
| 273 help='The relative filepath to a file containing ' | 282 help='The relative filepath to a file containing ' |
| 274 'command-line flags to set on the device') | 283 'command-line flags to set on the device') |
| 284 option_parser.add_option('--isolate_file_path', |
| 285 '--isolate-file-path', |
| 286 dest='isolate_file_path', |
| 287 help='.isolate file path to override the default ' |
| 288 'path') |
| 275 | 289 |
| 276 | 290 |
| 277 def ProcessInstrumentationOptions(options, error_func): | 291 def ProcessInstrumentationOptions(options, error_func): |
| 278 """Processes options/arguments and populate |options| with defaults. | 292 """Processes options/arguments and populate |options| with defaults. |
| 279 | 293 |
| 280 Args: | 294 Args: |
| 281 options: optparse.Options object. | 295 options: optparse.Options object. |
| 282 error_func: Function to call with the error message in case of an error. | 296 error_func: Function to call with the error message in case of an error. |
| 283 | 297 |
| 284 Returns: | 298 Returns: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 options.test_data, | 341 options.test_data, |
| 328 options.save_perf_json, | 342 options.save_perf_json, |
| 329 options.screenshot_failures, | 343 options.screenshot_failures, |
| 330 options.wait_for_debugger, | 344 options.wait_for_debugger, |
| 331 options.coverage_dir, | 345 options.coverage_dir, |
| 332 options.test_apk, | 346 options.test_apk, |
| 333 options.test_apk_path, | 347 options.test_apk_path, |
| 334 options.test_apk_jar_path, | 348 options.test_apk_jar_path, |
| 335 options.test_runner, | 349 options.test_runner, |
| 336 options.test_support_apk_path, | 350 options.test_support_apk_path, |
| 337 options.device_flags | 351 options.device_flags, |
| 352 options.isolate_file_path |
| 338 ) | 353 ) |
| 339 | 354 |
| 340 | 355 |
| 341 def AddUIAutomatorTestOptions(option_parser): | 356 def AddUIAutomatorTestOptions(option_parser): |
| 342 """Adds UI Automator test options to |option_parser|.""" | 357 """Adds UI Automator test options to |option_parser|.""" |
| 343 | 358 |
| 344 option_parser.usage = '%prog uiautomator [options]' | 359 option_parser.usage = '%prog uiautomator [options]' |
| 345 option_parser.commands_dict = {} | 360 option_parser.commands_dict = {} |
| 346 option_parser.example = ( | 361 option_parser.example = ( |
| 347 '%prog uiautomator --test-jar=chrome_shell_uiautomator_tests' | 362 '%prog uiautomator --test-jar=chrome_shell_uiautomator_tests' |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 instrumentation_options = ProcessInstrumentationOptions(options, error_func) | 665 instrumentation_options = ProcessInstrumentationOptions(options, error_func) |
| 651 | 666 |
| 652 if len(devices) > 1 and options.wait_for_debugger: | 667 if len(devices) > 1 and options.wait_for_debugger: |
| 653 logging.warning('Debugger can not be sharded, using first available device') | 668 logging.warning('Debugger can not be sharded, using first available device') |
| 654 devices = devices[:1] | 669 devices = devices[:1] |
| 655 | 670 |
| 656 results = base_test_result.TestRunResults() | 671 results = base_test_result.TestRunResults() |
| 657 exit_code = 0 | 672 exit_code = 0 |
| 658 | 673 |
| 659 if options.run_java_tests: | 674 if options.run_java_tests: |
| 660 runner_factory, tests = instrumentation_setup.Setup(instrumentation_options) | 675 runner_factory, tests = instrumentation_setup.Setup( |
| 676 instrumentation_options, devices) |
| 661 | 677 |
| 662 test_results, exit_code = test_dispatcher.RunTests( | 678 test_results, exit_code = test_dispatcher.RunTests( |
| 663 tests, runner_factory, devices, shard=True, test_timeout=None, | 679 tests, runner_factory, devices, shard=True, test_timeout=None, |
| 664 num_retries=options.num_retries) | 680 num_retries=options.num_retries) |
| 665 | 681 |
| 666 results.AddTestRunResults(test_results) | 682 results.AddTestRunResults(test_results) |
| 667 | 683 |
| 668 if options.run_python_tests: | 684 if options.run_python_tests: |
| 669 runner_factory, tests = host_driven_setup.InstrumentationSetup( | 685 runner_factory, tests = host_driven_setup.InstrumentationSetup( |
| 670 options.host_driven_root, options.official_build, | 686 options.host_driven_root, options.official_build, |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 | 1002 |
| 987 def main(): | 1003 def main(): |
| 988 signal.signal(signal.SIGUSR1, DumpThreadStacks) | 1004 signal.signal(signal.SIGUSR1, DumpThreadStacks) |
| 989 option_parser = command_option_parser.CommandOptionParser( | 1005 option_parser = command_option_parser.CommandOptionParser( |
| 990 commands_dict=VALID_COMMANDS) | 1006 commands_dict=VALID_COMMANDS) |
| 991 return command_option_parser.ParseAndExecute(option_parser) | 1007 return command_option_parser.ParseAndExecute(option_parser) |
| 992 | 1008 |
| 993 | 1009 |
| 994 if __name__ == '__main__': | 1010 if __name__ == '__main__': |
| 995 sys.exit(main()) | 1011 sys.exit(main()) |
| OLD | NEW |