blob: 25970c7606e62dfa700f6b912fab86f74481a1ae [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
jbudorick0c2a94a2015-12-04 14:27:4319import devil_chromium
jbudorick061629442015-09-03 18:00:5720from devil import base_error
jbudoricke29693be2015-12-07 15:53:2321from devil import devil_env
jbudorick061629442015-09-03 18:00:5722from devil.android import device_blacklist
23from devil.android import device_errors
24from devil.android import device_utils
jbudorickd645efe82015-12-11 19:09:5925from devil.android import forwarder
jbudorick061629442015-09-03 18:00:5726from devil.android import ports
27from devil.utils import reraiser_thread
28from devil.utils import run_tests_helper
29
[email protected]fbe29322013-07-09 09:03:2630from pylib import constants
jbudorickd28554a2016-01-11 16:22:5931from pylib.constants import host_paths
[email protected]fbe29322013-07-09 09:03:2632from pylib.base import base_test_result
jbudorick66dc3722014-11-06 21:33:5133from pylib.base import environment_factory
[email protected]6bc1bda22013-07-19 22:08:3734from pylib.base import test_dispatcher
jbudorick66dc3722014-11-06 21:33:5135from pylib.base import test_instance_factory
36from pylib.base import test_run_factory
[email protected]6b6abac6d2013-10-03 11:56:3837from pylib.linker import setup as linker_setup
jbudorick9a6b7b332014-09-20 00:01:0738from pylib.junit import setup as junit_setup
39from pylib.junit import test_dispatcher as junit_dispatcher
[email protected]3dbdfa42013-08-08 01:08:1440from pylib.monkey import setup as monkey_setup
41from pylib.monkey import test_options as monkey_test_options
[email protected]ec3170b2013-08-14 14:39:4742from pylib.perf import setup as perf_setup
43from pylib.perf import test_options as perf_test_options
44from pylib.perf import test_runner as perf_test_runner
jbudorickb8c42072014-12-01 18:07:5445from pylib.results import json_results
46from pylib.results import report_results
[email protected]fbe29322013-07-09 09:03:2647
48
jbudorick0c2a94a2015-12-04 14:27:4349_DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join(
jbudorickd28554a2016-01-11 16:22:5950 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json'))
jbudorick0c2a94a2015-12-04 14:27:4351
52
jama47ca85c2014-12-03 18:38:0753def AddCommonOptions(parser):
54 """Adds all common options to |parser|."""
[email protected]fbe29322013-07-09 09:03:2655
jama47ca85c2014-12-03 18:38:0756 group = parser.add_argument_group('Common Options')
57
[email protected]dfffbcbc2013-09-17 22:06:0158 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
jama47ca85c2014-12-03 18:38:0759
60 debug_or_release_group = group.add_mutually_exclusive_group()
61 debug_or_release_group.add_argument(
62 '--debug', action='store_const', const='Debug', dest='build_type',
63 default=default_build_type,
64 help=('If set, run test suites under out/Debug. '
65 'Default is env var BUILDTYPE or Debug.'))
66 debug_or_release_group.add_argument(
67 '--release', action='store_const', const='Release', dest='build_type',
68 help=('If set, run test suites under out/Release. '
69 'Default is env var BUILDTYPE or Debug.'))
70
71 group.add_argument('--build-directory', dest='build_directory',
72 help=('Path to the directory in which build files are'
73 ' located (should not include build type)'))
74 group.add_argument('--output-directory', dest='output_directory',
75 help=('Path to the directory in which build files are'
76 ' located (must include build type). This will take'
77 ' precedence over --debug, --release and'
78 ' --build-directory'))
agrieveddb11f12015-10-23 17:03:4379 group.add_argument('--num_retries', '--num-retries', dest='num_retries',
80 type=int, default=2,
jama47ca85c2014-12-03 18:38:0781 help=('Number of retries for a test before '
82 'giving up (default: %(default)s).'))
83 group.add_argument('-v',
84 '--verbose',
85 dest='verbose_count',
86 default=0,
87 action='count',
88 help='Verbose level (multiple times for more)')
89 group.add_argument('--flakiness-dashboard-server',
90 dest='flakiness_dashboard_server',
91 help=('Address of the server that is hosting the '
92 'Chrome for Android flakiness dashboard.'))
93 group.add_argument('--enable-platform-mode', action='store_true',
94 help=('Run the test scripts in platform mode, which '
95 'conceptually separates the test runner from the '
96 '"device" (local or remote, real or emulated) on '
97 'which the tests are running. [experimental]'))
98 group.add_argument('-e', '--environment', default='local',
99 choices=constants.VALID_ENVIRONMENTS,
100 help='Test environment to run in (default: %(default)s).')
101 group.add_argument('--adb-path',
102 help=('Specify the absolute path of the adb binary that '
103 'should be used.'))
stipa5733b52015-12-02 08:17:19104 group.add_argument('--json-results-file', '--test-launcher-summary-output',
105 dest='json_results_file',
jama47ca85c2014-12-03 18:38:07106 help='If set, will dump results in JSON form '
107 'to specified file.')
mikecaseb0bafb02016-02-09 04:24:44108
109 logcat_output_group = group.add_mutually_exclusive_group()
110 logcat_output_group.add_argument(
111 '--logcat-output-dir',
112 help='If set, will dump logcats recorded during test run to directory. '
113 'File names will be the device ids with timestamps.')
114 logcat_output_group.add_argument(
115 '--logcat-output-file',
116 help='If set, will merge logcats recorded during test run and dump them '
117 'to the specified file.')
[email protected]fbe29322013-07-09 09:03:26118
agrieve7acf04a2016-02-09 18:36:38119 class FastLocalDevAction(argparse.Action):
120 def __call__(self, parser, namespace, values, option_string=None):
121 namespace.verbose_count = max(namespace.verbose_count, 1)
122 namespace.num_retries = 0
123 namespace.enable_device_cache = True
agrieve2e8027602016-02-10 22:26:22124 namespace.enable_concurrent_adb = True
agrieve7acf04a2016-02-09 18:36:38125 namespace.skip_clear_data = True
126 namespace.extract_test_list_from_filter = True
127
128 group.add_argument('--fast-local-dev', type=bool, nargs=0,
129 action=FastLocalDevAction,
130 help='Alias for: --verbose --num-retries=0 '
agrieve2e8027602016-02-10 22:26:22131 '--enable-device-cache --enable-concurrent-adb '
132 '--skip-clear-data --extract-test-list-from-filter')
agrieve7acf04a2016-02-09 18:36:38133
jama47ca85c2014-12-03 18:38:07134def ProcessCommonOptions(args):
[email protected]fbe29322013-07-09 09:03:26135 """Processes and handles all common options."""
jama47ca85c2014-12-03 18:38:07136 run_tests_helper.SetLogLevel(args.verbose_count)
137 constants.SetBuildType(args.build_type)
138 if args.build_directory:
139 constants.SetBuildDirectory(args.build_directory)
140 if args.output_directory:
mikecase0aea9c52015-04-30 00:12:33141 constants.SetOutputDirectory(args.output_directory)
jbudorick0c2a94a2015-12-04 14:27:43142
143 devil_custom_deps = None
jama47ca85c2014-12-03 18:38:07144 if args.adb_path:
jbudorick0c2a94a2015-12-04 14:27:43145 devil_custom_deps = {
146 'adb': {
jbudoricke29693be2015-12-07 15:53:23147 devil_env.GetPlatform(): [args.adb_path]
jbudorick0c2a94a2015-12-04 14:27:43148 }
149 }
150
151 devil_chromium.Initialize(
152 output_directory=constants.GetOutDirectory(),
153 custom_deps=devil_custom_deps)
154
mikecase48e16bf2014-11-19 22:46:45155 # Some things such as Forwarder require ADB to be in the environment path.
156 adb_dir = os.path.dirname(constants.GetAdbPath())
157 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep):
158 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
[email protected]fbe29322013-07-09 09:03:26159
160
rnephew5c499782014-12-12 19:08:55161def AddRemoteDeviceOptions(parser):
162 group = parser.add_argument_group('Remote Device Options')
163
rnephewefe44b42015-02-04 04:45:15164 group.add_argument('--trigger',
jbudoricke6c560152015-01-13 23:49:28165 help=('Only triggers the test if set. Stores test_run_id '
166 'in given file path. '))
rnephewefe44b42015-02-04 04:45:15167 group.add_argument('--collect',
jbudoricke6c560152015-01-13 23:49:28168 help=('Only collects the test results if set. '
169 'Gets test_run_id from given file path.'))
rnephewefe44b42015-02-04 04:45:15170 group.add_argument('--remote-device', action='append',
jbudoricke6c560152015-01-13 23:49:28171 help='Device type to run test on.')
rnephewefe44b42015-02-04 04:45:15172 group.add_argument('--results-path',
jbudoricke6c560152015-01-13 23:49:28173 help='File path to download results to.')
rnephew7f1e2052014-12-12 23:00:11174 group.add_argument('--api-protocol',
jbudoricke6c560152015-01-13 23:49:28175 help='HTTP protocol to use. (http or https)')
rnephewefe44b42015-02-04 04:45:15176 group.add_argument('--api-address',
177 help='Address to send HTTP requests.')
178 group.add_argument('--api-port',
179 help='Port to send HTTP requests to.')
180 group.add_argument('--runner-type',
jbudoricke6c560152015-01-13 23:49:28181 help='Type of test to run as.')
rnephewefe44b42015-02-04 04:45:15182 group.add_argument('--runner-package',
183 help='Package name of test.')
184 group.add_argument('--device-type',
rnephewa46fc562015-01-23 16:00:14185 choices=constants.VALID_DEVICE_TYPES,
186 help=('Type of device to run on. iOS or android'))
rnephewefe44b42015-02-04 04:45:15187 group.add_argument('--device-oem', action='append',
188 help='Device OEM to run on.')
189 group.add_argument('--remote-device-file',
190 help=('File with JSON to select remote device. '
191 'Overrides all other flags.'))
rnephewc9ae8f52015-02-13 03:02:55192 group.add_argument('--remote-device-timeout', type=int,
193 help='Times to retry finding remote device')
mikecase520cbbb52015-04-21 18:51:18194 group.add_argument('--network-config', type=int,
195 help='Integer that specifies the network environment '
196 'that the tests will be run in.')
mikecaseddfa35d2015-10-28 01:14:27197 group.add_argument('--test-timeout', type=int,
198 help='Test run timeout in seconds.')
rnephewefe44b42015-02-04 04:45:15199
200 device_os_group = group.add_mutually_exclusive_group()
201 device_os_group.add_argument('--remote-device-minimum-os',
202 help='Minimum OS on device.')
203 device_os_group.add_argument('--remote-device-os', action='append',
204 help='OS to have on the device.')
rnephew5c499782014-12-12 19:08:55205
206 api_secret_group = group.add_mutually_exclusive_group()
207 api_secret_group.add_argument('--api-secret', default='',
jbudoricke6c560152015-01-13 23:49:28208 help='API secret for remote devices.')
rnephew5c499782014-12-12 19:08:55209 api_secret_group.add_argument('--api-secret-file', default='',
jbudoricke6c560152015-01-13 23:49:28210 help='Path to file that contains API secret.')
rnephew5c499782014-12-12 19:08:55211
212 api_key_group = group.add_mutually_exclusive_group()
213 api_key_group.add_argument('--api-key', default='',
jbudoricke6c560152015-01-13 23:49:28214 help='API key for remote devices.')
rnephew5c499782014-12-12 19:08:55215 api_key_group.add_argument('--api-key-file', default='',
jbudoricke6c560152015-01-13 23:49:28216 help='Path to file that contains API key.')
rnephew5c499782014-12-12 19:08:55217
218
jama47ca85c2014-12-03 18:38:07219def AddDeviceOptions(parser):
220 """Adds device options to |parser|."""
221 group = parser.add_argument_group(title='Device Options')
jama47ca85c2014-12-03 18:38:07222 group.add_argument('--tool',
223 dest='tool',
224 help=('Run the test under a tool '
225 '(use --tool help to list them)'))
226 group.add_argument('-d', '--device', dest='test_device',
227 help=('Target device for the test suite '
228 'to run on.'))
jbudorickdde688fb2015-08-27 03:00:17229 group.add_argument('--blacklist-file', help='Device blacklist file.')
agrievea538a142015-10-09 15:45:56230 group.add_argument('--enable-device-cache', action='store_true',
231 help='Cache device state to disk between runs')
agrieve8bcb52e2015-10-20 19:38:33232 group.add_argument('--enable-concurrent-adb', action='store_true',
233 help='Run multiple adb commands at the same time, even '
234 'for the same device.')
agrievecd243a22016-02-08 23:25:14235 group.add_argument('--skip-clear-data', action='store_true',
236 help='Do not wipe app data between tests. Use this to '
237 'speed up local development and never on bots '
238 '(increases flakiness)')
jbudorick256fd532014-10-24 01:50:13239
240
jama47ca85c2014-12-03 18:38:07241def AddGTestOptions(parser):
242 """Adds gtest options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26243
jama47ca85c2014-12-03 18:38:07244 group = parser.add_argument_group('GTest Options')
jbudorick15cdcd52014-12-03 19:58:49245 group.add_argument('-s', '--suite', dest='suite_name',
jama47ca85c2014-12-03 18:38:07246 nargs='+', metavar='SUITE_NAME', required=True,
jbudorick277f2312015-09-24 16:37:43247 help='Executable name of the test suite to run.')
agrieve62ab00282016-04-05 02:03:45248 group.add_argument('--executable-dist-dir',
249 help="Path to executable's dist directory for native"
250 " (non-apk) tests.")
agrieve4931af8c2016-02-10 19:25:26251 group.add_argument('--test-apk-incremental-install-script',
252 help='Path to install script for the test apk.')
jama47ca85c2014-12-03 18:38:07253 group.add_argument('--gtest_also_run_disabled_tests',
254 '--gtest-also-run-disabled-tests',
255 dest='run_disabled', action='store_true',
256 help='Also run disabled tests if applicable.')
257 group.add_argument('-a', '--test-arguments', dest='test_arguments',
258 default='',
259 help='Additional arguments to pass to the test.')
jbudorick24616eb2015-10-06 02:40:57260 group.add_argument('-t', '--shard-timeout',
mikecase68bcfc82016-01-22 20:14:38261 dest='shard_timeout', type=int, default=120,
jama47ca85c2014-12-03 18:38:07262 help='Timeout to wait for each test '
263 '(default: %(default)s).')
264 group.add_argument('--isolate_file_path',
265 '--isolate-file-path',
266 dest='isolate_file_path',
267 help='.isolate file path to override the default '
268 'path')
jbudorick5ee45892015-06-10 18:46:22269 group.add_argument('--app-data-file', action='append', dest='app_data_files',
270 help='A file path relative to the app data directory '
271 'that should be saved to the host.')
272 group.add_argument('--app-data-file-dir',
273 help='Host directory to which app data files will be'
274 ' saved. Used with --app-data-file.')
mlliud7f9fe92015-06-15 19:36:56275 group.add_argument('--delete-stale-data', dest='delete_stale_data',
276 action='store_true',
277 help='Delete stale test data on the device.')
jbudorickeb7ea71c2015-09-28 16:40:20278 group.add_argument('--repeat', '--gtest_repeat', '--gtest-repeat',
279 dest='repeat', type=int, default=0,
280 help='Number of times to repeat the specified set of '
281 'tests.')
alexandermonta3f03bf2015-12-02 18:56:45282 group.add_argument('--break-on-failure', '--break_on_failure',
283 dest='break_on_failure', action='store_true',
284 help='Whether to break on failure.')
agrieve0f5e53e2016-02-04 03:47:37285 group.add_argument('--extract-test-list-from-filter',
286 action='store_true',
287 help='When a test filter is specified, and the list of '
288 'tests can be determined from it, skip querying the '
289 'device for the list of all tests. Speeds up local '
290 'development, but is not safe to use on bots ('
291 'http://crbug.com/549214')
jbudorick442a6932015-02-03 03:01:15292
293 filter_group = group.add_mutually_exclusive_group()
294 filter_group.add_argument('-f', '--gtest_filter', '--gtest-filter',
295 dest='test_filter',
296 help='googletest-style filter string.')
297 filter_group.add_argument('--gtest-filter-file', dest='test_filter_file',
298 help='Path to file that contains googletest-style '
299 'filter strings. (Lines will be joined with '
300 '":" to create a single filter string.)')
301
jama47ca85c2014-12-03 18:38:07302 AddDeviceOptions(parser)
303 AddCommonOptions(parser)
rnephew5c499782014-12-12 19:08:55304 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26305
306
jama47ca85c2014-12-03 18:38:07307def AddLinkerTestOptions(parser):
308 group = parser.add_argument_group('Linker Test Options')
309 group.add_argument('-f', '--gtest-filter', dest='test_filter',
310 help='googletest-style filter string.')
311 AddCommonOptions(parser)
312 AddDeviceOptions(parser)
[email protected]6b6abac6d2013-10-03 11:56:38313
314
jama47ca85c2014-12-03 18:38:07315def AddJavaTestOptions(argument_group):
[email protected]fbe29322013-07-09 09:03:26316 """Adds the Java test options to |option_parser|."""
317
jama47ca85c2014-12-03 18:38:07318 argument_group.add_argument(
stipf09861b682016-04-06 13:51:36319 '-f', '--test-filter', '--gtest_filter', '--gtest-filter',
320 dest='test_filter',
jama47ca85c2014-12-03 18:38:07321 help=('Test filter (if not fully qualified, will run all matches).'))
322 argument_group.add_argument(
jbudorickeb7ea71c2015-09-28 16:40:20323 '--repeat', dest='repeat', type=int, default=0,
324 help='Number of times to repeat the specified set of tests.')
325 argument_group.add_argument(
alexandermonta3f03bf2015-12-02 18:56:45326 '--break-on-failure', '--break_on_failure',
327 dest='break_on_failure', action='store_true',
328 help='Whether to break on failure.')
329 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26330 '-A', '--annotation', dest='annotation_str',
331 help=('Comma-separated list of annotations. Run only tests with any of '
332 'the given annotations. An annotation can be either a key or a '
333 'key-values pair. A test that has no annotation is considered '
334 '"SmallTest".'))
jama47ca85c2014-12-03 18:38:07335 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26336 '-E', '--exclude-annotation', dest='exclude_annotation_str',
337 help=('Comma-separated list of annotations. Exclude tests with these '
338 'annotations.'))
jama47ca85c2014-12-03 18:38:07339 argument_group.add_argument(
jbudorick5a6fa1e02016-05-20 01:40:41340 '--screenshot', dest='screenshot_failures', action='store_true',
jbudorickcbcc115d2014-09-18 17:50:59341 help='Capture screenshots of test failures')
jama47ca85c2014-12-03 18:38:07342 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59343 '--save-perf-json', action='store_true',
344 help='Saves the JSON file for each UI Perf test.')
jama47ca85c2014-12-03 18:38:07345 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59346 '--official-build', action='store_true', help='Run official build tests.')
jama47ca85c2014-12-03 18:38:07347 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59348 '--test_data', '--test-data', action='append', default=[],
349 help=('Each instance defines a directory of test data that should be '
350 'copied to the target(s) before running the tests. The argument '
351 'should be of the form <target>:<source>, <target> is relative to '
352 'the device data directory, and <source> is relative to the '
353 'chromium build directory.'))
davileen98efad12015-01-05 19:48:21354 argument_group.add_argument(
355 '--disable-dalvik-asserts', dest='set_asserts', action='store_false',
356 default=True, help='Removes the dalvik.vm.enableassertions property')
357
[email protected]fbe29322013-07-09 09:03:26358
359
jama47ca85c2014-12-03 18:38:07360def ProcessJavaTestOptions(args):
[email protected]fbe29322013-07-09 09:03:26361 """Processes options/arguments and populates |options| with defaults."""
362
jama47ca85c2014-12-03 18:38:07363 # TODO(jbudorick): Handle most of this function in argparse.
364 if args.annotation_str:
365 args.annotations = args.annotation_str.split(',')
366 elif args.test_filter:
367 args.annotations = []
[email protected]fbe29322013-07-09 09:03:26368 else:
jama47ca85c2014-12-03 18:38:07369 args.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
370 'EnormousTest', 'IntegrationTest']
[email protected]fbe29322013-07-09 09:03:26371
jama47ca85c2014-12-03 18:38:07372 if args.exclude_annotation_str:
373 args.exclude_annotations = args.exclude_annotation_str.split(',')
[email protected]fbe29322013-07-09 09:03:26374 else:
jama47ca85c2014-12-03 18:38:07375 args.exclude_annotations = []
[email protected]fbe29322013-07-09 09:03:26376
[email protected]fbe29322013-07-09 09:03:26377
jama47ca85c2014-12-03 18:38:07378def AddInstrumentationTestOptions(parser):
379 """Adds Instrumentation test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26380
jama47ca85c2014-12-03 18:38:07381 parser.usage = '%(prog)s [options]'
[email protected]fbe29322013-07-09 09:03:26382
jama47ca85c2014-12-03 18:38:07383 group = parser.add_argument_group('Instrumentation Test Options')
384 AddJavaTestOptions(group)
[email protected]fbe29322013-07-09 09:03:26385
jama47ca85c2014-12-03 18:38:07386 java_or_python_group = group.add_mutually_exclusive_group()
387 java_or_python_group.add_argument(
388 '-j', '--java-only', action='store_false',
389 dest='run_python_tests', default=True, help='Run only the Java tests.')
390 java_or_python_group.add_argument(
391 '-p', '--python-only', action='store_false',
392 dest='run_java_tests', default=True,
jbudorick39532fb2016-04-08 02:57:43393 help='DEPRECATED')
jama47ca85c2014-12-03 18:38:07394
395 group.add_argument('--host-driven-root',
jbudorick39532fb2016-04-08 02:57:43396 help='DEPRECATED')
jama47ca85c2014-12-03 18:38:07397 group.add_argument('-w', '--wait_debugger', dest='wait_for_debugger',
398 action='store_true',
399 help='Wait for debugger.')
agrieve4931af8c2016-02-10 19:25:26400 group.add_argument('--apk-under-test',
401 help='Path or name of the apk under test.')
402 group.add_argument('--apk-under-test-incremental-install-script',
403 help='Path to install script for the --apk-under-test.')
404 group.add_argument('--test-apk', required=True,
405 help='Path or name of the apk containing the tests '
406 '(name is without the .apk extension; '
407 'e.g. "ContentShellTest").')
408 group.add_argument('--test-apk-incremental-install-script',
409 help='Path to install script for the --test-apk.')
mikecasee7258622015-09-29 13:47:35410 group.add_argument('--additional-apk', action='append',
mikecase8c4ab302015-09-29 17:03:29411 dest='additional_apks', default=[],
mikecasee7258622015-09-29 13:47:35412 help='Additional apk that must be installed on '
413 'the device when the tests are run')
jama47ca85c2014-12-03 18:38:07414 group.add_argument('--coverage-dir',
415 help=('Directory in which to place all generated '
416 'EMMA coverage files.'))
417 group.add_argument('--device-flags', dest='device_flags', default='',
418 help='The relative filepath to a file containing '
419 'command-line flags to set on the device')
jbudorick911be58d2015-01-13 02:51:06420 group.add_argument('--device-flags-file', default='',
421 help='The relative filepath to a file containing '
422 'command-line flags to set on the device')
jama47ca85c2014-12-03 18:38:07423 group.add_argument('--isolate_file_path',
424 '--isolate-file-path',
425 dest='isolate_file_path',
426 help='.isolate file path to override the default '
427 'path')
mlliud7f9fe92015-06-15 19:36:56428 group.add_argument('--delete-stale-data', dest='delete_stale_data',
429 action='store_true',
430 help='Delete stale test data on the device.')
jbudorickede49722015-11-25 05:16:34431 group.add_argument('--timeout-scale', type=float,
432 help='Factor by which timeouts should be scaled.')
wnwen1d202892016-02-02 20:22:58433 group.add_argument('--strict-mode', dest='strict_mode', default='testing',
wnwen2b56c152016-01-12 16:40:10434 help='StrictMode command-line flag set on the device, '
435 'death/testing to kill the process, off to stop '
436 'checking, flash to flash only. Default testing.')
jama47ca85c2014-12-03 18:38:07437
438 AddCommonOptions(parser)
439 AddDeviceOptions(parser)
rnephewe416dff2015-01-21 21:26:37440 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26441
442
jama47ca85c2014-12-03 18:38:07443def AddJUnitTestOptions(parser):
444 """Adds junit test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07445
jama47ca85c2014-12-03 18:38:07446 group = parser.add_argument_group('JUnit Test Options')
447 group.add_argument(
448 '-s', '--test-suite', dest='test_suite', required=True,
jbudorick9a6b7b332014-09-20 00:01:07449 help=('JUnit test suite to run.'))
jama47ca85c2014-12-03 18:38:07450 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07451 '-f', '--test-filter', dest='test_filter',
452 help='Filters tests googletest-style.')
jama47ca85c2014-12-03 18:38:07453 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07454 '--package-filter', dest='package_filter',
455 help='Filters tests by package.')
jama47ca85c2014-12-03 18:38:07456 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07457 '--runner-filter', dest='runner_filter',
458 help='Filters tests by runner class. Must be fully qualified.')
jama47ca85c2014-12-03 18:38:07459 group.add_argument(
460 '--sdk-version', dest='sdk_version', type=int,
jbudorick9a6b7b332014-09-20 00:01:07461 help='The Android SDK version.')
hzle16476a2016-05-18 18:08:43462 group.add_argument(
463 '--coverage-dir', dest='coverage_dir',
464 help='Directory to store coverage info.')
jama47ca85c2014-12-03 18:38:07465 AddCommonOptions(parser)
jbudorick9a6b7b332014-09-20 00:01:07466
467
jama47ca85c2014-12-03 18:38:07468def AddMonkeyTestOptions(parser):
469 """Adds monkey test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07470
jama47ca85c2014-12-03 18:38:07471 group = parser.add_argument_group('Monkey Test Options')
472 group.add_argument(
473 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
474 metavar='PACKAGE', help='Package under test.')
475 group.add_argument(
476 '--event-count', default=10000, type=int,
477 help='Number of events to generate (default: %(default)s).')
478 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14479 '--category', default='',
[email protected]fb81b982013-08-09 00:07:12480 help='A list of allowed categories.')
jama47ca85c2014-12-03 18:38:07481 group.add_argument(
482 '--throttle', default=100, type=int,
483 help='Delay between events (ms) (default: %(default)s). ')
484 group.add_argument(
485 '--seed', type=int,
[email protected]3dbdfa42013-08-08 01:08:14486 help=('Seed value for pseudo-random generator. Same seed value generates '
487 'the same sequence of events. Seed is randomized by default.'))
jama47ca85c2014-12-03 18:38:07488 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14489 '--extra-args', default='',
jama47ca85c2014-12-03 18:38:07490 help=('String of other args to pass to the command verbatim.'))
[email protected]3dbdfa42013-08-08 01:08:14491
jama47ca85c2014-12-03 18:38:07492 AddCommonOptions(parser)
493 AddDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14494
jama47ca85c2014-12-03 18:38:07495def ProcessMonkeyTestOptions(args):
[email protected]3dbdfa42013-08-08 01:08:14496 """Processes all monkey test options.
497
498 Args:
jama47ca85c2014-12-03 18:38:07499 args: argparse.Namespace object.
[email protected]3dbdfa42013-08-08 01:08:14500
501 Returns:
502 A MonkeyOptions named tuple which contains all options relevant to
503 monkey tests.
504 """
jama47ca85c2014-12-03 18:38:07505 # TODO(jbudorick): Handle this directly in argparse with nargs='+'
506 category = args.category
[email protected]3dbdfa42013-08-08 01:08:14507 if category:
jama47ca85c2014-12-03 18:38:07508 category = args.category.split(',')
[email protected]3dbdfa42013-08-08 01:08:14509
jama47ca85c2014-12-03 18:38:07510 # TODO(jbudorick): Get rid of MonkeyOptions.
[email protected]3dbdfa42013-08-08 01:08:14511 return monkey_test_options.MonkeyOptions(
jama47ca85c2014-12-03 18:38:07512 args.verbose_count,
513 args.package,
514 args.event_count,
[email protected]3dbdfa42013-08-08 01:08:14515 category,
jama47ca85c2014-12-03 18:38:07516 args.throttle,
517 args.seed,
518 args.extra_args)
[email protected]3dbdfa42013-08-08 01:08:14519
rnephew5c499782014-12-12 19:08:55520def AddUirobotTestOptions(parser):
521 """Adds uirobot test options to |option_parser|."""
522 group = parser.add_argument_group('Uirobot Test Options')
523
rnephewefe44b42015-02-04 04:45:15524 group.add_argument('--app-under-test', required=True,
525 help='APK to run tests on.')
rnephew5c499782014-12-12 19:08:55526 group.add_argument(
mikecaseafa43842015-10-19 23:04:12527 '--repeat', dest='repeat', type=int, default=0,
528 help='Number of times to repeat the uirobot test.')
529 group.add_argument(
rnephew5c499782014-12-12 19:08:55530 '--minutes', default=5, type=int,
jbudorick676b1202015-02-06 22:02:27531 help='Number of minutes to run uirobot test [default: %(default)s].')
rnephew5c499782014-12-12 19:08:55532
533 AddCommonOptions(parser)
534 AddDeviceOptions(parser)
535 AddRemoteDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14536
jama47ca85c2014-12-03 18:38:07537def AddPerfTestOptions(parser):
538 """Adds perf test options to |parser|."""
[email protected]ec3170b2013-08-14 14:39:47539
jama47ca85c2014-12-03 18:38:07540 group = parser.add_argument_group('Perf Test Options')
[email protected]ec3170b2013-08-14 14:39:47541
jama47ca85c2014-12-03 18:38:07542 class SingleStepAction(argparse.Action):
543 def __call__(self, parser, namespace, values, option_string=None):
544 if values and not namespace.single_step:
545 parser.error('single step command provided, '
546 'but --single-step not specified.')
547 elif namespace.single_step and not values:
548 parser.error('--single-step specified, '
549 'but no single step command provided.')
550 setattr(namespace, self.dest, values)
551
552 step_group = group.add_mutually_exclusive_group(required=True)
553 # TODO(jbudorick): Revise --single-step to use argparse.REMAINDER.
554 # This requires removing "--" from client calls.
555 step_group.add_argument(
556 '--single-step', action='store_true',
[email protected]def4bce2013-11-12 12:59:52557 help='Execute the given command with retries, but only print the result '
558 'for the "most successful" round.')
jama47ca85c2014-12-03 18:38:07559 step_group.add_argument(
[email protected]181a5c92013-09-06 17:11:46560 '--steps',
[email protected]def4bce2013-11-12 12:59:52561 help='JSON file containing the list of commands to run.')
jama47ca85c2014-12-03 18:38:07562 step_group.add_argument(
563 '--print-step',
564 help='The name of a previously executed perf step to print.')
565
566 group.add_argument(
peterbd4e73d2014-12-03 15:47:36567 '--output-json-list',
568 help='Write a simple list of names from --steps into the given file.')
jama47ca85c2014-12-03 18:38:07569 group.add_argument(
peterbd4e73d2014-12-03 15:47:36570 '--collect-chartjson-data',
571 action='store_true',
572 help='Cache the chartjson output from each step for later use.')
jama47ca85c2014-12-03 18:38:07573 group.add_argument(
peterbd4e73d2014-12-03 15:47:36574 '--output-chartjson-data',
575 default='',
576 help='Write out chartjson into the given file.')
jama47ca85c2014-12-03 18:38:07577 group.add_argument(
perezju67cf7f12015-09-29 11:39:05578 '--get-output-dir-archive', metavar='FILENAME',
579 help='Write the chached output directory archived by a step into the'
580 ' given ZIP file.')
581 group.add_argument(
jama47ca85c2014-12-03 18:38:07582 '--flaky-steps',
583 help=('A JSON file containing steps that are flaky '
584 'and will have its exit code ignored.'))
585 group.add_argument(
[email protected]181a5c92013-09-06 17:11:46586 '--no-timeout', action='store_true',
587 help=('Do not impose a timeout. Each perf step is responsible for '
588 'implementing the timeout logic.'))
jama47ca85c2014-12-03 18:38:07589 group.add_argument(
[email protected]650487c2013-09-30 11:40:49590 '-f', '--test-filter',
591 help=('Test filter (will match against the names listed in --steps).'))
jama47ca85c2014-12-03 18:38:07592 group.add_argument(
593 '--dry-run', action='store_true',
[email protected]650487c2013-09-30 11:40:49594 help='Just print the steps without executing.')
jbudorick5cfff872015-07-01 18:46:13595 # Uses 0.1 degrees C because that's what Android does.
596 group.add_argument(
597 '--max-battery-temp', type=int,
598 help='Only start tests when the battery is at or below the given '
599 'temperature (0.1 C)')
jama47ca85c2014-12-03 18:38:07600 group.add_argument('single_step_command', nargs='*', action=SingleStepAction,
601 help='If --single-step is specified, the command to run.')
rnephewdde05da82015-07-09 20:31:01602 group.add_argument('--min-battery-level', type=int,
603 help='Only starts tests when the battery is charged above '
604 'given level.')
rnephewa66f59992016-02-26 18:29:05605 group.add_argument('--known-devices-file', help='Path to known device list.')
jama47ca85c2014-12-03 18:38:07606 AddCommonOptions(parser)
607 AddDeviceOptions(parser)
[email protected]ec3170b2013-08-14 14:39:47608
609
jama47ca85c2014-12-03 18:38:07610def ProcessPerfTestOptions(args):
[email protected]ec3170b2013-08-14 14:39:47611 """Processes all perf test options.
612
613 Args:
jama47ca85c2014-12-03 18:38:07614 args: argparse.Namespace object.
[email protected]ec3170b2013-08-14 14:39:47615
616 Returns:
617 A PerfOptions named tuple which contains all options relevant to
618 perf tests.
619 """
jama47ca85c2014-12-03 18:38:07620 # TODO(jbudorick): Move single_step handling down into the perf tests.
621 if args.single_step:
622 args.single_step = ' '.join(args.single_step_command)
623 # TODO(jbudorick): Get rid of PerfOptions.
[email protected]ec3170b2013-08-14 14:39:47624 return perf_test_options.PerfOptions(
jama47ca85c2014-12-03 18:38:07625 args.steps, args.flaky_steps, args.output_json_list,
626 args.print_step, args.no_timeout, args.test_filter,
627 args.dry_run, args.single_step, args.collect_chartjson_data,
perezju67cf7f12015-09-29 11:39:05628 args.output_chartjson_data, args.get_output_dir_archive,
rnephewa66f59992016-02-26 18:29:05629 args.max_battery_temp, args.min_battery_level,
630 args.known_devices_file)
[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 _RunJUnitTests(args):
jbudorick9a6b7b332014-09-20 00:01:07662 """Subcommand of RunTestsCommand which runs junit tests."""
jama47ca85c2014-12-03 18:38:07663 runner_factory, tests = junit_setup.Setup(args)
mikecasec638a072015-04-01 16:35:35664 results, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
665
666 report_results.LogFull(
667 results=results,
668 test_type='JUnit',
669 test_package=args.test_suite)
670
mikecase572401b2015-04-09 02:28:57671 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20672 json_results.GenerateJsonResultsFile([results], args.json_results_file)
mikecase572401b2015-04-09 02:28:57673
jbudorick9a6b7b332014-09-20 00:01:07674 return exit_code
675
676
jama47ca85c2014-12-03 18:38:07677def _RunMonkeyTests(args, devices):
[email protected]3dbdfa42013-08-08 01:08:14678 """Subcommand of RunTestsCommands which runs monkey tests."""
jama47ca85c2014-12-03 18:38:07679 monkey_options = ProcessMonkeyTestOptions(args)
[email protected]3dbdfa42013-08-08 01:08:14680
681 runner_factory, tests = monkey_setup.Setup(monkey_options)
682
683 results, exit_code = test_dispatcher.RunTests(
[email protected]181a5c92013-09-06 17:11:46684 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07685 num_retries=args.num_retries)
[email protected]3dbdfa42013-08-08 01:08:14686
687 report_results.LogFull(
688 results=results,
689 test_type='Monkey',
[email protected]14b3b1202013-08-15 22:25:28690 test_package='Monkey')
[email protected]3dbdfa42013-08-08 01:08:14691
jama47ca85c2014-12-03 18:38:07692 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20693 json_results.GenerateJsonResultsFile([results], args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54694
[email protected]3dbdfa42013-08-08 01:08:14695 return exit_code
696
697
jbudorickdde688fb2015-08-27 03:00:17698def _RunPerfTests(args, active_devices):
[email protected]ec3170b2013-08-14 14:39:47699 """Subcommand of RunTestsCommands which runs perf tests."""
jama47ca85c2014-12-03 18:38:07700 perf_options = ProcessPerfTestOptions(args)
[email protected]61487ed2014-06-09 12:33:56701
702 # Just save a simple json with a list of test names.
703 if perf_options.output_json_list:
704 return perf_test_runner.OutputJsonList(
705 perf_options.steps, perf_options.output_json_list)
706
[email protected]ad32f312013-11-13 04:03:29707 # Just print the results from a single previously executed step.
[email protected]ec3170b2013-08-14 14:39:47708 if perf_options.print_step:
simonhatch9b9256d2015-01-07 18:03:42709 return perf_test_runner.PrintTestOutput(
perezju67cf7f12015-09-29 11:39:05710 perf_options.print_step, perf_options.output_chartjson_data,
711 perf_options.get_output_dir_archive)
[email protected]ec3170b2013-08-14 14:39:47712
jbudorickdde688fb2015-08-27 03:00:17713 runner_factory, tests, devices = perf_setup.Setup(
714 perf_options, active_devices)
[email protected]ec3170b2013-08-14 14:39:47715
[email protected]a72f0752014-06-03 23:52:34716 # shard=False means that each device will get the full list of tests
717 # and then each one will decide their own affinity.
718 # shard=True means each device will pop the next test available from a queue,
719 # which increases throughput but have no affinity.
[email protected]86184c7b2013-08-15 15:06:57720 results, _ = test_dispatcher.RunTests(
[email protected]a72f0752014-06-03 23:52:34721 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07722 num_retries=args.num_retries)
[email protected]ec3170b2013-08-14 14:39:47723
724 report_results.LogFull(
725 results=results,
726 test_type='Perf',
[email protected]865a47a2013-08-16 14:01:12727 test_package='Perf')
[email protected]def4bce2013-11-12 12:59:52728
jama47ca85c2014-12-03 18:38:07729 if args.json_results_file:
jbudorickeb7ea71c2015-09-28 16:40:20730 json_results.GenerateJsonResultsFile([results], args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54731
[email protected]def4bce2013-11-12 12:59:52732 if perf_options.single_step:
733 return perf_test_runner.PrintTestOutput('single_step')
734
[email protected]11ce8452014-02-17 10:55:03735 perf_test_runner.PrintSummary(tests)
736
[email protected]86184c7b2013-08-15 15:06:57737 # Always return 0 on the sharding stage. Individual tests exit_code
738 # will be returned on the print_step stage.
739 return 0
[email protected]ec3170b2013-08-14 14:39:47740
[email protected]3dbdfa42013-08-08 01:08:14741
jama47ca85c2014-12-03 18:38:07742def _RunPythonTests(args):
jbudorick256fd532014-10-24 01:50:13743 """Subcommand of RunTestsCommand which runs python unit tests."""
jama47ca85c2014-12-03 18:38:07744 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name]
jbudorick256fd532014-10-24 01:50:13745 suite_path = suite_vars['path']
746 suite_test_modules = suite_vars['test_modules']
747
748 sys.path = [suite_path] + sys.path
749 try:
750 suite = unittest.TestSuite()
751 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
752 for m in suite_test_modules)
jama47ca85c2014-12-03 18:38:07753 runner = unittest.TextTestRunner(verbosity=1+args.verbose_count)
jbudorick256fd532014-10-24 01:50:13754 return 0 if runner.run(suite).wasSuccessful() else 1
755 finally:
756 sys.path = sys.path[1:]
757
758
agrieveebc6bfa2016-04-05 19:29:25759def _GetAttachedDevices(blacklist_file, test_device, enable_cache, num_retries):
[email protected]f7148dd42013-08-20 14:24:57760 """Get all attached devices.
761
762 Args:
agrievea538a142015-10-09 15:45:56763 blacklist_file: Path to device blacklist.
[email protected]f7148dd42013-08-20 14:24:57764 test_device: Name of a specific device to use.
agrievea538a142015-10-09 15:45:56765 enable_cache: Whether to enable checksum caching.
[email protected]f7148dd42013-08-20 14:24:57766
767 Returns:
768 A list of attached devices.
769 """
jbudoricka583ba32015-09-11 17:23:19770 blacklist = (device_blacklist.Blacklist(blacklist_file)
771 if blacklist_file
772 else None)
jbudorickdde688fb2015-08-27 03:00:17773
agrievea538a142015-10-09 15:45:56774 attached_devices = device_utils.DeviceUtils.HealthyDevices(
agrieveebc6bfa2016-04-05 19:29:25775 blacklist, enable_device_files_cache=enable_cache,
776 default_retries=num_retries)
aberent6a02a6182015-04-29 11:07:55777 if test_device:
jbudorick4551d0dc2015-04-29 16:07:06778 test_device = [d for d in attached_devices if d == test_device]
779 if not test_device:
780 raise device_errors.DeviceUnreachableError(
781 'Did not find device %s among attached device. Attached devices: %s'
782 % (test_device, ', '.join(attached_devices)))
783 return test_device
aberent6a02a6182015-04-29 11:07:55784
jbudorick4551d0dc2015-04-29 16:07:06785 else:
786 if not attached_devices:
787 raise device_errors.NoDevicesError()
788 return sorted(attached_devices)
[email protected]f7148dd42013-08-20 14:24:57789
790
agrieve63d20782016-02-04 17:47:26791def RunTestsCommand(args): # pylint: disable=too-many-return-statements
[email protected]fbe29322013-07-09 09:03:26792 """Checks test type and dispatches to the appropriate function.
793
794 Args:
jama47ca85c2014-12-03 18:38:07795 args: argparse.Namespace object.
[email protected]fbe29322013-07-09 09:03:26796
797 Returns:
798 Integer indicated exit code.
[email protected]b3873892013-07-10 04:57:10799
800 Raises:
801 Exception: Unknown command name passed in, or an exception from an
802 individual test runner.
[email protected]fbe29322013-07-09 09:03:26803 """
jama47ca85c2014-12-03 18:38:07804 command = args.command
[email protected]fbe29322013-07-09 09:03:26805
jama47ca85c2014-12-03 18:38:07806 ProcessCommonOptions(args)
jbudorick2be28ee2016-02-16 15:53:23807 logging.info('command: %s', ' '.join(sys.argv))
[email protected]d82f0252013-07-12 23:22:57808
jbudorickb71170d02016-03-30 01:32:08809 if args.enable_platform_mode or command in ('gtest', 'instrumentation'):
agrieve63d20782016-02-04 17:47:26810 return RunTestsInPlatformMode(args)
jbudorick66dc3722014-11-06 21:33:51811
[email protected]c0662e092013-11-12 11:51:25812 forwarder.Forwarder.RemoveHostLog()
[email protected]6b11583b2013-11-21 16:18:40813 if not ports.ResetTestServerPortAllocation():
814 raise Exception('Failed to reset test server port.')
[email protected]c0662e092013-11-12 11:51:25815
agrieve18930bd2015-10-09 17:41:42816 def get_devices():
817 return _GetAttachedDevices(args.blacklist_file, args.test_device,
agrieveebc6bfa2016-04-05 19:29:25818 args.enable_device_cache, args.num_retries)
agrieve18930bd2015-10-09 17:41:42819
jbudorickb71170d02016-03-30 01:32:08820 if command == 'linker':
agrieve18930bd2015-10-09 17:41:42821 return _RunLinkerTests(args, get_devices())
jbudorick9a6b7b332014-09-20 00:01:07822 elif command == 'junit':
jama47ca85c2014-12-03 18:38:07823 return _RunJUnitTests(args)
[email protected]3dbdfa42013-08-08 01:08:14824 elif command == 'monkey':
agrieve18930bd2015-10-09 17:41:42825 return _RunMonkeyTests(args, get_devices())
[email protected]ec3170b2013-08-14 14:39:47826 elif command == 'perf':
agrieve18930bd2015-10-09 17:41:42827 return _RunPerfTests(args, get_devices())
jbudorick256fd532014-10-24 01:50:13828 elif command == 'python':
jama47ca85c2014-12-03 18:38:07829 return _RunPythonTests(args)
[email protected]fbe29322013-07-09 09:03:26830 else:
[email protected]6bc1bda22013-07-19 22:08:37831 raise Exception('Unknown test type.')
[email protected]fbe29322013-07-09 09:03:26832
[email protected]fbe29322013-07-09 09:03:26833
jbudorick66dc3722014-11-06 21:33:51834_SUPPORTED_IN_PLATFORM_MODE = [
835 # TODO(jbudorick): Add support for more test types.
jbudorick911be58d2015-01-13 02:51:06836 'gtest',
837 'instrumentation',
838 'uirobot',
jbudorick66dc3722014-11-06 21:33:51839]
840
841
agrieve63d20782016-02-04 17:47:26842def RunTestsInPlatformMode(args):
jbudorick66dc3722014-11-06 21:33:51843
jbudorick566592ab2015-09-21 15:32:47844 def infra_error(message):
agrieve63d20782016-02-04 17:47:26845 logging.fatal(message)
846 sys.exit(constants.INFRA_EXIT_CODE)
jbudorickb9b0ada2015-09-17 22:52:58847
jbudorick566592ab2015-09-21 15:32:47848 if args.command not in _SUPPORTED_IN_PLATFORM_MODE:
849 infra_error('%s is not yet supported in platform mode' % args.command)
850
851 with environment_factory.CreateEnvironment(args, infra_error) as env:
852 with test_instance_factory.CreateTestInstance(args, infra_error) as test:
jbudorick66dc3722014-11-06 21:33:51853 with test_run_factory.CreateTestRun(
jbudorick566592ab2015-09-21 15:32:47854 args, env, test, infra_error) as test_run:
jbudorickeb7ea71c2015-09-28 16:40:20855 results = []
856 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0
857 else itertools.count())
alexandermonte2cbe022015-12-16 04:58:58858 result_counts = collections.defaultdict(
859 lambda: collections.defaultdict(int))
860 iteration_count = 0
jbudorickeb7ea71c2015-09-28 16:40:20861 for _ in repetitions:
862 iteration_results = test_run.RunTests()
jbudorickeb7ea71c2015-09-28 16:40:20863 if iteration_results is not None:
alexandermonte2cbe022015-12-16 04:58:58864 iteration_count += 1
jbudorickd4f77982015-09-28 21:09:18865 results.append(iteration_results)
alexandermonte2cbe022015-12-16 04:58:58866 for r in iteration_results.GetAll():
867 result_counts[r.GetName()][r.GetType()] += 1
jbudorickeb7ea71c2015-09-28 16:40:20868 report_results.LogFull(
869 results=iteration_results,
870 test_type=test.TestType(),
871 test_package=test_run.TestPackage(),
872 annotation=getattr(args, 'annotations', None),
873 flakiness_server=getattr(args, 'flakiness_dashboard_server',
874 None))
alexandermonta3f03bf2015-12-02 18:56:45875 if args.break_on_failure and not iteration_results.DidRunPass():
876 break
jbudorick66dc3722014-11-06 21:33:51877
alexandermonte2cbe022015-12-16 04:58:58878 if iteration_count > 1:
879 # display summary results
880 # only display results for a test if at least one test did not pass
881 all_pass = 0
882 tot_tests = 0
883 for test_name in result_counts:
884 tot_tests += 1
885 if any(result_counts[test_name][x] for x in (
886 base_test_result.ResultType.FAIL,
887 base_test_result.ResultType.CRASH,
888 base_test_result.ResultType.TIMEOUT,
889 base_test_result.ResultType.UNKNOWN)):
890 logging.critical(
891 '%s: %s',
892 test_name,
893 ', '.join('%s %s' % (str(result_counts[test_name][i]), i)
894 for i in base_test_result.ResultType.GetTypes()))
895 else:
896 all_pass += 1
897
898 logging.critical('%s of %s tests passed in all %s runs',
899 str(all_pass),
900 str(tot_tests),
901 str(iteration_count))
902
jama47ca85c2014-12-03 18:38:07903 if args.json_results_file:
jbudorickb8c42072014-12-01 18:07:54904 json_results.GenerateJsonResultsFile(
jama47ca85c2014-12-03 18:38:07905 results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54906
jbudorickeb7ea71c2015-09-28 16:40:20907 return (0 if all(r.DidRunPass() for r in results)
908 else constants.ERROR_EXIT_CODE)
jbudorick66dc3722014-11-06 21:33:51909
910
jama47ca85c2014-12-03 18:38:07911CommandConfigTuple = collections.namedtuple(
912 'CommandConfigTuple',
913 ['add_options_func', 'help_txt'])
[email protected]fbe29322013-07-09 09:03:26914VALID_COMMANDS = {
jama47ca85c2014-12-03 18:38:07915 'gtest': CommandConfigTuple(
916 AddGTestOptions,
917 'googletest-based C++ tests'),
918 'instrumentation': CommandConfigTuple(
919 AddInstrumentationTestOptions,
920 'InstrumentationTestCase-based Java tests'),
jama47ca85c2014-12-03 18:38:07921 'junit': CommandConfigTuple(
922 AddJUnitTestOptions,
923 'JUnit4-based Java tests'),
924 'monkey': CommandConfigTuple(
925 AddMonkeyTestOptions,
926 "Tests based on Android's monkey"),
927 'perf': CommandConfigTuple(
928 AddPerfTestOptions,
929 'Performance tests'),
930 'python': CommandConfigTuple(
931 AddPythonTestOptions,
932 'Python tests based on unittest.TestCase'),
933 'linker': CommandConfigTuple(
934 AddLinkerTestOptions,
935 'Linker tests'),
rnephew5c499782014-12-12 19:08:55936 'uirobot': CommandConfigTuple(
937 AddUirobotTestOptions,
938 'Uirobot test'),
jama47ca85c2014-12-03 18:38:07939}
[email protected]fbe29322013-07-09 09:03:26940
941
[email protected]7c53a602014-03-24 16:21:44942def DumpThreadStacks(_signal, _frame):
[email protected]71aec4b2013-11-20 00:35:24943 for thread in threading.enumerate():
944 reraiser_thread.LogThreadStack(thread)
[email protected]83bb8152013-11-19 15:02:21945
946
[email protected]7c53a602014-03-24 16:21:44947def main():
[email protected]83bb8152013-11-19 15:02:21948 signal.signal(signal.SIGUSR1, DumpThreadStacks)
jama47ca85c2014-12-03 18:38:07949
950 parser = argparse.ArgumentParser()
951 command_parsers = parser.add_subparsers(title='test types',
952 dest='command')
953
954 for test_type, config in sorted(VALID_COMMANDS.iteritems(),
955 key=lambda x: x[0]):
956 subparser = command_parsers.add_parser(
957 test_type, usage='%(prog)s [options]', help=config.help_txt)
958 config.add_options_func(subparser)
959
960 args = parser.parse_args()
mikecasee74051022015-02-26 23:08:22961
962 try:
agrieve63d20782016-02-04 17:47:26963 return RunTestsCommand(args)
mikecasee74051022015-02-26 23:08:22964 except base_error.BaseError as e:
965 logging.exception('Error occurred.')
966 if e.is_infra_error:
967 return constants.INFRA_EXIT_CODE
mswecce6732015-06-06 00:31:33968 return constants.ERROR_EXIT_CODE
mikecasee74051022015-02-26 23:08:22969 except: # pylint: disable=W0702
970 logging.exception('Unrecognized error occurred.')
971 return constants.ERROR_EXIT_CODE
[email protected]fbe29322013-07-09 09:03:26972
[email protected]fbe29322013-07-09 09:03:26973
974if __name__ == '__main__':
[email protected]7c53a602014-03-24 16:21:44975 sys.exit(main())