blob: e5016e2e9c4214048b622df1bd5d8ce5f08094d4 [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
jama47ca85c2014-12-03 18:38:079import argparse
[email protected]fbe29322013-07-09 09:03:2610import collections
[email protected]f7148dd42013-08-20 14:24:5711import logging
[email protected]fbe29322013-07-09 09:03:2612import 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
jbudorick66dc3722014-11-06 21:33:5124from pylib.base import environment_factory
[email protected]6bc1bda22013-07-19 22:08:3725from pylib.base import test_dispatcher
jbudorick66dc3722014-11-06 21:33:5126from pylib.base import test_instance_factory
27from pylib.base import test_run_factory
[email protected]6bc1bda22013-07-19 22:08:3728from pylib.gtest import gtest_config
[email protected]2a684222013-08-01 16:59:2229from pylib.gtest import setup as gtest_setup
30from pylib.gtest import test_options as gtest_test_options
[email protected]6b6abac6d2013-10-03 11:56:3831from pylib.linker import setup as linker_setup
[email protected]37ee0c792013-08-06 19:10:1332from pylib.host_driven import setup as host_driven_setup
[email protected]6bc1bda22013-07-19 22:08:3733from pylib.instrumentation import setup as instrumentation_setup
[email protected]2a684222013-08-01 16:59:2234from pylib.instrumentation import test_options as instrumentation_test_options
jbudorick9a6b7b332014-09-20 00:01:0735from pylib.junit import setup as junit_setup
36from pylib.junit import test_dispatcher as junit_dispatcher
[email protected]3dbdfa42013-08-08 01:08:1437from pylib.monkey import setup as monkey_setup
38from pylib.monkey import test_options as monkey_test_options
[email protected]ec3170b2013-08-14 14:39:4739from pylib.perf import setup as perf_setup
40from pylib.perf import test_options as perf_test_options
41from pylib.perf import test_runner as perf_test_runner
jbudorickb8c42072014-12-01 18:07:5442from pylib.results import json_results
43from pylib.results import report_results
[email protected]6bc1bda22013-07-19 22:08:3744from pylib.uiautomator import setup as uiautomator_setup
[email protected]2a684222013-08-01 16:59:2245from pylib.uiautomator import test_options as uiautomator_test_options
[email protected]2eea4872014-07-28 23:06:1746from pylib.utils import apk_helper
[email protected]71aec4b2013-11-20 00:35:2447from pylib.utils import reraiser_thread
[email protected]6bc1bda22013-07-19 22:08:3748from pylib.utils import run_tests_helper
[email protected]fbe29322013-07-09 09:03:2649
50
jama47ca85c2014-12-03 18:38:0751def AddCommonOptions(parser):
52 """Adds all common options to |parser|."""
[email protected]fbe29322013-07-09 09:03:2653
jama47ca85c2014-12-03 18:38:0754 group = parser.add_argument_group('Common Options')
55
[email protected]dfffbcbc2013-09-17 22:06:0156 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
jama47ca85c2014-12-03 18:38:0757
58 debug_or_release_group = group.add_mutually_exclusive_group()
59 debug_or_release_group.add_argument(
60 '--debug', action='store_const', const='Debug', dest='build_type',
61 default=default_build_type,
62 help=('If set, run test suites under out/Debug. '
63 'Default is env var BUILDTYPE or Debug.'))
64 debug_or_release_group.add_argument(
65 '--release', action='store_const', const='Release', dest='build_type',
66 help=('If set, run test suites under out/Release. '
67 'Default is env var BUILDTYPE or Debug.'))
68
69 group.add_argument('--build-directory', dest='build_directory',
70 help=('Path to the directory in which build files are'
71 ' located (should not include build type)'))
72 group.add_argument('--output-directory', dest='output_directory',
73 help=('Path to the directory in which build files are'
74 ' located (must include build type). This will take'
75 ' precedence over --debug, --release and'
76 ' --build-directory'))
77 group.add_argument('--num_retries', dest='num_retries', type=int, default=2,
78 help=('Number of retries for a test before '
79 'giving up (default: %(default)s).'))
80 group.add_argument('-v',
81 '--verbose',
82 dest='verbose_count',
83 default=0,
84 action='count',
85 help='Verbose level (multiple times for more)')
86 group.add_argument('--flakiness-dashboard-server',
87 dest='flakiness_dashboard_server',
88 help=('Address of the server that is hosting the '
89 'Chrome for Android flakiness dashboard.'))
90 group.add_argument('--enable-platform-mode', action='store_true',
91 help=('Run the test scripts in platform mode, which '
92 'conceptually separates the test runner from the '
93 '"device" (local or remote, real or emulated) on '
94 'which the tests are running. [experimental]'))
95 group.add_argument('-e', '--environment', default='local',
96 choices=constants.VALID_ENVIRONMENTS,
97 help='Test environment to run in (default: %(default)s).')
98 group.add_argument('--adb-path',
99 help=('Specify the absolute path of the adb binary that '
100 'should be used.'))
101 group.add_argument('--json-results-file', dest='json_results_file',
102 help='If set, will dump results in JSON form '
103 'to specified file.')
[email protected]fbe29322013-07-09 09:03:26104
105
jama47ca85c2014-12-03 18:38:07106def ProcessCommonOptions(args):
[email protected]fbe29322013-07-09 09:03:26107 """Processes and handles all common options."""
jama47ca85c2014-12-03 18:38:07108 run_tests_helper.SetLogLevel(args.verbose_count)
109 constants.SetBuildType(args.build_type)
110 if args.build_directory:
111 constants.SetBuildDirectory(args.build_directory)
112 if args.output_directory:
113 constants.SetOutputDirectort(args.output_directory)
114 if args.adb_path:
115 constants.SetAdbPath(args.adb_path)
mikecase48e16bf2014-11-19 22:46:45116 # Some things such as Forwarder require ADB to be in the environment path.
117 adb_dir = os.path.dirname(constants.GetAdbPath())
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']
[email protected]fbe29322013-07-09 09:03:26120
121
jama47ca85c2014-12-03 18:38:07122def AddDeviceOptions(parser):
123 """Adds device options to |parser|."""
124 group = parser.add_argument_group(title='Device Options')
125 group.add_argument('-c', dest='cleanup_test_files',
126 help='Cleanup test files on the device after run',
127 action='store_true')
128 group.add_argument('--tool',
129 dest='tool',
130 help=('Run the test under a tool '
131 '(use --tool help to list them)'))
132 group.add_argument('-d', '--device', dest='test_device',
133 help=('Target device for the test suite '
134 'to run on.'))
jbudorick256fd532014-10-24 01:50:13135
136
jama47ca85c2014-12-03 18:38:07137def AddGTestOptions(parser):
138 """Adds gtest options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26139
jama47ca85c2014-12-03 18:38:07140 gtest_suites = list(gtest_config.STABLE_TEST_SUITES
141 + gtest_config.EXPERIMENTAL_TEST_SUITES)
[email protected]fbe29322013-07-09 09:03:26142
jama47ca85c2014-12-03 18:38:07143 group = parser.add_argument_group('GTest Options')
144 group.add_argument('-s', '--suite', dest='suite_name', choices=gtest_suites,
145 nargs='+', metavar='SUITE_NAME', required=True,
146 help=('Executable name of the test suite to run.'))
147 group.add_argument('-f', '--gtest_filter', '--gtest-filter',
148 dest='test_filter',
149 help='googletest-style filter string.')
150 group.add_argument('--gtest_also_run_disabled_tests',
151 '--gtest-also-run-disabled-tests',
152 dest='run_disabled', action='store_true',
153 help='Also run disabled tests if applicable.')
154 group.add_argument('-a', '--test-arguments', dest='test_arguments',
155 default='',
156 help='Additional arguments to pass to the test.')
157 group.add_argument('-t', dest='timeout', type=int, default=60,
158 help='Timeout to wait for each test '
159 '(default: %(default)s).')
160 group.add_argument('--isolate_file_path',
161 '--isolate-file-path',
162 dest='isolate_file_path',
163 help='.isolate file path to override the default '
164 'path')
165 AddDeviceOptions(parser)
166 AddCommonOptions(parser)
[email protected]fbe29322013-07-09 09:03:26167
168
jama47ca85c2014-12-03 18:38:07169def AddLinkerTestOptions(parser):
170 group = parser.add_argument_group('Linker Test Options')
171 group.add_argument('-f', '--gtest-filter', dest='test_filter',
172 help='googletest-style filter string.')
173 AddCommonOptions(parser)
174 AddDeviceOptions(parser)
[email protected]6b6abac6d2013-10-03 11:56:38175
176
jama47ca85c2014-12-03 18:38:07177def AddJavaTestOptions(argument_group):
[email protected]fbe29322013-07-09 09:03:26178 """Adds the Java test options to |option_parser|."""
179
jama47ca85c2014-12-03 18:38:07180 argument_group.add_argument(
181 '-f', '--test-filter', dest='test_filter',
182 help=('Test filter (if not fully qualified, will run all matches).'))
183 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26184 '-A', '--annotation', dest='annotation_str',
185 help=('Comma-separated list of annotations. Run only tests with any of '
186 'the given annotations. An annotation can be either a key or a '
187 'key-values pair. A test that has no annotation is considered '
188 '"SmallTest".'))
jama47ca85c2014-12-03 18:38:07189 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26190 '-E', '--exclude-annotation', dest='exclude_annotation_str',
191 help=('Comma-separated list of annotations. Exclude tests with these '
192 'annotations.'))
jama47ca85c2014-12-03 18:38:07193 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59194 '--screenshot', dest='screenshot_failures', action='store_true',
195 help='Capture screenshots of test failures')
jama47ca85c2014-12-03 18:38:07196 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59197 '--save-perf-json', action='store_true',
198 help='Saves the JSON file for each UI Perf test.')
jama47ca85c2014-12-03 18:38:07199 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59200 '--official-build', action='store_true', help='Run official build tests.')
jama47ca85c2014-12-03 18:38:07201 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59202 '--test_data', '--test-data', action='append', default=[],
203 help=('Each instance defines a directory of test data that should be '
204 'copied to the target(s) before running the tests. The argument '
205 'should be of the form <target>:<source>, <target> is relative to '
206 'the device data directory, and <source> is relative to the '
207 'chromium build directory.'))
[email protected]fbe29322013-07-09 09:03:26208
209
jama47ca85c2014-12-03 18:38:07210def ProcessJavaTestOptions(args):
[email protected]fbe29322013-07-09 09:03:26211 """Processes options/arguments and populates |options| with defaults."""
212
jama47ca85c2014-12-03 18:38:07213 # TODO(jbudorick): Handle most of this function in argparse.
214 if args.annotation_str:
215 args.annotations = args.annotation_str.split(',')
216 elif args.test_filter:
217 args.annotations = []
[email protected]fbe29322013-07-09 09:03:26218 else:
jama47ca85c2014-12-03 18:38:07219 args.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
220 'EnormousTest', 'IntegrationTest']
[email protected]fbe29322013-07-09 09:03:26221
jama47ca85c2014-12-03 18:38:07222 if args.exclude_annotation_str:
223 args.exclude_annotations = args.exclude_annotation_str.split(',')
[email protected]fbe29322013-07-09 09:03:26224 else:
jama47ca85c2014-12-03 18:38:07225 args.exclude_annotations = []
[email protected]fbe29322013-07-09 09:03:26226
[email protected]fbe29322013-07-09 09:03:26227
jama47ca85c2014-12-03 18:38:07228def AddInstrumentationTestOptions(parser):
229 """Adds Instrumentation test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26230
jama47ca85c2014-12-03 18:38:07231 parser.usage = '%(prog)s [options]'
[email protected]fbe29322013-07-09 09:03:26232
jama47ca85c2014-12-03 18:38:07233 group = parser.add_argument_group('Instrumentation Test Options')
234 AddJavaTestOptions(group)
[email protected]fbe29322013-07-09 09:03:26235
jama47ca85c2014-12-03 18:38:07236 java_or_python_group = group.add_mutually_exclusive_group()
237 java_or_python_group.add_argument(
238 '-j', '--java-only', action='store_false',
239 dest='run_python_tests', default=True, help='Run only the Java tests.')
240 java_or_python_group.add_argument(
241 '-p', '--python-only', action='store_false',
242 dest='run_java_tests', default=True,
243 help='Run only the host-driven tests.')
244
245 group.add_argument('--host-driven-root',
246 help='Root of the host-driven tests.')
247 group.add_argument('-w', '--wait_debugger', dest='wait_for_debugger',
248 action='store_true',
249 help='Wait for debugger.')
250 group.add_argument('--test-apk', dest='test_apk', required=True,
251 help=('The name of the apk containing the tests '
252 '(without the .apk extension; '
253 'e.g. "ContentShellTest").'))
254 group.add_argument('--coverage-dir',
255 help=('Directory in which to place all generated '
256 'EMMA coverage files.'))
257 group.add_argument('--device-flags', dest='device_flags', default='',
258 help='The relative filepath to a file containing '
259 'command-line flags to set on the device')
260 group.add_argument('--isolate_file_path',
261 '--isolate-file-path',
262 dest='isolate_file_path',
263 help='.isolate file path to override the default '
264 'path')
265
266 AddCommonOptions(parser)
267 AddDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26268
269
jama47ca85c2014-12-03 18:38:07270def ProcessInstrumentationOptions(args):
[email protected]2a684222013-08-01 16:59:22271 """Processes options/arguments and populate |options| with defaults.
272
273 Args:
jama47ca85c2014-12-03 18:38:07274 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22275
276 Returns:
277 An InstrumentationOptions named tuple which contains all options relevant to
278 instrumentation tests.
279 """
[email protected]fbe29322013-07-09 09:03:26280
jama47ca85c2014-12-03 18:38:07281 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26282
jama47ca85c2014-12-03 18:38:07283 if not args.host_driven_root:
284 args.run_python_tests = False
[email protected]37ee0c792013-08-06 19:10:13285
jama47ca85c2014-12-03 18:38:07286 args.test_apk_path = os.path.join(
[email protected]2eea4872014-07-28 23:06:17287 constants.GetOutDirectory(),
288 constants.SDK_BUILD_APKS_DIR,
jama47ca85c2014-12-03 18:38:07289 '%s.apk' % args.test_apk)
290 args.test_apk_jar_path = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15291 constants.GetOutDirectory(),
292 constants.SDK_BUILD_TEST_JAVALIB_DIR,
jama47ca85c2014-12-03 18:38:07293 '%s.jar' % args.test_apk)
294 args.test_support_apk_path = '%sSupport%s' % (
295 os.path.splitext(args.test_apk_path))
[email protected]5e2f3f62014-06-23 12:31:46296
jama47ca85c2014-12-03 18:38:07297 args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path)
[email protected]5e2f3f62014-06-23 12:31:46298
jama47ca85c2014-12-03 18:38:07299 # TODO(jbudorick): Get rid of InstrumentationOptions.
[email protected]2a684222013-08-01 16:59:22300 return instrumentation_test_options.InstrumentationOptions(
jama47ca85c2014-12-03 18:38:07301 args.tool,
302 args.cleanup_test_files,
303 args.annotations,
304 args.exclude_annotations,
305 args.test_filter,
306 args.test_data,
307 args.save_perf_json,
308 args.screenshot_failures,
309 args.wait_for_debugger,
310 args.coverage_dir,
311 args.test_apk,
312 args.test_apk_path,
313 args.test_apk_jar_path,
314 args.test_runner,
315 args.test_support_apk_path,
316 args.device_flags,
317 args.isolate_file_path
[email protected]5e2f3f62014-06-23 12:31:46318 )
[email protected]2a684222013-08-01 16:59:22319
[email protected]fbe29322013-07-09 09:03:26320
jama47ca85c2014-12-03 18:38:07321def AddUIAutomatorTestOptions(parser):
322 """Adds UI Automator test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26323
jama47ca85c2014-12-03 18:38:07324 group = parser.add_argument_group('UIAutomator Test Options')
325 AddJavaTestOptions(group)
326 group.add_argument(
327 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
328 metavar='PACKAGE', help='Package under test.')
329 group.add_argument(
330 '--test-jar', dest='test_jar', required=True,
[email protected]fbe29322013-07-09 09:03:26331 help=('The name of the dexed jar containing the tests (without the '
332 '.dex.jar extension). Alternatively, this can be a full path '
333 'to the jar.'))
334
jama47ca85c2014-12-03 18:38:07335 AddCommonOptions(parser)
336 AddDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26337
338
jama47ca85c2014-12-03 18:38:07339def ProcessUIAutomatorOptions(args):
[email protected]2a684222013-08-01 16:59:22340 """Processes UIAutomator options/arguments.
341
342 Args:
jama47ca85c2014-12-03 18:38:07343 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22344
345 Returns:
346 A UIAutomatorOptions named tuple which contains all options relevant to
[email protected]3dbdfa42013-08-08 01:08:14347 uiautomator tests.
[email protected]2a684222013-08-01 16:59:22348 """
[email protected]fbe29322013-07-09 09:03:26349
jama47ca85c2014-12-03 18:38:07350 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26351
jama47ca85c2014-12-03 18:38:07352 if os.path.exists(args.test_jar):
[email protected]fbe29322013-07-09 09:03:26353 # The dexed JAR is fully qualified, assume the info JAR lives along side.
jama47ca85c2014-12-03 18:38:07354 args.uiautomator_jar = args.test_jar
[email protected]fbe29322013-07-09 09:03:26355 else:
jama47ca85c2014-12-03 18:38:07356 args.uiautomator_jar = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15357 constants.GetOutDirectory(),
358 constants.SDK_BUILD_JAVALIB_DIR,
jama47ca85c2014-12-03 18:38:07359 '%s.dex.jar' % args.test_jar)
360 args.uiautomator_info_jar = (
361 args.uiautomator_jar[:args.uiautomator_jar.find('.dex.jar')] +
[email protected]fbe29322013-07-09 09:03:26362 '_java.jar')
363
[email protected]2a684222013-08-01 16:59:22364 return uiautomator_test_options.UIAutomatorOptions(
jama47ca85c2014-12-03 18:38:07365 args.tool,
366 args.cleanup_test_files,
367 args.annotations,
368 args.exclude_annotations,
369 args.test_filter,
370 args.test_data,
371 args.save_perf_json,
372 args.screenshot_failures,
373 args.uiautomator_jar,
374 args.uiautomator_info_jar,
375 args.package)
[email protected]2a684222013-08-01 16:59:22376
[email protected]fbe29322013-07-09 09:03:26377
jama47ca85c2014-12-03 18:38:07378def AddJUnitTestOptions(parser):
379 """Adds junit test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07380
jama47ca85c2014-12-03 18:38:07381 group = parser.add_argument_group('JUnit Test Options')
382 group.add_argument(
383 '-s', '--test-suite', dest='test_suite', required=True,
jbudorick9a6b7b332014-09-20 00:01:07384 help=('JUnit test suite to run.'))
jama47ca85c2014-12-03 18:38:07385 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07386 '-f', '--test-filter', dest='test_filter',
387 help='Filters tests googletest-style.')
jama47ca85c2014-12-03 18:38:07388 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07389 '--package-filter', dest='package_filter',
390 help='Filters tests by package.')
jama47ca85c2014-12-03 18:38:07391 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07392 '--runner-filter', dest='runner_filter',
393 help='Filters tests by runner class. Must be fully qualified.')
jama47ca85c2014-12-03 18:38:07394 group.add_argument(
395 '--sdk-version', dest='sdk_version', type=int,
jbudorick9a6b7b332014-09-20 00:01:07396 help='The Android SDK version.')
jama47ca85c2014-12-03 18:38:07397 AddCommonOptions(parser)
jbudorick9a6b7b332014-09-20 00:01:07398
399
jama47ca85c2014-12-03 18:38:07400def AddMonkeyTestOptions(parser):
401 """Adds monkey test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07402
jama47ca85c2014-12-03 18:38:07403 group = parser.add_argument_group('Monkey Test Options')
404 group.add_argument(
405 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
406 metavar='PACKAGE', help='Package under test.')
407 group.add_argument(
408 '--event-count', default=10000, type=int,
409 help='Number of events to generate (default: %(default)s).')
410 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14411 '--category', default='',
[email protected]fb81b982013-08-09 00:07:12412 help='A list of allowed categories.')
jama47ca85c2014-12-03 18:38:07413 group.add_argument(
414 '--throttle', default=100, type=int,
415 help='Delay between events (ms) (default: %(default)s). ')
416 group.add_argument(
417 '--seed', type=int,
[email protected]3dbdfa42013-08-08 01:08:14418 help=('Seed value for pseudo-random generator. Same seed value generates '
419 'the same sequence of events. Seed is randomized by default.'))
jama47ca85c2014-12-03 18:38:07420 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14421 '--extra-args', default='',
jama47ca85c2014-12-03 18:38:07422 help=('String of other args to pass to the command verbatim.'))
[email protected]3dbdfa42013-08-08 01:08:14423
jama47ca85c2014-12-03 18:38:07424 AddCommonOptions(parser)
425 AddDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14426
427
jama47ca85c2014-12-03 18:38:07428def ProcessMonkeyTestOptions(args):
[email protected]3dbdfa42013-08-08 01:08:14429 """Processes all monkey test options.
430
431 Args:
jama47ca85c2014-12-03 18:38:07432 args: argparse.Namespace object.
[email protected]3dbdfa42013-08-08 01:08:14433
434 Returns:
435 A MonkeyOptions named tuple which contains all options relevant to
436 monkey tests.
437 """
jama47ca85c2014-12-03 18:38:07438 # TODO(jbudorick): Handle this directly in argparse with nargs='+'
439 category = args.category
[email protected]3dbdfa42013-08-08 01:08:14440 if category:
jama47ca85c2014-12-03 18:38:07441 category = args.category.split(',')
[email protected]3dbdfa42013-08-08 01:08:14442
jama47ca85c2014-12-03 18:38:07443 # TODO(jbudorick): Get rid of MonkeyOptions.
[email protected]3dbdfa42013-08-08 01:08:14444 return monkey_test_options.MonkeyOptions(
jama47ca85c2014-12-03 18:38:07445 args.verbose_count,
446 args.package,
447 args.event_count,
[email protected]3dbdfa42013-08-08 01:08:14448 category,
jama47ca85c2014-12-03 18:38:07449 args.throttle,
450 args.seed,
451 args.extra_args)
[email protected]3dbdfa42013-08-08 01:08:14452
453
jama47ca85c2014-12-03 18:38:07454def AddPerfTestOptions(parser):
455 """Adds perf test options to |parser|."""
[email protected]ec3170b2013-08-14 14:39:47456
jama47ca85c2014-12-03 18:38:07457 group = parser.add_argument_group('Perf Test Options')
[email protected]ec3170b2013-08-14 14:39:47458
jama47ca85c2014-12-03 18:38:07459 class SingleStepAction(argparse.Action):
460 def __call__(self, parser, namespace, values, option_string=None):
461 if values and not namespace.single_step:
462 parser.error('single step command provided, '
463 'but --single-step not specified.')
464 elif namespace.single_step and not values:
465 parser.error('--single-step specified, '
466 'but no single step command provided.')
467 setattr(namespace, self.dest, values)
468
469 step_group = group.add_mutually_exclusive_group(required=True)
470 # TODO(jbudorick): Revise --single-step to use argparse.REMAINDER.
471 # This requires removing "--" from client calls.
472 step_group.add_argument(
473 '--single-step', action='store_true',
[email protected]def4bce2013-11-12 12:59:52474 help='Execute the given command with retries, but only print the result '
475 'for the "most successful" round.')
jama47ca85c2014-12-03 18:38:07476 step_group.add_argument(
[email protected]181a5c92013-09-06 17:11:46477 '--steps',
[email protected]def4bce2013-11-12 12:59:52478 help='JSON file containing the list of commands to run.')
jama47ca85c2014-12-03 18:38:07479 step_group.add_argument(
480 '--print-step',
481 help='The name of a previously executed perf step to print.')
482
483 group.add_argument(
peterbd4e73d2014-12-03 15:47:36484 '--output-json-list',
485 help='Write a simple list of names from --steps into the given file.')
jama47ca85c2014-12-03 18:38:07486 group.add_argument(
peterbd4e73d2014-12-03 15:47:36487 '--collect-chartjson-data',
488 action='store_true',
489 help='Cache the chartjson output from each step for later use.')
jama47ca85c2014-12-03 18:38:07490 group.add_argument(
peterbd4e73d2014-12-03 15:47:36491 '--output-chartjson-data',
492 default='',
493 help='Write out chartjson into the given file.')
jama47ca85c2014-12-03 18:38:07494 group.add_argument(
495 '--flaky-steps',
496 help=('A JSON file containing steps that are flaky '
497 'and will have its exit code ignored.'))
498 group.add_argument(
[email protected]181a5c92013-09-06 17:11:46499 '--no-timeout', action='store_true',
500 help=('Do not impose a timeout. Each perf step is responsible for '
501 'implementing the timeout logic.'))
jama47ca85c2014-12-03 18:38:07502 group.add_argument(
[email protected]650487c2013-09-30 11:40:49503 '-f', '--test-filter',
504 help=('Test filter (will match against the names listed in --steps).'))
jama47ca85c2014-12-03 18:38:07505 group.add_argument(
506 '--dry-run', action='store_true',
[email protected]650487c2013-09-30 11:40:49507 help='Just print the steps without executing.')
jama47ca85c2014-12-03 18:38:07508 group.add_argument('single_step_command', nargs='*', action=SingleStepAction,
509 help='If --single-step is specified, the command to run.')
510 AddCommonOptions(parser)
511 AddDeviceOptions(parser)
[email protected]ec3170b2013-08-14 14:39:47512
513
jama47ca85c2014-12-03 18:38:07514def ProcessPerfTestOptions(args):
[email protected]ec3170b2013-08-14 14:39:47515 """Processes all perf test options.
516
517 Args:
jama47ca85c2014-12-03 18:38:07518 args: argparse.Namespace object.
[email protected]ec3170b2013-08-14 14:39:47519
520 Returns:
521 A PerfOptions named tuple which contains all options relevant to
522 perf tests.
523 """
jama47ca85c2014-12-03 18:38:07524 # TODO(jbudorick): Move single_step handling down into the perf tests.
525 if args.single_step:
526 args.single_step = ' '.join(args.single_step_command)
527 # TODO(jbudorick): Get rid of PerfOptions.
[email protected]ec3170b2013-08-14 14:39:47528 return perf_test_options.PerfOptions(
jama47ca85c2014-12-03 18:38:07529 args.steps, args.flaky_steps, args.output_json_list,
530 args.print_step, args.no_timeout, args.test_filter,
531 args.dry_run, args.single_step, args.collect_chartjson_data,
532 args.output_chartjson_data)
[email protected]ec3170b2013-08-14 14:39:47533
534
jama47ca85c2014-12-03 18:38:07535def AddPythonTestOptions(parser):
536 group = parser.add_argument_group('Python Test Options')
537 group.add_argument(
538 '-s', '--suite', dest='suite_name', metavar='SUITE_NAME',
539 choices=constants.PYTHON_UNIT_TEST_SUITES.keys(),
540 help='Name of the test suite to run.')
541 AddCommonOptions(parser)
jbudorick256fd532014-10-24 01:50:13542
543
jama47ca85c2014-12-03 18:38:07544def _RunGTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37545 """Subcommand of RunTestsCommands which runs gtests."""
[email protected]6bc1bda22013-07-19 22:08:37546 exit_code = 0
jama47ca85c2014-12-03 18:38:07547 for suite_name in args.suite_name:
548 # TODO(jbudorick): Either deprecate multi-suite or move its handling down
549 # into the gtest code.
[email protected]2a684222013-08-01 16:59:22550 gtest_options = gtest_test_options.GTestOptions(
jama47ca85c2014-12-03 18:38:07551 args.tool,
552 args.cleanup_test_files,
553 args.test_filter,
554 args.run_disabled,
555 args.test_arguments,
556 args.timeout,
557 args.isolate_file_path,
[email protected]2a684222013-08-01 16:59:22558 suite_name)
[email protected]f7148dd42013-08-20 14:24:57559 runner_factory, tests = gtest_setup.Setup(gtest_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37560
561 results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57562 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07563 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37564
565 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
566 exit_code = test_exit_code
567
568 report_results.LogFull(
569 results=results,
570 test_type='Unit test',
571 test_package=suite_name,
jama47ca85c2014-12-03 18:38:07572 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37573
jama47ca85c2014-12-03 18:38:07574 if args.json_results_file:
575 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54576
[email protected]6bc1bda22013-07-19 22:08:37577 if os.path.isdir(constants.ISOLATE_DEPS_DIR):
578 shutil.rmtree(constants.ISOLATE_DEPS_DIR)
579
580 return exit_code
581
582
jama47ca85c2014-12-03 18:38:07583def _RunLinkerTests(args, devices):
[email protected]6b6abac6d2013-10-03 11:56:38584 """Subcommand of RunTestsCommands which runs linker tests."""
jama47ca85c2014-12-03 18:38:07585 runner_factory, tests = linker_setup.Setup(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38586
587 results, exit_code = test_dispatcher.RunTests(
588 tests, runner_factory, devices, shard=True, test_timeout=60,
jama47ca85c2014-12-03 18:38:07589 num_retries=args.num_retries)
[email protected]6b6abac6d2013-10-03 11:56:38590
591 report_results.LogFull(
592 results=results,
593 test_type='Linker test',
[email protected]93c9f9b2014-02-10 16:19:22594 test_package='ChromiumLinkerTest')
[email protected]6b6abac6d2013-10-03 11:56:38595
jama47ca85c2014-12-03 18:38:07596 if args.json_results_file:
597 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54598
[email protected]6b6abac6d2013-10-03 11:56:38599 return exit_code
600
601
jama47ca85c2014-12-03 18:38:07602def _RunInstrumentationTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37603 """Subcommand of RunTestsCommands which runs instrumentation tests."""
jama47ca85c2014-12-03 18:38:07604 logging.info('_RunInstrumentationTests(%s, %s)' % (str(args), str(devices)))
[email protected]6bc1bda22013-07-19 22:08:37605
jama47ca85c2014-12-03 18:38:07606 instrumentation_options = ProcessInstrumentationOptions(args)
607
608 if len(devices) > 1 and args.wait_for_debugger:
[email protected]f7148dd42013-08-20 14:24:57609 logging.warning('Debugger can not be sharded, using first available device')
610 devices = devices[:1]
611
[email protected]6bc1bda22013-07-19 22:08:37612 results = base_test_result.TestRunResults()
613 exit_code = 0
614
jama47ca85c2014-12-03 18:38:07615 if args.run_java_tests:
mikecase526d68e2014-11-19 20:02:05616 runner_factory, tests = instrumentation_setup.Setup(
617 instrumentation_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37618
619 test_results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57620 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07621 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37622
623 results.AddTestRunResults(test_results)
624
jama47ca85c2014-12-03 18:38:07625 if args.run_python_tests:
[email protected]37ee0c792013-08-06 19:10:13626 runner_factory, tests = host_driven_setup.InstrumentationSetup(
jama47ca85c2014-12-03 18:38:07627 args.host_driven_root, args.official_build,
[email protected]37ee0c792013-08-06 19:10:13628 instrumentation_options)
629
[email protected]34020022013-08-06 23:35:34630 if tests:
631 test_results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57632 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07633 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37634
[email protected]34020022013-08-06 23:35:34635 results.AddTestRunResults(test_results)
[email protected]6bc1bda22013-07-19 22:08:37636
[email protected]34020022013-08-06 23:35:34637 # Only allow exit code escalation
638 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
639 exit_code = test_exit_code
[email protected]6bc1bda22013-07-19 22:08:37640
jama47ca85c2014-12-03 18:38:07641 if args.device_flags:
642 args.device_flags = os.path.join(constants.DIR_SOURCE_ROOT,
643 args.device_flags)
[email protected]4f777ca2014-08-08 01:45:59644
[email protected]6bc1bda22013-07-19 22:08:37645 report_results.LogFull(
646 results=results,
647 test_type='Instrumentation',
jama47ca85c2014-12-03 18:38:07648 test_package=os.path.basename(args.test_apk),
649 annotation=args.annotations,
650 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37651
jama47ca85c2014-12-03 18:38:07652 if args.json_results_file:
653 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54654
[email protected]6bc1bda22013-07-19 22:08:37655 return exit_code
656
657
jama47ca85c2014-12-03 18:38:07658def _RunUIAutomatorTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37659 """Subcommand of RunTestsCommands which runs uiautomator tests."""
jama47ca85c2014-12-03 18:38:07660 uiautomator_options = ProcessUIAutomatorOptions(args)
[email protected]6bc1bda22013-07-19 22:08:37661
[email protected]37ee0c792013-08-06 19:10:13662 runner_factory, tests = uiautomator_setup.Setup(uiautomator_options)
[email protected]6bc1bda22013-07-19 22:08:37663
[email protected]37ee0c792013-08-06 19:10:13664 results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57665 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07666 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37667
668 report_results.LogFull(
669 results=results,
670 test_type='UIAutomator',
jama47ca85c2014-12-03 18:38:07671 test_package=os.path.basename(args.test_jar),
672 annotation=args.annotations,
673 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37674
jama47ca85c2014-12-03 18:38:07675 if args.json_results_file:
676 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54677
[email protected]6bc1bda22013-07-19 22:08:37678 return exit_code
679
680
jama47ca85c2014-12-03 18:38:07681def _RunJUnitTests(args):
jbudorick9a6b7b332014-09-20 00:01:07682 """Subcommand of RunTestsCommand which runs junit tests."""
jama47ca85c2014-12-03 18:38:07683 runner_factory, tests = junit_setup.Setup(args)
jbudorick9a6b7b332014-09-20 00:01:07684 _, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
jbudorick9a6b7b332014-09-20 00:01:07685 return exit_code
686
687
jama47ca85c2014-12-03 18:38:07688def _RunMonkeyTests(args, devices):
[email protected]3dbdfa42013-08-08 01:08:14689 """Subcommand of RunTestsCommands which runs monkey tests."""
jama47ca85c2014-12-03 18:38:07690 monkey_options = ProcessMonkeyTestOptions(args)
[email protected]3dbdfa42013-08-08 01:08:14691
692 runner_factory, tests = monkey_setup.Setup(monkey_options)
693
694 results, exit_code = test_dispatcher.RunTests(
[email protected]181a5c92013-09-06 17:11:46695 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07696 num_retries=args.num_retries)
[email protected]3dbdfa42013-08-08 01:08:14697
698 report_results.LogFull(
699 results=results,
700 test_type='Monkey',
[email protected]14b3b1202013-08-15 22:25:28701 test_package='Monkey')
[email protected]3dbdfa42013-08-08 01:08:14702
jama47ca85c2014-12-03 18:38:07703 if args.json_results_file:
704 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54705
[email protected]3dbdfa42013-08-08 01:08:14706 return exit_code
707
708
jama47ca85c2014-12-03 18:38:07709def _RunPerfTests(args):
[email protected]ec3170b2013-08-14 14:39:47710 """Subcommand of RunTestsCommands which runs perf tests."""
jama47ca85c2014-12-03 18:38:07711 perf_options = ProcessPerfTestOptions(args)
[email protected]61487ed2014-06-09 12:33:56712
713 # Just save a simple json with a list of test names.
714 if perf_options.output_json_list:
715 return perf_test_runner.OutputJsonList(
716 perf_options.steps, perf_options.output_json_list)
717
simonhatchbe8da0c2014-11-27 23:33:03718 if perf_options.output_chartjson_data:
719 return perf_test_runner.OutputChartjson(
720 perf_options.print_step, perf_options.output_chartjson_data)
721
[email protected]ad32f312013-11-13 04:03:29722 # Just print the results from a single previously executed step.
[email protected]ec3170b2013-08-14 14:39:47723 if perf_options.print_step:
724 return perf_test_runner.PrintTestOutput(perf_options.print_step)
725
[email protected]a72f0752014-06-03 23:52:34726 runner_factory, tests, devices = perf_setup.Setup(perf_options)
[email protected]ec3170b2013-08-14 14:39:47727
[email protected]a72f0752014-06-03 23:52:34728 # shard=False means that each device will get the full list of tests
729 # and then each one will decide their own affinity.
730 # shard=True means each device will pop the next test available from a queue,
731 # which increases throughput but have no affinity.
[email protected]86184c7b2013-08-15 15:06:57732 results, _ = test_dispatcher.RunTests(
[email protected]a72f0752014-06-03 23:52:34733 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07734 num_retries=args.num_retries)
[email protected]ec3170b2013-08-14 14:39:47735
736 report_results.LogFull(
737 results=results,
738 test_type='Perf',
[email protected]865a47a2013-08-16 14:01:12739 test_package='Perf')
[email protected]def4bce2013-11-12 12:59:52740
jama47ca85c2014-12-03 18:38:07741 if args.json_results_file:
742 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54743
[email protected]def4bce2013-11-12 12:59:52744 if perf_options.single_step:
745 return perf_test_runner.PrintTestOutput('single_step')
746
[email protected]11ce8452014-02-17 10:55:03747 perf_test_runner.PrintSummary(tests)
748
[email protected]86184c7b2013-08-15 15:06:57749 # Always return 0 on the sharding stage. Individual tests exit_code
750 # will be returned on the print_step stage.
751 return 0
[email protected]ec3170b2013-08-14 14:39:47752
[email protected]3dbdfa42013-08-08 01:08:14753
jama47ca85c2014-12-03 18:38:07754def _RunPythonTests(args):
jbudorick256fd532014-10-24 01:50:13755 """Subcommand of RunTestsCommand which runs python unit tests."""
jama47ca85c2014-12-03 18:38:07756 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name]
jbudorick256fd532014-10-24 01:50:13757 suite_path = suite_vars['path']
758 suite_test_modules = suite_vars['test_modules']
759
760 sys.path = [suite_path] + sys.path
761 try:
762 suite = unittest.TestSuite()
763 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
764 for m in suite_test_modules)
jama47ca85c2014-12-03 18:38:07765 runner = unittest.TextTestRunner(verbosity=1+args.verbose_count)
jbudorick256fd532014-10-24 01:50:13766 return 0 if runner.run(suite).wasSuccessful() else 1
767 finally:
768 sys.path = sys.path[1:]
769
770
[email protected]f7148dd42013-08-20 14:24:57771def _GetAttachedDevices(test_device=None):
772 """Get all attached devices.
773
774 Args:
775 test_device: Name of a specific device to use.
776
777 Returns:
778 A list of attached devices.
779 """
780 attached_devices = []
781
782 attached_devices = android_commands.GetAttachedDevices()
783 if test_device:
784 assert test_device in attached_devices, (
785 'Did not find device %s among attached device. Attached devices: %s'
786 % (test_device, ', '.join(attached_devices)))
787 attached_devices = [test_device]
788
789 assert attached_devices, 'No devices attached.'
790
791 return sorted(attached_devices)
792
793
jama47ca85c2014-12-03 18:38:07794def RunTestsCommand(args, parser):
[email protected]fbe29322013-07-09 09:03:26795 """Checks test type and dispatches to the appropriate function.
796
797 Args:
jama47ca85c2014-12-03 18:38:07798 args: argparse.Namespace object.
799 parser: argparse.ArgumentParser object.
[email protected]fbe29322013-07-09 09:03:26800
801 Returns:
802 Integer indicated exit code.
[email protected]b3873892013-07-10 04:57:10803
804 Raises:
805 Exception: Unknown command name passed in, or an exception from an
806 individual test runner.
[email protected]fbe29322013-07-09 09:03:26807 """
jama47ca85c2014-12-03 18:38:07808 command = args.command
[email protected]fbe29322013-07-09 09:03:26809
jama47ca85c2014-12-03 18:38:07810 ProcessCommonOptions(args)
[email protected]d82f0252013-07-12 23:22:57811
jama47ca85c2014-12-03 18:38:07812 if args.enable_platform_mode:
813 return RunTestsInPlatformMode(args, parser.error)
jbudorick66dc3722014-11-06 21:33:51814
815 if command in constants.LOCAL_MACHINE_TESTS:
jbudorick256fd532014-10-24 01:50:13816 devices = []
817 else:
jama47ca85c2014-12-03 18:38:07818 devices = _GetAttachedDevices(args.test_device)
[email protected]f7148dd42013-08-20 14:24:57819
[email protected]c0662e092013-11-12 11:51:25820 forwarder.Forwarder.RemoveHostLog()
[email protected]6b11583b2013-11-21 16:18:40821 if not ports.ResetTestServerPortAllocation():
822 raise Exception('Failed to reset test server port.')
[email protected]c0662e092013-11-12 11:51:25823
[email protected]fbe29322013-07-09 09:03:26824 if command == 'gtest':
jama47ca85c2014-12-03 18:38:07825 return _RunGTests(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38826 elif command == 'linker':
jama47ca85c2014-12-03 18:38:07827 return _RunLinkerTests(args, devices)
[email protected]fbe29322013-07-09 09:03:26828 elif command == 'instrumentation':
jama47ca85c2014-12-03 18:38:07829 return _RunInstrumentationTests(args, devices)
[email protected]fbe29322013-07-09 09:03:26830 elif command == 'uiautomator':
jama47ca85c2014-12-03 18:38:07831 return _RunUIAutomatorTests(args, devices)
jbudorick9a6b7b332014-09-20 00:01:07832 elif command == 'junit':
jama47ca85c2014-12-03 18:38:07833 return _RunJUnitTests(args)
[email protected]3dbdfa42013-08-08 01:08:14834 elif command == 'monkey':
jama47ca85c2014-12-03 18:38:07835 return _RunMonkeyTests(args, devices)
[email protected]ec3170b2013-08-14 14:39:47836 elif command == 'perf':
jama47ca85c2014-12-03 18:38:07837 return _RunPerfTests(args)
jbudorick256fd532014-10-24 01:50:13838 elif command == 'python':
jama47ca85c2014-12-03 18:38:07839 return _RunPythonTests(args)
[email protected]fbe29322013-07-09 09:03:26840 else:
[email protected]6bc1bda22013-07-19 22:08:37841 raise Exception('Unknown test type.')
[email protected]fbe29322013-07-09 09:03:26842
[email protected]fbe29322013-07-09 09:03:26843
jbudorick66dc3722014-11-06 21:33:51844_SUPPORTED_IN_PLATFORM_MODE = [
845 # TODO(jbudorick): Add support for more test types.
846 'gtest',
847]
848
849
jama47ca85c2014-12-03 18:38:07850def RunTestsInPlatformMode(args, parser):
jbudorick66dc3722014-11-06 21:33:51851
jama47ca85c2014-12-03 18:38:07852 if args.command not in _SUPPORTED_IN_PLATFORM_MODE:
853 parser.error('%s is not yet supported in platform mode' % args.command)
jbudorick66dc3722014-11-06 21:33:51854
jama47ca85c2014-12-03 18:38:07855 with environment_factory.CreateEnvironment(args, parser.error) as env:
856 with test_instance_factory.CreateTestInstance(args, parser.error) as test:
jbudorick66dc3722014-11-06 21:33:51857 with test_run_factory.CreateTestRun(
jama47ca85c2014-12-03 18:38:07858 args, env, test, parser.error) as test_run:
jbudorick66dc3722014-11-06 21:33:51859 results = test_run.RunTests()
860
861 report_results.LogFull(
862 results=results,
863 test_type=test.TestType(),
864 test_package=test_run.TestPackage(),
jama47ca85c2014-12-03 18:38:07865 annotation=args.annotations,
866 flakiness_server=args.flakiness_dashboard_server)
jbudorick66dc3722014-11-06 21:33:51867
jama47ca85c2014-12-03 18:38:07868 if args.json_results_file:
jbudorickb8c42072014-12-01 18:07:54869 json_results.GenerateJsonResultsFile(
jama47ca85c2014-12-03 18:38:07870 results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54871
jbudorick66dc3722014-11-06 21:33:51872 return results
873
874
jama47ca85c2014-12-03 18:38:07875CommandConfigTuple = collections.namedtuple(
876 'CommandConfigTuple',
877 ['add_options_func', 'help_txt'])
[email protected]fbe29322013-07-09 09:03:26878VALID_COMMANDS = {
jama47ca85c2014-12-03 18:38:07879 'gtest': CommandConfigTuple(
880 AddGTestOptions,
881 'googletest-based C++ tests'),
882 'instrumentation': CommandConfigTuple(
883 AddInstrumentationTestOptions,
884 'InstrumentationTestCase-based Java tests'),
885 'uiautomator': CommandConfigTuple(
886 AddUIAutomatorTestOptions,
887 "Tests that run via Android's uiautomator command"),
888 'junit': CommandConfigTuple(
889 AddJUnitTestOptions,
890 'JUnit4-based Java tests'),
891 'monkey': CommandConfigTuple(
892 AddMonkeyTestOptions,
893 "Tests based on Android's monkey"),
894 'perf': CommandConfigTuple(
895 AddPerfTestOptions,
896 'Performance tests'),
897 'python': CommandConfigTuple(
898 AddPythonTestOptions,
899 'Python tests based on unittest.TestCase'),
900 'linker': CommandConfigTuple(
901 AddLinkerTestOptions,
902 'Linker tests'),
903}
[email protected]fbe29322013-07-09 09:03:26904
905
[email protected]7c53a602014-03-24 16:21:44906def DumpThreadStacks(_signal, _frame):
[email protected]71aec4b2013-11-20 00:35:24907 for thread in threading.enumerate():
908 reraiser_thread.LogThreadStack(thread)
[email protected]83bb8152013-11-19 15:02:21909
910
[email protected]7c53a602014-03-24 16:21:44911def main():
[email protected]83bb8152013-11-19 15:02:21912 signal.signal(signal.SIGUSR1, DumpThreadStacks)
jama47ca85c2014-12-03 18:38:07913
914 parser = argparse.ArgumentParser()
915 command_parsers = parser.add_subparsers(title='test types',
916 dest='command')
917
918 for test_type, config in sorted(VALID_COMMANDS.iteritems(),
919 key=lambda x: x[0]):
920 subparser = command_parsers.add_parser(
921 test_type, usage='%(prog)s [options]', help=config.help_txt)
922 config.add_options_func(subparser)
923
924 args = parser.parse_args()
925 RunTestsCommand(args, parser)
926
927 return 0
[email protected]fbe29322013-07-09 09:03:26928
[email protected]fbe29322013-07-09 09:03:26929
930if __name__ == '__main__':
[email protected]7c53a602014-03-24 16:21:44931 sys.exit(main())