blob: 2f5058fe564a7a4dacb2864bba77cf20f8c26f71 [file] [log] [blame]
[email protected]fbe29322013-07-09 09:03:261#!/usr/bin/env python
2#
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
5# found in the LICENSE file.
6
[email protected]181a5c92013-09-06 17:11:467"""Runs all types of tests from one unified interface."""
[email protected]fbe29322013-07-09 09:03:268
9import collections
[email protected]f7148dd42013-08-20 14:24:5710import logging
[email protected]fbe29322013-07-09 09:03:2611import optparse
12import os
[email protected]6bc1bda22013-07-19 22:08:3713import shutil
[email protected]83bb8152013-11-19 15:02:2114import signal
[email protected]fbe29322013-07-09 09:03:2615import sys
[email protected]83bb8152013-11-19 15:02:2116import threading
jbudorick256fd532014-10-24 01:50:1317import unittest
[email protected]fbe29322013-07-09 09:03:2618
[email protected]f7148dd42013-08-20 14:24:5719from pylib import android_commands
[email protected]fbe29322013-07-09 09:03:2620from pylib import constants
[email protected]c0662e092013-11-12 11:51:2521from pylib import forwarder
[email protected]fbe29322013-07-09 09:03:2622from pylib import ports
23from pylib.base import base_test_result
[email protected]6bc1bda22013-07-19 22:08:3724from pylib.base import test_dispatcher
[email protected]6bc1bda22013-07-19 22:08:3725from pylib.gtest import gtest_config
[email protected]2a684222013-08-01 16:59:2226from pylib.gtest import setup as gtest_setup
27from pylib.gtest import test_options as gtest_test_options
[email protected]6b6abac6d2013-10-03 11:56:3828from pylib.linker import setup as linker_setup
[email protected]37ee0c792013-08-06 19:10:1329from pylib.host_driven import setup as host_driven_setup
[email protected]6bc1bda22013-07-19 22:08:3730from pylib.instrumentation import setup as instrumentation_setup
[email protected]2a684222013-08-01 16:59:2231from pylib.instrumentation import test_options as instrumentation_test_options
jbudorick9a6b7b332014-09-20 00:01:0732from pylib.junit import setup as junit_setup
33from pylib.junit import test_dispatcher as junit_dispatcher
[email protected]3dbdfa42013-08-08 01:08:1434from pylib.monkey import setup as monkey_setup
35from pylib.monkey import test_options as monkey_test_options
[email protected]ec3170b2013-08-14 14:39:4736from pylib.perf import setup as perf_setup
37from pylib.perf import test_options as perf_test_options
38from pylib.perf import test_runner as perf_test_runner
[email protected]6bc1bda22013-07-19 22:08:3739from pylib.uiautomator import setup as uiautomator_setup
[email protected]2a684222013-08-01 16:59:2240from pylib.uiautomator import test_options as uiautomator_test_options
[email protected]2eea4872014-07-28 23:06:1741from pylib.utils import apk_helper
[email protected]803f65a72013-08-20 19:11:3042from pylib.utils import command_option_parser
[email protected]6bc1bda22013-07-19 22:08:3743from pylib.utils import report_results
[email protected]71aec4b2013-11-20 00:35:2444from pylib.utils import reraiser_thread
[email protected]6bc1bda22013-07-19 22:08:3745from pylib.utils import run_tests_helper
[email protected]fbe29322013-07-09 09:03:2646
47
jbudorick256fd532014-10-24 01:50:1348HOST_TESTS = ['junit', 'python']
49
50
[email protected]fbe29322013-07-09 09:03:2651def AddCommonOptions(option_parser):
52 """Adds all common options to |option_parser|."""
53
[email protected]dfffbcbc2013-09-17 22:06:0154 group = optparse.OptionGroup(option_parser, 'Common Options')
55 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
56 group.add_option('--debug', action='store_const', const='Debug',
57 dest='build_type', default=default_build_type,
58 help=('If set, run test suites under out/Debug. '
59 'Default is env var BUILDTYPE or Debug.'))
60 group.add_option('--release', action='store_const',
61 const='Release', dest='build_type',
62 help=('If set, run test suites under out/Release.'
63 ' Default is env var BUILDTYPE or Debug.'))
r.kasibhatla3d57cba2014-10-09 10:55:5764 group.add_option('--build-directory', dest='build_directory',
65 help=('Path to the directory in which build files are'
66 ' located (should not include build type)'))
[email protected]dfffbcbc2013-09-17 22:06:0167 group.add_option('--num_retries', dest='num_retries', type='int',
68 default=2,
69 help=('Number of retries for a test before '
70 'giving up.'))
71 group.add_option('-v',
72 '--verbose',
73 dest='verbose_count',
74 default=0,
75 action='count',
76 help='Verbose level (multiple times for more)')
[email protected]dfffbcbc2013-09-17 22:06:0177 group.add_option('--flakiness-dashboard-server',
78 dest='flakiness_dashboard_server',
79 help=('Address of the server that is hosting the '
80 'Chrome for Android flakiness dashboard.'))
[email protected]dfffbcbc2013-09-17 22:06:0181 option_parser.add_option_group(group)
[email protected]fbe29322013-07-09 09:03:2682
83
84def ProcessCommonOptions(options):
85 """Processes and handles all common options."""
[email protected]fbe29322013-07-09 09:03:2686 run_tests_helper.SetLogLevel(options.verbose_count)
[email protected]14b3b1202013-08-15 22:25:2887 constants.SetBuildType(options.build_type)
r.kasibhatla3d57cba2014-10-09 10:55:5788 if options.build_directory:
89 constants.SetBuildDirectory(options.build_directory)
[email protected]fbe29322013-07-09 09:03:2690
91
jbudorick256fd532014-10-24 01:50:1392def AddDeviceOptions(option_parser):
93 group = optparse.OptionGroup(option_parser, 'Device Options')
94 group.add_option('-c', dest='cleanup_test_files',
95 help='Cleanup test files on the device after run',
96 action='store_true')
97 group.add_option('--tool',
98 dest='tool',
99 help=('Run the test under a tool '
100 '(use --tool help to list them)'))
101 group.add_option('--skip-deps-push', dest='push_deps',
102 action='store_false', default=True,
103 help=('Do not push dependencies to the device. '
104 'Use this at own risk for speeding up test '
105 'execution on local machine.'))
106 group.add_option('-d', '--device', dest='test_device',
107 help=('Target device for the test suite '
108 'to run on.'))
109 option_parser.add_option_group(group)
110
111
[email protected]fbe29322013-07-09 09:03:26112def AddGTestOptions(option_parser):
113 """Adds gtest options to |option_parser|."""
114
115 option_parser.usage = '%prog gtest [options]'
[email protected]dfffbcbc2013-09-17 22:06:01116 option_parser.commands_dict = {}
[email protected]fbe29322013-07-09 09:03:26117 option_parser.example = '%prog gtest -s base_unittests'
118
[email protected]6bc1bda22013-07-19 22:08:37119 # TODO(gkanwar): Make this option required
120 option_parser.add_option('-s', '--suite', dest='suite_name',
[email protected]fbe29322013-07-09 09:03:26121 help=('Executable name of the test suite to run '
122 '(use -s help to list them).'))
[email protected]c53dc4332013-11-20 04:38:03123 option_parser.add_option('-f', '--gtest_filter', '--gtest-filter',
124 dest='test_filter',
[email protected]9e689252013-07-30 20:14:36125 help='googletest-style filter string.')
[email protected]c53dc4332013-11-20 04:38:03126 option_parser.add_option('--gtest_also_run_disabled_tests',
127 '--gtest-also-run-disabled-tests',
[email protected]dfffbcbc2013-09-17 22:06:01128 dest='run_disabled', action='store_true',
129 help='Also run disabled tests if applicable.')
130 option_parser.add_option('-a', '--test-arguments', dest='test_arguments',
131 default='',
[email protected]9e689252013-07-30 20:14:36132 help='Additional arguments to pass to the test.')
133 option_parser.add_option('-t', dest='timeout',
134 help='Timeout to wait for each test',
135 type='int',
136 default=60)
[email protected]5b8b8742014-05-22 08:18:50137 option_parser.add_option('--isolate_file_path',
138 '--isolate-file-path',
139 dest='isolate_file_path',
140 help='.isolate file path to override the default '
141 'path')
[email protected]fbe29322013-07-09 09:03:26142 # TODO(gkanwar): Move these to Common Options once we have the plumbing
143 # in our other test types to handle these commands
[email protected]fbe29322013-07-09 09:03:26144 AddCommonOptions(option_parser)
jbudorick256fd532014-10-24 01:50:13145 AddDeviceOptions(option_parser)
[email protected]fbe29322013-07-09 09:03:26146
147
[email protected]6b6abac6d2013-10-03 11:56:38148def AddLinkerTestOptions(option_parser):
149 option_parser.usage = '%prog linker'
150 option_parser.commands_dict = {}
151 option_parser.example = '%prog linker'
152
[email protected]98c4feef2013-10-08 01:19:05153 option_parser.add_option('-f', '--gtest-filter', dest='test_filter',
154 help='googletest-style filter string.')
[email protected]6b6abac6d2013-10-03 11:56:38155 AddCommonOptions(option_parser)
jbudorick256fd532014-10-24 01:50:13156 AddDeviceOptions(option_parser)
[email protected]6b6abac6d2013-10-03 11:56:38157
158
[email protected]6bc1bda22013-07-19 22:08:37159def ProcessGTestOptions(options):
160 """Intercept test suite help to list test suites.
161
162 Args:
163 options: Command line options.
[email protected]6bc1bda22013-07-19 22:08:37164 """
165 if options.suite_name == 'help':
166 print 'Available test suites are:'
[email protected]9e689252013-07-30 20:14:36167 for test_suite in (gtest_config.STABLE_TEST_SUITES +
168 gtest_config.EXPERIMENTAL_TEST_SUITES):
169 print test_suite
[email protected]2a684222013-08-01 16:59:22170 sys.exit(0)
[email protected]6bc1bda22013-07-19 22:08:37171
172 # Convert to a list, assuming all test suites if nothing was specified.
173 # TODO(gkanwar): Require having a test suite
174 if options.suite_name:
175 options.suite_name = [options.suite_name]
176 else:
[email protected]9e689252013-07-30 20:14:36177 options.suite_name = [s for s in gtest_config.STABLE_TEST_SUITES]
[email protected]6bc1bda22013-07-19 22:08:37178
179
[email protected]fbe29322013-07-09 09:03:26180def AddJavaTestOptions(option_parser):
181 """Adds the Java test options to |option_parser|."""
182
[email protected]dfffbcbc2013-09-17 22:06:01183 option_parser.add_option('-f', '--test-filter', dest='test_filter',
[email protected]fbe29322013-07-09 09:03:26184 help=('Test filter (if not fully qualified, '
185 'will run all matches).'))
186 option_parser.add_option(
187 '-A', '--annotation', dest='annotation_str',
188 help=('Comma-separated list of annotations. Run only tests with any of '
189 'the given annotations. An annotation can be either a key or a '
190 'key-values pair. A test that has no annotation is considered '
191 '"SmallTest".'))
192 option_parser.add_option(
193 '-E', '--exclude-annotation', dest='exclude_annotation_str',
194 help=('Comma-separated list of annotations. Exclude tests with these '
195 'annotations.'))
jbudorickcbcc115d2014-09-18 17:50:59196 option_parser.add_option(
197 '--screenshot', dest='screenshot_failures', action='store_true',
198 help='Capture screenshots of test failures')
199 option_parser.add_option(
200 '--save-perf-json', action='store_true',
201 help='Saves the JSON file for each UI Perf test.')
202 option_parser.add_option(
203 '--official-build', action='store_true', help='Run official build tests.')
204 option_parser.add_option(
205 '--test_data', '--test-data', action='append', default=[],
206 help=('Each instance defines a directory of test data that should be '
207 'copied to the target(s) before running the tests. The argument '
208 'should be of the form <target>:<source>, <target> is relative to '
209 'the device data directory, and <source> is relative to the '
210 'chromium build directory.'))
[email protected]fbe29322013-07-09 09:03:26211
212
[email protected]7c53a602014-03-24 16:21:44213def ProcessJavaTestOptions(options):
[email protected]fbe29322013-07-09 09:03:26214 """Processes options/arguments and populates |options| with defaults."""
215
[email protected]fbe29322013-07-09 09:03:26216 if options.annotation_str:
217 options.annotations = options.annotation_str.split(',')
218 elif options.test_filter:
219 options.annotations = []
220 else:
[email protected]6bc1bda22013-07-19 22:08:37221 options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
[email protected]4f777ca2014-08-08 01:45:59222 'EnormousTest', 'IntegrationTest']
[email protected]fbe29322013-07-09 09:03:26223
224 if options.exclude_annotation_str:
225 options.exclude_annotations = options.exclude_annotation_str.split(',')
226 else:
227 options.exclude_annotations = []
228
[email protected]fbe29322013-07-09 09:03:26229
230def AddInstrumentationTestOptions(option_parser):
231 """Adds Instrumentation test options to |option_parser|."""
232
233 option_parser.usage = '%prog instrumentation [options]'
[email protected]dfffbcbc2013-09-17 22:06:01234 option_parser.commands_dict = {}
[email protected]fb7ab5e82013-07-26 18:31:20235 option_parser.example = ('%prog instrumentation '
[email protected]efeb59e2014-03-12 01:31:26236 '--test-apk=ChromeShellTest')
[email protected]fbe29322013-07-09 09:03:26237
238 AddJavaTestOptions(option_parser)
239 AddCommonOptions(option_parser)
jbudorick256fd532014-10-24 01:50:13240 AddDeviceOptions(option_parser)
[email protected]fbe29322013-07-09 09:03:26241
[email protected]dfffbcbc2013-09-17 22:06:01242 option_parser.add_option('-j', '--java-only', action='store_true',
[email protected]37ee0c792013-08-06 19:10:13243 default=False, help='Run only the Java tests.')
[email protected]dfffbcbc2013-09-17 22:06:01244 option_parser.add_option('-p', '--python-only', action='store_true',
[email protected]37ee0c792013-08-06 19:10:13245 default=False,
246 help='Run only the host-driven tests.')
[email protected]a69e85bc2013-08-16 18:07:26247 option_parser.add_option('--host-driven-root',
[email protected]37ee0c792013-08-06 19:10:13248 help='Root of the host-driven tests.')
[email protected]fbe29322013-07-09 09:03:26249 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger',
250 action='store_true',
251 help='Wait for debugger.')
[email protected]fbe29322013-07-09 09:03:26252 option_parser.add_option(
253 '--test-apk', dest='test_apk',
254 help=('The name of the apk containing the tests '
[email protected]ae68d4a2013-09-24 21:57:15255 '(without the .apk extension; e.g. "ContentShellTest").'))
[email protected]803f65a72013-08-20 19:11:30256 option_parser.add_option('--coverage-dir',
257 help=('Directory in which to place all generated '
258 'EMMA coverage files.'))
[email protected]4f777ca2014-08-08 01:45:59259 option_parser.add_option('--device-flags', dest='device_flags', default='',
260 help='The relative filepath to a file containing '
261 'command-line flags to set on the device')
[email protected]fbe29322013-07-09 09:03:26262
263
264def ProcessInstrumentationOptions(options, error_func):
[email protected]2a684222013-08-01 16:59:22265 """Processes options/arguments and populate |options| with defaults.
266
267 Args:
268 options: optparse.Options object.
269 error_func: Function to call with the error message in case of an error.
270
271 Returns:
272 An InstrumentationOptions named tuple which contains all options relevant to
273 instrumentation tests.
274 """
[email protected]fbe29322013-07-09 09:03:26275
[email protected]7c53a602014-03-24 16:21:44276 ProcessJavaTestOptions(options)
[email protected]fbe29322013-07-09 09:03:26277
[email protected]37ee0c792013-08-06 19:10:13278 if options.java_only and options.python_only:
279 error_func('Options java_only (-j) and python_only (-p) '
280 'are mutually exclusive.')
281 options.run_java_tests = True
282 options.run_python_tests = True
283 if options.java_only:
284 options.run_python_tests = False
285 elif options.python_only:
286 options.run_java_tests = False
287
[email protected]67954f822013-08-14 18:09:08288 if not options.host_driven_root:
[email protected]37ee0c792013-08-06 19:10:13289 options.run_python_tests = False
290
[email protected]fbe29322013-07-09 09:03:26291 if not options.test_apk:
292 error_func('--test-apk must be specified.')
293
[email protected]ae68d4a2013-09-24 21:57:15294
[email protected]2eea4872014-07-28 23:06:17295 options.test_apk_path = os.path.join(
296 constants.GetOutDirectory(),
297 constants.SDK_BUILD_APKS_DIR,
298 '%s.apk' % options.test_apk)
[email protected]ae68d4a2013-09-24 21:57:15299 options.test_apk_jar_path = os.path.join(
300 constants.GetOutDirectory(),
301 constants.SDK_BUILD_TEST_JAVALIB_DIR,
302 '%s.jar' % options.test_apk)
[email protected]5e2f3f62014-06-23 12:31:46303 options.test_support_apk_path = '%sSupport%s' % (
[email protected]2eea4872014-07-28 23:06:17304 os.path.splitext(options.test_apk_path))
[email protected]5e2f3f62014-06-23 12:31:46305
[email protected]2eea4872014-07-28 23:06:17306 options.test_runner = apk_helper.GetInstrumentationName(options.test_apk_path)
[email protected]5e2f3f62014-06-23 12:31:46307
[email protected]2a684222013-08-01 16:59:22308 return instrumentation_test_options.InstrumentationOptions(
[email protected]2a684222013-08-01 16:59:22309 options.tool,
310 options.cleanup_test_files,
311 options.push_deps,
312 options.annotations,
313 options.exclude_annotations,
314 options.test_filter,
315 options.test_data,
316 options.save_perf_json,
317 options.screenshot_failures,
[email protected]2a684222013-08-01 16:59:22318 options.wait_for_debugger,
[email protected]803f65a72013-08-20 19:11:30319 options.coverage_dir,
[email protected]2a684222013-08-01 16:59:22320 options.test_apk,
321 options.test_apk_path,
[email protected]5e2f3f62014-06-23 12:31:46322 options.test_apk_jar_path,
[email protected]65bd8fb2014-08-02 17:02:02323 options.test_runner,
[email protected]4f777ca2014-08-08 01:45:59324 options.test_support_apk_path,
325 options.device_flags
[email protected]5e2f3f62014-06-23 12:31:46326 )
[email protected]2a684222013-08-01 16:59:22327
[email protected]fbe29322013-07-09 09:03:26328
329def AddUIAutomatorTestOptions(option_parser):
330 """Adds UI Automator test options to |option_parser|."""
331
332 option_parser.usage = '%prog uiautomator [options]'
[email protected]dfffbcbc2013-09-17 22:06:01333 option_parser.commands_dict = {}
[email protected]fbe29322013-07-09 09:03:26334 option_parser.example = (
[email protected]efeb59e2014-03-12 01:31:26335 '%prog uiautomator --test-jar=chrome_shell_uiautomator_tests'
336 ' --package=chrome_shell')
[email protected]fbe29322013-07-09 09:03:26337 option_parser.add_option(
[email protected]a8886c8a92013-10-08 17:29:30338 '--package',
339 help=('Package under test. Possible values: %s' %
340 constants.PACKAGE_INFO.keys()))
[email protected]fbe29322013-07-09 09:03:26341 option_parser.add_option(
342 '--test-jar', dest='test_jar',
343 help=('The name of the dexed jar containing the tests (without the '
344 '.dex.jar extension). Alternatively, this can be a full path '
345 'to the jar.'))
346
347 AddJavaTestOptions(option_parser)
348 AddCommonOptions(option_parser)
jbudorick256fd532014-10-24 01:50:13349 AddDeviceOptions(option_parser)
[email protected]fbe29322013-07-09 09:03:26350
351
352def ProcessUIAutomatorOptions(options, error_func):
[email protected]2a684222013-08-01 16:59:22353 """Processes UIAutomator options/arguments.
354
355 Args:
356 options: optparse.Options object.
357 error_func: Function to call with the error message in case of an error.
358
359 Returns:
360 A UIAutomatorOptions named tuple which contains all options relevant to
[email protected]3dbdfa42013-08-08 01:08:14361 uiautomator tests.
[email protected]2a684222013-08-01 16:59:22362 """
[email protected]fbe29322013-07-09 09:03:26363
[email protected]7c53a602014-03-24 16:21:44364 ProcessJavaTestOptions(options)
[email protected]fbe29322013-07-09 09:03:26365
[email protected]a8886c8a92013-10-08 17:29:30366 if not options.package:
367 error_func('--package is required.')
368
369 if options.package not in constants.PACKAGE_INFO:
370 error_func('Invalid package.')
[email protected]fbe29322013-07-09 09:03:26371
372 if not options.test_jar:
373 error_func('--test-jar must be specified.')
374
375 if os.path.exists(options.test_jar):
376 # The dexed JAR is fully qualified, assume the info JAR lives along side.
377 options.uiautomator_jar = options.test_jar
378 else:
379 options.uiautomator_jar = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15380 constants.GetOutDirectory(),
381 constants.SDK_BUILD_JAVALIB_DIR,
[email protected]fbe29322013-07-09 09:03:26382 '%s.dex.jar' % options.test_jar)
383 options.uiautomator_info_jar = (
384 options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] +
385 '_java.jar')
386
[email protected]2a684222013-08-01 16:59:22387 return uiautomator_test_options.UIAutomatorOptions(
[email protected]2a684222013-08-01 16:59:22388 options.tool,
389 options.cleanup_test_files,
390 options.push_deps,
391 options.annotations,
392 options.exclude_annotations,
393 options.test_filter,
394 options.test_data,
395 options.save_perf_json,
396 options.screenshot_failures,
[email protected]2a684222013-08-01 16:59:22397 options.uiautomator_jar,
398 options.uiautomator_info_jar,
[email protected]a8886c8a92013-10-08 17:29:30399 options.package)
[email protected]2a684222013-08-01 16:59:22400
[email protected]fbe29322013-07-09 09:03:26401
jbudorick9a6b7b332014-09-20 00:01:07402def AddJUnitTestOptions(option_parser):
403 """Adds junit test options to |option_parser|."""
404 option_parser.usage = '%prog junit -s [test suite name]'
405 option_parser.commands_dict = {}
406
407 option_parser.add_option(
408 '-s', '--test-suite', dest='test_suite',
409 help=('JUnit test suite to run.'))
410 option_parser.add_option(
411 '-f', '--test-filter', dest='test_filter',
412 help='Filters tests googletest-style.')
413 option_parser.add_option(
414 '--package-filter', dest='package_filter',
415 help='Filters tests by package.')
416 option_parser.add_option(
417 '--runner-filter', dest='runner_filter',
418 help='Filters tests by runner class. Must be fully qualified.')
419 option_parser.add_option(
420 '--sdk-version', dest='sdk_version', type="int",
421 help='The Android SDK version.')
422 AddCommonOptions(option_parser)
423
424
425def ProcessJUnitTestOptions(options, error_func):
426 """Processes all JUnit test options."""
427 if not options.test_suite:
428 error_func('No test suite specified.')
429 return options
430
431
[email protected]3dbdfa42013-08-08 01:08:14432def AddMonkeyTestOptions(option_parser):
433 """Adds monkey test options to |option_parser|."""
[email protected]fb81b982013-08-09 00:07:12434
435 option_parser.usage = '%prog monkey [options]'
[email protected]dfffbcbc2013-09-17 22:06:01436 option_parser.commands_dict = {}
[email protected]fb81b982013-08-09 00:07:12437 option_parser.example = (
[email protected]efeb59e2014-03-12 01:31:26438 '%prog monkey --package=chrome_shell')
[email protected]fb81b982013-08-09 00:07:12439
[email protected]3dbdfa42013-08-08 01:08:14440 option_parser.add_option(
[email protected]a8886c8a92013-10-08 17:29:30441 '--package',
442 help=('Package under test. Possible values: %s' %
443 constants.PACKAGE_INFO.keys()))
[email protected]3dbdfa42013-08-08 01:08:14444 option_parser.add_option(
445 '--event-count', default=10000, type='int',
446 help='Number of events to generate [default: %default].')
447 option_parser.add_option(
448 '--category', default='',
[email protected]fb81b982013-08-09 00:07:12449 help='A list of allowed categories.')
[email protected]3dbdfa42013-08-08 01:08:14450 option_parser.add_option(
451 '--throttle', default=100, type='int',
452 help='Delay between events (ms) [default: %default]. ')
453 option_parser.add_option(
454 '--seed', type='int',
455 help=('Seed value for pseudo-random generator. Same seed value generates '
456 'the same sequence of events. Seed is randomized by default.'))
457 option_parser.add_option(
458 '--extra-args', default='',
459 help=('String of other args to pass to the command verbatim '
460 '[default: "%default"].'))
461
462 AddCommonOptions(option_parser)
jbudorick256fd532014-10-24 01:50:13463 AddDeviceOptions(option_parser)
[email protected]3dbdfa42013-08-08 01:08:14464
465
466def ProcessMonkeyTestOptions(options, error_func):
467 """Processes all monkey test options.
468
469 Args:
470 options: optparse.Options object.
471 error_func: Function to call with the error message in case of an error.
472
473 Returns:
474 A MonkeyOptions named tuple which contains all options relevant to
475 monkey tests.
476 """
[email protected]a8886c8a92013-10-08 17:29:30477 if not options.package:
478 error_func('--package is required.')
479
480 if options.package not in constants.PACKAGE_INFO:
481 error_func('Invalid package.')
[email protected]3dbdfa42013-08-08 01:08:14482
483 category = options.category
484 if category:
485 category = options.category.split(',')
486
487 return monkey_test_options.MonkeyOptions(
[email protected]3dbdfa42013-08-08 01:08:14488 options.verbose_count,
[email protected]a8886c8a92013-10-08 17:29:30489 options.package,
[email protected]3dbdfa42013-08-08 01:08:14490 options.event_count,
491 category,
492 options.throttle,
493 options.seed,
494 options.extra_args)
495
496
[email protected]ec3170b2013-08-14 14:39:47497def AddPerfTestOptions(option_parser):
498 """Adds perf test options to |option_parser|."""
499
500 option_parser.usage = '%prog perf [options]'
[email protected]dfffbcbc2013-09-17 22:06:01501 option_parser.commands_dict = {}
[email protected]def4bce2013-11-12 12:59:52502 option_parser.example = ('%prog perf '
[email protected]ad32f312013-11-13 04:03:29503 '[--single-step -- command args] or '
[email protected]def4bce2013-11-12 12:59:52504 '[--steps perf_steps.json] or '
[email protected]ad32f312013-11-13 04:03:29505 '[--print-step step]')
[email protected]ec3170b2013-08-14 14:39:47506
[email protected]181a5c92013-09-06 17:11:46507 option_parser.add_option(
[email protected]def4bce2013-11-12 12:59:52508 '--single-step',
[email protected]ad32f312013-11-13 04:03:29509 action='store_true',
[email protected]def4bce2013-11-12 12:59:52510 help='Execute the given command with retries, but only print the result '
511 'for the "most successful" round.')
512 option_parser.add_option(
[email protected]181a5c92013-09-06 17:11:46513 '--steps',
[email protected]def4bce2013-11-12 12:59:52514 help='JSON file containing the list of commands to run.')
[email protected]181a5c92013-09-06 17:11:46515 option_parser.add_option(
516 '--flaky-steps',
517 help=('A JSON file containing steps that are flaky '
518 'and will have its exit code ignored.'))
519 option_parser.add_option(
[email protected]61487ed2014-06-09 12:33:56520 '--output-json-list',
521 help='Write a simple list of names from --steps into the given file.')
522 option_parser.add_option(
[email protected]181a5c92013-09-06 17:11:46523 '--print-step',
524 help='The name of a previously executed perf step to print.')
525 option_parser.add_option(
526 '--no-timeout', action='store_true',
527 help=('Do not impose a timeout. Each perf step is responsible for '
528 'implementing the timeout logic.'))
[email protected]650487c2013-09-30 11:40:49529 option_parser.add_option(
530 '-f', '--test-filter',
531 help=('Test filter (will match against the names listed in --steps).'))
532 option_parser.add_option(
533 '--dry-run',
534 action='store_true',
535 help='Just print the steps without executing.')
[email protected]ec3170b2013-08-14 14:39:47536 AddCommonOptions(option_parser)
jbudorick256fd532014-10-24 01:50:13537 AddDeviceOptions(option_parser)
[email protected]ec3170b2013-08-14 14:39:47538
539
[email protected]ad32f312013-11-13 04:03:29540def ProcessPerfTestOptions(options, args, error_func):
[email protected]ec3170b2013-08-14 14:39:47541 """Processes all perf test options.
542
543 Args:
544 options: optparse.Options object.
545 error_func: Function to call with the error message in case of an error.
546
547 Returns:
548 A PerfOptions named tuple which contains all options relevant to
549 perf tests.
550 """
[email protected]def4bce2013-11-12 12:59:52551 # Only one of steps, print_step or single_step must be provided.
552 count = len(filter(None,
553 [options.steps, options.print_step, options.single_step]))
554 if count != 1:
555 error_func('Please specify one of: --steps, --print-step, --single-step.')
[email protected]ad32f312013-11-13 04:03:29556 single_step = None
557 if options.single_step:
558 single_step = ' '.join(args[2:])
[email protected]ec3170b2013-08-14 14:39:47559 return perf_test_options.PerfOptions(
[email protected]61487ed2014-06-09 12:33:56560 options.steps, options.flaky_steps, options.output_json_list,
561 options.print_step, options.no_timeout, options.test_filter,
562 options.dry_run, single_step)
[email protected]ec3170b2013-08-14 14:39:47563
564
jbudorick256fd532014-10-24 01:50:13565def AddPythonTestOptions(option_parser):
566 option_parser.add_option('-s', '--suite', dest='suite_name',
567 help=('Name of the test suite to run'
568 '(use -s help to list them).'))
569 AddCommonOptions(option_parser)
570
571
572def ProcessPythonTestOptions(options, error_func):
573 if options.suite_name not in constants.PYTHON_UNIT_TEST_SUITES:
574 available = ('Available test suites: [%s]' %
575 ', '.join(constants.PYTHON_UNIT_TEST_SUITES.iterkeys()))
576 if options.suite_name == 'help':
577 print available
578 else:
579 error_func('"%s" is not a valid suite. %s' %
580 (options.suite_name, available))
581
582
[email protected]7c53a602014-03-24 16:21:44583def _RunGTests(options, devices):
[email protected]6bc1bda22013-07-19 22:08:37584 """Subcommand of RunTestsCommands which runs gtests."""
[email protected]2a684222013-08-01 16:59:22585 ProcessGTestOptions(options)
[email protected]6bc1bda22013-07-19 22:08:37586
587 exit_code = 0
588 for suite_name in options.suite_name:
[email protected]2a684222013-08-01 16:59:22589 # TODO(gkanwar): Move this into ProcessGTestOptions once we require -s for
590 # the gtest command.
591 gtest_options = gtest_test_options.GTestOptions(
[email protected]2a684222013-08-01 16:59:22592 options.tool,
593 options.cleanup_test_files,
594 options.push_deps,
595 options.test_filter,
[email protected]dfffbcbc2013-09-17 22:06:01596 options.run_disabled,
[email protected]2a684222013-08-01 16:59:22597 options.test_arguments,
598 options.timeout,
[email protected]5b8b8742014-05-22 08:18:50599 options.isolate_file_path,
[email protected]2a684222013-08-01 16:59:22600 suite_name)
[email protected]f7148dd42013-08-20 14:24:57601 runner_factory, tests = gtest_setup.Setup(gtest_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37602
603 results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57604 tests, runner_factory, devices, shard=True, test_timeout=None,
[email protected]6bc1bda22013-07-19 22:08:37605 num_retries=options.num_retries)
606
607 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
608 exit_code = test_exit_code
609
610 report_results.LogFull(
611 results=results,
612 test_type='Unit test',
613 test_package=suite_name,
[email protected]6bc1bda22013-07-19 22:08:37614 flakiness_server=options.flakiness_dashboard_server)
615
616 if os.path.isdir(constants.ISOLATE_DEPS_DIR):
617 shutil.rmtree(constants.ISOLATE_DEPS_DIR)
618
619 return exit_code
620
621
[email protected]7c53a602014-03-24 16:21:44622def _RunLinkerTests(options, devices):
[email protected]6b6abac6d2013-10-03 11:56:38623 """Subcommand of RunTestsCommands which runs linker tests."""
624 runner_factory, tests = linker_setup.Setup(options, devices)
625
626 results, exit_code = test_dispatcher.RunTests(
627 tests, runner_factory, devices, shard=True, test_timeout=60,
628 num_retries=options.num_retries)
629
630 report_results.LogFull(
631 results=results,
632 test_type='Linker test',
[email protected]93c9f9b2014-02-10 16:19:22633 test_package='ChromiumLinkerTest')
[email protected]6b6abac6d2013-10-03 11:56:38634
635 return exit_code
636
637
[email protected]f7148dd42013-08-20 14:24:57638def _RunInstrumentationTests(options, error_func, devices):
[email protected]6bc1bda22013-07-19 22:08:37639 """Subcommand of RunTestsCommands which runs instrumentation tests."""
[email protected]2a684222013-08-01 16:59:22640 instrumentation_options = ProcessInstrumentationOptions(options, error_func)
[email protected]6bc1bda22013-07-19 22:08:37641
[email protected]f7148dd42013-08-20 14:24:57642 if len(devices) > 1 and options.wait_for_debugger:
643 logging.warning('Debugger can not be sharded, using first available device')
644 devices = devices[:1]
645
[email protected]6bc1bda22013-07-19 22:08:37646 results = base_test_result.TestRunResults()
647 exit_code = 0
648
649 if options.run_java_tests:
[email protected]2a684222013-08-01 16:59:22650 runner_factory, tests = instrumentation_setup.Setup(instrumentation_options)
[email protected]6bc1bda22013-07-19 22:08:37651
652 test_results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57653 tests, runner_factory, devices, shard=True, test_timeout=None,
[email protected]6bc1bda22013-07-19 22:08:37654 num_retries=options.num_retries)
655
656 results.AddTestRunResults(test_results)
657
658 if options.run_python_tests:
[email protected]37ee0c792013-08-06 19:10:13659 runner_factory, tests = host_driven_setup.InstrumentationSetup(
[email protected]67954f822013-08-14 18:09:08660 options.host_driven_root, options.official_build,
[email protected]37ee0c792013-08-06 19:10:13661 instrumentation_options)
662
[email protected]34020022013-08-06 23:35:34663 if tests:
664 test_results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57665 tests, runner_factory, devices, shard=True, test_timeout=None,
[email protected]34020022013-08-06 23:35:34666 num_retries=options.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37667
[email protected]34020022013-08-06 23:35:34668 results.AddTestRunResults(test_results)
[email protected]6bc1bda22013-07-19 22:08:37669
[email protected]34020022013-08-06 23:35:34670 # Only allow exit code escalation
671 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
672 exit_code = test_exit_code
[email protected]6bc1bda22013-07-19 22:08:37673
[email protected]4f777ca2014-08-08 01:45:59674 if options.device_flags:
675 options.device_flags = os.path.join(constants.DIR_SOURCE_ROOT,
676 options.device_flags)
677
[email protected]6bc1bda22013-07-19 22:08:37678 report_results.LogFull(
679 results=results,
680 test_type='Instrumentation',
681 test_package=os.path.basename(options.test_apk),
682 annotation=options.annotations,
[email protected]6bc1bda22013-07-19 22:08:37683 flakiness_server=options.flakiness_dashboard_server)
684
685 return exit_code
686
687
[email protected]f7148dd42013-08-20 14:24:57688def _RunUIAutomatorTests(options, error_func, devices):
[email protected]6bc1bda22013-07-19 22:08:37689 """Subcommand of RunTestsCommands which runs uiautomator tests."""
[email protected]2a684222013-08-01 16:59:22690 uiautomator_options = ProcessUIAutomatorOptions(options, error_func)
[email protected]6bc1bda22013-07-19 22:08:37691
[email protected]37ee0c792013-08-06 19:10:13692 runner_factory, tests = uiautomator_setup.Setup(uiautomator_options)
[email protected]6bc1bda22013-07-19 22:08:37693
[email protected]37ee0c792013-08-06 19:10:13694 results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57695 tests, runner_factory, devices, shard=True, test_timeout=None,
[email protected]37ee0c792013-08-06 19:10:13696 num_retries=options.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37697
698 report_results.LogFull(
699 results=results,
700 test_type='UIAutomator',
701 test_package=os.path.basename(options.test_jar),
702 annotation=options.annotations,
[email protected]6bc1bda22013-07-19 22:08:37703 flakiness_server=options.flakiness_dashboard_server)
704
705 return exit_code
706
707
jbudorick9a6b7b332014-09-20 00:01:07708def _RunJUnitTests(options, error_func):
709 """Subcommand of RunTestsCommand which runs junit tests."""
710 junit_options = ProcessJUnitTestOptions(options, error_func)
711 runner_factory, tests = junit_setup.Setup(junit_options)
712 _, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
713
714 return exit_code
715
716
[email protected]f7148dd42013-08-20 14:24:57717def _RunMonkeyTests(options, error_func, devices):
[email protected]3dbdfa42013-08-08 01:08:14718 """Subcommand of RunTestsCommands which runs monkey tests."""
719 monkey_options = ProcessMonkeyTestOptions(options, error_func)
720
721 runner_factory, tests = monkey_setup.Setup(monkey_options)
722
723 results, exit_code = test_dispatcher.RunTests(
[email protected]181a5c92013-09-06 17:11:46724 tests, runner_factory, devices, shard=False, test_timeout=None,
725 num_retries=options.num_retries)
[email protected]3dbdfa42013-08-08 01:08:14726
727 report_results.LogFull(
728 results=results,
729 test_type='Monkey',
[email protected]14b3b1202013-08-15 22:25:28730 test_package='Monkey')
[email protected]3dbdfa42013-08-08 01:08:14731
732 return exit_code
733
734
[email protected]a72f0752014-06-03 23:52:34735def _RunPerfTests(options, args, error_func):
[email protected]ec3170b2013-08-14 14:39:47736 """Subcommand of RunTestsCommands which runs perf tests."""
[email protected]ad32f312013-11-13 04:03:29737 perf_options = ProcessPerfTestOptions(options, args, error_func)
[email protected]61487ed2014-06-09 12:33:56738
739 # Just save a simple json with a list of test names.
740 if perf_options.output_json_list:
741 return perf_test_runner.OutputJsonList(
742 perf_options.steps, perf_options.output_json_list)
743
[email protected]ad32f312013-11-13 04:03:29744 # Just print the results from a single previously executed step.
[email protected]ec3170b2013-08-14 14:39:47745 if perf_options.print_step:
746 return perf_test_runner.PrintTestOutput(perf_options.print_step)
747
[email protected]a72f0752014-06-03 23:52:34748 runner_factory, tests, devices = perf_setup.Setup(perf_options)
[email protected]ec3170b2013-08-14 14:39:47749
[email protected]a72f0752014-06-03 23:52:34750 # shard=False means that each device will get the full list of tests
751 # and then each one will decide their own affinity.
752 # shard=True means each device will pop the next test available from a queue,
753 # which increases throughput but have no affinity.
[email protected]86184c7b2013-08-15 15:06:57754 results, _ = test_dispatcher.RunTests(
[email protected]a72f0752014-06-03 23:52:34755 tests, runner_factory, devices, shard=False, test_timeout=None,
[email protected]181a5c92013-09-06 17:11:46756 num_retries=options.num_retries)
[email protected]ec3170b2013-08-14 14:39:47757
758 report_results.LogFull(
759 results=results,
760 test_type='Perf',
[email protected]865a47a2013-08-16 14:01:12761 test_package='Perf')
[email protected]def4bce2013-11-12 12:59:52762
763 if perf_options.single_step:
764 return perf_test_runner.PrintTestOutput('single_step')
765
[email protected]11ce8452014-02-17 10:55:03766 perf_test_runner.PrintSummary(tests)
767
[email protected]86184c7b2013-08-15 15:06:57768 # Always return 0 on the sharding stage. Individual tests exit_code
769 # will be returned on the print_step stage.
770 return 0
[email protected]ec3170b2013-08-14 14:39:47771
[email protected]3dbdfa42013-08-08 01:08:14772
jbudorick256fd532014-10-24 01:50:13773def _RunPythonTests(options, error_func):
774 """Subcommand of RunTestsCommand which runs python unit tests."""
775 ProcessPythonTestOptions(options, error_func)
776
777 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[options.suite_name]
778 suite_path = suite_vars['path']
779 suite_test_modules = suite_vars['test_modules']
780
781 sys.path = [suite_path] + sys.path
782 try:
783 suite = unittest.TestSuite()
784 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
785 for m in suite_test_modules)
786 runner = unittest.TextTestRunner(verbosity=1+options.verbose_count)
787 return 0 if runner.run(suite).wasSuccessful() else 1
788 finally:
789 sys.path = sys.path[1:]
790
791
[email protected]f7148dd42013-08-20 14:24:57792def _GetAttachedDevices(test_device=None):
793 """Get all attached devices.
794
795 Args:
796 test_device: Name of a specific device to use.
797
798 Returns:
799 A list of attached devices.
800 """
801 attached_devices = []
802
803 attached_devices = android_commands.GetAttachedDevices()
804 if test_device:
805 assert test_device in attached_devices, (
806 'Did not find device %s among attached device. Attached devices: %s'
807 % (test_device, ', '.join(attached_devices)))
808 attached_devices = [test_device]
809
810 assert attached_devices, 'No devices attached.'
811
812 return sorted(attached_devices)
813
814
[email protected]fbe29322013-07-09 09:03:26815def RunTestsCommand(command, options, args, option_parser):
816 """Checks test type and dispatches to the appropriate function.
817
818 Args:
819 command: String indicating the command that was received to trigger
820 this function.
821 options: optparse options dictionary.
822 args: List of extra args from optparse.
823 option_parser: optparse.OptionParser object.
824
825 Returns:
826 Integer indicated exit code.
[email protected]b3873892013-07-10 04:57:10827
828 Raises:
829 Exception: Unknown command name passed in, or an exception from an
830 individual test runner.
[email protected]fbe29322013-07-09 09:03:26831 """
832
[email protected]d82f0252013-07-12 23:22:57833 # Check for extra arguments
[email protected]ad32f312013-11-13 04:03:29834 if len(args) > 2 and command != 'perf':
[email protected]d82f0252013-07-12 23:22:57835 option_parser.error('Unrecognized arguments: %s' % (' '.join(args[2:])))
836 return constants.ERROR_EXIT_CODE
[email protected]ad32f312013-11-13 04:03:29837 if command == 'perf':
838 if ((options.single_step and len(args) <= 2) or
839 (not options.single_step and len(args) > 2)):
840 option_parser.error('Unrecognized arguments: %s' % (' '.join(args)))
841 return constants.ERROR_EXIT_CODE
[email protected]d82f0252013-07-12 23:22:57842
[email protected]fbe29322013-07-09 09:03:26843 ProcessCommonOptions(options)
844
jbudorick256fd532014-10-24 01:50:13845 if command in HOST_TESTS:
846 devices = []
847 else:
848 devices = _GetAttachedDevices(options.test_device)
[email protected]f7148dd42013-08-20 14:24:57849
[email protected]c0662e092013-11-12 11:51:25850 forwarder.Forwarder.RemoveHostLog()
[email protected]6b11583b2013-11-21 16:18:40851 if not ports.ResetTestServerPortAllocation():
852 raise Exception('Failed to reset test server port.')
[email protected]c0662e092013-11-12 11:51:25853
[email protected]fbe29322013-07-09 09:03:26854 if command == 'gtest':
[email protected]7c53a602014-03-24 16:21:44855 return _RunGTests(options, devices)
[email protected]6b6abac6d2013-10-03 11:56:38856 elif command == 'linker':
[email protected]7c53a602014-03-24 16:21:44857 return _RunLinkerTests(options, devices)
[email protected]fbe29322013-07-09 09:03:26858 elif command == 'instrumentation':
[email protected]f7148dd42013-08-20 14:24:57859 return _RunInstrumentationTests(options, option_parser.error, devices)
[email protected]fbe29322013-07-09 09:03:26860 elif command == 'uiautomator':
[email protected]f7148dd42013-08-20 14:24:57861 return _RunUIAutomatorTests(options, option_parser.error, devices)
jbudorick9a6b7b332014-09-20 00:01:07862 elif command == 'junit':
863 return _RunJUnitTests(options, option_parser.error)
[email protected]3dbdfa42013-08-08 01:08:14864 elif command == 'monkey':
[email protected]f7148dd42013-08-20 14:24:57865 return _RunMonkeyTests(options, option_parser.error, devices)
[email protected]ec3170b2013-08-14 14:39:47866 elif command == 'perf':
[email protected]a72f0752014-06-03 23:52:34867 return _RunPerfTests(options, args, option_parser.error)
jbudorick256fd532014-10-24 01:50:13868 elif command == 'python':
869 return _RunPythonTests(options, option_parser.error)
[email protected]fbe29322013-07-09 09:03:26870 else:
[email protected]6bc1bda22013-07-19 22:08:37871 raise Exception('Unknown test type.')
[email protected]fbe29322013-07-09 09:03:26872
[email protected]fbe29322013-07-09 09:03:26873
[email protected]7c53a602014-03-24 16:21:44874def HelpCommand(command, _options, args, option_parser):
[email protected]fbe29322013-07-09 09:03:26875 """Display help for a certain command, or overall help.
876
877 Args:
878 command: String indicating the command that was received to trigger
879 this function.
[email protected]7c53a602014-03-24 16:21:44880 options: optparse options dictionary. unused.
[email protected]fbe29322013-07-09 09:03:26881 args: List of extra args from optparse.
882 option_parser: optparse.OptionParser object.
883
884 Returns:
885 Integer indicated exit code.
886 """
887 # If we don't have any args, display overall help
888 if len(args) < 3:
889 option_parser.print_help()
890 return 0
[email protected]d82f0252013-07-12 23:22:57891 # If we have too many args, print an error
892 if len(args) > 3:
893 option_parser.error('Unrecognized arguments: %s' % (' '.join(args[3:])))
894 return constants.ERROR_EXIT_CODE
[email protected]fbe29322013-07-09 09:03:26895
896 command = args[2]
897
898 if command not in VALID_COMMANDS:
899 option_parser.error('Unrecognized command.')
900
901 # Treat the help command as a special case. We don't care about showing a
902 # specific help page for itself.
903 if command == 'help':
904 option_parser.print_help()
905 return 0
906
907 VALID_COMMANDS[command].add_options_func(option_parser)
908 option_parser.usage = '%prog ' + command + ' [options]'
[email protected]dfffbcbc2013-09-17 22:06:01909 option_parser.commands_dict = {}
[email protected]fbe29322013-07-09 09:03:26910 option_parser.print_help()
911
912 return 0
913
914
915# Define a named tuple for the values in the VALID_COMMANDS dictionary so the
916# syntax is a bit prettier. The tuple is two functions: (add options, run
917# command).
918CommandFunctionTuple = collections.namedtuple(
919 'CommandFunctionTuple', ['add_options_func', 'run_command_func'])
920VALID_COMMANDS = {
921 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand),
[email protected]fbe29322013-07-09 09:03:26922 'instrumentation': CommandFunctionTuple(
923 AddInstrumentationTestOptions, RunTestsCommand),
924 'uiautomator': CommandFunctionTuple(
925 AddUIAutomatorTestOptions, RunTestsCommand),
jbudorick9a6b7b332014-09-20 00:01:07926 'junit': CommandFunctionTuple(
927 AddJUnitTestOptions, RunTestsCommand),
[email protected]3dbdfa42013-08-08 01:08:14928 'monkey': CommandFunctionTuple(
929 AddMonkeyTestOptions, RunTestsCommand),
[email protected]ec3170b2013-08-14 14:39:47930 'perf': CommandFunctionTuple(
931 AddPerfTestOptions, RunTestsCommand),
jbudorick256fd532014-10-24 01:50:13932 'python': CommandFunctionTuple(
933 AddPythonTestOptions, RunTestsCommand),
[email protected]6b6abac6d2013-10-03 11:56:38934 'linker': CommandFunctionTuple(
935 AddLinkerTestOptions, RunTestsCommand),
[email protected]fbe29322013-07-09 09:03:26936 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand)
937 }
938
939
[email protected]7c53a602014-03-24 16:21:44940def DumpThreadStacks(_signal, _frame):
[email protected]71aec4b2013-11-20 00:35:24941 for thread in threading.enumerate():
942 reraiser_thread.LogThreadStack(thread)
[email protected]83bb8152013-11-19 15:02:21943
944
[email protected]7c53a602014-03-24 16:21:44945def main():
[email protected]83bb8152013-11-19 15:02:21946 signal.signal(signal.SIGUSR1, DumpThreadStacks)
[email protected]803f65a72013-08-20 19:11:30947 option_parser = command_option_parser.CommandOptionParser(
948 commands_dict=VALID_COMMANDS)
949 return command_option_parser.ParseAndExecute(option_parser)
[email protected]fbe29322013-07-09 09:03:26950
[email protected]fbe29322013-07-09 09:03:26951
952if __name__ == '__main__':
[email protected]7c53a602014-03-24 16:21:44953 sys.exit(main())