| 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 collections | 9 import collections |
| 10 import logging | 10 import logging |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 constants.SetAdbPath(options.adb_path) | 109 constants.SetAdbPath(options.adb_path) |
| 110 # Some things such as Forwarder require ADB to be in the environment path. | 110 # Some things such as Forwarder require ADB to be in the environment path. |
| 111 adb_dir = os.path.dirname(constants.GetAdbPath()) | 111 adb_dir = os.path.dirname(constants.GetAdbPath()) |
| 112 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): | 112 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): |
| 113 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH'] | 113 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH'] |
| 114 if options.environment not in constants.VALID_ENVIRONMENTS: | 114 if options.environment not in constants.VALID_ENVIRONMENTS: |
| 115 error_func('--environment must be one of: %s' % | 115 error_func('--environment must be one of: %s' % |
| 116 ', '.join(constants.VALID_ENVIRONMENTS)) | 116 ', '.join(constants.VALID_ENVIRONMENTS)) |
| 117 | 117 |
| 118 | 118 |
| 119 def AddRemoteDeviceOptions(option_parser): |
| 120 group = optparse.OptionGroup(option_parser, 'Remote Device Options') |
| 121 group.add_option('--remote-device', default='Nexus 5', type='string', |
| 122 help=('Device type to run test on.')) |
| 123 group.add_option('--remote-device-os', default='4.4.2', type='string', |
| 124 help=('OS to have on the device.')) |
| 125 group.add_option('--api-key', default='', type='string', |
| 126 help=('API key for remote devices. Overrides api-key-file')) |
| 127 group.add_option('--api-secret', default='', type='string', |
| 128 help=('API secret for remote devices. ' |
| 129 'Overrides api-secret-file')) |
| 130 group.add_option('--api-key-file', default='', type='string', |
| 131 help=('Path to file that contains API key.')) |
| 132 group.add_option('--api-secret-file', default='', type='string', |
| 133 help=('Path to file that contains API secret.')) |
| 134 group.add_option('--results-path', default='', type='string', |
| 135 help=('File path to download results to.')) |
| 136 group.add_option('--api-protocol', default='http', type='string', |
| 137 help=('HTTP protocol to use. (http or https)')) |
| 138 group.add_option('--api-address', default='172.22.21.180', type='string', |
| 139 help=('Address to send HTTP requests.')) |
| 140 group.add_option('--runner-type', default='', type='string', |
| 141 help=('Type of test to run as.')) |
| 142 group.add_option('--runner-package', default='', type='string', |
| 143 help=('Package name of test.')) |
| 144 group.add_option('--apk-under-test', default='apks/Chrome.apk', type='string', |
| 145 help=('APK to run tests on.')) |
| 146 option_parser.add_option_group(group) |
| 147 |
| 148 |
| 119 def AddDeviceOptions(option_parser): | 149 def AddDeviceOptions(option_parser): |
| 120 group = optparse.OptionGroup(option_parser, 'Device Options') | 150 group = optparse.OptionGroup(option_parser, 'Device Options') |
| 121 group.add_option('-c', dest='cleanup_test_files', | 151 group.add_option('-c', dest='cleanup_test_files', |
| 122 help='Cleanup test files on the device after run', | 152 help='Cleanup test files on the device after run', |
| 123 action='store_true') | 153 action='store_true') |
| 124 group.add_option('--tool', | 154 group.add_option('--tool', |
| 125 dest='tool', | 155 dest='tool', |
| 126 help=('Run the test under a tool ' | 156 help=('Run the test under a tool ' |
| 127 '(use --tool help to list them)')) | 157 '(use --tool help to list them)')) |
| 128 group.add_option('-d', '--device', dest='test_device', | 158 group.add_option('-d', '--device', dest='test_device', |
| (...skipping 29 matching lines...) Expand all Loading... |
| 158 default=60) | 188 default=60) |
| 159 option_parser.add_option('--isolate_file_path', | 189 option_parser.add_option('--isolate_file_path', |
| 160 '--isolate-file-path', | 190 '--isolate-file-path', |
| 161 dest='isolate_file_path', | 191 dest='isolate_file_path', |
| 162 help='.isolate file path to override the default ' | 192 help='.isolate file path to override the default ' |
| 163 'path') | 193 'path') |
| 164 # TODO(gkanwar): Move these to Common Options once we have the plumbing | 194 # TODO(gkanwar): Move these to Common Options once we have the plumbing |
| 165 # in our other test types to handle these commands | 195 # in our other test types to handle these commands |
| 166 AddCommonOptions(option_parser) | 196 AddCommonOptions(option_parser) |
| 167 AddDeviceOptions(option_parser) | 197 AddDeviceOptions(option_parser) |
| 198 AddRemoteDeviceOptions(option_parser) |
| 168 | 199 |
| 169 | 200 |
| 170 def AddLinkerTestOptions(option_parser): | 201 def AddLinkerTestOptions(option_parser): |
| 171 option_parser.usage = '%prog linker' | 202 option_parser.usage = '%prog linker' |
| 172 option_parser.commands_dict = {} | 203 option_parser.commands_dict = {} |
| 173 option_parser.example = '%prog linker' | 204 option_parser.example = '%prog linker' |
| 174 | 205 |
| 175 option_parser.add_option('-f', '--gtest-filter', dest='test_filter', | 206 option_parser.add_option('-f', '--gtest-filter', dest='test_filter', |
| 176 help='googletest-style filter string.') | 207 help='googletest-style filter string.') |
| 177 AddCommonOptions(option_parser) | 208 AddCommonOptions(option_parser) |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 return monkey_test_options.MonkeyOptions( | 544 return monkey_test_options.MonkeyOptions( |
| 514 options.verbose_count, | 545 options.verbose_count, |
| 515 options.package, | 546 options.package, |
| 516 options.event_count, | 547 options.event_count, |
| 517 category, | 548 category, |
| 518 options.throttle, | 549 options.throttle, |
| 519 options.seed, | 550 options.seed, |
| 520 options.extra_args) | 551 options.extra_args) |
| 521 | 552 |
| 522 | 553 |
| 554 def AddUirobotTestOptions(option_parser): |
| 555 """Adds uirobot test options to |option_parser|.""" |
| 556 |
| 557 option_parser.usage = '%prog uirobot [options]' |
| 558 option_parser.commands_dict = {} |
| 559 option_parser.example = ( |
| 560 '%prog monkey --minutes=1') |
| 561 |
| 562 option_parser.add_option( |
| 563 '--minutes', default=5, type='string', |
| 564 help='Number of minutes to run uirobot test [default: %default].') |
| 565 |
| 566 AddCommonOptions(option_parser) |
| 567 AddDeviceOptions(option_parser) |
| 568 AddRemoteDeviceOptions(option_parser) |
| 569 |
| 523 def AddPerfTestOptions(option_parser): | 570 def AddPerfTestOptions(option_parser): |
| 524 """Adds perf test options to |option_parser|.""" | 571 """Adds perf test options to |option_parser|.""" |
| 525 | 572 |
| 526 option_parser.usage = '%prog perf [options]' | 573 option_parser.usage = '%prog perf [options]' |
| 527 option_parser.commands_dict = {} | 574 option_parser.commands_dict = {} |
| 528 option_parser.example = ('%prog perf ' | 575 option_parser.example = ('%prog perf ' |
| 529 '[--single-step -- command args] or ' | 576 '[--single-step -- command args] or ' |
| 530 '[--steps perf_steps.json] or ' | 577 '[--steps perf_steps.json] or ' |
| 531 '[--print-step step]') | 578 '[--print-step step]') |
| 532 | 579 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 elif command == 'perf': | 955 elif command == 'perf': |
| 909 return _RunPerfTests(options, args, option_parser.error) | 956 return _RunPerfTests(options, args, option_parser.error) |
| 910 elif command == 'python': | 957 elif command == 'python': |
| 911 return _RunPythonTests(options, option_parser.error) | 958 return _RunPythonTests(options, option_parser.error) |
| 912 else: | 959 else: |
| 913 raise Exception('Unknown test type.') | 960 raise Exception('Unknown test type.') |
| 914 | 961 |
| 915 | 962 |
| 916 _SUPPORTED_IN_PLATFORM_MODE = [ | 963 _SUPPORTED_IN_PLATFORM_MODE = [ |
| 917 # TODO(jbudorick): Add support for more test types. | 964 # TODO(jbudorick): Add support for more test types. |
| 918 'gtest', | 965 'gtest', 'uirobot', |
| 919 ] | 966 ] |
| 920 | 967 |
| 921 | 968 |
| 922 def RunTestsInPlatformMode(command, options, option_parser): | 969 def RunTestsInPlatformMode(command, options, option_parser): |
| 923 | 970 |
| 924 if command not in _SUPPORTED_IN_PLATFORM_MODE: | 971 if command not in _SUPPORTED_IN_PLATFORM_MODE: |
| 925 option_parser.error('%s is not yet supported in platform mode' % command) | 972 option_parser.error('%s is not yet supported in platform mode' % command) |
| 926 | 973 |
| 927 with environment_factory.CreateEnvironment( | 974 with environment_factory.CreateEnvironment( |
| 928 command, options, option_parser.error) as env: | 975 command, options, option_parser.error) as env: |
| 929 with test_instance_factory.CreateTestInstance( | 976 with test_instance_factory.CreateTestInstance( |
| 930 command, options, option_parser.error) as test: | 977 command, options, option_parser.error) as test: |
| 931 with test_run_factory.CreateTestRun( | 978 with test_run_factory.CreateTestRun( |
| 932 options, env, test, option_parser.error) as test_run: | 979 options, env, test, option_parser.error) as test_run: |
| 933 results = test_run.RunTests() | 980 results = test_run.RunTest() |
| 934 | 981 |
| 935 report_results.LogFull( | 982 report_results.LogFull( |
| 936 results=results, | 983 results=results, |
| 937 test_type=test.TestType(), | 984 test_type=test.TestType(), |
| 938 test_package=test_run.TestPackage(), | 985 test_package=test_run.TestPackage(), |
| 939 annotation=options.annotations, | 986 annotation=options.annotations, |
| 940 flakiness_server=options.flakiness_dashboard_server) | 987 flakiness_server=options.flakiness_dashboard_server) |
| 941 | 988 |
| 942 return results | 989 return results |
| 943 | 990 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 'junit': CommandFunctionTuple( | 1044 'junit': CommandFunctionTuple( |
| 998 AddJUnitTestOptions, RunTestsCommand), | 1045 AddJUnitTestOptions, RunTestsCommand), |
| 999 'monkey': CommandFunctionTuple( | 1046 'monkey': CommandFunctionTuple( |
| 1000 AddMonkeyTestOptions, RunTestsCommand), | 1047 AddMonkeyTestOptions, RunTestsCommand), |
| 1001 'perf': CommandFunctionTuple( | 1048 'perf': CommandFunctionTuple( |
| 1002 AddPerfTestOptions, RunTestsCommand), | 1049 AddPerfTestOptions, RunTestsCommand), |
| 1003 'python': CommandFunctionTuple( | 1050 'python': CommandFunctionTuple( |
| 1004 AddPythonTestOptions, RunTestsCommand), | 1051 AddPythonTestOptions, RunTestsCommand), |
| 1005 'linker': CommandFunctionTuple( | 1052 'linker': CommandFunctionTuple( |
| 1006 AddLinkerTestOptions, RunTestsCommand), | 1053 AddLinkerTestOptions, RunTestsCommand), |
| 1054 'uirobot': CommandFunctionTuple( |
| 1055 AddUirobotTestOptions, RunTestsCommand), |
| 1007 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 1056 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
| 1008 } | 1057 } |
| 1009 | 1058 |
| 1010 | 1059 |
| 1011 def DumpThreadStacks(_signal, _frame): | 1060 def DumpThreadStacks(_signal, _frame): |
| 1012 for thread in threading.enumerate(): | 1061 for thread in threading.enumerate(): |
| 1013 reraiser_thread.LogThreadStack(thread) | 1062 reraiser_thread.LogThreadStack(thread) |
| 1014 | 1063 |
| 1015 | 1064 |
| 1016 def main(): | 1065 def main(): |
| 1017 signal.signal(signal.SIGUSR1, DumpThreadStacks) | 1066 signal.signal(signal.SIGUSR1, DumpThreadStacks) |
| 1018 option_parser = command_option_parser.CommandOptionParser( | 1067 option_parser = command_option_parser.CommandOptionParser( |
| 1019 commands_dict=VALID_COMMANDS) | 1068 commands_dict=VALID_COMMANDS) |
| 1020 return command_option_parser.ParseAndExecute(option_parser) | 1069 return command_option_parser.ParseAndExecute(option_parser) |
| 1021 | 1070 |
| 1022 | 1071 |
| 1023 if __name__ == '__main__': | 1072 if __name__ == '__main__': |
| 1024 sys.exit(main()) | 1073 sys.exit(main()) |
| OLD | NEW |