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 import argparse | 9 import argparse |
10 import collections | 10 import collections |
(...skipping 20 matching lines...) Expand all Loading... |
31 from pylib.base import environment_factory | 31 from pylib.base import environment_factory |
32 from pylib.base import test_dispatcher | 32 from pylib.base import test_dispatcher |
33 from pylib.base import test_instance_factory | 33 from pylib.base import test_instance_factory |
34 from pylib.base import test_run_factory | 34 from pylib.base import test_run_factory |
35 from pylib.constants import host_paths | 35 from pylib.constants import host_paths |
36 from pylib.linker import setup as linker_setup | 36 from pylib.linker import setup as linker_setup |
37 from pylib.junit import setup as junit_setup | 37 from pylib.junit import setup as junit_setup |
38 from pylib.junit import test_dispatcher as junit_dispatcher | 38 from pylib.junit import test_dispatcher as junit_dispatcher |
39 from pylib.monkey import setup as monkey_setup | 39 from pylib.monkey import setup as monkey_setup |
40 from pylib.monkey import test_options as monkey_test_options | 40 from pylib.monkey import test_options as monkey_test_options |
41 from pylib.perf import setup as perf_setup | |
42 from pylib.perf import test_options as perf_test_options | |
43 from pylib.perf import test_runner as perf_test_runner | |
44 from pylib.results import json_results | 41 from pylib.results import json_results |
45 from pylib.results import report_results | 42 from pylib.results import report_results |
46 | 43 |
47 | 44 |
48 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( | 45 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( |
49 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) | 46 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) |
50 | 47 |
51 | 48 |
52 def AddCommonOptions(parser): | 49 def AddCommonOptions(parser): |
53 """Adds all common options to |parser|.""" | 50 """Adds all common options to |parser|.""" |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 group.add_argument( | 602 group.add_argument( |
606 '--break-on-failure', '--break_on_failure', dest='break_on_failure', | 603 '--break-on-failure', '--break_on_failure', dest='break_on_failure', |
607 action='store_true', help='Whether to break on failure.') | 604 action='store_true', help='Whether to break on failure.') |
608 group.add_argument( | 605 group.add_argument( |
609 '--write-buildbot-json', action='store_true', | 606 '--write-buildbot-json', action='store_true', |
610 help='Whether to output buildbot json.') | 607 help='Whether to output buildbot json.') |
611 AddCommonOptions(parser) | 608 AddCommonOptions(parser) |
612 AddDeviceOptions(parser) | 609 AddDeviceOptions(parser) |
613 | 610 |
614 | 611 |
615 def ProcessPerfTestOptions(args): | |
616 """Processes all perf test options. | |
617 | |
618 Args: | |
619 args: argparse.Namespace object. | |
620 | |
621 Returns: | |
622 A PerfOptions named tuple which contains all options relevant to | |
623 perf tests. | |
624 """ | |
625 # TODO(jbudorick): Move single_step handling down into the perf tests. | |
626 if args.single_step: | |
627 args.single_step = ' '.join(args.single_step_command) | |
628 # TODO(jbudorick): Get rid of PerfOptions. | |
629 return perf_test_options.PerfOptions( | |
630 args.steps, args.flaky_steps, args.output_json_list, | |
631 args.print_step, args.no_timeout, args.test_filter, | |
632 args.dry_run, args.single_step, args.collect_chartjson_data, | |
633 args.output_chartjson_data, args.get_output_dir_archive, | |
634 args.max_battery_temp, args.min_battery_level, | |
635 args.known_devices_file) | |
636 | |
637 | |
638 def AddPythonTestOptions(parser): | 612 def AddPythonTestOptions(parser): |
639 group = parser.add_argument_group('Python Test Options') | 613 group = parser.add_argument_group('Python Test Options') |
640 group.add_argument( | 614 group.add_argument( |
641 '-s', '--suite', dest='suite_name', metavar='SUITE_NAME', | 615 '-s', '--suite', dest='suite_name', metavar='SUITE_NAME', |
642 choices=constants.PYTHON_UNIT_TEST_SUITES.keys(), | 616 choices=constants.PYTHON_UNIT_TEST_SUITES.keys(), |
643 help='Name of the test suite to run.') | 617 help='Name of the test suite to run.') |
644 AddCommonOptions(parser) | 618 AddCommonOptions(parser) |
645 | 619 |
646 | 620 |
647 def _RunLinkerTests(args, devices): | 621 def _RunLinkerTests(args, devices): |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 results=results, | 667 results=results, |
694 test_type='Monkey', | 668 test_type='Monkey', |
695 test_package='Monkey') | 669 test_package='Monkey') |
696 | 670 |
697 if args.json_results_file: | 671 if args.json_results_file: |
698 json_results.GenerateJsonResultsFile([results], args.json_results_file) | 672 json_results.GenerateJsonResultsFile([results], args.json_results_file) |
699 | 673 |
700 return exit_code | 674 return exit_code |
701 | 675 |
702 | 676 |
703 def _RunPerfTests(args, active_devices): | |
704 """Subcommand of RunTestsCommands which runs perf tests.""" | |
705 perf_options = ProcessPerfTestOptions(args) | |
706 | |
707 # Just save a simple json with a list of test names. | |
708 if perf_options.output_json_list: | |
709 return perf_test_runner.OutputJsonList( | |
710 perf_options.steps, perf_options.output_json_list) | |
711 | |
712 # Just print the results from a single previously executed step. | |
713 if perf_options.print_step: | |
714 return perf_test_runner.PrintTestOutput( | |
715 perf_options.print_step, perf_options.output_chartjson_data, | |
716 perf_options.get_output_dir_archive) | |
717 | |
718 runner_factory, tests, devices = perf_setup.Setup( | |
719 perf_options, active_devices) | |
720 | |
721 # shard=False means that each device will get the full list of tests | |
722 # and then each one will decide their own affinity. | |
723 # shard=True means each device will pop the next test available from a queue, | |
724 # which increases throughput but have no affinity. | |
725 results, _ = test_dispatcher.RunTests( | |
726 tests, runner_factory, devices, shard=False, test_timeout=None, | |
727 num_retries=args.num_retries) | |
728 | |
729 report_results.LogFull( | |
730 results=results, | |
731 test_type='Perf', | |
732 test_package='Perf') | |
733 | |
734 if args.json_results_file: | |
735 json_results.GenerateJsonResultsFile([results], args.json_results_file) | |
736 | |
737 if perf_options.single_step: | |
738 return perf_test_runner.PrintTestOutput('single_step') | |
739 | |
740 perf_test_runner.PrintSummary(tests) | |
741 | |
742 # Always return 0 on the sharding stage. Individual tests exit_code | |
743 # will be returned on the print_step stage. | |
744 return 0 | |
745 | |
746 | |
747 def _RunPythonTests(args): | 677 def _RunPythonTests(args): |
748 """Subcommand of RunTestsCommand which runs python unit tests.""" | 678 """Subcommand of RunTestsCommand which runs python unit tests.""" |
749 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name] | 679 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name] |
750 suite_path = suite_vars['path'] | 680 suite_path = suite_vars['path'] |
751 suite_test_modules = suite_vars['test_modules'] | 681 suite_test_modules = suite_vars['test_modules'] |
752 | 682 |
753 sys.path = [suite_path] + sys.path | 683 sys.path = [suite_path] + sys.path |
754 try: | 684 try: |
755 suite = unittest.TestSuite() | 685 suite = unittest.TestSuite() |
756 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m) | 686 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 def get_devices(): | 758 def get_devices(): |
829 return _GetAttachedDevices(args.blacklist_file, args.test_device, | 759 return _GetAttachedDevices(args.blacklist_file, args.test_device, |
830 args.enable_device_cache, args.num_retries) | 760 args.enable_device_cache, args.num_retries) |
831 | 761 |
832 if command == 'linker': | 762 if command == 'linker': |
833 return _RunLinkerTests(args, get_devices()) | 763 return _RunLinkerTests(args, get_devices()) |
834 elif command == 'junit': | 764 elif command == 'junit': |
835 return _RunJUnitTests(args) | 765 return _RunJUnitTests(args) |
836 elif command == 'monkey': | 766 elif command == 'monkey': |
837 return _RunMonkeyTests(args, get_devices()) | 767 return _RunMonkeyTests(args, get_devices()) |
838 elif command == 'perf': | |
839 return _RunPerfTests(args, get_devices()) | |
840 elif command == 'python': | 768 elif command == 'python': |
841 return _RunPythonTests(args) | 769 return _RunPythonTests(args) |
842 else: | 770 else: |
843 raise Exception('Unknown test type.') | 771 raise Exception('Unknown test type.') |
844 | 772 |
845 | 773 |
846 _SUPPORTED_IN_PLATFORM_MODE = [ | 774 _SUPPORTED_IN_PLATFORM_MODE = [ |
847 # TODO(jbudorick): Add support for more test types. | 775 # TODO(jbudorick): Add support for more test types. |
848 'gtest', | 776 'gtest', |
849 'instrumentation', | 777 'instrumentation', |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 if e.is_infra_error: | 930 if e.is_infra_error: |
1003 return constants.INFRA_EXIT_CODE | 931 return constants.INFRA_EXIT_CODE |
1004 return constants.ERROR_EXIT_CODE | 932 return constants.ERROR_EXIT_CODE |
1005 except: # pylint: disable=W0702 | 933 except: # pylint: disable=W0702 |
1006 logging.exception('Unrecognized error occurred.') | 934 logging.exception('Unrecognized error occurred.') |
1007 return constants.ERROR_EXIT_CODE | 935 return constants.ERROR_EXIT_CODE |
1008 | 936 |
1009 | 937 |
1010 if __name__ == '__main__': | 938 if __name__ == '__main__': |
1011 sys.exit(main()) | 939 sys.exit(main()) |
OLD | NEW |