| 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 sys | 16 import sys |
| 17 | 17 |
| 18 from pylib import cmd_helper | 18 from pylib import cmd_helper |
| 19 from pylib import constants | 19 from pylib import constants |
| 20 from pylib import ports | 20 from pylib import ports |
| 21 from pylib.base import base_test_result | 21 from pylib.base import base_test_result |
| 22 from pylib.browsertests import dispatch as browsertests_dispatch | 22 from pylib.browsertests import dispatch as browsertests_dispatch |
| 23 from pylib.gtest import dispatch as gtest_dispatch | 23 from pylib.gtest import dispatch as gtest_dispatch |
| 24 from pylib.host_driven import run_python_tests as python_dispatch | 24 from pylib.host_driven import run_python_tests as host_driven_dispatch |
| 25 from pylib.instrumentation import dispatch as instrumentation_dispatch | 25 from pylib.instrumentation import dispatch as instrumentation_dispatch |
| 26 from pylib.uiautomator import dispatch as uiautomator_dispatch | 26 from pylib.uiautomator import dispatch as uiautomator_dispatch |
| 27 from pylib.utils import emulator, report_results, run_tests_helper | 27 from pylib.utils import report_results |
| 28 from pylib.utils import run_tests_helper |
| 28 | 29 |
| 29 | 30 |
| 30 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') | 31 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
| 31 | 32 |
| 32 | 33 |
| 33 def AddBuildTypeOption(option_parser): | 34 def AddBuildTypeOption(option_parser): |
| 34 """Adds the build type option to |option_parser|.""" | 35 """Adds the build type option to |option_parser|.""" |
| 35 default_build_type = 'Debug' | 36 default_build_type = 'Debug' |
| 36 if 'BUILDTYPE' in os.environ: | 37 if 'BUILDTYPE' in os.environ: |
| 37 default_build_type = os.environ['BUILDTYPE'] | 38 default_build_type = os.environ['BUILDTYPE'] |
| 38 option_parser.add_option('--debug', action='store_const', const='Debug', | 39 option_parser.add_option('--debug', action='store_const', const='Debug', |
| 39 dest='build_type', default=default_build_type, | 40 dest='build_type', default=default_build_type, |
| 40 help=('If set, run test suites under out/Debug. ' | 41 help=('If set, run test suites under out/Debug. ' |
| 41 'Default is env var BUILDTYPE or Debug.')) | 42 'Default is env var BUILDTYPE or Debug.')) |
| 42 option_parser.add_option('--release', action='store_const', | 43 option_parser.add_option('--release', action='store_const', |
| 43 const='Release', dest='build_type', | 44 const='Release', dest='build_type', |
| 44 help=('If set, run test suites under out/Release.' | 45 help=('If set, run test suites under out/Release.' |
| 45 ' Default is env var BUILDTYPE or Debug.')) | 46 ' Default is env var BUILDTYPE or Debug.')) |
| 46 | 47 |
| 47 | 48 |
| 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): | 49 def AddCommonOptions(option_parser): |
| 71 """Adds all common options to |option_parser|.""" | 50 """Adds all common options to |option_parser|.""" |
| 72 | 51 |
| 73 AddBuildTypeOption(option_parser) | 52 AddBuildTypeOption(option_parser) |
| 74 | 53 |
| 75 option_parser.add_option('--out-directory', dest='out_directory', | 54 option_parser.add_option('--out-directory', dest='out_directory', |
| 76 help=('Path to the out/ directory, irrespective of ' | 55 help=('Path to the out/ directory, irrespective of ' |
| 77 'the build type. Only for non-Chromium uses.')) | 56 'the build type. Only for non-Chromium uses.')) |
| 78 option_parser.add_option('-c', dest='cleanup_test_files', | 57 option_parser.add_option('-c', dest='cleanup_test_files', |
| 79 help='Cleanup test files on the device after run', | 58 help='Cleanup test files on the device after run', |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 101 |
| 123 def AddCoreGTestOptions(option_parser, default_timeout=60): | 102 def AddCoreGTestOptions(option_parser, default_timeout=60): |
| 124 """Add options specific to the gtest framework to |option_parser|.""" | 103 """Add options specific to the gtest framework to |option_parser|.""" |
| 125 | 104 |
| 126 # TODO(gkanwar): Consolidate and clean up test filtering for gtests and | 105 # TODO(gkanwar): Consolidate and clean up test filtering for gtests and |
| 127 # content_browsertests. | 106 # content_browsertests. |
| 128 option_parser.add_option('--gtest_filter', dest='test_filter', | 107 option_parser.add_option('--gtest_filter', dest='test_filter', |
| 129 help='Filter GTests by name.') | 108 help='Filter GTests by name.') |
| 130 option_parser.add_option('-a', '--test_arguments', dest='test_arguments', | 109 option_parser.add_option('-a', '--test_arguments', dest='test_arguments', |
| 131 help='Additional arguments to pass to the test.') | 110 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 | 111 # TODO(gkanwar): Possible deprecate this flag. Waiting on word from Peter |
| 138 # Beverloo. | 112 # Beverloo. |
| 139 option_parser.add_option('--webkit', action='store_true', | 113 option_parser.add_option('--webkit', action='store_true', |
| 140 help='Run the tests from a WebKit checkout.') | 114 help='Run the tests from a WebKit checkout.') |
| 141 option_parser.add_option('--exe', action='store_true', | 115 option_parser.add_option('--exe', action='store_true', |
| 142 help='If set, use the exe test runner instead of ' | 116 help='If set, use the exe test runner instead of ' |
| 143 'the APK.') | 117 'the APK.') |
| 144 option_parser.add_option('-t', dest='timeout', | 118 option_parser.add_option('-t', dest='timeout', |
| 145 help='Timeout to wait for each test', | 119 help='Timeout to wait for each test', |
| 146 type='int', | 120 type='int', |
| (...skipping 17 matching lines...) Expand all Loading... |
| 164 option_parser.usage = '%prog gtest [options]' | 138 option_parser.usage = '%prog gtest [options]' |
| 165 option_parser.command_list = [] | 139 option_parser.command_list = [] |
| 166 option_parser.example = '%prog gtest -s base_unittests' | 140 option_parser.example = '%prog gtest -s base_unittests' |
| 167 | 141 |
| 168 option_parser.add_option('-s', '--suite', dest='test_suite', | 142 option_parser.add_option('-s', '--suite', dest='test_suite', |
| 169 help=('Executable name of the test suite to run ' | 143 help=('Executable name of the test suite to run ' |
| 170 '(use -s help to list them).')) | 144 '(use -s help to list them).')) |
| 171 AddCoreGTestOptions(option_parser) | 145 AddCoreGTestOptions(option_parser) |
| 172 # TODO(gkanwar): Move these to Common Options once we have the plumbing | 146 # TODO(gkanwar): Move these to Common Options once we have the plumbing |
| 173 # in our other test types to handle these commands | 147 # in our other test types to handle these commands |
| 174 AddEmulatorOptions(option_parser) | |
| 175 AddCommonOptions(option_parser) | 148 AddCommonOptions(option_parser) |
| 176 | 149 |
| 177 | 150 |
| 178 def AddJavaTestOptions(option_parser): | 151 def AddJavaTestOptions(option_parser): |
| 179 """Adds the Java test options to |option_parser|.""" | 152 """Adds the Java test options to |option_parser|.""" |
| 180 | 153 |
| 181 option_parser.add_option('-f', '--test_filter', dest='test_filter', | 154 option_parser.add_option('-f', '--test_filter', dest='test_filter', |
| 182 help=('Test filter (if not fully qualified, ' | 155 help=('Test filter (if not fully qualified, ' |
| 183 'will run all matches).')) | 156 'will run all matches).')) |
| 184 option_parser.add_option( | 157 option_parser.add_option( |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 Integer indicated exit code. | 338 Integer indicated exit code. |
| 366 | 339 |
| 367 Raises: | 340 Raises: |
| 368 Exception: Unknown command name passed in, or an exception from an | 341 Exception: Unknown command name passed in, or an exception from an |
| 369 individual test runner. | 342 individual test runner. |
| 370 """ | 343 """ |
| 371 | 344 |
| 372 ProcessCommonOptions(options) | 345 ProcessCommonOptions(options) |
| 373 | 346 |
| 374 if command == 'gtest': | 347 if command == 'gtest': |
| 375 # TODO(gkanwar): See the emulator TODO above -- this call should either go | 348 results, exit_code = gtest_dispatch.RunGTests(options) |
| 376 # away or become generalized. | |
| 377 ProcessEmulatorOptions(options) | |
| 378 results, exit_code = gtest_dispatch.Dispatch(options) | |
| 379 elif command == 'content_browsertests': | 349 elif command == 'content_browsertests': |
| 380 results, exit_code = browsertests_dispatch.Dispatch(options) | 350 results, exit_code = browsertests_dispatch.RunContentBrowserTests(options) |
| 381 elif command == 'instrumentation': | 351 elif command == 'instrumentation': |
| 382 ProcessInstrumentationOptions(options, option_parser.error) | 352 ProcessInstrumentationOptions(options, option_parser.error) |
| 383 results = base_test_result.TestRunResults() | 353 results = base_test_result.TestRunResults() |
| 384 exit_code = 0 | 354 exit_code = 0 |
| 385 if options.run_java_tests: | 355 if options.run_java_tests: |
| 386 test_results, exit_code = instrumentation_dispatch.Dispatch(options) | 356 test_results, exit_code = (instrumentation_dispatch. |
| 357 RunInstrumentationTests(options)) |
| 387 results.AddTestRunResults(test_results) | 358 results.AddTestRunResults(test_results) |
| 388 if options.run_python_tests: | 359 if options.run_python_tests: |
| 389 test_results, test_exit_code = (python_dispatch. | 360 test_results, test_exit_code = (host_driven_dispatch. |
| 390 DispatchPythonTests(options)) | 361 RunHostDrivenTests(options)) |
| 391 results.AddTestRunResults(test_results) | 362 results.AddTestRunResults(test_results) |
| 392 # Only allow exit code escalation | 363 # Only allow exit code escalation |
| 393 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | 364 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 394 exit_code = test_exit_code | 365 exit_code = test_exit_code |
| 395 report_results.LogFull( | 366 report_results.LogFull( |
| 396 results=results, | 367 results=results, |
| 397 test_type='Instrumentation', | 368 test_type='Instrumentation', |
| 398 test_package=os.path.basename(options.test_apk), | 369 test_package=os.path.basename(options.test_apk), |
| 399 annotation=options.annotations, | 370 annotation=options.annotations, |
| 400 build_type=options.build_type, | 371 build_type=options.build_type, |
| 401 flakiness_server=options.flakiness_dashboard_server) | 372 flakiness_server=options.flakiness_dashboard_server) |
| 402 elif command == 'uiautomator': | 373 elif command == 'uiautomator': |
| 403 ProcessUIAutomatorOptions(options, option_parser.error) | 374 ProcessUIAutomatorOptions(options, option_parser.error) |
| 404 results = base_test_result.TestRunResults() | 375 results = base_test_result.TestRunResults() |
| 405 exit_code = 0 | 376 exit_code = 0 |
| 406 if options.run_java_tests: | 377 if options.run_java_tests: |
| 407 test_results, exit_code = uiautomator_dispatch.Dispatch(options) | 378 test_results, exit_code = (uiautomator_dispatch. |
| 379 RunUIAutomatorTests(options)) |
| 408 results.AddTestRunResults(test_results) | 380 results.AddTestRunResults(test_results) |
| 409 if options.run_python_tests: | 381 if options.run_python_tests: |
| 410 test_results, test_exit_code = (python_dispatch. | 382 test_results, test_exit_code = (host_driven_dispatch. |
| 411 DispatchPythonTests(options)) | 383 RunHostDrivenTests(options)) |
| 412 results.AddTestRunResults(test_results) | 384 results.AddTestRunResults(test_results) |
| 413 # Only allow exit code escalation | 385 # Only allow exit code escalation |
| 414 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | 386 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 415 exit_code = test_exit_code | 387 exit_code = test_exit_code |
| 416 report_results.LogFull( | 388 report_results.LogFull( |
| 417 results=results, | 389 results=results, |
| 418 test_type='UIAutomator', | 390 test_type='UIAutomator', |
| 419 test_package=os.path.basename(options.test_jar), | 391 test_package=os.path.basename(options.test_jar), |
| 420 annotation=options.annotations, | 392 annotation=options.annotations, |
| 421 build_type=options.build_type, | 393 build_type=options.build_type, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 return 0 | 489 return 0 |
| 518 command = argv[1] | 490 command = argv[1] |
| 519 VALID_COMMANDS[command].add_options_func(option_parser) | 491 VALID_COMMANDS[command].add_options_func(option_parser) |
| 520 options, args = option_parser.parse_args(argv) | 492 options, args = option_parser.parse_args(argv) |
| 521 return VALID_COMMANDS[command].run_command_func( | 493 return VALID_COMMANDS[command].run_command_func( |
| 522 command, options, args, option_parser) | 494 command, options, args, option_parser) |
| 523 | 495 |
| 524 | 496 |
| 525 if __name__ == '__main__': | 497 if __name__ == '__main__': |
| 526 sys.exit(main(sys.argv)) | 498 sys.exit(main(sys.argv)) |
| OLD | NEW |