| 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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 'Did not find device %s among attached device. Attached devices: %s' | 906 'Did not find device %s among attached device. Attached devices: %s' |
| 907 % (test_device, ', '.join(attached_devices))) | 907 % (test_device, ', '.join(attached_devices))) |
| 908 return test_device | 908 return test_device |
| 909 | 909 |
| 910 else: | 910 else: |
| 911 if not attached_devices: | 911 if not attached_devices: |
| 912 raise device_errors.NoDevicesError() | 912 raise device_errors.NoDevicesError() |
| 913 return sorted(attached_devices) | 913 return sorted(attached_devices) |
| 914 | 914 |
| 915 | 915 |
| 916 def RunTestsCommand(args, parser): # pylint: disable=too-many-return-statements | 916 def RunTestsCommand(args): # pylint: disable=too-many-return-statements |
| 917 """Checks test type and dispatches to the appropriate function. | 917 """Checks test type and dispatches to the appropriate function. |
| 918 | 918 |
| 919 Args: | 919 Args: |
| 920 args: argparse.Namespace object. | 920 args: argparse.Namespace object. |
| 921 parser: argparse.ArgumentParser object. | |
| 922 | 921 |
| 923 Returns: | 922 Returns: |
| 924 Integer indicated exit code. | 923 Integer indicated exit code. |
| 925 | 924 |
| 926 Raises: | 925 Raises: |
| 927 Exception: Unknown command name passed in, or an exception from an | 926 Exception: Unknown command name passed in, or an exception from an |
| 928 individual test runner. | 927 individual test runner. |
| 929 """ | 928 """ |
| 930 command = args.command | 929 command = args.command |
| 931 | 930 |
| 932 ProcessCommonOptions(args) | 931 ProcessCommonOptions(args) |
| 933 | 932 |
| 934 if args.enable_platform_mode: | 933 if args.enable_platform_mode: |
| 935 return RunTestsInPlatformMode(args, parser) | 934 return RunTestsInPlatformMode(args) |
| 936 | 935 |
| 937 forwarder.Forwarder.RemoveHostLog() | 936 forwarder.Forwarder.RemoveHostLog() |
| 938 if not ports.ResetTestServerPortAllocation(): | 937 if not ports.ResetTestServerPortAllocation(): |
| 939 raise Exception('Failed to reset test server port.') | 938 raise Exception('Failed to reset test server port.') |
| 940 | 939 |
| 941 def get_devices(): | 940 def get_devices(): |
| 942 return _GetAttachedDevices(args.blacklist_file, args.test_device, | 941 return _GetAttachedDevices(args.blacklist_file, args.test_device, |
| 943 args.enable_device_cache) | 942 args.enable_device_cache) |
| 944 | 943 |
| 945 if command == 'gtest': | 944 if command == 'gtest': |
| 946 return RunTestsInPlatformMode(args, parser) | 945 return RunTestsInPlatformMode(args) |
| 947 elif command == 'linker': | 946 elif command == 'linker': |
| 948 return _RunLinkerTests(args, get_devices()) | 947 return _RunLinkerTests(args, get_devices()) |
| 949 elif command == 'instrumentation': | 948 elif command == 'instrumentation': |
| 950 return _RunInstrumentationTests(args, get_devices()) | 949 return _RunInstrumentationTests(args, get_devices()) |
| 951 elif command == 'junit': | 950 elif command == 'junit': |
| 952 return _RunJUnitTests(args) | 951 return _RunJUnitTests(args) |
| 953 elif command == 'monkey': | 952 elif command == 'monkey': |
| 954 return _RunMonkeyTests(args, get_devices()) | 953 return _RunMonkeyTests(args, get_devices()) |
| 955 elif command == 'perf': | 954 elif command == 'perf': |
| 956 return _RunPerfTests(args, get_devices()) | 955 return _RunPerfTests(args, get_devices()) |
| 957 elif command == 'python': | 956 elif command == 'python': |
| 958 return _RunPythonTests(args) | 957 return _RunPythonTests(args) |
| 959 else: | 958 else: |
| 960 raise Exception('Unknown test type.') | 959 raise Exception('Unknown test type.') |
| 961 | 960 |
| 962 | 961 |
| 963 _SUPPORTED_IN_PLATFORM_MODE = [ | 962 _SUPPORTED_IN_PLATFORM_MODE = [ |
| 964 # TODO(jbudorick): Add support for more test types. | 963 # TODO(jbudorick): Add support for more test types. |
| 965 'gtest', | 964 'gtest', |
| 966 'instrumentation', | 965 'instrumentation', |
| 967 'uirobot', | 966 'uirobot', |
| 968 ] | 967 ] |
| 969 | 968 |
| 970 | 969 |
| 971 def RunTestsInPlatformMode(args, parser): | 970 def RunTestsInPlatformMode(args): |
| 972 | 971 |
| 973 def infra_error(message): | 972 def infra_error(message): |
| 974 parser.exit(status=constants.INFRA_EXIT_CODE, message=message) | 973 logging.fatal(message) |
| 974 sys.exit(constants.INFRA_EXIT_CODE) |
| 975 | 975 |
| 976 if args.command not in _SUPPORTED_IN_PLATFORM_MODE: | 976 if args.command not in _SUPPORTED_IN_PLATFORM_MODE: |
| 977 infra_error('%s is not yet supported in platform mode' % args.command) | 977 infra_error('%s is not yet supported in platform mode' % args.command) |
| 978 | 978 |
| 979 with environment_factory.CreateEnvironment(args, infra_error) as env: | 979 with environment_factory.CreateEnvironment(args, infra_error) as env: |
| 980 with test_instance_factory.CreateTestInstance(args, infra_error) as test: | 980 with test_instance_factory.CreateTestInstance(args, infra_error) as test: |
| 981 with test_run_factory.CreateTestRun( | 981 with test_run_factory.CreateTestRun( |
| 982 args, env, test, infra_error) as test_run: | 982 args, env, test, infra_error) as test_run: |
| 983 results = [] | 983 results = [] |
| 984 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 | 984 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 | 1081 |
| 1082 for test_type, config in sorted(VALID_COMMANDS.iteritems(), | 1082 for test_type, config in sorted(VALID_COMMANDS.iteritems(), |
| 1083 key=lambda x: x[0]): | 1083 key=lambda x: x[0]): |
| 1084 subparser = command_parsers.add_parser( | 1084 subparser = command_parsers.add_parser( |
| 1085 test_type, usage='%(prog)s [options]', help=config.help_txt) | 1085 test_type, usage='%(prog)s [options]', help=config.help_txt) |
| 1086 config.add_options_func(subparser) | 1086 config.add_options_func(subparser) |
| 1087 | 1087 |
| 1088 args = parser.parse_args() | 1088 args = parser.parse_args() |
| 1089 | 1089 |
| 1090 try: | 1090 try: |
| 1091 return RunTestsCommand(args, parser) | 1091 return RunTestsCommand(args) |
| 1092 except base_error.BaseError as e: | 1092 except base_error.BaseError as e: |
| 1093 logging.exception('Error occurred.') | 1093 logging.exception('Error occurred.') |
| 1094 if e.is_infra_error: | 1094 if e.is_infra_error: |
| 1095 return constants.INFRA_EXIT_CODE | 1095 return constants.INFRA_EXIT_CODE |
| 1096 return constants.ERROR_EXIT_CODE | 1096 return constants.ERROR_EXIT_CODE |
| 1097 except: # pylint: disable=W0702 | 1097 except: # pylint: disable=W0702 |
| 1098 logging.exception('Unrecognized error occurred.') | 1098 logging.exception('Unrecognized error occurred.') |
| 1099 return constants.ERROR_EXIT_CODE | 1099 return constants.ERROR_EXIT_CODE |
| 1100 | 1100 |
| 1101 | 1101 |
| 1102 if __name__ == '__main__': | 1102 if __name__ == '__main__': |
| 1103 sys.exit(main()) | 1103 sys.exit(main()) |
| OLD | NEW |