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 TODO(gkanwar): | 9 TODO(gkanwar): |
10 * Add options to run Monkey tests. | 10 * Add options to run Monkey tests. |
11 """ | 11 """ |
12 | 12 |
13 import collections | 13 import collections |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import sys | 16 import sys |
17 | 17 |
18 from pylib import cmd_helper | 18 from pylib import cmd_helper |
19 from pylib import constants | 19 from pylib import constants |
20 from pylib import ports | 20 from pylib import ports |
21 from pylib.base import base_test_result | 21 from pylib.base import base_test_result |
22 from pylib.browsertests import dispatch as browsertests_dispatch | 22 from pylib.base import test_dispatcher |
23 from pylib.gtest import dispatch as gtest_dispatch | 23 from pylib.browsertests import setup as browsertests_setup |
| 24 from pylib.gtest import setup as gtest_setup |
| 25 from pylib.gtest import gtest_config |
24 from pylib.host_driven import run_python_tests as python_dispatch | 26 from pylib.host_driven import run_python_tests as python_dispatch |
25 from pylib.instrumentation import dispatch as instrumentation_dispatch | 27 from pylib.instrumentation import setup as instrumentation_setup |
26 from pylib.uiautomator import dispatch as uiautomator_dispatch | 28 from pylib.uiautomator import setup as uiautomator_setup |
27 from pylib.utils import emulator, report_results, run_tests_helper | 29 from pylib.utils import report_results |
| 30 from pylib.utils import run_tests_helper |
28 | 31 |
29 | 32 |
30 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') | 33 _SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out') |
31 | 34 |
32 | 35 |
33 def AddBuildTypeOption(option_parser): | 36 def AddBuildTypeOption(option_parser): |
34 """Adds the build type option to |option_parser|.""" | 37 """Adds the build type option to |option_parser|.""" |
35 default_build_type = 'Debug' | 38 default_build_type = 'Debug' |
36 if 'BUILDTYPE' in os.environ: | 39 if 'BUILDTYPE' in os.environ: |
37 default_build_type = os.environ['BUILDTYPE'] | 40 default_build_type = os.environ['BUILDTYPE'] |
38 option_parser.add_option('--debug', action='store_const', const='Debug', | 41 option_parser.add_option('--debug', action='store_const', const='Debug', |
39 dest='build_type', default=default_build_type, | 42 dest='build_type', default=default_build_type, |
40 help=('If set, run test suites under out/Debug. ' | 43 help=('If set, run test suites under out/Debug. ' |
41 'Default is env var BUILDTYPE or Debug.')) | 44 'Default is env var BUILDTYPE or Debug.')) |
42 option_parser.add_option('--release', action='store_const', | 45 option_parser.add_option('--release', action='store_const', |
43 const='Release', dest='build_type', | 46 const='Release', dest='build_type', |
44 help=('If set, run test suites under out/Release.' | 47 help=('If set, run test suites under out/Release.' |
45 ' Default is env var BUILDTYPE or Debug.')) | 48 ' Default is env var BUILDTYPE or Debug.')) |
46 | 49 |
47 | 50 |
48 def AddEmulatorOptions(option_parser): | 51 def AddCommonOptions(option_parser, default_timeout=60): |
49 """Adds all emulator-related options to |option_parser|.""" | |
50 | |
51 # TODO(gkanwar): Figure out what we're doing with the emulator setup | |
52 # and determine whether these options should be deprecated/removed. | |
53 option_parser.add_option('-e', '--emulator', dest='use_emulator', | |
54 action='store_true', | |
55 help='Run tests in a new instance of emulator.') | |
56 option_parser.add_option('-n', '--emulator-count', | |
57 type='int', default=1, | |
58 help=('Number of emulators to launch for ' | |
59 'running the tests.')) | |
60 option_parser.add_option('--abi', default='armeabi-v7a', | |
61 help='Platform of emulators to launch.') | |
62 | |
63 | |
64 def ProcessEmulatorOptions(options): | |
65 """Processes emulator options.""" | |
66 if options.use_emulator: | |
67 emulator.DeleteAllTempAVDs() | |
68 | |
69 | |
70 def AddCommonOptions(option_parser): | |
71 """Adds all common options to |option_parser|.""" | 52 """Adds all common options to |option_parser|.""" |
72 | 53 |
73 AddBuildTypeOption(option_parser) | 54 AddBuildTypeOption(option_parser) |
74 | 55 |
75 option_parser.add_option('--out-directory', dest='out_directory', | 56 option_parser.add_option('--out-directory', dest='out_directory', |
76 help=('Path to the out/ directory, irrespective of ' | 57 help=('Path to the out/ directory, irrespective of ' |
77 'the build type. Only for non-Chromium uses.')) | 58 'the build type. Only for non-Chromium uses.')) |
78 option_parser.add_option('-c', dest='cleanup_test_files', | 59 option_parser.add_option('-c', dest='cleanup_test_files', |
79 help='Cleanup test files on the device after run', | 60 help='Cleanup test files on the device after run', |
80 action='store_true') | 61 action='store_true') |
(...skipping 23 matching lines...) Expand all Loading... |
104 help=('Address of the server that is hosting the ' | 85 help=('Address of the server that is hosting the ' |
105 'Chrome for Android flakiness dashboard.')) | 86 'Chrome for Android flakiness dashboard.')) |
106 option_parser.add_option('--skip-deps-push', dest='push_deps', | 87 option_parser.add_option('--skip-deps-push', dest='push_deps', |
107 action='store_false', default=True, | 88 action='store_false', default=True, |
108 help=('Do not push dependencies to the device. ' | 89 help=('Do not push dependencies to the device. ' |
109 'Use this at own risk for speeding up test ' | 90 'Use this at own risk for speeding up test ' |
110 'execution on local machine.')) | 91 'execution on local machine.')) |
111 option_parser.add_option('-d', '--device', dest='test_device', | 92 option_parser.add_option('-d', '--device', dest='test_device', |
112 help=('Target device for the test suite ' | 93 help=('Target device for the test suite ' |
113 'to run on.')) | 94 'to run on.')) |
| 95 option_parser.add_option('-t', dest='timeout', |
| 96 help='Timeout to wait for each test', |
| 97 type='int', |
| 98 default=default_timeout) |
114 | 99 |
115 | 100 |
116 def ProcessCommonOptions(options): | 101 def ProcessCommonOptions(options): |
117 """Processes and handles all common options.""" | 102 """Processes and handles all common options.""" |
118 if options.out_directory: | 103 if options.out_directory: |
119 cmd_helper.OutDirectory.set(options.out_directory) | 104 cmd_helper.OutDirectory.set(options.out_directory) |
120 run_tests_helper.SetLogLevel(options.verbose_count) | 105 run_tests_helper.SetLogLevel(options.verbose_count) |
121 | 106 |
122 | 107 |
123 def AddCoreGTestOptions(option_parser, default_timeout=60): | 108 def AddCoreGTestOptions(option_parser): |
124 """Add options specific to the gtest framework to |option_parser|.""" | 109 """Add options specific to the gtest framework to |option_parser|.""" |
125 | 110 |
126 # TODO(gkanwar): Consolidate and clean up test filtering for gtests and | 111 # TODO(gkanwar): Consolidate and clean up test filtering for gtests and |
127 # content_browsertests. | 112 # content_browsertests. |
128 option_parser.add_option('--gtest_filter', dest='test_filter', | 113 option_parser.add_option('--gtest_filter', dest='gtest_filter', |
129 help='Filter GTests by name.') | 114 help='Filter GTests by name.') |
130 option_parser.add_option('-a', '--test_arguments', dest='test_arguments', | 115 option_parser.add_option('-a', '--test_arguments', dest='test_arguments', |
131 help='Additional arguments to pass to the test.') | 116 help='Additional arguments to pass to the test.') |
132 # TODO(gkanwar): Most likely deprecate/remove this option once we've pinned | |
133 # down what we're doing with the emulator setup. | |
134 option_parser.add_option('-x', '--xvfb', dest='use_xvfb', | |
135 action='store_true', | |
136 help='Use Xvfb around tests (ignored if not Linux).') | |
137 # TODO(gkanwar): Possible deprecate this flag. Waiting on word from Peter | 117 # TODO(gkanwar): Possible deprecate this flag. Waiting on word from Peter |
138 # Beverloo. | 118 # Beverloo. |
139 option_parser.add_option('--webkit', action='store_true', | 119 option_parser.add_option('--webkit', action='store_true', |
140 help='Run the tests from a WebKit checkout.') | 120 help='Run the tests from a WebKit checkout.') |
141 option_parser.add_option('--exe', action='store_true', | 121 option_parser.add_option('--exe', action='store_true', |
142 help='If set, use the exe test runner instead of ' | 122 help='If set, use the exe test runner instead of ' |
143 'the APK.') | 123 'the APK.') |
144 option_parser.add_option('-t', dest='timeout', | |
145 help='Timeout to wait for each test', | |
146 type='int', | |
147 default=default_timeout) | |
148 | 124 |
149 | 125 |
150 def AddContentBrowserTestOptions(option_parser): | 126 def AddContentBrowserTestOptions(option_parser): |
151 """Adds Content Browser test options to |option_parser|.""" | 127 """Adds Content Browser test options to |option_parser|.""" |
152 | 128 |
153 option_parser.usage = '%prog content_browsertests [options]' | 129 option_parser.usage = '%prog content_browsertests [options]' |
154 option_parser.command_list = [] | 130 option_parser.command_list = [] |
155 option_parser.example = '%prog content_browsertests' | 131 option_parser.example = '%prog content_browsertests' |
156 | 132 |
157 AddCoreGTestOptions(option_parser) | 133 AddCoreGTestOptions(option_parser) |
158 AddCommonOptions(option_parser) | 134 AddCommonOptions(option_parser) |
159 | 135 |
160 | 136 |
161 def AddGTestOptions(option_parser): | 137 def AddGTestOptions(option_parser): |
162 """Adds gtest options to |option_parser|.""" | 138 """Adds gtest options to |option_parser|.""" |
163 | 139 |
164 option_parser.usage = '%prog gtest [options]' | 140 option_parser.usage = '%prog gtest [options]' |
165 option_parser.command_list = [] | 141 option_parser.command_list = [] |
166 option_parser.example = '%prog gtest -s base_unittests' | 142 option_parser.example = '%prog gtest -s base_unittests' |
167 | 143 |
| 144 # TODO(gkanwar): Make this option required |
168 option_parser.add_option('-s', '--suite', dest='test_suite', | 145 option_parser.add_option('-s', '--suite', dest='test_suite', |
169 help=('Executable name of the test suite to run ' | 146 help=('Executable name of the test suite to run ' |
170 '(use -s help to list them).')) | 147 '(use -s help to list them).')) |
171 AddCoreGTestOptions(option_parser) | 148 AddCoreGTestOptions(option_parser) |
172 # TODO(gkanwar): Move these to Common Options once we have the plumbing | 149 # TODO(gkanwar): Move these to Common Options once we have the plumbing |
173 # in our other test types to handle these commands | 150 # in our other test types to handle these commands |
174 AddEmulatorOptions(option_parser) | |
175 AddCommonOptions(option_parser) | 151 AddCommonOptions(option_parser) |
176 | 152 |
177 | 153 |
| 154 def ProcessGTestOptions(options): |
| 155 """Intercept test suite help to list test suites. |
| 156 |
| 157 Args: |
| 158 options: command line options. |
| 159 |
| 160 Returns: |
| 161 True if the command should continue. |
| 162 """ |
| 163 if options.test_suite == 'help': |
| 164 print 'Available test suites are:' |
| 165 for test_suite in gtest_config.STABLE_TEST_SUITES: |
| 166 print test_suite |
| 167 return False |
| 168 return True |
| 169 |
| 170 |
178 def AddJavaTestOptions(option_parser): | 171 def AddJavaTestOptions(option_parser): |
179 """Adds the Java test options to |option_parser|.""" | 172 """Adds the Java test options to |option_parser|.""" |
180 | 173 |
181 option_parser.add_option('-f', '--test_filter', dest='test_filter', | 174 option_parser.add_option('-f', '--test_filter', dest='test_filter', |
182 help=('Test filter (if not fully qualified, ' | 175 help=('Test filter (if not fully qualified, ' |
183 'will run all matches).')) | 176 'will run all matches).')) |
184 option_parser.add_option( | 177 option_parser.add_option( |
185 '-A', '--annotation', dest='annotation_str', | 178 '-A', '--annotation', dest='annotation_str', |
186 help=('Comma-separated list of annotations. Run only tests with any of ' | 179 help=('Comma-separated list of annotations. Run only tests with any of ' |
187 'the given annotations. An annotation can be either a key or a ' | 180 'the given annotations. An annotation can be either a key or a ' |
188 'key-values pair. A test that has no annotation is considered ' | 181 'key-values pair. A test that has no annotation is considered ' |
189 '"SmallTest".')) | 182 '"SmallTest".')) |
190 option_parser.add_option( | 183 option_parser.add_option( |
191 '-E', '--exclude-annotation', dest='exclude_annotation_str', | 184 '-E', '--exclude-annotation', dest='exclude_annotation_str', |
192 help=('Comma-separated list of annotations. Exclude tests with these ' | 185 help=('Comma-separated list of annotations. Exclude tests with these ' |
193 'annotations.')) | 186 'annotations.')) |
194 option_parser.add_option('-j', '--java_only', action='store_true', | 187 option_parser.add_option('-j', '--java_only', action='store_true', |
195 default=False, help='Run only the Java tests.') | 188 default=False, help='Run only the Java tests.') |
196 option_parser.add_option('-p', '--python_only', action='store_true', | 189 option_parser.add_option('-p', '--python_only', action='store_true', |
197 default=False, | 190 default=False, |
198 help='Run only the host-driven tests.') | 191 help='Run only the host-driven tests.') |
199 option_parser.add_option('--screenshot', dest='screenshot_failures', | 192 option_parser.add_option('--screenshot', dest='screenshot_failures', |
200 action='store_true', | 193 action='store_true', |
201 help='Capture screenshots of test failures') | 194 help='Capture screenshots of test failures') |
202 option_parser.add_option('--save-perf-json', action='store_true', | 195 option_parser.add_option('--save-perf-json', action='store_true', |
203 help='Saves the JSON file for each UI Perf test.') | 196 help='Saves the JSON file for each UI Perf test.') |
204 # TODO(gkanwar): Remove this option. It is not used anywhere. | |
205 option_parser.add_option('--shard_retries', type=int, default=1, | |
206 help=('Number of times to retry each failure when ' | |
207 'sharding.')) | |
208 option_parser.add_option('--official-build', help='Run official build tests.') | 197 option_parser.add_option('--official-build', help='Run official build tests.') |
209 option_parser.add_option('--python_test_root', | 198 option_parser.add_option('--python_test_root', |
210 help='Root of the host-driven tests.') | 199 help='Root of the host-driven tests.') |
211 option_parser.add_option('--keep_test_server_ports', | 200 option_parser.add_option('--keep_test_server_ports', |
212 action='store_true', | 201 action='store_true', |
213 help=('Indicates the test server ports must be ' | 202 help=('Indicates the test server ports must be ' |
214 'kept. When this is run via a sharder ' | 203 'kept. When this is run via a sharder ' |
215 'the test server ports should be kept and ' | 204 'the test server ports should be kept and ' |
216 'should not be reset.')) | 205 'should not be reset.')) |
217 # TODO(gkanwar): This option is deprecated. Remove it in the future. | 206 # TODO(gkanwar): This option is deprecated. Remove it in the future. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 options.uiautomator_jar = options.test_jar | 333 options.uiautomator_jar = options.test_jar |
345 else: | 334 else: |
346 options.uiautomator_jar = os.path.join( | 335 options.uiautomator_jar = os.path.join( |
347 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR, | 336 _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR, |
348 '%s.dex.jar' % options.test_jar) | 337 '%s.dex.jar' % options.test_jar) |
349 options.uiautomator_info_jar = ( | 338 options.uiautomator_info_jar = ( |
350 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] + | 339 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] + |
351 '_java.jar') | 340 '_java.jar') |
352 | 341 |
353 | 342 |
| 343 def _RunGTests(options, error_func): |
| 344 """Subcommand of RunTestsCommands which runs gtests.""" |
| 345 if not ProcessGTestOptions(options): |
| 346 return 0 |
| 347 |
| 348 tests_dict = gtest_setup.Setup( |
| 349 options.exe, options.test_suite, options.test_arguments, |
| 350 options.timeout, options.cleanup_test_files, options.tool, |
| 351 options.build_type, options.webkit, options.push_deps, |
| 352 options.gtest_filter) |
| 353 |
| 354 exit_code = 0 |
| 355 results = base_test_result.TestRunResults() |
| 356 for suite_name in tests_dict: |
| 357 runner_factory, tests = tests_dict[suite_name] |
| 358 test_results, test_exit_code = test_dispatcher.RunTests( |
| 359 tests, runner_factory, False, options.test_device, |
| 360 test_allocation='shard', |
| 361 build_type=options.build_type, |
| 362 test_timeout=options.timeout, |
| 363 num_retries=options.num_retries) |
| 364 results.AddTestRunResults(test_results) |
| 365 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 366 exit_code = test_exit_code |
| 367 |
| 368 report_results.LogFull( |
| 369 results=results, |
| 370 test_type='Unit test', |
| 371 test_package=options.test_suite, |
| 372 build_type=options.build_type, |
| 373 flakiness_server=options.flakiness_dashboard_server) |
| 374 |
| 375 return exit_code |
| 376 |
| 377 |
| 378 def _RunContentBrowserTests(options, error_func): |
| 379 """Subcommand of RunTestsCommands which runs content_browsertests.""" |
| 380 runner_factory, tests = browsertests_setup.Setup( |
| 381 options.test_arguments, options.timeout, options.cleanup_test_files, |
| 382 options.tool, options.build_type, options.webkit, options.push_deps, |
| 383 options.gtest_filter) |
| 384 |
| 385 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer |
| 386 # files are pushed to the devices for content_browsertests: crbug.com/138275 |
| 387 setup_timeout = 20 * 60 # 20 minutes |
| 388 results, exit_code = test_dispatcher.RunTests( |
| 389 tests, runner_factory, False, options.test_device, |
| 390 test_allocation='shard', |
| 391 build_type=options.build_type, |
| 392 test_timeout=options.timeout, |
| 393 setup_timeout=setup_timeout, |
| 394 num_retries=options.num_retries) |
| 395 |
| 396 report_results.LogFull( |
| 397 results=results, |
| 398 test_type='Unit test', |
| 399 test_package=constants.BROWSERTEST_SUITE_NAME, |
| 400 build_type=options.build_type, |
| 401 flakiness_server=options.flakiness_dashboard_server) |
| 402 |
| 403 return exit_code |
| 404 |
| 405 |
| 406 def _RunInstrumentationTests(options, error_func): |
| 407 """Subcommand of RunTestsCommands which runs instrumentation tests.""" |
| 408 ProcessInstrumentationOptions(options, error_func) |
| 409 |
| 410 results = base_test_result.TestRunResults() |
| 411 exit_code = 0 |
| 412 |
| 413 if options.run_java_tests: |
| 414 runner_factory, tests = instrumentation_setup.Setup( |
| 415 options.test_apk_path, options.test_apk_jar_path, options.annotations, |
| 416 options.exclude_annotations, options.test_filter, options.build_type, |
| 417 options.test_data, options.install_apk, options.save_perf_json, |
| 418 options.screenshot_failures, options.tool, options.wait_for_debugger, |
| 419 options.disable_assertions, options.push_deps) |
| 420 |
| 421 test_results, exit_code = test_dispatcher.ShardAndRunTests( |
| 422 tests, runner_factory, options.wait_for_debugger, options.test_device, |
| 423 test_allocation='shard', |
| 424 build_type=options.build_type, |
| 425 test_timeout=options.timeout, |
| 426 num_retries=options.num_retries) |
| 427 |
| 428 results.AddTestRunResults(test_results) |
| 429 |
| 430 if options.run_python_tests: |
| 431 test_results, test_exit_code = (python_dispatch. |
| 432 DispatchPythonTests(options)) |
| 433 results.AddTestRunResults(test_results) |
| 434 # Only allow exit code escalation |
| 435 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 436 exit_code = test_exit_code |
| 437 |
| 438 report_results.LogFull( |
| 439 results=results, |
| 440 test_type='Instrumentation', |
| 441 test_package=os.path.basename(options.test_apk), |
| 442 annotation=options.annotations, |
| 443 build_type=options.build_type, |
| 444 flakiness_server=options.flakiness_dashboard_server) |
| 445 |
| 446 return exit_code |
| 447 |
| 448 |
| 449 def _RunUIAutomatorTests(options, error_func): |
| 450 """Subcommand of RunTestsCommands which runs uiautomator tests.""" |
| 451 ProcessUIAutomatorOptions(options, error_func) |
| 452 |
| 453 results = base_test_result.TestRunResults() |
| 454 exit_code = 0 |
| 455 |
| 456 if options.run_java_tests: |
| 457 runner_factory, tests = uiautomator_setup.Setup( |
| 458 options.uiautomator_jar, options.uiautomator_info_jar, |
| 459 options.annotations, options.exclude_annotations, options.test_filter, |
| 460 options.package_name, options.build_type, options.test_data, |
| 461 options.save_perf_json, options.screenshot_failures, options.tool, |
| 462 options.disable_assertions, options.push_deps) |
| 463 |
| 464 test_results, exit_code = test_dispatcher.ShardAndRunTests( |
| 465 tests, runner_factory, False, options.test_device, |
| 466 test_allocation='shard', |
| 467 build_type=options.build_type, |
| 468 test_timeout=options.timeout, |
| 469 num_retries=options.num_retries) |
| 470 |
| 471 results.AddTestRunResults(test_results) |
| 472 |
| 473 if options.run_python_tests: |
| 474 test_results, test_exit_code = (python_dispatch. |
| 475 DispatchPythonTests(options)) |
| 476 results.AddTestRunResults(test_results) |
| 477 # Only allow exit code escalation |
| 478 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: |
| 479 exit_code = test_exit_code |
| 480 |
| 481 report_results.LogFull( |
| 482 results=results, |
| 483 test_type='UIAutomator', |
| 484 test_package=os.path.basename(options.test_jar), |
| 485 annotation=options.annotations, |
| 486 build_type=options.build_type, |
| 487 flakiness_server=options.flakiness_dashboard_server) |
| 488 |
| 489 return exit_code |
| 490 |
| 491 |
354 def RunTestsCommand(command, options, args, option_parser): | 492 def RunTestsCommand(command, options, args, option_parser): |
355 """Checks test type and dispatches to the appropriate function. | 493 """Checks test type and dispatches to the appropriate function. |
356 | 494 |
357 Args: | 495 Args: |
358 command: String indicating the command that was received to trigger | 496 command: String indicating the command that was received to trigger |
359 this function. | 497 this function. |
360 options: optparse options dictionary. | 498 options: optparse options dictionary. |
361 args: List of extra args from optparse. | 499 args: List of extra args from optparse. |
362 option_parser: optparse.OptionParser object. | 500 option_parser: optparse.OptionParser object. |
363 | 501 |
364 Returns: | 502 Returns: |
365 Integer indicated exit code. | 503 Integer indicated exit code. |
366 | 504 |
367 Raises: | 505 Raises: |
368 Exception: Unknown command name passed in, or an exception from an | 506 Exception: Unknown command name passed in, or an exception from an |
369 individual test runner. | 507 individual test runner. |
370 """ | 508 """ |
371 | 509 |
372 ProcessCommonOptions(options) | 510 ProcessCommonOptions(options) |
373 | 511 |
374 if command == 'gtest': | 512 if command == 'gtest': |
375 # TODO(gkanwar): See the emulator TODO above -- this call should either go | 513 return _RunGTests(options, option_parser.error) |
376 # away or become generalized. | |
377 ProcessEmulatorOptions(options) | |
378 results, exit_code = gtest_dispatch.Dispatch(options) | |
379 elif command == 'content_browsertests': | 514 elif command == 'content_browsertests': |
380 results, exit_code = browsertests_dispatch.Dispatch(options) | 515 return _RunContentBrowserTests(options, option_parser.error) |
381 elif command == 'instrumentation': | 516 elif command == 'instrumentation': |
382 ProcessInstrumentationOptions(options, option_parser.error) | 517 return _RunInstrumentationTests(options, option_parser.error) |
383 results = base_test_result.TestRunResults() | |
384 exit_code = 0 | |
385 if options.run_java_tests: | |
386 test_results, exit_code = instrumentation_dispatch.Dispatch(options) | |
387 results.AddTestRunResults(test_results) | |
388 if options.run_python_tests: | |
389 test_results, test_exit_code = (python_dispatch. | |
390 DispatchPythonTests(options)) | |
391 results.AddTestRunResults(test_results) | |
392 # Only allow exit code escalation | |
393 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | |
394 exit_code = test_exit_code | |
395 report_results.LogFull( | |
396 results=results, | |
397 test_type='Instrumentation', | |
398 test_package=os.path.basename(options.test_apk), | |
399 annotation=options.annotations, | |
400 build_type=options.build_type, | |
401 flakiness_server=options.flakiness_dashboard_server) | |
402 elif command == 'uiautomator': | 518 elif command == 'uiautomator': |
403 ProcessUIAutomatorOptions(options, option_parser.error) | 519 return _RunUIAutomatorTests(options, option_parser.error) |
404 results = base_test_result.TestRunResults() | |
405 exit_code = 0 | |
406 if options.run_java_tests: | |
407 test_results, exit_code = uiautomator_dispatch.Dispatch(options) | |
408 results.AddTestRunResults(test_results) | |
409 if options.run_python_tests: | |
410 test_results, test_exit_code = (python_dispatch. | |
411 DispatchPythonTests(options)) | |
412 results.AddTestRunResults(test_results) | |
413 # Only allow exit code escalation | |
414 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE: | |
415 exit_code = test_exit_code | |
416 report_results.LogFull( | |
417 results=results, | |
418 test_type='UIAutomator', | |
419 test_package=os.path.basename(options.test_jar), | |
420 annotation=options.annotations, | |
421 build_type=options.build_type, | |
422 flakiness_server=options.flakiness_dashboard_server) | |
423 else: | 520 else: |
424 raise Exception('Unknown test type state') | 521 raise Exception('Unknown test type state') |
425 | 522 |
426 return exit_code | 523 return exit_code |
427 | 524 |
428 | 525 |
429 def HelpCommand(command, options, args, option_parser): | 526 def HelpCommand(command, options, args, option_parser): |
430 """Display help for a certain command, or overall help. | 527 """Display help for a certain command, or overall help. |
431 | 528 |
432 Args: | 529 Args: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 return 0 | 614 return 0 |
518 command = argv[1] | 615 command = argv[1] |
519 VALID_COMMANDS[command].add_options_func(option_parser) | 616 VALID_COMMANDS[command].add_options_func(option_parser) |
520 options, args = option_parser.parse_args(argv) | 617 options, args = option_parser.parse_args(argv) |
521 return VALID_COMMANDS[command].run_command_func( | 618 return VALID_COMMANDS[command].run_command_func( |
522 command, options, args, option_parser) | 619 command, options, args, option_parser) |
523 | 620 |
524 | 621 |
525 if __name__ == '__main__': | 622 if __name__ == '__main__': |
526 sys.exit(main(sys.argv)) | 623 sys.exit(main(sys.argv)) |
OLD | NEW |