blob: 48909f588096efe7a750262aa968f4e4acff8ef4 [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
jbudorickeb7ea71c2015-09-28 16:40:2011import itertools
[email protected]f7148dd42013-08-20 14:24:5712import logging
[email protected]fbe29322013-07-09 09:03:2613import os
[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
jbudorick061629442015-09-03 18:00:5719from devil import base_error
20from devil.android import apk_helper
21from devil.android import device_blacklist
22from devil.android import device_errors
23from devil.android import device_utils
24from devil.android import ports
25from devil.utils import reraiser_thread
26from devil.utils import run_tests_helper
27
[email protected]fbe29322013-07-09 09:03:2628from pylib import constants
[email protected]c0662e092013-11-12 11:51:2529from pylib import forwarder
[email protected]fbe29322013-07-09 09:03:2630from pylib.base import base_test_result
jbudorick66dc3722014-11-06 21:33:5131from pylib.base import environment_factory
[email protected]6bc1bda22013-07-19 22:08:3732from pylib.base import test_dispatcher
jbudorick66dc3722014-11-06 21:33:5133from pylib.base import test_instance_factory
34from pylib.base import test_run_factory
[email protected]6b6abac6d2013-10-03 11:56:3835from pylib.linker import setup as linker_setup
[email protected]37ee0c792013-08-06 19:10:1336from pylib.host_driven import setup as host_driven_setup
[email protected]6bc1bda22013-07-19 22:08:3737from pylib.instrumentation import setup as instrumentation_setup
[email protected]2a684222013-08-01 16:59:2238from pylib.instrumentation import test_options as instrumentation_test_options
jbudorick9a6b7b332014-09-20 00:01:0739from pylib.junit import setup as junit_setup
40from pylib.junit import test_dispatcher as junit_dispatcher
[email protected]3dbdfa42013-08-08 01:08:1441from pylib.monkey import setup as monkey_setup
42from pylib.monkey import test_options as monkey_test_options
[email protected]ec3170b2013-08-14 14:39:4743from pylib.perf import setup as perf_setup
44from pylib.perf import test_options as perf_test_options
45from pylib.perf import test_runner as perf_test_runner
jbudorickb8c42072014-12-01 18:07:5446from pylib.results import json_results
47from pylib.results import report_results
[email protected]fbe29322013-07-09 09:03:2648
49
jama47ca85c2014-12-03 18:38:0750def AddCommonOptions(parser):
51 """Adds all common options to |parser|."""
[email protected]fbe29322013-07-09 09:03:2652
jama47ca85c2014-12-03 18:38:0753 group = parser.add_argument_group('Common Options')
54
[email protected]dfffbcbc2013-09-17 22:06:0155 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
jama47ca85c2014-12-03 18:38:0756
57 debug_or_release_group = group.add_mutually_exclusive_group()
58 debug_or_release_group.add_argument(
59 '--debug', action='store_const', const='Debug', dest='build_type',
60 default=default_build_type,
61 help=('If set, run test suites under out/Debug. '
62 'Default is env var BUILDTYPE or Debug.'))
63 debug_or_release_group.add_argument(
64 '--release', action='store_const', const='Release', dest='build_type',
65 help=('If set, run test suites under out/Release. '
66 'Default is env var BUILDTYPE or Debug.'))
67
68 group.add_argument('--build-directory', dest='build_directory',
69 help=('Path to the directory in which build files are'
70 ' located (should not include build type)'))
71 group.add_argument('--output-directory', dest='output_directory',
72 help=('Path to the directory in which build files are'
73 ' located (must include build type). This will take'
74 ' precedence over --debug, --release and'
75 ' --build-directory'))
agrieveddb11f12015-10-23 17:03:4376 group.add_argument('--num_retries', '--num-retries', dest='num_retries',
77 type=int, default=2,
jama47ca85c2014-12-03 18:38:0778 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
jama47ca85c2014-12-03 18:38:07105def ProcessCommonOptions(args):
[email protected]fbe29322013-07-09 09:03:26106 """Processes and handles all common options."""
jama47ca85c2014-12-03 18:38:07107 run_tests_helper.SetLogLevel(args.verbose_count)
108 constants.SetBuildType(args.build_type)
109 if args.build_directory:
110 constants.SetBuildDirectory(args.build_directory)
111 if args.output_directory:
mikecase0aea9c52015-04-30 00:12:33112 constants.SetOutputDirectory(args.output_directory)
jama47ca85c2014-12-03 18:38:07113 if args.adb_path:
114 constants.SetAdbPath(args.adb_path)
mikecase48e16bf2014-11-19 22:46:45115 # Some things such as Forwarder require ADB to be in the environment path.
116 adb_dir = os.path.dirname(constants.GetAdbPath())
117 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep):
118 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
[email protected]fbe29322013-07-09 09:03:26119
120
rnephew5c499782014-12-12 19:08:55121def AddRemoteDeviceOptions(parser):
122 group = parser.add_argument_group('Remote Device Options')
123
rnephewefe44b42015-02-04 04:45:15124 group.add_argument('--trigger',
jbudoricke6c560152015-01-13 23:49:28125 help=('Only triggers the test if set. Stores test_run_id '
126 'in given file path. '))
rnephewefe44b42015-02-04 04:45:15127 group.add_argument('--collect',
jbudoricke6c560152015-01-13 23:49:28128 help=('Only collects the test results if set. '
129 'Gets test_run_id from given file path.'))
rnephewefe44b42015-02-04 04:45:15130 group.add_argument('--remote-device', action='append',
jbudoricke6c560152015-01-13 23:49:28131 help='Device type to run test on.')
rnephewefe44b42015-02-04 04:45:15132 group.add_argument('--results-path',
jbudoricke6c560152015-01-13 23:49:28133 help='File path to download results to.')
rnephew7f1e2052014-12-12 23:00:11134 group.add_argument('--api-protocol',
jbudoricke6c560152015-01-13 23:49:28135 help='HTTP protocol to use. (http or https)')
rnephewefe44b42015-02-04 04:45:15136 group.add_argument('--api-address',
137 help='Address to send HTTP requests.')
138 group.add_argument('--api-port',
139 help='Port to send HTTP requests to.')
140 group.add_argument('--runner-type',
jbudoricke6c560152015-01-13 23:49:28141 help='Type of test to run as.')
rnephewefe44b42015-02-04 04:45:15142 group.add_argument('--runner-package',
143 help='Package name of test.')
144 group.add_argument('--device-type',
rnephewa46fc562015-01-23 16:00:14145 choices=constants.VALID_DEVICE_TYPES,
146 help=('Type of device to run on. iOS or android'))
rnephewefe44b42015-02-04 04:45:15147 group.add_argument('--device-oem', action='append',
148 help='Device OEM to run on.')
149 group.add_argument('--remote-device-file',
150 help=('File with JSON to select remote device. '
151 'Overrides all other flags.'))
rnephewc9ae8f52015-02-13 03:02:55152 group.add_argument('--remote-device-timeout', type=int,
153 help='Times to retry finding remote device')
mikecase520cbbb52015-04-21 18:51:18154 group.add_argument('--network-config', type=int,
155 help='Integer that specifies the network environment '
156 'that the tests will be run in.')
mikecaseddfa35d2015-10-28 01:14:27157 group.add_argument('--test-timeout', type=int,
158 help='Test run timeout in seconds.')
rnephewefe44b42015-02-04 04:45:15159
160 device_os_group = group.add_mutually_exclusive_group()
161 device_os_group.add_argument('--remote-device-minimum-os',
162 help='Minimum OS on device.')
163 device_os_group.add_argument('--remote-device-os', action='append',
164 help='OS to have on the device.')
rnephew5c499782014-12-12 19:08:55165
166 api_secret_group = group.add_mutually_exclusive_group()
167 api_secret_group.add_argument('--api-secret', default='',
jbudoricke6c560152015-01-13 23:49:28168 help='API secret for remote devices.')
rnephew5c499782014-12-12 19:08:55169 api_secret_group.add_argument('--api-secret-file', default='',
jbudoricke6c560152015-01-13 23:49:28170 help='Path to file that contains API secret.')
rnephew5c499782014-12-12 19:08:55171
172 api_key_group = group.add_mutually_exclusive_group()
173 api_key_group.add_argument('--api-key', default='',
jbudoricke6c560152015-01-13 23:49:28174 help='API key for remote devices.')
rnephew5c499782014-12-12 19:08:55175 api_key_group.add_argument('--api-key-file', default='',
jbudoricke6c560152015-01-13 23:49:28176 help='Path to file that contains API key.')
rnephew5c499782014-12-12 19:08:55177
178
jama47ca85c2014-12-03 18:38:07179def AddDeviceOptions(parser):
180 """Adds device options to |parser|."""
181 group = parser.add_argument_group(title='Device Options')
jama47ca85c2014-12-03 18:38:07182 group.add_argument('--tool',
183 dest='tool',
184 help=('Run the test under a tool '
185 '(use --tool help to list them)'))
186 group.add_argument('-d', '--device', dest='test_device',
187 help=('Target device for the test suite '
188 'to run on.'))
jbudorickdde688fb2015-08-27 03:00:17189 group.add_argument('--blacklist-file', help='Device blacklist file.')
agrievea538a142015-10-09 15:45:56190 group.add_argument('--enable-device-cache', action='store_true',
191 help='Cache device state to disk between runs')
agrieve1a02e582015-10-15 21:35:39192 group.add_argument('--incremental-install', action='store_true',
193 help='Use an _incremental apk.')
agrieve8bcb52e2015-10-20 19:38:33194 group.add_argument('--enable-concurrent-adb', action='store_true',
195 help='Run multiple adb commands at the same time, even '
196 'for the same device.')
jbudorick256fd532014-10-24 01:50:13197
198
jama47ca85c2014-12-03 18:38:07199def AddGTestOptions(parser):
200 """Adds gtest options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26201
jama47ca85c2014-12-03 18:38:07202 group = parser.add_argument_group('GTest Options')
jbudorick15cdcd52014-12-03 19:58:49203 group.add_argument('-s', '--suite', dest='suite_name',
jama47ca85c2014-12-03 18:38:07204 nargs='+', metavar='SUITE_NAME', required=True,
jbudorick277f2312015-09-24 16:37:43205 help='Executable name of the test suite to run.')
jama47ca85c2014-12-03 18:38:07206 group.add_argument('--gtest_also_run_disabled_tests',
207 '--gtest-also-run-disabled-tests',
208 dest='run_disabled', action='store_true',
209 help='Also run disabled tests if applicable.')
210 group.add_argument('-a', '--test-arguments', dest='test_arguments',
211 default='',
212 help='Additional arguments to pass to the test.')
jbudorick24616eb2015-10-06 02:40:57213 group.add_argument('-t', '--shard-timeout',
214 dest='shard_timeout', type=int, default=60,
jama47ca85c2014-12-03 18:38:07215 help='Timeout to wait for each test '
216 '(default: %(default)s).')
217 group.add_argument('--isolate_file_path',
218 '--isolate-file-path',
219 dest='isolate_file_path',
220 help='.isolate file path to override the default '
221 'path')
jbudorick5ee45892015-06-10 18:46:22222 group.add_argument('--app-data-file', action='append', dest='app_data_files',
223 help='A file path relative to the app data directory '
224 'that should be saved to the host.')
225 group.add_argument('--app-data-file-dir',
226 help='Host directory to which app data files will be'
227 ' saved. Used with --app-data-file.')
mlliud7f9fe92015-06-15 19:36:56228 group.add_argument('--delete-stale-data', dest='delete_stale_data',
229 action='store_true',
230 help='Delete stale test data on the device.')
jbudorickeb7ea71c2015-09-28 16:40:20231 group.add_argument('--repeat', '--gtest_repeat', '--gtest-repeat',
232 dest='repeat', type=int, default=0,
233 help='Number of times to repeat the specified set of '
234 'tests.')
jbudorick442a6932015-02-03 03:01:15235
236 filter_group = group.add_mutually_exclusive_group()
237 filter_group.add_argument('-f', '--gtest_filter', '--gtest-filter',
238 dest='test_filter',
239 help='googletest-style filter string.')
240 filter_group.add_argument('--gtest-filter-file', dest='test_filter_file',
241 help='Path to file that contains googletest-style '
242 'filter strings. (Lines will be joined with '
243 '":" to create a single filter string.)')
244
jama47ca85c2014-12-03 18:38:07245 AddDeviceOptions(parser)
246 AddCommonOptions(parser)
rnephew5c499782014-12-12 19:08:55247 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26248
249
jama47ca85c2014-12-03 18:38:07250def AddLinkerTestOptions(parser):
251 group = parser.add_argument_group('Linker Test Options')
252 group.add_argument('-f', '--gtest-filter', dest='test_filter',
253 help='googletest-style filter string.')
254 AddCommonOptions(parser)
255 AddDeviceOptions(parser)
[email protected]6b6abac6d2013-10-03 11:56:38256
257
jama47ca85c2014-12-03 18:38:07258def AddJavaTestOptions(argument_group):
[email protected]fbe29322013-07-09 09:03:26259 """Adds the Java test options to |option_parser|."""
260
jama47ca85c2014-12-03 18:38:07261 argument_group.add_argument(
262 '-f', '--test-filter', dest='test_filter',
263 help=('Test filter (if not fully qualified, will run all matches).'))
264 argument_group.add_argument(
jbudorickeb7ea71c2015-09-28 16:40:20265 '--repeat', dest='repeat', type=int, default=0,
266 help='Number of times to repeat the specified set of tests.')
267 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26268 '-A', '--annotation', dest='annotation_str',
269 help=('Comma-separated list of annotations. Run only tests with any of '
270 'the given annotations. An annotation can be either a key or a '
271 'key-values pair. A test that has no annotation is considered '
272 '"SmallTest".'))
jama47ca85c2014-12-03 18:38:07273 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26274 '-E', '--exclude-annotation', dest='exclude_annotation_str',
275 help=('Comma-separated list of annotations. Exclude tests with these '
276 'annotations.'))
jama47ca85c2014-12-03 18:38:07277 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59278 '--screenshot', dest='screenshot_failures', action='store_true',
279 help='Capture screenshots of test failures')
jama47ca85c2014-12-03 18:38:07280 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59281 '--save-perf-json', action='store_true',
282 help='Saves the JSON file for each UI Perf test.')
jama47ca85c2014-12-03 18:38:07283 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59284 '--official-build', action='store_true', help='Run official build tests.')
jama47ca85c2014-12-03 18:38:07285 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59286 '--test_data', '--test-data', action='append', default=[],
287 help=('Each instance defines a directory of test data that should be '
288 'copied to the target(s) before running the tests. The argument '
289 'should be of the form <target>:<source>, <target> is relative to '
290 'the device data directory, and <source> is relative to the '
291 'chromium build directory.'))
davileen98efad12015-01-05 19:48:21292 argument_group.add_argument(
293 '--disable-dalvik-asserts', dest='set_asserts', action='store_false',
294 default=True, help='Removes the dalvik.vm.enableassertions property')
295
[email protected]fbe29322013-07-09 09:03:26296
297
jama47ca85c2014-12-03 18:38:07298def ProcessJavaTestOptions(args):
[email protected]fbe29322013-07-09 09:03:26299 """Processes options/arguments and populates |options| with defaults."""
300
jama47ca85c2014-12-03 18:38:07301 # TODO(jbudorick): Handle most of this function in argparse.
302 if args.annotation_str:
303 args.annotations = args.annotation_str.split(',')
304 elif args.test_filter:
305 args.annotations = []
[email protected]fbe29322013-07-09 09:03:26306 else:
jama47ca85c2014-12-03 18:38:07307 args.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
308 'EnormousTest', 'IntegrationTest']
[email protected]fbe29322013-07-09 09:03:26309
jama47ca85c2014-12-03 18:38:07310 if args.exclude_annotation_str:
311 args.exclude_annotations = args.exclude_annotation_str.split(',')
[email protected]fbe29322013-07-09 09:03:26312 else:
jama47ca85c2014-12-03 18:38:07313 args.exclude_annotations = []
[email protected]fbe29322013-07-09 09:03:26314
[email protected]fbe29322013-07-09 09:03:26315
jama47ca85c2014-12-03 18:38:07316def AddInstrumentationTestOptions(parser):
317 """Adds Instrumentation test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26318
jama47ca85c2014-12-03 18:38:07319 parser.usage = '%(prog)s [options]'
[email protected]fbe29322013-07-09 09:03:26320
jama47ca85c2014-12-03 18:38:07321 group = parser.add_argument_group('Instrumentation Test Options')
322 AddJavaTestOptions(group)
[email protected]fbe29322013-07-09 09:03:26323
jama47ca85c2014-12-03 18:38:07324 java_or_python_group = group.add_mutually_exclusive_group()
325 java_or_python_group.add_argument(
326 '-j', '--java-only', action='store_false',
327 dest='run_python_tests', default=True, help='Run only the Java tests.')
328 java_or_python_group.add_argument(
329 '-p', '--python-only', action='store_false',
330 dest='run_java_tests', default=True,
331 help='Run only the host-driven tests.')
332
333 group.add_argument('--host-driven-root',
334 help='Root of the host-driven tests.')
335 group.add_argument('-w', '--wait_debugger', dest='wait_for_debugger',
336 action='store_true',
337 help='Wait for debugger.')
jbudorick911be58d2015-01-13 02:51:06338 group.add_argument('--apk-under-test', dest='apk_under_test',
339 help=('the name of the apk under test.'))
jama47ca85c2014-12-03 18:38:07340 group.add_argument('--test-apk', dest='test_apk', required=True,
341 help=('The name of the apk containing the tests '
342 '(without the .apk extension; '
343 'e.g. "ContentShellTest").'))
mikecasee7258622015-09-29 13:47:35344 group.add_argument('--additional-apk', action='append',
mikecase8c4ab302015-09-29 17:03:29345 dest='additional_apks', default=[],
mikecasee7258622015-09-29 13:47:35346 help='Additional apk that must be installed on '
347 'the device when the tests are run')
jama47ca85c2014-12-03 18:38:07348 group.add_argument('--coverage-dir',
349 help=('Directory in which to place all generated '
350 'EMMA coverage files.'))
351 group.add_argument('--device-flags', dest='device_flags', default='',
352 help='The relative filepath to a file containing '
353 'command-line flags to set on the device')
jbudorick911be58d2015-01-13 02:51:06354 group.add_argument('--device-flags-file', default='',
355 help='The relative filepath to a file containing '
356 'command-line flags to set on the device')
jama47ca85c2014-12-03 18:38:07357 group.add_argument('--isolate_file_path',
358 '--isolate-file-path',
359 dest='isolate_file_path',
360 help='.isolate file path to override the default '
361 'path')
mlliud7f9fe92015-06-15 19:36:56362 group.add_argument('--delete-stale-data', dest='delete_stale_data',
363 action='store_true',
364 help='Delete stale test data on the device.')
jbudorickede49722015-11-25 05:16:34365 group.add_argument('--timeout-scale', type=float,
366 help='Factor by which timeouts should be scaled.')
jama47ca85c2014-12-03 18:38:07367
368 AddCommonOptions(parser)
369 AddDeviceOptions(parser)
rnephewe416dff2015-01-21 21:26:37370 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26371
372
jama47ca85c2014-12-03 18:38:07373def ProcessInstrumentationOptions(args):
[email protected]2a684222013-08-01 16:59:22374 """Processes options/arguments and populate |options| with defaults.
375
376 Args:
jama47ca85c2014-12-03 18:38:07377 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22378
379 Returns:
380 An InstrumentationOptions named tuple which contains all options relevant to
381 instrumentation tests.
382 """
[email protected]fbe29322013-07-09 09:03:26383
jama47ca85c2014-12-03 18:38:07384 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26385
jama47ca85c2014-12-03 18:38:07386 if not args.host_driven_root:
387 args.run_python_tests = False
[email protected]37ee0c792013-08-06 19:10:13388
jbudorick9ef3f9552015-10-20 22:58:33389 if os.path.exists(args.test_apk):
390 args.test_apk_path = args.test_apk
391 args.test_apk, _ = os.path.splitext(os.path.basename(args.test_apk))
392 else:
393 args.test_apk_path = os.path.join(
394 constants.GetOutDirectory(),
395 constants.SDK_BUILD_APKS_DIR,
396 '%s.apk' % args.test_apk)
397
jama47ca85c2014-12-03 18:38:07398 args.test_apk_jar_path = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15399 constants.GetOutDirectory(),
400 constants.SDK_BUILD_TEST_JAVALIB_DIR,
jbudorick9ef3f9552015-10-20 22:58:33401 '%s.jar' % args.test_apk)
yusufo72c598c02015-07-16 23:40:20402 args.test_support_apk_path = '%sSupport%s' % (
403 os.path.splitext(args.test_apk_path))
[email protected]5e2f3f62014-06-23 12:31:46404
jama47ca85c2014-12-03 18:38:07405 args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path)
[email protected]5e2f3f62014-06-23 12:31:46406
jama47ca85c2014-12-03 18:38:07407 # TODO(jbudorick): Get rid of InstrumentationOptions.
[email protected]2a684222013-08-01 16:59:22408 return instrumentation_test_options.InstrumentationOptions(
jama47ca85c2014-12-03 18:38:07409 args.tool,
jama47ca85c2014-12-03 18:38:07410 args.annotations,
411 args.exclude_annotations,
412 args.test_filter,
413 args.test_data,
414 args.save_perf_json,
415 args.screenshot_failures,
416 args.wait_for_debugger,
417 args.coverage_dir,
418 args.test_apk,
419 args.test_apk_path,
420 args.test_apk_jar_path,
421 args.test_runner,
422 args.test_support_apk_path,
423 args.device_flags,
davileen98efad12015-01-05 19:48:21424 args.isolate_file_path,
mlliud7f9fe92015-06-15 19:36:56425 args.set_asserts,
jbudorickede49722015-11-25 05:16:34426 args.delete_stale_data,
427 args.timeout_scale)
[email protected]2a684222013-08-01 16:59:22428
[email protected]fbe29322013-07-09 09:03:26429
jama47ca85c2014-12-03 18:38:07430def AddUIAutomatorTestOptions(parser):
431 """Adds UI Automator test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26432
jama47ca85c2014-12-03 18:38:07433 group = parser.add_argument_group('UIAutomator Test Options')
434 AddJavaTestOptions(group)
435 group.add_argument(
436 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
437 metavar='PACKAGE', help='Package under test.')
438 group.add_argument(
439 '--test-jar', dest='test_jar', required=True,
[email protected]fbe29322013-07-09 09:03:26440 help=('The name of the dexed jar containing the tests (without the '
441 '.dex.jar extension). Alternatively, this can be a full path '
442 'to the jar.'))
443
jama47ca85c2014-12-03 18:38:07444 AddCommonOptions(parser)
445 AddDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26446
447
jama47ca85c2014-12-03 18:38:07448def AddJUnitTestOptions(parser):
449 """Adds junit test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07450
jama47ca85c2014-12-03 18:38:07451 group = parser.add_argument_group('JUnit Test Options')
452 group.add_argument(
453 '-s', '--test-suite', dest='test_suite', required=True,
jbudorick9a6b7b332014-09-20 00:01:07454 help=('JUnit test suite to run.'))
jama47ca85c2014-12-03 18:38:07455 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07456 '-f', '--test-filter', dest='test_filter',
457 help='Filters tests googletest-style.')
jama47ca85c2014-12-03 18:38:07458 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07459 '--package-filter', dest='package_filter',
460 help='Filters tests by package.')
jama47ca85c2014-12-03 18:38:07461 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07462 '--runner-filter', dest='runner_filter',
463 help='Filters tests by runner class. Must be fully qualified.')
jama47ca85c2014-12-03 18:38:07464 group.add_argument(
465 '--sdk-version', dest='sdk_version', type=int,
jbudorick9a6b7b332014-09-20 00:01:07466 help='The Android SDK version.')
jama47ca85c2014-12-03 18:38:07467 AddCommonOptions(parser)
jbudorick9a6b7b332014-09-20 00:01:07468
469
jama47ca85c2014-12-03 18:38:07470def AddMonkeyTestOptions(parser):
471 """Adds monkey test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07472
jama47ca85c2014-12-03 18:38:07473 group = parser.add_argument_group('Monkey Test Options')
474 group.add_argument(
475 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
476 metavar='PACKAGE', help='Package under test.')
477 group.add_argument(
478 '--event-count', default=10000, type=int,
479 help='Number of events to generate (default: %(default)s).')
480 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14481 '--category', default='',
[email protected]fb81b982013-08-09 00:07:12482 help='A list of allowed categories.')
jama47ca85c2014-12-03 18:38:07483 group.add_argument(
484 '--throttle', default=100, type=int,
485 help='Delay between events (ms) (default: %(default)s). ')
486 group.add_argument(
487 '--seed', type=int,
[email protected]3dbdfa42013-08-08 01:08:14488 help=('Seed value for pseudo-random generator. Same seed value generates '
489 'the same sequence of events. Seed is randomized by default.'))
jama47ca85c2014-12-03 18:38:07490 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14491 '--extra-args', default='',
jama47ca85c2014-12-03 18:38:07492 help=('String of other args to pass to the command verbatim.'))
[email protected]3dbdfa42013-08-08 01:08:14493
jama47ca85c2014-12-03 18:38:07494 AddCommonOptions(parser)
495 AddDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14496
jama47ca85c2014-12-03 18:38:07497def ProcessMonkeyTestOptions(args):
[email protected]3dbdfa42013-08-08 01:08:14498 """Processes all monkey test options.
499
500 Args:
jama47ca85c2014-12-03 18:38:07501 args: argparse.Namespace object.
[email protected]3dbdfa42013-08-08 01:08:14502
503 Returns:
504 A MonkeyOptions named tuple which contains all options relevant to
505 monkey tests.
506 """
jama47ca85c2014-12-03 18:38:07507 # TODO(jbudorick): Handle this directly in argparse with nargs='+'
508 category = args.category
[email protected]3dbdfa42013-08-08 01:08:14509 if category:
jama47ca85c2014-12-03 18:38:07510 category = args.category.split(',')
[email protected]3dbdfa42013-08-08 01:08:14511
jama47ca85c2014-12-03 18:38:07512 # TODO(jbudorick): Get rid of MonkeyOptions.
[email protected]3dbdfa42013-08-08 01:08:14513 return monkey_test_options.MonkeyOptions(
jama47ca85c2014-12-03 18:38:07514 args.verbose_count,
515 args.package,
516 args.event_count,
[email protected]3dbdfa42013-08-08 01:08:14517 category,
jama47ca85c2014-12-03 18:38:07518 args.throttle,
519 args.seed,
520 args.extra_args)
[email protected]3dbdfa42013-08-08 01:08:14521
rnephew5c499782014-12-12 19:08:55522def AddUirobotTestOptions(parser):
523 """Adds uirobot test options to |option_parser|."""
524 group = parser.add_argument_group('Uirobot Test Options')
525
rnephewefe44b42015-02-04 04:45:15526 group.add_argument('--app-under-test', required=True,
527 help='APK to run tests on.')
rnephew5c499782014-12-12 19:08:55528 group.add_argument(
mikecaseafa43842015-10-19 23:04:12529 '--repeat', dest='repeat', type=int, default=0,
530 help='Number of times to repeat the uirobot test.')
531 group.add_argument(
rnephew5c499782014-12-12 19:08:55532 '--minutes', default=5, type=int,
jbudorick676b1202015-02-06 22:02:27533 help='Number of minutes to run uirobot test [default: %(default)s].')
rnephew5c499782014-12-12 19:08:55534
535 AddCommonOptions(parser)
536 AddDeviceOptions(parser)
537 AddRemoteDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14538
jama47ca85c2014-12-03 18:38:07539def AddPerfTestOptions(parser):
540 """Adds perf test options to |parser|."""
[email protected]ec3170b2013-08-14 14:39:47541
jama47ca85c2014-12-03 18:38:07542 group = parser.add_argument_group('Perf Test Options')
[email protected]ec3170b2013-08-14 14:39:47543
jama47ca85c2014-12-03 18:38:07544 class SingleStepAction(argparse.Action):
545 def __call__(self, parser, namespace, values, option_string=None):
546 if values and not namespace.single_step:
547 parser.error('single step command provided, '
548 'but --single-step not specified.')
549 elif namespace.single_step and not values:
550 parser.error('--single-step specified, '
551 'but no single step command provided.')
552 setattr(namespace, self.dest, values)
553
554 step_group = group.add_mutually_exclusive_group(required=True)
555 # TODO(jbudorick): Revise --single-step to use argparse.REMAINDER.
556 # This requires removing "--" from client calls.
557 step_group.add_argument(
558 '--single-step', action='store_true',
[email protected]def4bce2013-11-12 12:59:52559 help='Execute the given command with retries, but only print the result '
560 'for the "most successful" round.')
jama47ca85c2014-12-03 18:38:07561 step_group.add_argument(
[email protected]181a5c92013-09-06 17:11:46562 '--steps',
[email protected]def4bce2013-11-12 12:59:52563 help='JSON file containing the list of commands to run.')
jama47ca85c2014-12-03 18:38:07564 step_group.add_argument(
565 '--print-step',
566 help='The name of a previously executed perf step to print.')
567
568 group.add_argument(
peterbd4e73d2014-12-03 15:47:36569 '--output-json-list',
570 help='Write a simple list of names from --steps into the given file.')
jama47ca85c2014-12-03 18:38:07571 group.add_argument(
peterbd4e73d2014-12-03 15:47:36572 '--collect-chartjson-data',
573 action='store_true',
574 help='Cache the chartjson output from each step for later use.')
jama47ca85c2014-12-03 18:38:07575 group.add_argument(
peterbd4e73d2014-12-03 15:47:36576 '--output-chartjson-data',
577 default='',
578 help='Write out chartjson into the given file.')
jama47ca85c2014-12-03 18:38:07579 group.add_argument(
perezju67cf7f12015-09-29 11:39:05580 '--get-output-dir-archive', metavar='FILENAME',
581 help='Write the chached output directory archived by a step into the'
582 ' given ZIP file.')
583 group.add_argument(
jama47ca85c2014-12-03 18:38:07584 '--flaky-steps',
585 help=('A JSON file containing steps that are flaky '
586 'and will have its exit code ignored.'))
587 group.add_argument(
[email protected]181a5c92013-09-06 17:11:46588 '--no-timeout', action='store_true',
589 help=('Do not impose a timeout. Each perf step is responsible for '
590 'implementing the timeout logic.'))
jama47ca85c2014-12-03 18:38:07591 group.add_argument(
[email protected]650487c2013-09-30 11:40:49592 '-f', '--test-filter',
593 help=('Test filter (will match against the names listed in --steps).'))
jama47ca85c2014-12-03 18:38:07594 group.add_argument(
595 '--dry-run', action='store_true',
[email protected]650487c2013-09-30 11:40:49596 help='Just print the steps without executing.')
jbudorick5cfff872015-07-01 18:46:13597 # Uses 0.1 degrees C because that's what Android does.
598 group.add_argument(
599 '--max-battery-temp', type=int,
600 help='Only start tests when the battery is at or below the given '
601 'temperature (0.1 C)')
jama47ca85c2014-12-03 18:38:07602 group.add_argument('single_step_command', nargs='*', action=SingleStepAction,
603 help='If --single-step is specified, the command to run.')
rnephewdde05da82015-07-09 20:31:01604 group.add_argument('--min-battery-level', type=int,
605 help='Only starts tests when the battery is charged above '
606 'given level.')
jama47ca85c2014-12-03 18:38:07607 AddCommonOptions(parser)
608 AddDeviceOptions(parser)
[email protected]ec3170b2013-08-14 14:39:47609
610
jama47ca85c2014-12-03 18:38:07611def ProcessPerfTestOptions(args):
[email protected]ec3170b2013-08-14 14:39:47612 """Processes all perf test options.
613
614 Args:
jama47ca85c2014-12-03 18:38:07615 args: argparse.Namespace object.
[email protected]ec3170b2013-08-14 14:39:47616
617 Returns:
618 A PerfOptions named tuple which contains all options relevant to
619 perf tests.
620 """
jama47ca85c2014-12-03 18:38:07621 # TODO(jbudorick): Move single_step handling down into the perf tests.
622 if args.single_step:
623 args.single_step = ' '.join(args.single_step_command)
624 # TODO(jbudorick): Get rid of PerfOptions.
[email protected]ec3170b2013-08-14 14:39:47625 return perf_test_options.PerfOptions(
jama47ca85c2014-12-03 18:38:07626 args.steps, args.flaky_steps, args.output_json_list,
627 args.print_step, args.no_timeout, args.test_filter,
628 args.dry_run, args.single_step, args.collect_chartjson_data,
perezju67cf7f12015-09-29 11:39:05629 args.output_chartjson_data, args.get_output_dir_archive,
630 args.max_battery_temp, args.min_battery_level)
[email protected]ec3170b2013-08-14 14:39:47631
632
jama47ca85c2014-12-03 18:38:07633def AddPythonTestOptions(parser):
634 group = parser.add_argument_group('Python Test Options')
635 group.add_argument(
636 '-s', '--suite', dest='suite_name', metavar='SUITE_NAME',
637 choices=constants.PYTHON_UNIT_TEST_SUITES.keys(),
638 help='Name of the test suite to run.')
639 AddCommonOptions(parser)
jbudorick256fd532014-10-24 01:50:13640
641
jama47ca85c2014-12-03 18:38:07642def _RunLinkerTests(args, devices):
[email protected]6b6abac6d2013-10-03 11:56:38643 """Subcommand of RunTestsCommands which runs linker tests."""
jama47ca85c2014-12-03 18:38:07644 runner_factory, tests = linker_setup.Setup(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38645
646 results, exit_code = test_dispatcher.RunTests(
647 tests, runner_factory, devices, shard=True, test_timeout=60,
jama47ca85c2014-12-03 18:38:07648 num_retries=args.num_retries)
[email protected]6b6abac6d2013-10-03 11:56:38649
650 report_results.LogFull(
651 results=results,
652 test_type='Linker test',
[email protected]93c9f9b2014-02-10 16:19:22653 test_package='ChromiumLinkerTest')
[email protected]6b6abac6d2013-10-03 11:56:38654
jama47ca85c2014-12-03 18:38:07655 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20656 json_results.GenerateJsonResultsFile([results], args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54657
[email protected]6b6abac6d2013-10-03 11:56:38658 return exit_code
659
660
jama47ca85c2014-12-03 18:38:07661def _RunInstrumentationTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37662 """Subcommand of RunTestsCommands which runs instrumentation tests."""
jbudorick58b4d362015-09-08 16:44:59663 logging.info('_RunInstrumentationTests(%s, %s)', str(args), str(devices))
[email protected]6bc1bda22013-07-19 22:08:37664
jama47ca85c2014-12-03 18:38:07665 instrumentation_options = ProcessInstrumentationOptions(args)
666
667 if len(devices) > 1 and args.wait_for_debugger:
[email protected]f7148dd42013-08-20 14:24:57668 logging.warning('Debugger can not be sharded, using first available device')
669 devices = devices[:1]
670
[email protected]6bc1bda22013-07-19 22:08:37671 results = base_test_result.TestRunResults()
672 exit_code = 0
673
jama47ca85c2014-12-03 18:38:07674 if args.run_java_tests:
jbudorickeb7ea71c2015-09-28 16:40:20675 java_runner_factory, java_tests = instrumentation_setup.Setup(
mikecase526d68e2014-11-19 20:02:05676 instrumentation_options, devices)
jbudorickeb7ea71c2015-09-28 16:40:20677 else:
678 java_runner_factory = None
679 java_tests = None
[email protected]6bc1bda22013-07-19 22:08:37680
jama47ca85c2014-12-03 18:38:07681 if args.run_python_tests:
jbudorickeb7ea71c2015-09-28 16:40:20682 py_runner_factory, py_tests = host_driven_setup.InstrumentationSetup(
jama47ca85c2014-12-03 18:38:07683 args.host_driven_root, args.official_build,
[email protected]37ee0c792013-08-06 19:10:13684 instrumentation_options)
jbudorickeb7ea71c2015-09-28 16:40:20685 else:
686 py_runner_factory = None
687 py_tests = None
[email protected]37ee0c792013-08-06 19:10:13688
jbudorickeb7ea71c2015-09-28 16:40:20689 results = []
690 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0
691 else itertools.count())
692 for _ in repetitions:
693 iteration_results = base_test_result.TestRunResults()
694 if java_tests:
[email protected]34020022013-08-06 23:35:34695 test_results, test_exit_code = test_dispatcher.RunTests(
jbudorickeb7ea71c2015-09-28 16:40:20696 java_tests, java_runner_factory, devices, shard=True,
697 test_timeout=None, num_retries=args.num_retries)
698 iteration_results.AddTestRunResults(test_results)
[email protected]6bc1bda22013-07-19 22:08:37699
[email protected]34020022013-08-06 23:35:34700 # Only allow exit code escalation
701 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
702 exit_code = test_exit_code
[email protected]6bc1bda22013-07-19 22:08:37703
jbudorickeb7ea71c2015-09-28 16:40:20704 if py_tests:
705 test_results, test_exit_code = test_dispatcher.RunTests(
706 py_tests, py_runner_factory, devices, shard=True, test_timeout=None,
707 num_retries=args.num_retries)
708 iteration_results.AddTestRunResults(test_results)
[email protected]4f777ca2014-08-08 01:45:59709
jbudorickeb7ea71c2015-09-28 16:40:20710 # Only allow exit code escalation
711 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
712 exit_code = test_exit_code
713
714 results.append(iteration_results)
715 report_results.LogFull(
716 results=iteration_results,
717 test_type='Instrumentation',
718 test_package=os.path.basename(args.test_apk),
719 annotation=args.annotations,
720 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37721
jama47ca85c2014-12-03 18:38:07722 if args.json_results_file:
723 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54724
[email protected]6bc1bda22013-07-19 22:08:37725 return exit_code
726
727
jama47ca85c2014-12-03 18:38:07728def _RunJUnitTests(args):
jbudorick9a6b7b332014-09-20 00:01:07729 """Subcommand of RunTestsCommand which runs junit tests."""
jama47ca85c2014-12-03 18:38:07730 runner_factory, tests = junit_setup.Setup(args)
mikecasec638a072015-04-01 16:35:35731 results, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
732
733 report_results.LogFull(
734 results=results,
735 test_type='JUnit',
736 test_package=args.test_suite)
737
mikecase572401b2015-04-09 02:28:57738 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20739 json_results.GenerateJsonResultsFile([results], args.json_results_file)
mikecase572401b2015-04-09 02:28:57740
jbudorick9a6b7b332014-09-20 00:01:07741 return exit_code
742
743
jama47ca85c2014-12-03 18:38:07744def _RunMonkeyTests(args, devices):
[email protected]3dbdfa42013-08-08 01:08:14745 """Subcommand of RunTestsCommands which runs monkey tests."""
jama47ca85c2014-12-03 18:38:07746 monkey_options = ProcessMonkeyTestOptions(args)
[email protected]3dbdfa42013-08-08 01:08:14747
748 runner_factory, tests = monkey_setup.Setup(monkey_options)
749
750 results, exit_code = test_dispatcher.RunTests(
[email protected]181a5c92013-09-06 17:11:46751 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07752 num_retries=args.num_retries)
[email protected]3dbdfa42013-08-08 01:08:14753
754 report_results.LogFull(
755 results=results,
756 test_type='Monkey',
[email protected]14b3b1202013-08-15 22:25:28757 test_package='Monkey')
[email protected]3dbdfa42013-08-08 01:08:14758
jama47ca85c2014-12-03 18:38:07759 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20760 json_results.GenerateJsonResultsFile([results], args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54761
[email protected]3dbdfa42013-08-08 01:08:14762 return exit_code
763
764
jbudorickdde688fb2015-08-27 03:00:17765def _RunPerfTests(args, active_devices):
[email protected]ec3170b2013-08-14 14:39:47766 """Subcommand of RunTestsCommands which runs perf tests."""
jama47ca85c2014-12-03 18:38:07767 perf_options = ProcessPerfTestOptions(args)
[email protected]61487ed2014-06-09 12:33:56768
769 # Just save a simple json with a list of test names.
770 if perf_options.output_json_list:
771 return perf_test_runner.OutputJsonList(
772 perf_options.steps, perf_options.output_json_list)
773
[email protected]ad32f312013-11-13 04:03:29774 # Just print the results from a single previously executed step.
[email protected]ec3170b2013-08-14 14:39:47775 if perf_options.print_step:
simonhatch9b9256d2015-01-07 18:03:42776 return perf_test_runner.PrintTestOutput(
perezju67cf7f12015-09-29 11:39:05777 perf_options.print_step, perf_options.output_chartjson_data,
778 perf_options.get_output_dir_archive)
[email protected]ec3170b2013-08-14 14:39:47779
jbudorickdde688fb2015-08-27 03:00:17780 runner_factory, tests, devices = perf_setup.Setup(
781 perf_options, active_devices)
[email protected]ec3170b2013-08-14 14:39:47782
[email protected]a72f0752014-06-03 23:52:34783 # shard=False means that each device will get the full list of tests
784 # and then each one will decide their own affinity.
785 # shard=True means each device will pop the next test available from a queue,
786 # which increases throughput but have no affinity.
[email protected]86184c7b2013-08-15 15:06:57787 results, _ = test_dispatcher.RunTests(
[email protected]a72f0752014-06-03 23:52:34788 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07789 num_retries=args.num_retries)
[email protected]ec3170b2013-08-14 14:39:47790
791 report_results.LogFull(
792 results=results,
793 test_type='Perf',
[email protected]865a47a2013-08-16 14:01:12794 test_package='Perf')
[email protected]def4bce2013-11-12 12:59:52795
jama47ca85c2014-12-03 18:38:07796 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20797 json_results.GenerateJsonResultsFile([results], args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54798
[email protected]def4bce2013-11-12 12:59:52799 if perf_options.single_step:
800 return perf_test_runner.PrintTestOutput('single_step')
801
[email protected]11ce8452014-02-17 10:55:03802 perf_test_runner.PrintSummary(tests)
803
[email protected]86184c7b2013-08-15 15:06:57804 # Always return 0 on the sharding stage. Individual tests exit_code
805 # will be returned on the print_step stage.
806 return 0
[email protected]ec3170b2013-08-14 14:39:47807
[email protected]3dbdfa42013-08-08 01:08:14808
jama47ca85c2014-12-03 18:38:07809def _RunPythonTests(args):
jbudorick256fd532014-10-24 01:50:13810 """Subcommand of RunTestsCommand which runs python unit tests."""
jama47ca85c2014-12-03 18:38:07811 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name]
jbudorick256fd532014-10-24 01:50:13812 suite_path = suite_vars['path']
813 suite_test_modules = suite_vars['test_modules']
814
815 sys.path = [suite_path] + sys.path
816 try:
817 suite = unittest.TestSuite()
818 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
819 for m in suite_test_modules)
jama47ca85c2014-12-03 18:38:07820 runner = unittest.TextTestRunner(verbosity=1+args.verbose_count)
jbudorick256fd532014-10-24 01:50:13821 return 0 if runner.run(suite).wasSuccessful() else 1
822 finally:
823 sys.path = sys.path[1:]
824
825
agrievea538a142015-10-09 15:45:56826def _GetAttachedDevices(blacklist_file, test_device, enable_cache):
[email protected]f7148dd42013-08-20 14:24:57827 """Get all attached devices.
828
829 Args:
agrievea538a142015-10-09 15:45:56830 blacklist_file: Path to device blacklist.
[email protected]f7148dd42013-08-20 14:24:57831 test_device: Name of a specific device to use.
agrievea538a142015-10-09 15:45:56832 enable_cache: Whether to enable checksum caching.
[email protected]f7148dd42013-08-20 14:24:57833
834 Returns:
835 A list of attached devices.
836 """
jbudoricka583ba32015-09-11 17:23:19837 blacklist = (device_blacklist.Blacklist(blacklist_file)
838 if blacklist_file
839 else None)
jbudorickdde688fb2015-08-27 03:00:17840
agrievea538a142015-10-09 15:45:56841 attached_devices = device_utils.DeviceUtils.HealthyDevices(
842 blacklist, enable_device_files_cache=enable_cache)
aberent6a02a6182015-04-29 11:07:55843 if test_device:
jbudorick4551d0dc2015-04-29 16:07:06844 test_device = [d for d in attached_devices if d == test_device]
845 if not test_device:
846 raise device_errors.DeviceUnreachableError(
847 'Did not find device %s among attached device. Attached devices: %s'
848 % (test_device, ', '.join(attached_devices)))
849 return test_device
aberent6a02a6182015-04-29 11:07:55850
jbudorick4551d0dc2015-04-29 16:07:06851 else:
852 if not attached_devices:
853 raise device_errors.NoDevicesError()
854 return sorted(attached_devices)
[email protected]f7148dd42013-08-20 14:24:57855
856
jbudorick58b4d362015-09-08 16:44:59857def RunTestsCommand(args, parser): # pylint: disable=too-many-return-statements
[email protected]fbe29322013-07-09 09:03:26858 """Checks test type and dispatches to the appropriate function.
859
860 Args:
jama47ca85c2014-12-03 18:38:07861 args: argparse.Namespace object.
862 parser: argparse.ArgumentParser object.
[email protected]fbe29322013-07-09 09:03:26863
864 Returns:
865 Integer indicated exit code.
[email protected]b3873892013-07-10 04:57:10866
867 Raises:
868 Exception: Unknown command name passed in, or an exception from an
869 individual test runner.
[email protected]fbe29322013-07-09 09:03:26870 """
jama47ca85c2014-12-03 18:38:07871 command = args.command
[email protected]fbe29322013-07-09 09:03:26872
jama47ca85c2014-12-03 18:38:07873 ProcessCommonOptions(args)
[email protected]d82f0252013-07-12 23:22:57874
jama47ca85c2014-12-03 18:38:07875 if args.enable_platform_mode:
rnephew5c499782014-12-12 19:08:55876 return RunTestsInPlatformMode(args, parser)
jbudorick66dc3722014-11-06 21:33:51877
[email protected]c0662e092013-11-12 11:51:25878 forwarder.Forwarder.RemoveHostLog()
[email protected]6b11583b2013-11-21 16:18:40879 if not ports.ResetTestServerPortAllocation():
880 raise Exception('Failed to reset test server port.')
[email protected]c0662e092013-11-12 11:51:25881
agrieve18930bd2015-10-09 17:41:42882 def get_devices():
883 return _GetAttachedDevices(args.blacklist_file, args.test_device,
884 args.enable_device_cache)
885
[email protected]fbe29322013-07-09 09:03:26886 if command == 'gtest':
jbudorick566592ab2015-09-21 15:32:47887 return RunTestsInPlatformMode(args, parser)
[email protected]6b6abac6d2013-10-03 11:56:38888 elif command == 'linker':
agrieve18930bd2015-10-09 17:41:42889 return _RunLinkerTests(args, get_devices())
[email protected]fbe29322013-07-09 09:03:26890 elif command == 'instrumentation':
agrieve18930bd2015-10-09 17:41:42891 return _RunInstrumentationTests(args, get_devices())
jbudorick9a6b7b332014-09-20 00:01:07892 elif command == 'junit':
jama47ca85c2014-12-03 18:38:07893 return _RunJUnitTests(args)
[email protected]3dbdfa42013-08-08 01:08:14894 elif command == 'monkey':
agrieve18930bd2015-10-09 17:41:42895 return _RunMonkeyTests(args, get_devices())
[email protected]ec3170b2013-08-14 14:39:47896 elif command == 'perf':
agrieve18930bd2015-10-09 17:41:42897 return _RunPerfTests(args, get_devices())
jbudorick256fd532014-10-24 01:50:13898 elif command == 'python':
jama47ca85c2014-12-03 18:38:07899 return _RunPythonTests(args)
[email protected]fbe29322013-07-09 09:03:26900 else:
[email protected]6bc1bda22013-07-19 22:08:37901 raise Exception('Unknown test type.')
[email protected]fbe29322013-07-09 09:03:26902
[email protected]fbe29322013-07-09 09:03:26903
jbudorick66dc3722014-11-06 21:33:51904_SUPPORTED_IN_PLATFORM_MODE = [
905 # TODO(jbudorick): Add support for more test types.
jbudorick911be58d2015-01-13 02:51:06906 'gtest',
907 'instrumentation',
908 'uirobot',
jbudorick66dc3722014-11-06 21:33:51909]
910
911
jama47ca85c2014-12-03 18:38:07912def RunTestsInPlatformMode(args, parser):
jbudorick66dc3722014-11-06 21:33:51913
jbudorick566592ab2015-09-21 15:32:47914 def infra_error(message):
915 parser.exit(status=constants.INFRA_EXIT_CODE, message=message)
jbudorickb9b0ada2015-09-17 22:52:58916
jbudorick566592ab2015-09-21 15:32:47917 if args.command not in _SUPPORTED_IN_PLATFORM_MODE:
918 infra_error('%s is not yet supported in platform mode' % args.command)
919
920 with environment_factory.CreateEnvironment(args, infra_error) as env:
921 with test_instance_factory.CreateTestInstance(args, infra_error) as test:
jbudorick66dc3722014-11-06 21:33:51922 with test_run_factory.CreateTestRun(
jbudorick566592ab2015-09-21 15:32:47923 args, env, test, infra_error) as test_run:
jbudorickeb7ea71c2015-09-28 16:40:20924 results = []
925 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0
926 else itertools.count())
927 for _ in repetitions:
928 iteration_results = test_run.RunTests()
jbudorick66dc3722014-11-06 21:33:51929
jbudorickeb7ea71c2015-09-28 16:40:20930 if iteration_results is not None:
jbudorickd4f77982015-09-28 21:09:18931 results.append(iteration_results)
jbudorickeb7ea71c2015-09-28 16:40:20932 report_results.LogFull(
933 results=iteration_results,
934 test_type=test.TestType(),
935 test_package=test_run.TestPackage(),
936 annotation=getattr(args, 'annotations', None),
937 flakiness_server=getattr(args, 'flakiness_dashboard_server',
938 None))
jbudorick66dc3722014-11-06 21:33:51939
jama47ca85c2014-12-03 18:38:07940 if args.json_results_file:
jbudorickb8c42072014-12-01 18:07:54941 json_results.GenerateJsonResultsFile(
jama47ca85c2014-12-03 18:38:07942 results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54943
jbudorickeb7ea71c2015-09-28 16:40:20944 return (0 if all(r.DidRunPass() for r in results)
945 else constants.ERROR_EXIT_CODE)
jbudorick66dc3722014-11-06 21:33:51946
947
jama47ca85c2014-12-03 18:38:07948CommandConfigTuple = collections.namedtuple(
949 'CommandConfigTuple',
950 ['add_options_func', 'help_txt'])
[email protected]fbe29322013-07-09 09:03:26951VALID_COMMANDS = {
jama47ca85c2014-12-03 18:38:07952 'gtest': CommandConfigTuple(
953 AddGTestOptions,
954 'googletest-based C++ tests'),
955 'instrumentation': CommandConfigTuple(
956 AddInstrumentationTestOptions,
957 'InstrumentationTestCase-based Java tests'),
jama47ca85c2014-12-03 18:38:07958 'junit': CommandConfigTuple(
959 AddJUnitTestOptions,
960 'JUnit4-based Java tests'),
961 'monkey': CommandConfigTuple(
962 AddMonkeyTestOptions,
963 "Tests based on Android's monkey"),
964 'perf': CommandConfigTuple(
965 AddPerfTestOptions,
966 'Performance tests'),
967 'python': CommandConfigTuple(
968 AddPythonTestOptions,
969 'Python tests based on unittest.TestCase'),
970 'linker': CommandConfigTuple(
971 AddLinkerTestOptions,
972 'Linker tests'),
rnephew5c499782014-12-12 19:08:55973 'uirobot': CommandConfigTuple(
974 AddUirobotTestOptions,
975 'Uirobot test'),
jama47ca85c2014-12-03 18:38:07976}
[email protected]fbe29322013-07-09 09:03:26977
978
[email protected]7c53a602014-03-24 16:21:44979def DumpThreadStacks(_signal, _frame):
[email protected]71aec4b2013-11-20 00:35:24980 for thread in threading.enumerate():
981 reraiser_thread.LogThreadStack(thread)
[email protected]83bb8152013-11-19 15:02:21982
983
[email protected]7c53a602014-03-24 16:21:44984def main():
[email protected]83bb8152013-11-19 15:02:21985 signal.signal(signal.SIGUSR1, DumpThreadStacks)
jama47ca85c2014-12-03 18:38:07986
987 parser = argparse.ArgumentParser()
988 command_parsers = parser.add_subparsers(title='test types',
989 dest='command')
990
991 for test_type, config in sorted(VALID_COMMANDS.iteritems(),
992 key=lambda x: x[0]):
993 subparser = command_parsers.add_parser(
994 test_type, usage='%(prog)s [options]', help=config.help_txt)
995 config.add_options_func(subparser)
996
997 args = parser.parse_args()
mikecasee74051022015-02-26 23:08:22998
999 try:
1000 return RunTestsCommand(args, parser)
1001 except base_error.BaseError as e:
1002 logging.exception('Error occurred.')
1003 if e.is_infra_error:
1004 return constants.INFRA_EXIT_CODE
mswecce6732015-06-06 00:31:331005 return constants.ERROR_EXIT_CODE
mikecasee74051022015-02-26 23:08:221006 except: # pylint: disable=W0702
1007 logging.exception('Unrecognized error occurred.')
1008 return constants.ERROR_EXIT_CODE
[email protected]fbe29322013-07-09 09:03:261009
[email protected]fbe29322013-07-09 09:03:261010
1011if __name__ == '__main__':
[email protected]7c53a602014-03-24 16:21:441012 sys.exit(main())