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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 group.add_argument( | 587 group.add_argument( |
588 '--max-battery-temp', type=int, | 588 '--max-battery-temp', type=int, |
589 help='Only start tests when the battery is at or below the given ' | 589 help='Only start tests when the battery is at or below the given ' |
590 'temperature (0.1 C)') | 590 'temperature (0.1 C)') |
591 group.add_argument('single_step_command', nargs='*', action=SingleStepAction, | 591 group.add_argument('single_step_command', nargs='*', action=SingleStepAction, |
592 help='If --single-step is specified, the command to run.') | 592 help='If --single-step is specified, the command to run.') |
593 group.add_argument('--min-battery-level', type=int, | 593 group.add_argument('--min-battery-level', type=int, |
594 help='Only starts tests when the battery is charged above ' | 594 help='Only starts tests when the battery is charged above ' |
595 'given level.') | 595 'given level.') |
596 group.add_argument('--known-devices-file', help='Path to known device list.') | 596 group.add_argument('--known-devices-file', help='Path to known device list.') |
597 group.add_argument( | |
598 '--repeat', dest='repeat', type=int, default=0, | |
599 help='Number of times to repeat the specified set of tests.') | |
600 group.add_argument('--break-on-failure', '--break_on_failure', | |
601 dest='break_on_failure', action='store_true', | |
602 help='Whether to break on failure.') | |
603 | |
597 AddCommonOptions(parser) | 604 AddCommonOptions(parser) |
598 AddDeviceOptions(parser) | 605 AddDeviceOptions(parser) |
599 | 606 |
600 | 607 |
601 def ProcessPerfTestOptions(args): | 608 def ProcessPerfTestOptions(args): |
602 """Processes all perf test options. | 609 """Processes all perf test options. |
603 | 610 |
604 Args: | 611 Args: |
605 args: argparse.Namespace object. | 612 args: argparse.Namespace object. |
606 | 613 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 results=results, | 686 results=results, |
680 test_type='Monkey', | 687 test_type='Monkey', |
681 test_package='Monkey') | 688 test_package='Monkey') |
682 | 689 |
683 if args.json_results_file: | 690 if args.json_results_file: |
684 json_results.GenerateJsonResultsFile([results], args.json_results_file) | 691 json_results.GenerateJsonResultsFile([results], args.json_results_file) |
685 | 692 |
686 return exit_code | 693 return exit_code |
687 | 694 |
688 | 695 |
696 def RunPerfTestsInPlatformMode(args): | |
697 def infra_error(message): | |
698 logging.fatal(message) | |
699 sys.exit(constants.INFRA_EXIT_CODE) | |
700 | |
701 if args.single_step or args.steps: | |
702 return RunTestsInPlatformMode(args) | |
703 | |
704 # These are not full perf test runs, they are for printing out past runs or | |
705 # lists of tests. As such, they do not require the retry logic or results | |
706 # logic. They only need to perform the action required and return the correct | |
707 # return code. | |
708 with environment_factory.CreateEnvironment(args, infra_error) as env: | |
709 with test_instance_factory.CreateTestInstance(args, infra_error) as test: | |
710 with test_run_factory.CreateTestRun( | |
711 args, env, test, infra_error) as test_run: | |
712 return test_run.RunTests() | |
mikecase (-- gone --)
2016/06/01 17:40:28
Not sure I 100% sure I get what this does.
rnephew (Reviews Here)
2016/06/01 20:32:05
Talked offline about it. Also, before landing this
| |
713 | |
689 def _RunPerfTests(args, active_devices): | 714 def _RunPerfTests(args, active_devices): |
690 """Subcommand of RunTestsCommands which runs perf tests.""" | 715 """Subcommand of RunTestsCommands which runs perf tests.""" |
691 perf_options = ProcessPerfTestOptions(args) | 716 perf_options = ProcessPerfTestOptions(args) |
692 | 717 |
693 # Just save a simple json with a list of test names. | 718 # Just save a simple json with a list of test names. |
694 if perf_options.output_json_list: | 719 if perf_options.output_json_list: |
695 return perf_test_runner.OutputJsonList( | 720 return perf_test_runner.OutputJsonList( |
696 perf_options.steps, perf_options.output_json_list) | 721 perf_options.steps, perf_options.output_json_list) |
697 | 722 |
698 # Just print the results from a single previously executed step. | 723 # Just print the results from a single previously executed step. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 Exception: Unknown command name passed in, or an exception from an | 817 Exception: Unknown command name passed in, or an exception from an |
793 individual test runner. | 818 individual test runner. |
794 """ | 819 """ |
795 command = args.command | 820 command = args.command |
796 | 821 |
797 ProcessCommonOptions(args) | 822 ProcessCommonOptions(args) |
798 logging.info('command: %s', ' '.join(sys.argv)) | 823 logging.info('command: %s', ' '.join(sys.argv)) |
799 | 824 |
800 if args.enable_platform_mode or command in ('gtest', 'instrumentation'): | 825 if args.enable_platform_mode or command in ('gtest', 'instrumentation'): |
801 return RunTestsInPlatformMode(args) | 826 return RunTestsInPlatformMode(args) |
827 if command == 'perf': | |
828 return RunPerfTestsInPlatformMode(args) | |
802 | 829 |
803 forwarder.Forwarder.RemoveHostLog() | 830 forwarder.Forwarder.RemoveHostLog() |
804 if not ports.ResetTestServerPortAllocation(): | 831 if not ports.ResetTestServerPortAllocation(): |
805 raise Exception('Failed to reset test server port.') | 832 raise Exception('Failed to reset test server port.') |
806 | 833 |
807 def get_devices(): | 834 def get_devices(): |
808 return _GetAttachedDevices(args.blacklist_file, args.test_device, | 835 return _GetAttachedDevices(args.blacklist_file, args.test_device, |
809 args.enable_device_cache, args.num_retries) | 836 args.enable_device_cache, args.num_retries) |
810 | 837 |
811 if command == 'linker': | 838 if command == 'linker': |
812 return _RunLinkerTests(args, get_devices()) | 839 return _RunLinkerTests(args, get_devices()) |
813 elif command == 'junit': | 840 elif command == 'junit': |
814 return _RunJUnitTests(args) | 841 return _RunJUnitTests(args) |
815 elif command == 'monkey': | 842 elif command == 'monkey': |
816 return _RunMonkeyTests(args, get_devices()) | 843 return _RunMonkeyTests(args, get_devices()) |
817 elif command == 'perf': | 844 elif command == 'perf': |
818 return _RunPerfTests(args, get_devices()) | 845 return _RunPerfTests(args, get_devices()) |
819 elif command == 'python': | 846 elif command == 'python': |
820 return _RunPythonTests(args) | 847 return _RunPythonTests(args) |
821 else: | 848 else: |
822 raise Exception('Unknown test type.') | 849 raise Exception('Unknown test type.') |
823 | 850 |
824 | 851 |
825 _SUPPORTED_IN_PLATFORM_MODE = [ | 852 _SUPPORTED_IN_PLATFORM_MODE = [ |
826 # TODO(jbudorick): Add support for more test types. | 853 # TODO(jbudorick): Add support for more test types. |
827 'gtest', | 854 'gtest', |
828 'instrumentation', | 855 'instrumentation', |
829 'uirobot', | 856 'uirobot', |
857 'perf', | |
mikecase (-- gone --)
2016/06/01 17:40:28
super nit: alphabetize
rnephew (Reviews Here)
2016/06/01 20:32:05
Done.
| |
830 ] | 858 ] |
831 | 859 |
832 | 860 |
833 def RunTestsInPlatformMode(args): | 861 def RunTestsInPlatformMode(args): |
834 | 862 |
835 def infra_error(message): | 863 def infra_error(message): |
836 logging.fatal(message) | 864 logging.fatal(message) |
837 sys.exit(constants.INFRA_EXIT_CODE) | 865 sys.exit(constants.INFRA_EXIT_CODE) |
838 | 866 |
839 if args.command not in _SUPPORTED_IN_PLATFORM_MODE: | 867 if args.command not in _SUPPORTED_IN_PLATFORM_MODE: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 if e.is_infra_error: | 1005 if e.is_infra_error: |
978 return constants.INFRA_EXIT_CODE | 1006 return constants.INFRA_EXIT_CODE |
979 return constants.ERROR_EXIT_CODE | 1007 return constants.ERROR_EXIT_CODE |
980 except: # pylint: disable=W0702 | 1008 except: # pylint: disable=W0702 |
981 logging.exception('Unrecognized error occurred.') | 1009 logging.exception('Unrecognized error occurred.') |
982 return constants.ERROR_EXIT_CODE | 1010 return constants.ERROR_EXIT_CODE |
983 | 1011 |
984 | 1012 |
985 if __name__ == '__main__': | 1013 if __name__ == '__main__': |
986 sys.exit(main()) | 1014 sys.exit(main()) |
OLD | NEW |