| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if args.output_directory: | 112 if args.output_directory: |
| 113 constants.SetOutputDirectort(args.output_directory) | 113 constants.SetOutputDirectort(args.output_directory) |
| 114 if args.adb_path: | 114 if args.adb_path: |
| 115 constants.SetAdbPath(args.adb_path) | 115 constants.SetAdbPath(args.adb_path) |
| 116 # Some things such as Forwarder require ADB to be in the environment path. | 116 # Some things such as Forwarder require ADB to be in the environment path. |
| 117 adb_dir = os.path.dirname(constants.GetAdbPath()) | 117 adb_dir = os.path.dirname(constants.GetAdbPath()) |
| 118 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): | 118 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): |
| 119 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH'] | 119 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH'] |
| 120 | 120 |
| 121 | 121 |
| 122 def AddRemoteDeviceOptions(parser): |
| 123 group = parser.add_argument_group('Remote Device Options') |
| 124 |
| 125 group.add_argument('--trigger', default='', |
| 126 help=('Only triggers the test if set. Stores test_run_id ' |
| 127 'in given file path. ')) |
| 128 group.add_argument('--collect', default='', |
| 129 help=('Only collects the test results if set. ' |
| 130 'Gets test_run_id from given file path.')) |
| 131 group.add_argument('--remote-device', default='Nexus 5', |
| 132 help=('Device type to run test on.')) |
| 133 group.add_argument('--remote-device-os', default='4.4.2', |
| 134 help=('OS to have on the device.')) |
| 135 group.add_argument('--results-path', default='', |
| 136 help=('File path to download results to.')) |
| 137 group.add_argument('--api-protocol', |
| 138 help=('HTTP protocol to use. (http or https)')) |
| 139 group.add_argument('--api-address', help=('Address to send HTTP requests.')) |
| 140 group.add_argument('--api-port', help=('Port to send HTTP requests to.')) |
| 141 group.add_argument('--runner-type', default='', |
| 142 help=('Type of test to run as.')) |
| 143 group.add_argument('--runner-package', default='', |
| 144 help=('Package name of test.')) |
| 145 group.add_argument('--apk-under-test', default='apks/Chrome.apk', |
| 146 help=('APK to run tests on.')) |
| 147 |
| 148 api_secret_group = group.add_mutually_exclusive_group() |
| 149 api_secret_group.add_argument('--api-secret', default='', |
| 150 help=('API secret for remote devices.')) |
| 151 api_secret_group.add_argument('--api-secret-file', default='', |
| 152 help=('Path to file that contains API secret.')) |
| 153 |
| 154 api_key_group = group.add_mutually_exclusive_group() |
| 155 api_key_group.add_argument('--api-key', default='', |
| 156 help=('API key for remote devices.')) |
| 157 api_key_group.add_argument('--api-key-file', default='', |
| 158 help=('Path to file that contains API key.')) |
| 159 |
| 160 |
| 122 def AddDeviceOptions(parser): | 161 def AddDeviceOptions(parser): |
| 123 """Adds device options to |parser|.""" | 162 """Adds device options to |parser|.""" |
| 124 group = parser.add_argument_group(title='Device Options') | 163 group = parser.add_argument_group(title='Device Options') |
| 125 group.add_argument('-c', dest='cleanup_test_files', | 164 group.add_argument('-c', dest='cleanup_test_files', |
| 126 help='Cleanup test files on the device after run', | 165 help='Cleanup test files on the device after run', |
| 127 action='store_true') | 166 action='store_true') |
| 128 group.add_argument('--tool', | 167 group.add_argument('--tool', |
| 129 dest='tool', | 168 dest='tool', |
| 130 help=('Run the test under a tool ' | 169 help=('Run the test under a tool ' |
| 131 '(use --tool help to list them)')) | 170 '(use --tool help to list them)')) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 159 group.add_argument('-t', dest='timeout', type=int, default=60, | 198 group.add_argument('-t', dest='timeout', type=int, default=60, |
| 160 help='Timeout to wait for each test ' | 199 help='Timeout to wait for each test ' |
| 161 '(default: %(default)s).') | 200 '(default: %(default)s).') |
| 162 group.add_argument('--isolate_file_path', | 201 group.add_argument('--isolate_file_path', |
| 163 '--isolate-file-path', | 202 '--isolate-file-path', |
| 164 dest='isolate_file_path', | 203 dest='isolate_file_path', |
| 165 help='.isolate file path to override the default ' | 204 help='.isolate file path to override the default ' |
| 166 'path') | 205 'path') |
| 167 AddDeviceOptions(parser) | 206 AddDeviceOptions(parser) |
| 168 AddCommonOptions(parser) | 207 AddCommonOptions(parser) |
| 208 AddRemoteDeviceOptions(parser) |
| 169 | 209 |
| 170 | 210 |
| 171 def AddLinkerTestOptions(parser): | 211 def AddLinkerTestOptions(parser): |
| 172 group = parser.add_argument_group('Linker Test Options') | 212 group = parser.add_argument_group('Linker Test Options') |
| 173 group.add_argument('-f', '--gtest-filter', dest='test_filter', | 213 group.add_argument('-f', '--gtest-filter', dest='test_filter', |
| 174 help='googletest-style filter string.') | 214 help='googletest-style filter string.') |
| 175 AddCommonOptions(parser) | 215 AddCommonOptions(parser) |
| 176 AddDeviceOptions(parser) | 216 AddDeviceOptions(parser) |
| 177 | 217 |
| 178 | 218 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 '--seed', type=int, | 459 '--seed', type=int, |
| 420 help=('Seed value for pseudo-random generator. Same seed value generates ' | 460 help=('Seed value for pseudo-random generator. Same seed value generates ' |
| 421 'the same sequence of events. Seed is randomized by default.')) | 461 'the same sequence of events. Seed is randomized by default.')) |
| 422 group.add_argument( | 462 group.add_argument( |
| 423 '--extra-args', default='', | 463 '--extra-args', default='', |
| 424 help=('String of other args to pass to the command verbatim.')) | 464 help=('String of other args to pass to the command verbatim.')) |
| 425 | 465 |
| 426 AddCommonOptions(parser) | 466 AddCommonOptions(parser) |
| 427 AddDeviceOptions(parser) | 467 AddDeviceOptions(parser) |
| 428 | 468 |
| 429 | |
| 430 def ProcessMonkeyTestOptions(args): | 469 def ProcessMonkeyTestOptions(args): |
| 431 """Processes all monkey test options. | 470 """Processes all monkey test options. |
| 432 | 471 |
| 433 Args: | 472 Args: |
| 434 args: argparse.Namespace object. | 473 args: argparse.Namespace object. |
| 435 | 474 |
| 436 Returns: | 475 Returns: |
| 437 A MonkeyOptions named tuple which contains all options relevant to | 476 A MonkeyOptions named tuple which contains all options relevant to |
| 438 monkey tests. | 477 monkey tests. |
| 439 """ | 478 """ |
| 440 # TODO(jbudorick): Handle this directly in argparse with nargs='+' | 479 # TODO(jbudorick): Handle this directly in argparse with nargs='+' |
| 441 category = args.category | 480 category = args.category |
| 442 if category: | 481 if category: |
| 443 category = args.category.split(',') | 482 category = args.category.split(',') |
| 444 | 483 |
| 445 # TODO(jbudorick): Get rid of MonkeyOptions. | 484 # TODO(jbudorick): Get rid of MonkeyOptions. |
| 446 return monkey_test_options.MonkeyOptions( | 485 return monkey_test_options.MonkeyOptions( |
| 447 args.verbose_count, | 486 args.verbose_count, |
| 448 args.package, | 487 args.package, |
| 449 args.event_count, | 488 args.event_count, |
| 450 category, | 489 category, |
| 451 args.throttle, | 490 args.throttle, |
| 452 args.seed, | 491 args.seed, |
| 453 args.extra_args) | 492 args.extra_args) |
| 454 | 493 |
| 494 def AddUirobotTestOptions(parser): |
| 495 """Adds uirobot test options to |option_parser|.""" |
| 496 group = parser.add_argument_group('Uirobot Test Options') |
| 497 |
| 498 group.add_argument( |
| 499 '--minutes', default=5, type=int, |
| 500 help='Number of minutes to run uirobot test [default: %default].') |
| 501 |
| 502 AddCommonOptions(parser) |
| 503 AddDeviceOptions(parser) |
| 504 AddRemoteDeviceOptions(parser) |
| 455 | 505 |
| 456 def AddPerfTestOptions(parser): | 506 def AddPerfTestOptions(parser): |
| 457 """Adds perf test options to |parser|.""" | 507 """Adds perf test options to |parser|.""" |
| 458 | 508 |
| 459 group = parser.add_argument_group('Perf Test Options') | 509 group = parser.add_argument_group('Perf Test Options') |
| 460 | 510 |
| 461 class SingleStepAction(argparse.Action): | 511 class SingleStepAction(argparse.Action): |
| 462 def __call__(self, parser, namespace, values, option_string=None): | 512 def __call__(self, parser, namespace, values, option_string=None): |
| 463 if values and not namespace.single_step: | 513 if values and not namespace.single_step: |
| 464 parser.error('single step command provided, ' | 514 parser.error('single step command provided, ' |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 | 855 |
| 806 Raises: | 856 Raises: |
| 807 Exception: Unknown command name passed in, or an exception from an | 857 Exception: Unknown command name passed in, or an exception from an |
| 808 individual test runner. | 858 individual test runner. |
| 809 """ | 859 """ |
| 810 command = args.command | 860 command = args.command |
| 811 | 861 |
| 812 ProcessCommonOptions(args) | 862 ProcessCommonOptions(args) |
| 813 | 863 |
| 814 if args.enable_platform_mode: | 864 if args.enable_platform_mode: |
| 815 return RunTestsInPlatformMode(args, parser.error) | 865 return RunTestsInPlatformMode(args, parser) |
| 816 | 866 |
| 817 if command in constants.LOCAL_MACHINE_TESTS: | 867 if command in constants.LOCAL_MACHINE_TESTS: |
| 818 devices = [] | 868 devices = [] |
| 819 else: | 869 else: |
| 820 devices = _GetAttachedDevices(args.test_device) | 870 devices = _GetAttachedDevices(args.test_device) |
| 821 | 871 |
| 822 forwarder.Forwarder.RemoveHostLog() | 872 forwarder.Forwarder.RemoveHostLog() |
| 823 if not ports.ResetTestServerPortAllocation(): | 873 if not ports.ResetTestServerPortAllocation(): |
| 824 raise Exception('Failed to reset test server port.') | 874 raise Exception('Failed to reset test server port.') |
| 825 | 875 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 838 elif command == 'perf': | 888 elif command == 'perf': |
| 839 return _RunPerfTests(args) | 889 return _RunPerfTests(args) |
| 840 elif command == 'python': | 890 elif command == 'python': |
| 841 return _RunPythonTests(args) | 891 return _RunPythonTests(args) |
| 842 else: | 892 else: |
| 843 raise Exception('Unknown test type.') | 893 raise Exception('Unknown test type.') |
| 844 | 894 |
| 845 | 895 |
| 846 _SUPPORTED_IN_PLATFORM_MODE = [ | 896 _SUPPORTED_IN_PLATFORM_MODE = [ |
| 847 # TODO(jbudorick): Add support for more test types. | 897 # TODO(jbudorick): Add support for more test types. |
| 848 'gtest', | 898 'gtest', 'uirobot', |
| 849 ] | 899 ] |
| 850 | 900 |
| 851 | 901 |
| 852 def RunTestsInPlatformMode(args, parser): | 902 def RunTestsInPlatformMode(args, parser): |
| 853 | 903 |
| 854 if args.command not in _SUPPORTED_IN_PLATFORM_MODE: | 904 if args.command not in _SUPPORTED_IN_PLATFORM_MODE: |
| 855 parser.error('%s is not yet supported in platform mode' % args.command) | 905 parser.error('%s is not yet supported in platform mode' % args.command) |
| 856 | 906 |
| 857 with environment_factory.CreateEnvironment(args, parser.error) as env: | 907 with environment_factory.CreateEnvironment(args, parser.error) as env: |
| 858 with test_instance_factory.CreateTestInstance(args, parser.error) as test: | 908 with test_instance_factory.CreateTestInstance(args, parser.error) as test: |
| 859 with test_run_factory.CreateTestRun( | 909 with test_run_factory.CreateTestRun( |
| 860 args, env, test, parser.error) as test_run: | 910 args, env, test, parser.error) as test_run: |
| 861 results = test_run.RunTests() | 911 results = test_run.RunTests() |
| 862 | 912 |
| 913 if args.trigger: |
| 914 return 0 # Not returning results, only triggering. |
| 915 |
| 863 report_results.LogFull( | 916 report_results.LogFull( |
| 864 results=results, | 917 results=results, |
| 865 test_type=test.TestType(), | 918 test_type=test.TestType(), |
| 866 test_package=test_run.TestPackage(), | 919 test_package=test_run.TestPackage(), |
| 867 annotation=getattr(args, 'annotations', None), | 920 annotation=getattr(args, 'annotations', None), |
| 868 flakiness_server=getattr(args, 'flakiness_dashboard_server', None)) | 921 flakiness_server=getattr(args, 'flakiness_dashboard_server', None)) |
| 869 | 922 |
| 870 if args.json_results_file: | 923 if args.json_results_file: |
| 871 json_results.GenerateJsonResultsFile( | 924 json_results.GenerateJsonResultsFile( |
| 872 results, args.json_results_file) | 925 results, args.json_results_file) |
| 873 | 926 |
| 874 return results | 927 return 0 if results.DidRunPass() else 1 |
| 875 | 928 |
| 876 | 929 |
| 877 CommandConfigTuple = collections.namedtuple( | 930 CommandConfigTuple = collections.namedtuple( |
| 878 'CommandConfigTuple', | 931 'CommandConfigTuple', |
| 879 ['add_options_func', 'help_txt']) | 932 ['add_options_func', 'help_txt']) |
| 880 VALID_COMMANDS = { | 933 VALID_COMMANDS = { |
| 881 'gtest': CommandConfigTuple( | 934 'gtest': CommandConfigTuple( |
| 882 AddGTestOptions, | 935 AddGTestOptions, |
| 883 'googletest-based C++ tests'), | 936 'googletest-based C++ tests'), |
| 884 'instrumentation': CommandConfigTuple( | 937 'instrumentation': CommandConfigTuple( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 895 "Tests based on Android's monkey"), | 948 "Tests based on Android's monkey"), |
| 896 'perf': CommandConfigTuple( | 949 'perf': CommandConfigTuple( |
| 897 AddPerfTestOptions, | 950 AddPerfTestOptions, |
| 898 'Performance tests'), | 951 'Performance tests'), |
| 899 'python': CommandConfigTuple( | 952 'python': CommandConfigTuple( |
| 900 AddPythonTestOptions, | 953 AddPythonTestOptions, |
| 901 'Python tests based on unittest.TestCase'), | 954 'Python tests based on unittest.TestCase'), |
| 902 'linker': CommandConfigTuple( | 955 'linker': CommandConfigTuple( |
| 903 AddLinkerTestOptions, | 956 AddLinkerTestOptions, |
| 904 'Linker tests'), | 957 'Linker tests'), |
| 958 'uirobot': CommandConfigTuple( |
| 959 AddUirobotTestOptions, |
| 960 'Uirobot test'), |
| 905 } | 961 } |
| 906 | 962 |
| 907 | 963 |
| 908 def DumpThreadStacks(_signal, _frame): | 964 def DumpThreadStacks(_signal, _frame): |
| 909 for thread in threading.enumerate(): | 965 for thread in threading.enumerate(): |
| 910 reraiser_thread.LogThreadStack(thread) | 966 reraiser_thread.LogThreadStack(thread) |
| 911 | 967 |
| 912 | 968 |
| 913 def main(): | 969 def main(): |
| 914 signal.signal(signal.SIGUSR1, DumpThreadStacks) | 970 signal.signal(signal.SIGUSR1, DumpThreadStacks) |
| 915 | 971 |
| 916 parser = argparse.ArgumentParser() | 972 parser = argparse.ArgumentParser() |
| 917 command_parsers = parser.add_subparsers(title='test types', | 973 command_parsers = parser.add_subparsers(title='test types', |
| 918 dest='command') | 974 dest='command') |
| 919 | 975 |
| 920 for test_type, config in sorted(VALID_COMMANDS.iteritems(), | 976 for test_type, config in sorted(VALID_COMMANDS.iteritems(), |
| 921 key=lambda x: x[0]): | 977 key=lambda x: x[0]): |
| 922 subparser = command_parsers.add_parser( | 978 subparser = command_parsers.add_parser( |
| 923 test_type, usage='%(prog)s [options]', help=config.help_txt) | 979 test_type, usage='%(prog)s [options]', help=config.help_txt) |
| 924 config.add_options_func(subparser) | 980 config.add_options_func(subparser) |
| 925 | 981 |
| 926 args = parser.parse_args() | 982 args = parser.parse_args() |
| 927 return RunTestsCommand(args, parser) | 983 return RunTestsCommand(args, parser) |
| 928 | 984 |
| 929 | 985 |
| 930 if __name__ == '__main__': | 986 if __name__ == '__main__': |
| 931 sys.exit(main()) | 987 sys.exit(main()) |
| OLD | NEW |