| 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 TODO(gkanwar): | 9 TODO(gkanwar): |
| 10 * Add options to run Monkey tests. | 10 * Add options to run Monkey tests. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import collections | 13 import collections |
| 14 import optparse | 14 import optparse |
| 15 import os | 15 import os |
| 16 import shutil |
| 16 import sys | 17 import sys |
| 17 | 18 |
| 18 from pylib import cmd_helper | 19 from pylib import cmd_helper |
| 19 from pylib import constants | 20 from pylib import constants |
| 20 from pylib import ports | 21 from pylib import ports |
| 21 from pylib.base import base_test_result | 22 from pylib.base import base_test_result |
| 22 from pylib.browsertests import dispatch as browsertests_dispatch | 23 from pylib.base import test_dispatcher |
| 23 from pylib.gtest import dispatch as gtest_dispatch | 24 from pylib.browsertests import setup as browsertests_setup |
| 25 from pylib.gtest import setup as gtest_setup |
| 26 from pylib.gtest import gtest_config |
| 24 from pylib.host_driven import run_python_tests as python_dispatch | 27 from pylib.host_driven import run_python_tests as python_dispatch |
| 25 from pylib.instrumentation import dispatch as instrumentation_dispatch | 28 from pylib.instrumentation import setup as instrumentation_setup |
| 26 from pylib.uiautomator import dispatch as uiautomator_dispatch | 29 from pylib.uiautomator import setup as uiautomator_setup |
| 27 from pylib.utils import emulator, report_results, run_tests_helper | 30 from pylib.utils import report_results |
| 31 from pylib.utils import run_tests_helper |
| 28 | 32 |
| 29 | 33 |
| 30 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') | 34 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
| 31 | 35 |
| 32 | 36 |
| 33 def AddBuildTypeOption(option_parser): | 37 def AddBuildTypeOption(option_parser): |
| 34 """Adds the build type option to |option_parser|.""" | 38 """Adds the build type option to |option_parser|.""" |
| 35 default_build_type = 'Debug' | 39 default_build_type = 'Debug' |
| 36 if 'BUILDTYPE' in os.environ: | 40 if 'BUILDTYPE' in os.environ: |
| 37 default_build_type = os.environ['BUILDTYPE'] | 41 default_build_type = os.environ['BUILDTYPE'] |
| 38 option_parser.add_option('--debug', action='store_const', const='Debug', | 42 option_parser.add_option('--debug', action='store_const', const='Debug', |
| 39 dest='build_type', default=default_build_type, | 43 dest='build_type', default=default_build_type, |
| 40 help=('If set, run test suites under out/Debug. ' | 44 help=('If set, run test suites under out/Debug. ' |
| 41 'Default is env var BUILDTYPE or Debug.')) | 45 'Default is env var BUILDTYPE or Debug.')) |
| 42 option_parser.add_option('--release', action='store_const', | 46 option_parser.add_option('--release', action='store_const', |
| 43 const='Release', dest='build_type', | 47 const='Release', dest='build_type', |
| 44 help=('If set, run test suites under out/Release.' | 48 help=('If set, run test suites under out/Release.' |
| 45 ' Default is env var BUILDTYPE or Debug.')) | 49 ' Default is env var BUILDTYPE or Debug.')) |
| 46 | 50 |
| 47 | 51 |
| 48 def AddEmulatorOptions(option_parser): | |
| 49 """Adds all emulator-related options to |option_parser|.""" | |
| 50 | |
| 51 # TODO(gkanwar): Figure out what we're doing with the emulator setup | |
| 52 # and determine whether these options should be deprecated/removed. | |
| 53 option_parser.add_option('-e', '--emulator', dest='use_emulator', | |
| 54 action='store_true', | |
| 55 help='Run tests in a new instance of emulator.') | |
| 56 option_parser.add_option('-n', '--emulator-count', | |
| 57 type='int', default=1, | |
| 58 help=('Number of emulators to launch for ' | |
| 59 'running the tests.')) | |
| 60 option_parser.add_option('--abi', default='armeabi-v7a', | |
| 61 help='Platform of emulators to launch.') | |
| 62 | |
| 63 | |
| 64 def ProcessEmulatorOptions(options): | |
| 65 """Processes emulator options.""" | |
| 66 if options.use_emulator: | |
| 67 emulator.DeleteAllTempAVDs() | |
| 68 | |
| 69 | |
| 70 def AddCommonOptions(option_parser): | 52 def AddCommonOptions(option_parser): |
| 71 """Adds all common options to |option_parser|.""" | 53 """Adds all common options to |option_parser|.""" |
| 72 | 54 |
| 73 AddBuildTypeOption(option_parser) | 55 AddBuildTypeOption(option_parser) |
| 74 | 56 |
| 75 option_parser.add_option('--out-directory', dest='out_directory', | 57 option_parser.add_option('--out-directory', dest='out_directory', |
| 76 help=('Path to the out/ directory, irrespective of ' | 58 help=('Path to the out/ directory, irrespective of ' |
| 77 'the build type. Only for non-Chromium uses.')) | 59 'the build type. Only for non-Chromium uses.')) |
| 78 option_parser.add_option('-c', dest='cleanup_test_files', | 60 option_parser.add_option('-c', dest='cleanup_test_files', |
| 79 help='Cleanup test files on the device after run', | 61 help='Cleanup test files on the device after run', |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 'to run on.')) | 95 'to run on.')) |
| 114 | 96 |
| 115 | 97 |
| 116 def ProcessCommonOptions(options): | 98 def ProcessCommonOptions(options): |
| 117 """Processes and handles all common options.""" | 99 """Processes and handles all common options.""" |
| 118 if options.out_directory: | 100 if options.out_directory: |
| 119 cmd_helper.OutDirectory.set(options.out_directory) | 101 cmd_helper.OutDirectory.set(options.out_directory) |
| 120 run_tests_helper.SetLogLevel(options.verbose_count) | 102 run_tests_helper.SetLogLevel(options.verbose_count) |
| 121 | 103 |
| 122 | 104 |
| 123 def AddCoreGTestOptions(option_parser, default_timeout=60): | 105 def AddCoreGTestOptions(option_parser): |
| 124 """Add options specific to the gtest framework to |option_parser|.""" | 106 """Add options specific to the gtest framework to |option_parser|.""" |
| 125 | 107 |
| 126 # TODO(gkanwar): Consolidate and clean up test filtering for gtests and | 108 # TODO(gkanwar): Consolidate and clean up test filtering for gtests and |
| 127 # content_browsertests. | 109 # content_browsertests. |
| 128 option_parser.add_option('--gtest_filter', dest='test_filter', | 110 option_parser.add_option('-f', '--gtest_filter', dest='test_filter', |
| 129 help='googletest-style filter string.') | 111 help='googletest-style filter string.') |
| 130 option_parser.add_option('-a', '--test_arguments', dest='test_arguments', | 112 option_parser.add_option('-a', '--test_arguments', dest='test_arguments', |
| 131 help='Additional arguments to pass to the test.') | 113 help='Additional arguments to pass to the test.') |
| 132 # TODO(gkanwar): Most likely deprecate/remove this option once we've pinned | |
| 133 # down what we're doing with the emulator setup. | |
| 134 option_parser.add_option('-x', '--xvfb', dest='use_xvfb', | |
| 135 action='store_true', | |
| 136 help='Use Xvfb around tests (ignored if not Linux).') | |
| 137 # TODO(gkanwar): Possible deprecate this flag. Waiting on word from Peter | 114 # TODO(gkanwar): Possible deprecate this flag. Waiting on word from Peter |
| 138 # Beverloo. | 115 # Beverloo. |
| 139 option_parser.add_option('--webkit', action='store_true', | 116 option_parser.add_option('--webkit', action='store_true', |
| 140 help='Run the tests from a WebKit checkout.') | 117 help='Run the tests from a WebKit checkout.') |
| 141 option_parser.add_option('--exe', action='store_true', | 118 option_parser.add_option('--exe', action='store_true', |
| 142 help='If set, use the exe test runner instead of ' | 119 help='If set, use the exe test runner instead of ' |
| 143 'the APK.') | 120 'the APK.') |
| 144 option_parser.add_option('-t', dest='timeout', | 121 option_parser.add_option('-t', dest='timeout', |
| 145 help='Timeout to wait for each test', | 122 help='Timeout to wait for each test', |
| 146 type='int', | 123 type='int', |
| 147 default=default_timeout) | 124 default=60) |
| 148 | 125 |
| 149 | 126 |
| 150 def AddContentBrowserTestOptions(option_parser): | 127 def AddContentBrowserTestOptions(option_parser): |
| 151 """Adds Content Browser test options to |option_parser|.""" | 128 """Adds Content Browser test options to |option_parser|.""" |
| 152 | 129 |
| 153 option_parser.usage = '%prog content_browsertests [options]' | 130 option_parser.usage = '%prog content_browsertests [options]' |
| 154 option_parser.command_list = [] | 131 option_parser.command_list = [] |
| 155 option_parser.example = '%prog content_browsertests' | 132 option_parser.example = '%prog content_browsertests' |
| 156 | 133 |
| 157 AddCoreGTestOptions(option_parser) | 134 AddCoreGTestOptions(option_parser) |
| 158 AddCommonOptions(option_parser) | 135 AddCommonOptions(option_parser) |
| 159 | 136 |
| 160 | 137 |
| 161 def AddGTestOptions(option_parser): | 138 def AddGTestOptions(option_parser): |
| 162 """Adds gtest options to |option_parser|.""" | 139 """Adds gtest options to |option_parser|.""" |
| 163 | 140 |
| 164 option_parser.usage = '%prog gtest [options]' | 141 option_parser.usage = '%prog gtest [options]' |
| 165 option_parser.command_list = [] | 142 option_parser.command_list = [] |
| 166 option_parser.example = '%prog gtest -s base_unittests' | 143 option_parser.example = '%prog gtest -s base_unittests' |
| 167 | 144 |
| 168 option_parser.add_option('-s', '--suite', dest='test_suite', | 145 # TODO(gkanwar): Make this option required |
| 146 option_parser.add_option('-s', '--suite', dest='suite_name', |
| 169 help=('Executable name of the test suite to run ' | 147 help=('Executable name of the test suite to run ' |
| 170 '(use -s help to list them).')) | 148 '(use -s help to list them).')) |
| 171 AddCoreGTestOptions(option_parser) | 149 AddCoreGTestOptions(option_parser) |
| 172 # TODO(gkanwar): Move these to Common Options once we have the plumbing | 150 # TODO(gkanwar): Move these to Common Options once we have the plumbing |
| 173 # in our other test types to handle these commands | 151 # in our other test types to handle these commands |
| 174 AddEmulatorOptions(option_parser) | |
| 175 AddCommonOptions(option_parser) | 152 AddCommonOptions(option_parser) |
| 176 | 153 |
| 177 | 154 |
| 155 def ProcessGTestOptions(options): |
| 156 """Intercept test suite help to list test suites. |
| 157 |
| 158 Args: |
| 159 options: Command line options. |
| 160 |
| 161 Returns: |
| 162 True if the command should continue. |
| 163 """ |
| 164 if options.suite_name == 'help': |
| 165 print 'Available test suites are:' |
| 166 for test_suite in gtest_config.STABLE_TEST_SUITES: |
| 167 print test_suite.name |
| 168 return False |
| 169 |
| 170 # Convert to a list, assuming all test suites if nothing was specified. |
| 171 # TODO(gkanwar): Require having a test suite |
| 172 if options.suite_name: |
| 173 options.suite_name = [options.suite_name] |
| 174 else: |
| 175 options.suite_name = [suite.name |
| 176 for suite in gtest_config.STABLE_TEST_SUITES] |
| 177 return True |
| 178 |
| 179 |
| 178 def AddJavaTestOptions(option_parser): | 180 def AddJavaTestOptions(option_parser): |
| 179 """Adds the Java test options to |option_parser|.""" | 181 """Adds the Java test options to |option_parser|.""" |
| 180 | 182 |
| 181 option_parser.add_option('-f', '--test_filter', dest='test_filter', | 183 option_parser.add_option('-f', '--test_filter', dest='test_filter', |
| 182 help=('Test filter (if not fully qualified, ' | 184 help=('Test filter (if not fully qualified, ' |
| 183 'will run all matches).')) | 185 'will run all matches).')) |
| 184 option_parser.add_option( | 186 option_parser.add_option( |
| 185 '-A', '--annotation', dest='annotation_str', | 187 '-A', '--annotation', dest='annotation_str', |
| 186 help=('Comma-separated list of annotations. Run only tests with any of ' | 188 help=('Comma-separated list of annotations. Run only tests with any of ' |
| 187 'the given annotations. An annotation can be either a key or a ' | 189 'the given annotations. An annotation can be either a key or a ' |
| 188 'key-values pair. A test that has no annotation is considered ' | 190 'key-values pair. A test that has no annotation is considered ' |
| 189 '"SmallTest".')) | 191 '"SmallTest".')) |
| 190 option_parser.add_option( | 192 option_parser.add_option( |
| 191 '-E', '--exclude-annotation', dest='exclude_annotation_str', | 193 '-E', '--exclude-annotation', dest='exclude_annotation_str', |
| 192 help=('Comma-separated list of annotations. Exclude tests with these ' | 194 help=('Comma-separated list of annotations. Exclude tests with these ' |
| 193 'annotations.')) | 195 'annotations.')) |
| 194 option_parser.add_option('-j', '--java_only', action='store_true', | 196 option_parser.add_option('-j', '--java_only', action='store_true', |
| 195 default=False, help='Run only the Java tests.') | 197 default=False, help='Run only the Java tests.') |
| 196 option_parser.add_option('-p', '--python_only', action='store_true', | 198 option_parser.add_option('-p', '--python_only', action='store_true', |
| 197 default=False, | 199 default=False, |
| 198 help='Run only the host-driven tests.') | 200 help='Run only the host-driven tests.') |
| 199 option_parser.add_option('--screenshot', dest='screenshot_failures', | 201 option_parser.add_option('--screenshot', dest='screenshot_failures', |
| 200 action='store_true', | 202 action='store_true', |
| 201 help='Capture screenshots of test failures') | 203 help='Capture screenshots of test failures') |
| 202 option_parser.add_option('--save-perf-json', action='store_true', | 204 option_parser.add_option('--save-perf-json', action='store_true', |
| 203 help='Saves the JSON file for each UI Perf test.') | 205 help='Saves the JSON file for each UI Perf test.') |
| 204 # TODO(gkanwar): Remove this option. It is not used anywhere. | |
| 205 option_parser.add_option('--shard_retries', type=int, default=1, | |
| 206 help=('Number of times to retry each failure when ' | |
| 207 'sharding.')) | |
| 208 option_parser.add_option('--official-build', help='Run official build tests.') | 206 option_parser.add_option('--official-build', help='Run official build tests.') |
| 209 option_parser.add_option('--python_test_root', | 207 option_parser.add_option('--python_test_root', |
| 210 help='Root of the host-driven tests.') | 208 help='Root of the host-driven tests.') |
| 211 option_parser.add_option('--keep_test_server_ports', | 209 option_parser.add_option('--keep_test_server_ports', |
| 212 action='store_true', | 210 action='store_true', |
| 213 help=('Indicates the test server ports must be ' | 211 help=('Indicates the test server ports must be ' |
| 214 'kept. When this is run via a sharder ' | 212 'kept. When this is run via a sharder ' |
| 215 'the test server ports should be kept and ' | 213 'the test server ports should be kept and ' |
| 216 'should not be reset.')) | 214 'should not be reset.')) |
| 217 # TODO(gkanwar): This option is deprecated. Remove it in the future. | 215 # TODO(gkanwar): This option is deprecated. Remove it in the future. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 242 options.run_java_tests = False | 240 options.run_java_tests = False |
| 243 | 241 |
| 244 if not options.python_test_root: | 242 if not options.python_test_root: |
| 245 options.run_python_tests = False | 243 options.run_python_tests = False |
| 246 | 244 |
| 247 if options.annotation_str: | 245 if options.annotation_str: |
| 248 options.annotations = options.annotation_str.split(',') | 246 options.annotations = options.annotation_str.split(',') |
| 249 elif options.test_filter: | 247 elif options.test_filter: |
| 250 options.annotations = [] | 248 options.annotations = [] |
| 251 else: | 249 else: |
| 252 options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest'] | 250 options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', |
| 251 'EnormousTest'] |
| 253 | 252 |
| 254 if options.exclude_annotation_str: | 253 if options.exclude_annotation_str: |
| 255 options.exclude_annotations = options.exclude_annotation_str.split(',') | 254 options.exclude_annotations = options.exclude_annotation_str.split(',') |
| 256 else: | 255 else: |
| 257 options.exclude_annotations = [] | 256 options.exclude_annotations = [] |
| 258 | 257 |
| 259 if not options.keep_test_server_ports: | 258 if not options.keep_test_server_ports: |
| 260 if not ports.ResetTestServerPortAllocation(): | 259 if not ports.ResetTestServerPortAllocation(): |
| 261 raise Exception('Failed to reset test server port.') | 260 raise Exception('Failed to reset test server port.') |
| 262 | 261 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 options.uiautomator_jar = options.test_jar | 343 options.uiautomator_jar = options.test_jar |
| 345 else: | 344 else: |
| 346 options.uiautomator_jar = os.path.join( | 345 options.uiautomator_jar = os.path.join( |
| 347 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR, | 346 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR, |
| 348 '%s.dex.jar' % options.test_jar) | 347 '%s.dex.jar' % options.test_jar) |
| 349 options.uiautomator_info_jar = ( | 348 options.uiautomator_info_jar = ( |
| 350 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] + | 349 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] + |
| 351 '_java.jar') | 350 '_java.jar') |
| 352 | 351 |
| 353 | 352 |
| 353 def _RunGTests(options, error_func): |
| 354 """Subcommand of RunTestsCommands which runs gtests.""" |
| 355 if not ProcessGTestOptions(options): |
| 356 return 0 |
| 357 |
| 358 exit_code = 0 |
| 359 for suite_name in options.suite_name: |
| 360 runner_factory, tests = gtest_setup.Setup( |
| 361 options.exe, suite_name, options.test_arguments, |
| 362 options.timeout, options.cleanup_test_files, options.tool, |
| 363 options.build_type, options.webkit, options.push_deps, |
| 364 options.test_filter) |
| 365 |
| 366 results, test_exit_code = test_dispatcher.RunTests( |
| 367 tests, runner_factory, False, options.test_device, |
| 368 shard=True, |
| 369 build_type=options.build_type, |
| 370 test_timeout=None, |
| 371 num_retries=options.num_retries) |
| 372 |
| 373 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 374 exit_code = test_exit_code |
| 375 |
| 376 report_results.LogFull( |
| 377 results=results, |
| 378 test_type='Unit test', |
| 379 test_package=suite_name, |
| 380 build_type=options.build_type, |
| 381 flakiness_server=options.flakiness_dashboard_server) |
| 382 |
| 383 if os.path.isdir(constants.ISOLATE_DEPS_DIR): |
| 384 shutil.rmtree(constants.ISOLATE_DEPS_DIR) |
| 385 |
| 386 return exit_code |
| 387 |
| 388 |
| 389 def _RunContentBrowserTests(options, error_func): |
| 390 """Subcommand of RunTestsCommands which runs content_browsertests.""" |
| 391 runner_factory, tests = browsertests_setup.Setup( |
| 392 options.test_arguments, options.timeout, options.cleanup_test_files, |
| 393 options.tool, options.build_type, options.webkit, options.push_deps, |
| 394 options.test_filter) |
| 395 |
| 396 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer |
| 397 # files are pushed to the devices for content_browsertests: crbug.com/138275 |
| 398 setup_timeout = 20 * 60 # 20 minutes |
| 399 results, exit_code = test_dispatcher.RunTests( |
| 400 tests, runner_factory, False, options.test_device, |
| 401 shard=True, |
| 402 build_type=options.build_type, |
| 403 test_timeout=None, |
| 404 setup_timeout=setup_timeout, |
| 405 num_retries=options.num_retries) |
| 406 |
| 407 report_results.LogFull( |
| 408 results=results, |
| 409 test_type='Unit test', |
| 410 test_package=constants.BROWSERTEST_SUITE_NAME, |
| 411 build_type=options.build_type, |
| 412 flakiness_server=options.flakiness_dashboard_server) |
| 413 |
| 414 if os.path.isdir(constants.ISOLATE_DEPS_DIR): |
| 415 shutil.rmtree(constants.ISOLATE_DEPS_DIR) |
| 416 |
| 417 return exit_code |
| 418 |
| 419 |
| 420 def _RunInstrumentationTests(options, error_func): |
| 421 """Subcommand of RunTestsCommands which runs instrumentation tests.""" |
| 422 ProcessInstrumentationOptions(options, error_func) |
| 423 |
| 424 results = base_test_result.TestRunResults() |
| 425 exit_code = 0 |
| 426 |
| 427 if options.run_java_tests: |
| 428 runner_factory, tests = instrumentation_setup.Setup( |
| 429 options.test_apk_path, options.test_apk_jar_path, options.annotations, |
| 430 options.exclude_annotations, options.test_filter, options.build_type, |
| 431 options.test_data, options.install_apk, options.save_perf_json, |
| 432 options.screenshot_failures, options.tool, options.wait_for_debugger, |
| 433 options.disable_assertions, options.push_deps, |
| 434 options.cleanup_test_files) |
| 435 |
| 436 test_results, exit_code = test_dispatcher.RunTests( |
| 437 tests, runner_factory, options.wait_for_debugger, |
| 438 options.test_device, |
| 439 shard=True, |
| 440 build_type=options.build_type, |
| 441 test_timeout=None, |
| 442 num_retries=options.num_retries) |
| 443 |
| 444 results.AddTestRunResults(test_results) |
| 445 |
| 446 if options.run_python_tests: |
| 447 test_results, test_exit_code = ( |
| 448 python_dispatch.DispatchPythonTests(options)) |
| 449 |
| 450 results.AddTestRunResults(test_results) |
| 451 |
| 452 # Only allow exit code escalation |
| 453 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 454 exit_code = test_exit_code |
| 455 |
| 456 report_results.LogFull( |
| 457 results=results, |
| 458 test_type='Instrumentation', |
| 459 test_package=os.path.basename(options.test_apk), |
| 460 annotation=options.annotations, |
| 461 build_type=options.build_type, |
| 462 flakiness_server=options.flakiness_dashboard_server) |
| 463 |
| 464 return exit_code |
| 465 |
| 466 |
| 467 def _RunUIAutomatorTests(options, error_func): |
| 468 """Subcommand of RunTestsCommands which runs uiautomator tests.""" |
| 469 ProcessUIAutomatorOptions(options, error_func) |
| 470 |
| 471 results = base_test_result.TestRunResults() |
| 472 exit_code = 0 |
| 473 |
| 474 if options.run_java_tests: |
| 475 runner_factory, tests = uiautomator_setup.Setup( |
| 476 options.uiautomator_jar, options.uiautomator_info_jar, |
| 477 options.annotations, options.exclude_annotations, options.test_filter, |
| 478 options.package_name, options.build_type, options.test_data, |
| 479 options.save_perf_json, options.screenshot_failures, options.tool, |
| 480 options.disable_assertions, options.push_deps, |
| 481 options.cleanup_test_files) |
| 482 |
| 483 test_results, exit_code = test_dispatcher.RunTests( |
| 484 tests, runner_factory, False, options.test_device, |
| 485 shard=True, |
| 486 build_type=options.build_type, |
| 487 test_timeout=None, |
| 488 num_retries=options.num_retries) |
| 489 |
| 490 results.AddTestRunResults(test_results) |
| 491 |
| 492 if options.run_python_tests: |
| 493 test_results, test_exit_code = ( |
| 494 python_dispatch.DispatchPythonTests(options)) |
| 495 |
| 496 results.AddTestRunResults(test_results) |
| 497 |
| 498 # Only allow exit code escalation |
| 499 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 500 exit_code = test_exit_code |
| 501 |
| 502 report_results.LogFull( |
| 503 results=results, |
| 504 test_type='UIAutomator', |
| 505 test_package=os.path.basename(options.test_jar), |
| 506 annotation=options.annotations, |
| 507 build_type=options.build_type, |
| 508 flakiness_server=options.flakiness_dashboard_server) |
| 509 |
| 510 return exit_code |
| 511 |
| 512 |
| 354 def RunTestsCommand(command, options, args, option_parser): | 513 def RunTestsCommand(command, options, args, option_parser): |
| 355 """Checks test type and dispatches to the appropriate function. | 514 """Checks test type and dispatches to the appropriate function. |
| 356 | 515 |
| 357 Args: | 516 Args: |
| 358 command: String indicating the command that was received to trigger | 517 command: String indicating the command that was received to trigger |
| 359 this function. | 518 this function. |
| 360 options: optparse options dictionary. | 519 options: optparse options dictionary. |
| 361 args: List of extra args from optparse. | 520 args: List of extra args from optparse. |
| 362 option_parser: optparse.OptionParser object. | 521 option_parser: optparse.OptionParser object. |
| 363 | 522 |
| 364 Returns: | 523 Returns: |
| 365 Integer indicated exit code. | 524 Integer indicated exit code. |
| 366 | 525 |
| 367 Raises: | 526 Raises: |
| 368 Exception: Unknown command name passed in, or an exception from an | 527 Exception: Unknown command name passed in, or an exception from an |
| 369 individual test runner. | 528 individual test runner. |
| 370 """ | 529 """ |
| 371 | 530 |
| 372 # Check for extra arguments | 531 # Check for extra arguments |
| 373 if len(args) > 2: | 532 if len(args) > 2: |
| 374 option_parser.error('Unrecognized arguments: %s' % (' '.join(args[2:]))) | 533 option_parser.error('Unrecognized arguments: %s' % (' '.join(args[2:]))) |
| 375 return constants.ERROR_EXIT_CODE | 534 return constants.ERROR_EXIT_CODE |
| 376 | 535 |
| 377 ProcessCommonOptions(options) | 536 ProcessCommonOptions(options) |
| 378 | 537 |
| 379 if command == 'gtest': | 538 if command == 'gtest': |
| 380 # TODO(gkanwar): See the emulator TODO above -- this call should either go | 539 return _RunGTests(options, option_parser.error) |
| 381 # away or become generalized. | |
| 382 ProcessEmulatorOptions(options) | |
| 383 results, exit_code = gtest_dispatch.Dispatch(options) | |
| 384 elif command == 'content_browsertests': | 540 elif command == 'content_browsertests': |
| 385 results, exit_code = browsertests_dispatch.Dispatch(options) | 541 return _RunContentBrowserTests(options, option_parser.error) |
| 386 elif command == 'instrumentation': | 542 elif command == 'instrumentation': |
| 387 ProcessInstrumentationOptions(options, option_parser.error) | 543 return _RunInstrumentationTests(options, option_parser.error) |
| 388 results = base_test_result.TestRunResults() | |
| 389 exit_code = 0 | |
| 390 if options.run_java_tests: | |
| 391 test_results, exit_code = instrumentation_dispatch.Dispatch(options) | |
| 392 results.AddTestRunResults(test_results) | |
| 393 if options.run_python_tests: | |
| 394 test_results, test_exit_code = (python_dispatch. | |
| 395 DispatchPythonTests(options)) | |
| 396 results.AddTestRunResults(test_results) | |
| 397 # Only allow exit code escalation | |
| 398 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | |
| 399 exit_code = test_exit_code | |
| 400 report_results.LogFull( | |
| 401 results=results, | |
| 402 test_type='Instrumentation', | |
| 403 test_package=os.path.basename(options.test_apk), | |
| 404 annotation=options.annotations, | |
| 405 build_type=options.build_type, | |
| 406 flakiness_server=options.flakiness_dashboard_server) | |
| 407 elif command == 'uiautomator': | 544 elif command == 'uiautomator': |
| 408 ProcessUIAutomatorOptions(options, option_parser.error) | 545 return _RunUIAutomatorTests(options, option_parser.error) |
| 409 results = base_test_result.TestRunResults() | |
| 410 exit_code = 0 | |
| 411 if options.run_java_tests: | |
| 412 test_results, exit_code = uiautomator_dispatch.Dispatch(options) | |
| 413 results.AddTestRunResults(test_results) | |
| 414 if options.run_python_tests: | |
| 415 test_results, test_exit_code = (python_dispatch. | |
| 416 DispatchPythonTests(options)) | |
| 417 results.AddTestRunResults(test_results) | |
| 418 # Only allow exit code escalation | |
| 419 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | |
| 420 exit_code = test_exit_code | |
| 421 report_results.LogFull( | |
| 422 results=results, | |
| 423 test_type='UIAutomator', | |
| 424 test_package=os.path.basename(options.test_jar), | |
| 425 annotation=options.annotations, | |
| 426 build_type=options.build_type, | |
| 427 flakiness_server=options.flakiness_dashboard_server) | |
| 428 else: | 546 else: |
| 429 raise Exception('Unknown test type state') | 547 raise Exception('Unknown test type.') |
| 430 | 548 |
| 431 return exit_code | 549 return exit_code |
| 432 | 550 |
| 433 | 551 |
| 434 def HelpCommand(command, options, args, option_parser): | 552 def HelpCommand(command, options, args, option_parser): |
| 435 """Display help for a certain command, or overall help. | 553 """Display help for a certain command, or overall help. |
| 436 | 554 |
| 437 Args: | 555 Args: |
| 438 command: String indicating the command that was received to trigger | 556 command: String indicating the command that was received to trigger |
| 439 this function. | 557 this function. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return 0 | 644 return 0 |
| 527 command = argv[1] | 645 command = argv[1] |
| 528 VALID_COMMANDS[command].add_options_func(option_parser) | 646 VALID_COMMANDS[command].add_options_func(option_parser) |
| 529 options, args = option_parser.parse_args(argv) | 647 options, args = option_parser.parse_args(argv) |
| 530 return VALID_COMMANDS[command].run_command_func( | 648 return VALID_COMMANDS[command].run_command_func( |
| 531 command, options, args, option_parser) | 649 command, options, args, option_parser) |
| 532 | 650 |
| 533 | 651 |
| 534 if __name__ == '__main__': | 652 if __name__ == '__main__': |
| 535 sys.exit(main(sys.argv)) | 653 sys.exit(main(sys.argv)) |
| OLD | NEW |