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 10 matching lines...) Expand all Loading... | |
21 from pylib.base import base_test_result | 21 from pylib.base import base_test_result |
22 from pylib.base import test_dispatcher | 22 from pylib.base import test_dispatcher |
23 from pylib.gtest import gtest_config | 23 from pylib.gtest import gtest_config |
24 from pylib.gtest import setup as gtest_setup | 24 from pylib.gtest import setup as gtest_setup |
25 from pylib.gtest import test_options as gtest_test_options | 25 from pylib.gtest import test_options as gtest_test_options |
26 from pylib.host_driven import setup as host_driven_setup | 26 from pylib.host_driven import setup as host_driven_setup |
27 from pylib.instrumentation import setup as instrumentation_setup | 27 from pylib.instrumentation import setup as instrumentation_setup |
28 from pylib.instrumentation import test_options as instrumentation_test_options | 28 from pylib.instrumentation import test_options as instrumentation_test_options |
29 from pylib.monkey import setup as monkey_setup | 29 from pylib.monkey import setup as monkey_setup |
30 from pylib.monkey import test_options as monkey_test_options | 30 from pylib.monkey import test_options as monkey_test_options |
31 from pylib.perf import setup as perf_setup | |
32 from pylib.perf import test_options as perf_test_options | |
31 from pylib.uiautomator import setup as uiautomator_setup | 33 from pylib.uiautomator import setup as uiautomator_setup |
32 from pylib.uiautomator import test_options as uiautomator_test_options | 34 from pylib.uiautomator import test_options as uiautomator_test_options |
33 from pylib.utils import report_results | 35 from pylib.utils import report_results |
34 from pylib.utils import run_tests_helper | 36 from pylib.utils import run_tests_helper |
35 | 37 |
36 | 38 |
37 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') | 39 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
38 | 40 |
39 | 41 |
40 def AddBuildTypeOption(option_parser): | 42 def AddBuildTypeOption(option_parser): |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 options.verbose_count, | 413 options.verbose_count, |
412 options.package_name, | 414 options.package_name, |
413 options.activity_name, | 415 options.activity_name, |
414 options.event_count, | 416 options.event_count, |
415 category, | 417 category, |
416 options.throttle, | 418 options.throttle, |
417 options.seed, | 419 options.seed, |
418 options.extra_args) | 420 options.extra_args) |
419 | 421 |
420 | 422 |
423 def AddPerfTestOptions(option_parser): | |
424 """Adds perf test options to |option_parser|.""" | |
425 | |
426 option_parser.usage = '%prog perf [options]' | |
427 option_parser.command_list = [] | |
428 option_parser.example = ( | |
429 '%prog perf') | |
frankf
2013/08/12 23:09:52
This is incomplete
bulach
2013/08/13 08:58:19
Done.
| |
430 | |
431 option_parser.add_option('--steps', help='JSON file containing the list ' | |
432 'of perf steps to run.') | |
433 option_parser.add_option('--flaky-steps', | |
434 help='A JSON file containing steps that are flaky ' | |
435 'and will have its exit code ignored.') | |
436 option_parser.add_option('--print-step', help='The name of a previously ' | |
437 'executed perf step to print.') | |
438 | |
439 AddCommonOptions(option_parser) | |
440 | |
441 | |
442 def ProcessPerfTestOptions(options, error_func): | |
443 """Processes all perf test options. | |
444 | |
445 Args: | |
446 options: optparse.Options object. | |
447 error_func: Function to call with the error message in case of an error. | |
448 | |
449 Returns: | |
450 A PerfOptions named tuple which contains all options relevant to | |
451 perf tests. | |
452 """ | |
453 return perf_test_options.PerfOptions( | |
454 options.steps, options.flaky_steps, options.print_step) | |
455 | |
frankf
2013/08/12 23:09:52
Nit: verify one of {--steps, --print-step} is spec
bulach
2013/08/13 08:58:19
Done.
| |
456 | |
457 | |
421 def _RunGTests(options, error_func): | 458 def _RunGTests(options, error_func): |
422 """Subcommand of RunTestsCommands which runs gtests.""" | 459 """Subcommand of RunTestsCommands which runs gtests.""" |
423 ProcessGTestOptions(options) | 460 ProcessGTestOptions(options) |
424 | 461 |
425 exit_code = 0 | 462 exit_code = 0 |
426 for suite_name in options.suite_name: | 463 for suite_name in options.suite_name: |
427 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for | 464 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for |
428 # the gtest command. | 465 # the gtest command. |
429 gtest_options = gtest_test_options.GTestOptions( | 466 gtest_options = gtest_test_options.GTestOptions( |
430 options.build_type, | 467 options.build_type, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 | 583 |
547 report_results.LogFull( | 584 report_results.LogFull( |
548 results=results, | 585 results=results, |
549 test_type='Monkey', | 586 test_type='Monkey', |
550 test_package='Monkey', | 587 test_package='Monkey', |
551 build_type=options.build_type) | 588 build_type=options.build_type) |
552 | 589 |
553 return exit_code | 590 return exit_code |
554 | 591 |
555 | 592 |
593 def _RunPerfTests(options, error_func): | |
594 """Subcommand of RunTestsCommands which runs perf tests.""" | |
595 perf_options = ProcessPerfTestOptions(options, error_func) | |
596 | |
597 runner_factory, tests = perf_setup.Setup(perf_options) | |
598 | |
599 results, exit_code = test_dispatcher.RunTests( | |
600 tests, runner_factory, False, None, shard=True) | |
601 | |
602 report_results.LogFull( | |
603 results=results, | |
604 test_type='Perf', | |
605 test_package='Perf', | |
606 build_type=options.build_type) | |
607 | |
608 return exit_code | |
609 | |
556 | 610 |
557 def RunTestsCommand(command, options, args, option_parser): | 611 def RunTestsCommand(command, options, args, option_parser): |
558 """Checks test type and dispatches to the appropriate function. | 612 """Checks test type and dispatches to the appropriate function. |
559 | 613 |
560 Args: | 614 Args: |
561 command: String indicating the command that was received to trigger | 615 command: String indicating the command that was received to trigger |
562 this function. | 616 this function. |
563 options: optparse options dictionary. | 617 options: optparse options dictionary. |
564 args: List of extra args from optparse. | 618 args: List of extra args from optparse. |
565 option_parser: optparse.OptionParser object. | 619 option_parser: optparse.OptionParser object. |
(...skipping 14 matching lines...) Expand all Loading... | |
580 ProcessCommonOptions(options) | 634 ProcessCommonOptions(options) |
581 | 635 |
582 if command == 'gtest': | 636 if command == 'gtest': |
583 return _RunGTests(options, option_parser.error) | 637 return _RunGTests(options, option_parser.error) |
584 elif command == 'instrumentation': | 638 elif command == 'instrumentation': |
585 return _RunInstrumentationTests(options, option_parser.error) | 639 return _RunInstrumentationTests(options, option_parser.error) |
586 elif command == 'uiautomator': | 640 elif command == 'uiautomator': |
587 return _RunUIAutomatorTests(options, option_parser.error) | 641 return _RunUIAutomatorTests(options, option_parser.error) |
588 elif command == 'monkey': | 642 elif command == 'monkey': |
589 return _RunMonkeyTests(options, option_parser.error) | 643 return _RunMonkeyTests(options, option_parser.error) |
644 elif command == 'perf': | |
645 return _RunPerfTests(options, option_parser.error) | |
590 else: | 646 else: |
591 raise Exception('Unknown test type.') | 647 raise Exception('Unknown test type.') |
592 | 648 |
593 | 649 |
594 def HelpCommand(command, options, args, option_parser): | 650 def HelpCommand(command, options, args, option_parser): |
595 """Display help for a certain command, or overall help. | 651 """Display help for a certain command, or overall help. |
596 | 652 |
597 Args: | 653 Args: |
598 command: String indicating the command that was received to trigger | 654 command: String indicating the command that was received to trigger |
599 this function. | 655 this function. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 CommandFunctionTuple = collections.namedtuple( | 694 CommandFunctionTuple = collections.namedtuple( |
639 'CommandFunctionTuple', ['add_options_func', 'run_command_func']) | 695 'CommandFunctionTuple', ['add_options_func', 'run_command_func']) |
640 VALID_COMMANDS = { | 696 VALID_COMMANDS = { |
641 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand), | 697 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand), |
642 'instrumentation': CommandFunctionTuple( | 698 'instrumentation': CommandFunctionTuple( |
643 AddInstrumentationTestOptions, RunTestsCommand), | 699 AddInstrumentationTestOptions, RunTestsCommand), |
644 'uiautomator': CommandFunctionTuple( | 700 'uiautomator': CommandFunctionTuple( |
645 AddUIAutomatorTestOptions, RunTestsCommand), | 701 AddUIAutomatorTestOptions, RunTestsCommand), |
646 'monkey': CommandFunctionTuple( | 702 'monkey': CommandFunctionTuple( |
647 AddMonkeyTestOptions, RunTestsCommand), | 703 AddMonkeyTestOptions, RunTestsCommand), |
704 'perf': CommandFunctionTuple( | |
705 AddPerfTestOptions, RunTestsCommand), | |
648 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 706 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
649 } | 707 } |
650 | 708 |
651 | 709 |
652 class CommandOptionParser(optparse.OptionParser): | 710 class CommandOptionParser(optparse.OptionParser): |
653 """Wrapper class for OptionParser to help with listing commands.""" | 711 """Wrapper class for OptionParser to help with listing commands.""" |
654 | 712 |
655 def __init__(self, *args, **kwargs): | 713 def __init__(self, *args, **kwargs): |
656 self.command_list = kwargs.pop('command_list', []) | 714 self.command_list = kwargs.pop('command_list', []) |
657 self.example = kwargs.pop('example', '') | 715 self.example = kwargs.pop('example', '') |
(...skipping 27 matching lines...) Expand all Loading... | |
685 option_parser.error('Invalid command.') | 743 option_parser.error('Invalid command.') |
686 command = argv[1] | 744 command = argv[1] |
687 VALID_COMMANDS[command].add_options_func(option_parser) | 745 VALID_COMMANDS[command].add_options_func(option_parser) |
688 options, args = option_parser.parse_args(argv) | 746 options, args = option_parser.parse_args(argv) |
689 return VALID_COMMANDS[command].run_command_func( | 747 return VALID_COMMANDS[command].run_command_func( |
690 command, options, args, option_parser) | 748 command, options, args, option_parser) |
691 | 749 |
692 | 750 |
693 if __name__ == '__main__': | 751 if __name__ == '__main__': |
694 sys.exit(main(sys.argv)) | 752 sys.exit(main(sys.argv)) |
OLD | NEW |