Chromium Code Reviews| 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. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 '(use --tool help to list them)')) | 101 '(use --tool help to list them)')) |
| 102 option_parser.add_option('--flakiness-dashboard-server', | 102 option_parser.add_option('--flakiness-dashboard-server', |
| 103 dest='flakiness_dashboard_server', | 103 dest='flakiness_dashboard_server', |
| 104 help=('Address of the server that is hosting the ' | 104 help=('Address of the server that is hosting the ' |
| 105 'Chrome for Android flakiness dashboard.')) | 105 'Chrome for Android flakiness dashboard.')) |
| 106 option_parser.add_option('--skip-deps-push', dest='push_deps', | 106 option_parser.add_option('--skip-deps-push', dest='push_deps', |
| 107 action='store_false', default=True, | 107 action='store_false', default=True, |
| 108 help=('Do not push dependencies to the device. ' | 108 help=('Do not push dependencies to the device. ' |
| 109 'Use this at own risk for speeding up test ' | 109 'Use this at own risk for speeding up test ' |
| 110 'execution on local machine.')) | 110 'execution on local machine.')) |
| 111 # TODO(gkanwar): This option is deprecated. Remove it in the future. | |
| 112 option_parser.add_option('--exit-code', action='store_true', | |
| 113 help=('(DEPRECATED) If set, the exit code will be ' | |
| 114 'total number of failures.')) | |
| 115 # TODO(gkanwar): This option is deprecated. It is currently used to run tests | |
| 116 # with the FlakyTest annotation to prevent the bots going red downstream. We | |
| 117 # should instead use exit codes and let the Buildbot scripts deal with test | |
| 118 # failures appropriately. See crbug.com/170477. | |
| 119 option_parser.add_option('--buildbot-step-failure', | |
| 120 action='store_true', | |
| 121 help=('(DEPRECATED) If present, will set the ' | |
| 122 'buildbot status as STEP_FAILURE, otherwise ' | |
| 123 'as STEP_WARNINGS when test(s) fail.')) | |
| 124 option_parser.add_option('-d', '--device', dest='test_device', | 111 option_parser.add_option('-d', '--device', dest='test_device', |
| 125 help=('Target device for the test suite ' | 112 help=('Target device for the test suite ' |
| 126 'to run on.')) | 113 'to run on.')) |
| 127 | 114 |
| 128 | 115 |
| 129 def ProcessCommonOptions(options): | 116 def ProcessCommonOptions(options): |
| 130 """Processes and handles all common options.""" | 117 """Processes and handles all common options.""" |
| 131 if options.out_directory: | 118 if options.out_directory: |
| 132 cmd_helper.OutDirectory.set(options.out_directory) | 119 cmd_helper.OutDirectory.set(options.out_directory) |
| 133 run_tests_helper.SetLogLevel(options.verbose_count) | 120 run_tests_helper.SetLogLevel(options.verbose_count) |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 | 355 |
| 369 Args: | 356 Args: |
| 370 command: String indicating the command that was received to trigger | 357 command: String indicating the command that was received to trigger |
| 371 this function. | 358 this function. |
| 372 options: optparse options dictionary. | 359 options: optparse options dictionary. |
| 373 args: List of extra args from optparse. | 360 args: List of extra args from optparse. |
| 374 option_parser: optparse.OptionParser object. | 361 option_parser: optparse.OptionParser object. |
| 375 | 362 |
| 376 Returns: | 363 Returns: |
| 377 Integer indicated exit code. | 364 Integer indicated exit code. |
| 365 | |
| 366 Raises: | |
| 367 Exception: Unknown command name passed in. | |
| 378 """ | 368 """ |
| 379 | 369 |
| 380 ProcessCommonOptions(options) | 370 ProcessCommonOptions(options) |
| 381 | 371 |
| 382 total_failed = 0 | |
| 383 if command == 'gtest': | 372 if command == 'gtest': |
| 384 # TODO(gkanwar): See the emulator TODO above -- this call should either go | 373 # TODO(gkanwar): See the emulator TODO above -- this call should either go |
| 385 # away or become generalized. | 374 # away or become generalized. |
| 386 ProcessEmulatorOptions(options) | 375 ProcessEmulatorOptions(options) |
| 387 total_failed = gtest_dispatch.Dispatch(options) | 376 results, exit_code = gtest_dispatch.Dispatch(options) |
| 388 elif command == 'content_browsertests': | 377 elif command == 'content_browsertests': |
| 389 total_failed = browsertests_dispatch.Dispatch(options) | 378 results, exit_code = browsertests_dispatch.Dispatch(options) |
| 390 elif command == 'instrumentation': | 379 elif command == 'instrumentation': |
| 391 ProcessInstrumentationOptions(options, option_parser.error) | 380 ProcessInstrumentationOptions(options, option_parser.error) |
| 392 results = base_test_result.TestRunResults() | 381 results = base_test_result.TestRunResults() |
| 382 exit_code = 0 | |
| 393 if options.run_java_tests: | 383 if options.run_java_tests: |
| 394 results.AddTestRunResults(instrumentation_dispatch.Dispatch(options)) | 384 test_results, test_exit_code = instrumentation_dispatch.Dispatch(options) |
| 385 results.AddTestRunResults(test_results) | |
| 386 exit_code = test_exit_code | |
| 395 if options.run_python_tests: | 387 if options.run_python_tests: |
| 396 results.AddTestRunResults(python_dispatch.DispatchPythonTests(options)) | 388 test_results, test_exit_code = python_dispatch.DispatchPythonTests(options ) |
| 389 results.AddTestRunResults(test_results) | |
| 390 # Only allow exit code escalation | |
| 391 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | |
|
frankf
2013/07/04 00:46:19
Same here. You're throwing out the warning.
gkanwar
2013/07/08 18:50:25
See my other comment.
| |
| 392 exit_code = test_exit_code | |
| 397 report_results.LogFull( | 393 report_results.LogFull( |
| 398 results=results, | 394 results=results, |
| 399 test_type='Instrumentation', | 395 test_type='Instrumentation', |
| 400 test_package=os.path.basename(options.test_apk), | 396 test_package=os.path.basename(options.test_apk), |
| 401 annotation=options.annotations, | 397 annotation=options.annotations, |
| 402 build_type=options.build_type, | 398 build_type=options.build_type, |
| 403 flakiness_server=options.flakiness_dashboard_server) | 399 flakiness_server=options.flakiness_dashboard_server) |
| 404 total_failed += len(results.GetNotPass()) | |
| 405 elif command == 'uiautomator': | 400 elif command == 'uiautomator': |
| 406 ProcessUIAutomatorOptions(options, option_parser.error) | 401 ProcessUIAutomatorOptions(options, option_parser.error) |
| 407 results = base_test_result.TestRunResults() | 402 results = base_test_result.TestRunResults() |
| 403 exit_code = 0 | |
| 408 if options.run_java_tests: | 404 if options.run_java_tests: |
| 409 results.AddTestRunResults(uiautomator_dispatch.Dispatch(options)) | 405 test_results, test_exit_code = uiautomator_dispatch.Dispatch(options) |
| 406 results.AddTestRunResults(test_results) | |
| 407 exit_code = test_exit_code | |
| 410 if options.run_python_tests: | 408 if options.run_python_tests: |
| 411 results.AddTestRunResults(python_dispatch.Dispatch(options)) | 409 test_results, test_exit_code = python_dispatch.Dispatch(options) |
| 410 results.AddTestRunResults(test_results) | |
| 411 # Only allow exit code escalation | |
| 412 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | |
| 413 exit_code = test_exit_code | |
| 412 report_results.LogFull( | 414 report_results.LogFull( |
| 413 results=results, | 415 results=results, |
| 414 test_type='UIAutomator', | 416 test_type='UIAutomator', |
| 415 test_package=os.path.basename(options.test_jar), | 417 test_package=os.path.basename(options.test_jar), |
| 416 annotation=options.annotations, | 418 annotation=options.annotations, |
| 417 build_type=options.build_type, | 419 build_type=options.build_type, |
| 418 flakiness_server=options.flakiness_dashboard_server) | 420 flakiness_server=options.flakiness_dashboard_server) |
| 419 total_failed += len(results.GetNotPass()) | |
| 420 else: | 421 else: |
| 421 raise Exception('Unknown test type state') | 422 raise Exception('Unknown test type state') |
| 422 | 423 |
| 423 return total_failed | 424 return exit_code |
| 424 | 425 |
| 425 | 426 |
| 426 def HelpCommand(command, options, args, option_parser): | 427 def HelpCommand(command, options, args, option_parser): |
| 427 """Display help for a certain command, or overall help. | 428 """Display help for a certain command, or overall help. |
| 428 | 429 |
| 429 Args: | 430 Args: |
| 430 command: String indicating the command that was received to trigger | 431 command: String indicating the command that was received to trigger |
| 431 this function. | 432 this function. |
| 432 options: optparse options dictionary. | 433 options: optparse options dictionary. |
| 433 args: List of extra args from optparse. | 434 args: List of extra args from optparse. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 def get_command_list(self): | 497 def get_command_list(self): |
| 497 if self.command_list: | 498 if self.command_list: |
| 498 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list)) | 499 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list)) |
| 499 return '' | 500 return '' |
| 500 | 501 |
| 501 def get_example(self): | 502 def get_example(self): |
| 502 if self.example: | 503 if self.example: |
| 503 return '\nExample:\n %s\n' % self.example | 504 return '\nExample:\n %s\n' % self.example |
| 504 return '' | 505 return '' |
| 505 | 506 |
| 507 | |
| 506 def main(argv): | 508 def main(argv): |
| 507 option_parser = CommandOptionParser( | 509 option_parser = CommandOptionParser( |
| 508 usage='Usage: %prog <command> [options]', | 510 usage='Usage: %prog <command> [options]', |
| 509 command_list=VALID_COMMANDS.keys()) | 511 command_list=VALID_COMMANDS.keys()) |
| 510 | 512 |
| 511 if len(argv) < 2 or argv[1] not in VALID_COMMANDS: | 513 if len(argv) < 2 or argv[1] not in VALID_COMMANDS: |
| 512 option_parser.print_help() | 514 option_parser.print_help() |
| 513 return 0 | 515 return 0 |
| 514 command = argv[1] | 516 command = argv[1] |
| 515 VALID_COMMANDS[command].add_options_func(option_parser) | 517 VALID_COMMANDS[command].add_options_func(option_parser) |
| 516 options, args = option_parser.parse_args(argv) | 518 options, args = option_parser.parse_args(argv) |
| 517 exit_code = VALID_COMMANDS[command].run_command_func( | 519 exit_code = VALID_COMMANDS[command].run_command_func( |
| 518 command, options, args, option_parser) | 520 command, options, args, option_parser) |
| 519 | 521 |
| 520 # Failures of individual test suites are communicated by printing a | |
| 521 # STEP_FAILURE message. | |
| 522 # Returning a success exit status also prevents the buildbot from incorrectly | |
| 523 # marking the last suite as failed if there were failures in other suites in | |
| 524 # the batch (this happens because the exit status is a sum of all failures | |
| 525 # from all suites, but the buildbot associates the exit status only with the | |
| 526 # most recent step). | |
| 527 return exit_code | 522 return exit_code |
| 528 | 523 |
| 529 | 524 |
| 530 if __name__ == '__main__': | 525 if __name__ == '__main__': |
| 531 sys.exit(main(sys.argv)) | 526 sys.exit(main(sys.argv)) |
| OLD | NEW |