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, or an exception from an |
| 368 individual test runner. |
378 """ | 369 """ |
379 | 370 |
380 ProcessCommonOptions(options) | 371 ProcessCommonOptions(options) |
381 | 372 |
382 total_failed = 0 | |
383 if command == 'gtest': | 373 if command == 'gtest': |
384 # TODO(gkanwar): See the emulator TODO above -- this call should either go | 374 # TODO(gkanwar): See the emulator TODO above -- this call should either go |
385 # away or become generalized. | 375 # away or become generalized. |
386 ProcessEmulatorOptions(options) | 376 ProcessEmulatorOptions(options) |
387 total_failed = gtest_dispatch.Dispatch(options) | 377 results, exit_code = gtest_dispatch.Dispatch(options) |
388 elif command == 'content_browsertests': | 378 elif command == 'content_browsertests': |
389 total_failed = browsertests_dispatch.Dispatch(options) | 379 results, exit_code = browsertests_dispatch.Dispatch(options) |
390 elif command == 'instrumentation': | 380 elif command == 'instrumentation': |
391 ProcessInstrumentationOptions(options, option_parser.error) | 381 ProcessInstrumentationOptions(options, option_parser.error) |
392 results = base_test_result.TestRunResults() | 382 results = base_test_result.TestRunResults() |
| 383 exit_code = 0 |
393 if options.run_java_tests: | 384 if options.run_java_tests: |
394 results.AddTestRunResults(instrumentation_dispatch.Dispatch(options)) | 385 test_results, exit_code = instrumentation_dispatch.Dispatch(options) |
| 386 results.AddTestRunResults(test_results) |
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: |
| 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, exit_code = uiautomator_dispatch.Dispatch(options) |
| 406 results.AddTestRunResults(test_results) |
410 if options.run_python_tests: | 407 if options.run_python_tests: |
411 results.AddTestRunResults(python_dispatch.Dispatch(options)) | 408 test_results, test_exit_code = python_dispatch.Dispatch(options) |
| 409 results.AddTestRunResults(test_results) |
| 410 # Only allow exit code escalation |
| 411 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 412 exit_code = test_exit_code |
412 report_results.LogFull( | 413 report_results.LogFull( |
413 results=results, | 414 results=results, |
414 test_type='UIAutomator', | 415 test_type='UIAutomator', |
415 test_package=os.path.basename(options.test_jar), | 416 test_package=os.path.basename(options.test_jar), |
416 annotation=options.annotations, | 417 annotation=options.annotations, |
417 build_type=options.build_type, | 418 build_type=options.build_type, |
418 flakiness_server=options.flakiness_dashboard_server) | 419 flakiness_server=options.flakiness_dashboard_server) |
419 total_failed += len(results.GetNotPass()) | |
420 else: | 420 else: |
421 raise Exception('Unknown test type state') | 421 raise Exception('Unknown test type state') |
422 | 422 |
423 return total_failed | 423 return exit_code |
424 | 424 |
425 | 425 |
426 def HelpCommand(command, options, args, option_parser): | 426 def HelpCommand(command, options, args, option_parser): |
427 """Display help for a certain command, or overall help. | 427 """Display help for a certain command, or overall help. |
428 | 428 |
429 Args: | 429 Args: |
430 command: String indicating the command that was received to trigger | 430 command: String indicating the command that was received to trigger |
431 this function. | 431 this function. |
432 options: optparse options dictionary. | 432 options: optparse options dictionary. |
433 args: List of extra args from optparse. | 433 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): | 496 def get_command_list(self): |
497 if self.command_list: | 497 if self.command_list: |
498 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list)) | 498 return '\nCommands:\n %s\n' % '\n '.join(sorted(self.command_list)) |
499 return '' | 499 return '' |
500 | 500 |
501 def get_example(self): | 501 def get_example(self): |
502 if self.example: | 502 if self.example: |
503 return '\nExample:\n %s\n' % self.example | 503 return '\nExample:\n %s\n' % self.example |
504 return '' | 504 return '' |
505 | 505 |
| 506 |
506 def main(argv): | 507 def main(argv): |
507 option_parser = CommandOptionParser( | 508 option_parser = CommandOptionParser( |
508 usage='Usage: %prog <command> [options]', | 509 usage='Usage: %prog <command> [options]', |
509 command_list=VALID_COMMANDS.keys()) | 510 command_list=VALID_COMMANDS.keys()) |
510 | 511 |
511 if len(argv) < 2 or argv[1] not in VALID_COMMANDS: | 512 if len(argv) < 2 or argv[1] not in VALID_COMMANDS: |
512 option_parser.print_help() | 513 option_parser.print_help() |
513 return 0 | 514 return 0 |
514 command = argv[1] | 515 command = argv[1] |
515 VALID_COMMANDS[command].add_options_func(option_parser) | 516 VALID_COMMANDS[command].add_options_func(option_parser) |
516 options, args = option_parser.parse_args(argv) | 517 options, args = option_parser.parse_args(argv) |
517 exit_code = VALID_COMMANDS[command].run_command_func( | 518 return VALID_COMMANDS[command].run_command_func( |
518 command, options, args, option_parser) | 519 command, options, args, option_parser) |
519 | 520 |
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 | |
528 | |
529 | 521 |
530 if __name__ == '__main__': | 522 if __name__ == '__main__': |
531 sys.exit(main(sys.argv)) | 523 sys.exit(main(sys.argv)) |
OLD | NEW |