blob: 235d45bdaeb21f736467ff349579702e4fa06fb9 [file] [log] [blame]
[email protected]fbe29322013-07-09 09:03:261#!/usr/bin/env python
2#
3# Copyright 2013 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
[email protected]181a5c92013-09-06 17:11:467"""Runs all types of tests from one unified interface."""
[email protected]fbe29322013-07-09 09:03:268
jama47ca85c2014-12-03 18:38:079import argparse
[email protected]fbe29322013-07-09 09:03:2610import collections
[email protected]f7148dd42013-08-20 14:24:5711import logging
[email protected]fbe29322013-07-09 09:03:2612import os
[email protected]83bb8152013-11-19 15:02:2113import signal
[email protected]fbe29322013-07-09 09:03:2614import sys
[email protected]83bb8152013-11-19 15:02:2115import threading
jbudorick256fd532014-10-24 01:50:1316import unittest
[email protected]fbe29322013-07-09 09:03:2617
jbudorick061629442015-09-03 18:00:5718from devil import base_error
19from devil.android import apk_helper
20from devil.android import device_blacklist
21from devil.android import device_errors
22from devil.android import device_utils
23from devil.android import ports
24from devil.utils import reraiser_thread
25from devil.utils import run_tests_helper
26
[email protected]fbe29322013-07-09 09:03:2627from pylib import constants
[email protected]c0662e092013-11-12 11:51:2528from pylib import forwarder
[email protected]fbe29322013-07-09 09:03:2629from pylib.base import base_test_result
jbudorick66dc3722014-11-06 21:33:5130from pylib.base import environment_factory
[email protected]6bc1bda22013-07-19 22:08:3731from pylib.base import test_dispatcher
jbudorick66dc3722014-11-06 21:33:5132from pylib.base import test_instance_factory
33from pylib.base import test_run_factory
[email protected]6bc1bda22013-07-19 22:08:3734from pylib.gtest import gtest_config
jbudorick590a3d72015-06-12 23:53:3135# TODO(jbudorick): Remove this once we stop selectively enabling platform mode.
36from pylib.gtest import gtest_test_instance
[email protected]2a684222013-08-01 16:59:2237from pylib.gtest import setup as gtest_setup
38from pylib.gtest import test_options as gtest_test_options
[email protected]6b6abac6d2013-10-03 11:56:3839from pylib.linker import setup as linker_setup
[email protected]37ee0c792013-08-06 19:10:1340from pylib.host_driven import setup as host_driven_setup
[email protected]6bc1bda22013-07-19 22:08:3741from pylib.instrumentation import setup as instrumentation_setup
[email protected]2a684222013-08-01 16:59:2242from pylib.instrumentation import test_options as instrumentation_test_options
jbudorick9a6b7b332014-09-20 00:01:0743from pylib.junit import setup as junit_setup
44from pylib.junit import test_dispatcher as junit_dispatcher
[email protected]3dbdfa42013-08-08 01:08:1445from pylib.monkey import setup as monkey_setup
46from pylib.monkey import test_options as monkey_test_options
[email protected]ec3170b2013-08-14 14:39:4747from pylib.perf import setup as perf_setup
48from pylib.perf import test_options as perf_test_options
49from pylib.perf import test_runner as perf_test_runner
jbudorickb8c42072014-12-01 18:07:5450from pylib.results import json_results
51from pylib.results import report_results
[email protected]6bc1bda22013-07-19 22:08:3752from pylib.uiautomator import setup as uiautomator_setup
[email protected]2a684222013-08-01 16:59:2253from pylib.uiautomator import test_options as uiautomator_test_options
[email protected]fbe29322013-07-09 09:03:2654
55
jama47ca85c2014-12-03 18:38:0756def AddCommonOptions(parser):
57 """Adds all common options to |parser|."""
[email protected]fbe29322013-07-09 09:03:2658
jama47ca85c2014-12-03 18:38:0759 group = parser.add_argument_group('Common Options')
60
[email protected]dfffbcbc2013-09-17 22:06:0161 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
jama47ca85c2014-12-03 18:38:0762
63 debug_or_release_group = group.add_mutually_exclusive_group()
64 debug_or_release_group.add_argument(
65 '--debug', action='store_const', const='Debug', dest='build_type',
66 default=default_build_type,
67 help=('If set, run test suites under out/Debug. '
68 'Default is env var BUILDTYPE or Debug.'))
69 debug_or_release_group.add_argument(
70 '--release', action='store_const', const='Release', dest='build_type',
71 help=('If set, run test suites under out/Release. '
72 'Default is env var BUILDTYPE or Debug.'))
73
74 group.add_argument('--build-directory', dest='build_directory',
75 help=('Path to the directory in which build files are'
76 ' located (should not include build type)'))
77 group.add_argument('--output-directory', dest='output_directory',
78 help=('Path to the directory in which build files are'
79 ' located (must include build type). This will take'
80 ' precedence over --debug, --release and'
81 ' --build-directory'))
82 group.add_argument('--num_retries', dest='num_retries', type=int, default=2,
83 help=('Number of retries for a test before '
84 'giving up (default: %(default)s).'))
85 group.add_argument('-v',
86 '--verbose',
87 dest='verbose_count',
88 default=0,
89 action='count',
90 help='Verbose level (multiple times for more)')
91 group.add_argument('--flakiness-dashboard-server',
92 dest='flakiness_dashboard_server',
93 help=('Address of the server that is hosting the '
94 'Chrome for Android flakiness dashboard.'))
95 group.add_argument('--enable-platform-mode', action='store_true',
96 help=('Run the test scripts in platform mode, which '
97 'conceptually separates the test runner from the '
98 '"device" (local or remote, real or emulated) on '
99 'which the tests are running. [experimental]'))
100 group.add_argument('-e', '--environment', default='local',
101 choices=constants.VALID_ENVIRONMENTS,
102 help='Test environment to run in (default: %(default)s).')
103 group.add_argument('--adb-path',
104 help=('Specify the absolute path of the adb binary that '
105 'should be used.'))
106 group.add_argument('--json-results-file', dest='json_results_file',
107 help='If set, will dump results in JSON form '
108 'to specified file.')
[email protected]fbe29322013-07-09 09:03:26109
jama47ca85c2014-12-03 18:38:07110def ProcessCommonOptions(args):
[email protected]fbe29322013-07-09 09:03:26111 """Processes and handles all common options."""
jama47ca85c2014-12-03 18:38:07112 run_tests_helper.SetLogLevel(args.verbose_count)
113 constants.SetBuildType(args.build_type)
114 if args.build_directory:
115 constants.SetBuildDirectory(args.build_directory)
116 if args.output_directory:
mikecase0aea9c52015-04-30 00:12:33117 constants.SetOutputDirectory(args.output_directory)
jama47ca85c2014-12-03 18:38:07118 if args.adb_path:
119 constants.SetAdbPath(args.adb_path)
mikecase48e16bf2014-11-19 22:46:45120 # Some things such as Forwarder require ADB to be in the environment path.
121 adb_dir = os.path.dirname(constants.GetAdbPath())
122 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep):
123 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
[email protected]fbe29322013-07-09 09:03:26124
125
rnephew5c499782014-12-12 19:08:55126def AddRemoteDeviceOptions(parser):
127 group = parser.add_argument_group('Remote Device Options')
128
rnephewefe44b42015-02-04 04:45:15129 group.add_argument('--trigger',
jbudoricke6c560152015-01-13 23:49:28130 help=('Only triggers the test if set. Stores test_run_id '
131 'in given file path. '))
rnephewefe44b42015-02-04 04:45:15132 group.add_argument('--collect',
jbudoricke6c560152015-01-13 23:49:28133 help=('Only collects the test results if set. '
134 'Gets test_run_id from given file path.'))
rnephewefe44b42015-02-04 04:45:15135 group.add_argument('--remote-device', action='append',
jbudoricke6c560152015-01-13 23:49:28136 help='Device type to run test on.')
rnephewefe44b42015-02-04 04:45:15137 group.add_argument('--results-path',
jbudoricke6c560152015-01-13 23:49:28138 help='File path to download results to.')
rnephew7f1e2052014-12-12 23:00:11139 group.add_argument('--api-protocol',
jbudoricke6c560152015-01-13 23:49:28140 help='HTTP protocol to use. (http or https)')
rnephewefe44b42015-02-04 04:45:15141 group.add_argument('--api-address',
142 help='Address to send HTTP requests.')
143 group.add_argument('--api-port',
144 help='Port to send HTTP requests to.')
145 group.add_argument('--runner-type',
jbudoricke6c560152015-01-13 23:49:28146 help='Type of test to run as.')
rnephewefe44b42015-02-04 04:45:15147 group.add_argument('--runner-package',
148 help='Package name of test.')
149 group.add_argument('--device-type',
rnephewa46fc562015-01-23 16:00:14150 choices=constants.VALID_DEVICE_TYPES,
151 help=('Type of device to run on. iOS or android'))
rnephewefe44b42015-02-04 04:45:15152 group.add_argument('--device-oem', action='append',
153 help='Device OEM to run on.')
154 group.add_argument('--remote-device-file',
155 help=('File with JSON to select remote device. '
156 'Overrides all other flags.'))
rnephewc9ae8f52015-02-13 03:02:55157 group.add_argument('--remote-device-timeout', type=int,
158 help='Times to retry finding remote device')
mikecase520cbbb52015-04-21 18:51:18159 group.add_argument('--network-config', type=int,
160 help='Integer that specifies the network environment '
161 'that the tests will be run in.')
rnephewefe44b42015-02-04 04:45:15162
163 device_os_group = group.add_mutually_exclusive_group()
164 device_os_group.add_argument('--remote-device-minimum-os',
165 help='Minimum OS on device.')
166 device_os_group.add_argument('--remote-device-os', action='append',
167 help='OS to have on the device.')
rnephew5c499782014-12-12 19:08:55168
169 api_secret_group = group.add_mutually_exclusive_group()
170 api_secret_group.add_argument('--api-secret', default='',
jbudoricke6c560152015-01-13 23:49:28171 help='API secret for remote devices.')
rnephew5c499782014-12-12 19:08:55172 api_secret_group.add_argument('--api-secret-file', default='',
jbudoricke6c560152015-01-13 23:49:28173 help='Path to file that contains API secret.')
rnephew5c499782014-12-12 19:08:55174
175 api_key_group = group.add_mutually_exclusive_group()
176 api_key_group.add_argument('--api-key', default='',
jbudoricke6c560152015-01-13 23:49:28177 help='API key for remote devices.')
rnephew5c499782014-12-12 19:08:55178 api_key_group.add_argument('--api-key-file', default='',
jbudoricke6c560152015-01-13 23:49:28179 help='Path to file that contains API key.')
rnephew5c499782014-12-12 19:08:55180
181
jama47ca85c2014-12-03 18:38:07182def AddDeviceOptions(parser):
183 """Adds device options to |parser|."""
184 group = parser.add_argument_group(title='Device Options')
jama47ca85c2014-12-03 18:38:07185 group.add_argument('--tool',
186 dest='tool',
187 help=('Run the test under a tool '
188 '(use --tool help to list them)'))
189 group.add_argument('-d', '--device', dest='test_device',
190 help=('Target device for the test suite '
191 'to run on.'))
jbudorickdde688fb2015-08-27 03:00:17192 group.add_argument('--blacklist-file', help='Device blacklist file.')
jbudorick256fd532014-10-24 01:50:13193
194
jama47ca85c2014-12-03 18:38:07195def AddGTestOptions(parser):
196 """Adds gtest options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26197
jama47ca85c2014-12-03 18:38:07198 gtest_suites = list(gtest_config.STABLE_TEST_SUITES
199 + gtest_config.EXPERIMENTAL_TEST_SUITES)
[email protected]fbe29322013-07-09 09:03:26200
jama47ca85c2014-12-03 18:38:07201 group = parser.add_argument_group('GTest Options')
jbudorick15cdcd52014-12-03 19:58:49202 group.add_argument('-s', '--suite', dest='suite_name',
jama47ca85c2014-12-03 18:38:07203 nargs='+', metavar='SUITE_NAME', required=True,
jbudorick15cdcd52014-12-03 19:58:49204 help=('Executable name of the test suite to run. '
205 'Available suites include (but are not limited to): '
206 '%s' % ', '.join('"%s"' % s for s in gtest_suites)))
jama47ca85c2014-12-03 18:38:07207 group.add_argument('--gtest_also_run_disabled_tests',
208 '--gtest-also-run-disabled-tests',
209 dest='run_disabled', action='store_true',
210 help='Also run disabled tests if applicable.')
211 group.add_argument('-a', '--test-arguments', dest='test_arguments',
212 default='',
213 help='Additional arguments to pass to the test.')
214 group.add_argument('-t', dest='timeout', type=int, default=60,
215 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.')
jbudorick442a6932015-02-03 03:01:15231
232 filter_group = group.add_mutually_exclusive_group()
233 filter_group.add_argument('-f', '--gtest_filter', '--gtest-filter',
234 dest='test_filter',
235 help='googletest-style filter string.')
236 filter_group.add_argument('--gtest-filter-file', dest='test_filter_file',
237 help='Path to file that contains googletest-style '
238 'filter strings. (Lines will be joined with '
239 '":" to create a single filter string.)')
240
jama47ca85c2014-12-03 18:38:07241 AddDeviceOptions(parser)
242 AddCommonOptions(parser)
rnephew5c499782014-12-12 19:08:55243 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26244
245
jama47ca85c2014-12-03 18:38:07246def AddLinkerTestOptions(parser):
247 group = parser.add_argument_group('Linker Test Options')
248 group.add_argument('-f', '--gtest-filter', dest='test_filter',
249 help='googletest-style filter string.')
250 AddCommonOptions(parser)
251 AddDeviceOptions(parser)
[email protected]6b6abac6d2013-10-03 11:56:38252
253
jama47ca85c2014-12-03 18:38:07254def AddJavaTestOptions(argument_group):
[email protected]fbe29322013-07-09 09:03:26255 """Adds the Java test options to |option_parser|."""
256
jama47ca85c2014-12-03 18:38:07257 argument_group.add_argument(
258 '-f', '--test-filter', dest='test_filter',
259 help=('Test filter (if not fully qualified, will run all matches).'))
260 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26261 '-A', '--annotation', dest='annotation_str',
262 help=('Comma-separated list of annotations. Run only tests with any of '
263 'the given annotations. An annotation can be either a key or a '
264 'key-values pair. A test that has no annotation is considered '
265 '"SmallTest".'))
jama47ca85c2014-12-03 18:38:07266 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26267 '-E', '--exclude-annotation', dest='exclude_annotation_str',
268 help=('Comma-separated list of annotations. Exclude tests with these '
269 'annotations.'))
jama47ca85c2014-12-03 18:38:07270 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59271 '--screenshot', dest='screenshot_failures', action='store_true',
272 help='Capture screenshots of test failures')
jama47ca85c2014-12-03 18:38:07273 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59274 '--save-perf-json', action='store_true',
275 help='Saves the JSON file for each UI Perf test.')
jama47ca85c2014-12-03 18:38:07276 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59277 '--official-build', action='store_true', help='Run official build tests.')
jama47ca85c2014-12-03 18:38:07278 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59279 '--test_data', '--test-data', action='append', default=[],
280 help=('Each instance defines a directory of test data that should be '
281 'copied to the target(s) before running the tests. The argument '
282 'should be of the form <target>:<source>, <target> is relative to '
283 'the device data directory, and <source> is relative to the '
284 'chromium build directory.'))
davileen98efad12015-01-05 19:48:21285 argument_group.add_argument(
286 '--disable-dalvik-asserts', dest='set_asserts', action='store_false',
287 default=True, help='Removes the dalvik.vm.enableassertions property')
288
[email protected]fbe29322013-07-09 09:03:26289
290
jama47ca85c2014-12-03 18:38:07291def ProcessJavaTestOptions(args):
[email protected]fbe29322013-07-09 09:03:26292 """Processes options/arguments and populates |options| with defaults."""
293
jama47ca85c2014-12-03 18:38:07294 # TODO(jbudorick): Handle most of this function in argparse.
295 if args.annotation_str:
296 args.annotations = args.annotation_str.split(',')
297 elif args.test_filter:
298 args.annotations = []
[email protected]fbe29322013-07-09 09:03:26299 else:
jama47ca85c2014-12-03 18:38:07300 args.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
301 'EnormousTest', 'IntegrationTest']
[email protected]fbe29322013-07-09 09:03:26302
jama47ca85c2014-12-03 18:38:07303 if args.exclude_annotation_str:
304 args.exclude_annotations = args.exclude_annotation_str.split(',')
[email protected]fbe29322013-07-09 09:03:26305 else:
jama47ca85c2014-12-03 18:38:07306 args.exclude_annotations = []
[email protected]fbe29322013-07-09 09:03:26307
[email protected]fbe29322013-07-09 09:03:26308
jama47ca85c2014-12-03 18:38:07309def AddInstrumentationTestOptions(parser):
310 """Adds Instrumentation test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26311
jama47ca85c2014-12-03 18:38:07312 parser.usage = '%(prog)s [options]'
[email protected]fbe29322013-07-09 09:03:26313
jama47ca85c2014-12-03 18:38:07314 group = parser.add_argument_group('Instrumentation Test Options')
315 AddJavaTestOptions(group)
[email protected]fbe29322013-07-09 09:03:26316
jama47ca85c2014-12-03 18:38:07317 java_or_python_group = group.add_mutually_exclusive_group()
318 java_or_python_group.add_argument(
319 '-j', '--java-only', action='store_false',
320 dest='run_python_tests', default=True, help='Run only the Java tests.')
321 java_or_python_group.add_argument(
322 '-p', '--python-only', action='store_false',
323 dest='run_java_tests', default=True,
324 help='Run only the host-driven tests.')
325
326 group.add_argument('--host-driven-root',
327 help='Root of the host-driven tests.')
328 group.add_argument('-w', '--wait_debugger', dest='wait_for_debugger',
329 action='store_true',
330 help='Wait for debugger.')
jbudorick911be58d2015-01-13 02:51:06331 group.add_argument('--apk-under-test', dest='apk_under_test',
332 help=('the name of the apk under test.'))
jama47ca85c2014-12-03 18:38:07333 group.add_argument('--test-apk', dest='test_apk', required=True,
334 help=('The name of the apk containing the tests '
335 '(without the .apk extension; '
336 'e.g. "ContentShellTest").'))
337 group.add_argument('--coverage-dir',
338 help=('Directory in which to place all generated '
339 'EMMA coverage files.'))
340 group.add_argument('--device-flags', dest='device_flags', default='',
341 help='The relative filepath to a file containing '
342 'command-line flags to set on the device')
jbudorick911be58d2015-01-13 02:51:06343 group.add_argument('--device-flags-file', default='',
344 help='The relative filepath to a file containing '
345 'command-line flags to set on the device')
jama47ca85c2014-12-03 18:38:07346 group.add_argument('--isolate_file_path',
347 '--isolate-file-path',
348 dest='isolate_file_path',
349 help='.isolate file path to override the default '
350 'path')
mlliud7f9fe92015-06-15 19:36:56351 group.add_argument('--delete-stale-data', dest='delete_stale_data',
352 action='store_true',
353 help='Delete stale test data on the device.')
jama47ca85c2014-12-03 18:38:07354
355 AddCommonOptions(parser)
356 AddDeviceOptions(parser)
rnephewe416dff2015-01-21 21:26:37357 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26358
359
jama47ca85c2014-12-03 18:38:07360def ProcessInstrumentationOptions(args):
[email protected]2a684222013-08-01 16:59:22361 """Processes options/arguments and populate |options| with defaults.
362
363 Args:
jama47ca85c2014-12-03 18:38:07364 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22365
366 Returns:
367 An InstrumentationOptions named tuple which contains all options relevant to
368 instrumentation tests.
369 """
[email protected]fbe29322013-07-09 09:03:26370
jama47ca85c2014-12-03 18:38:07371 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26372
jama47ca85c2014-12-03 18:38:07373 if not args.host_driven_root:
374 args.run_python_tests = False
[email protected]37ee0c792013-08-06 19:10:13375
jama47ca85c2014-12-03 18:38:07376 args.test_apk_path = os.path.join(
[email protected]2eea4872014-07-28 23:06:17377 constants.GetOutDirectory(),
378 constants.SDK_BUILD_APKS_DIR,
jama47ca85c2014-12-03 18:38:07379 '%s.apk' % args.test_apk)
380 args.test_apk_jar_path = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15381 constants.GetOutDirectory(),
382 constants.SDK_BUILD_TEST_JAVALIB_DIR,
jama47ca85c2014-12-03 18:38:07383 '%s.jar' % args.test_apk)
yusufo72c598c02015-07-16 23:40:20384 args.test_support_apk_path = '%sSupport%s' % (
385 os.path.splitext(args.test_apk_path))
[email protected]5e2f3f62014-06-23 12:31:46386
jama47ca85c2014-12-03 18:38:07387 args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path)
[email protected]5e2f3f62014-06-23 12:31:46388
jama47ca85c2014-12-03 18:38:07389 # TODO(jbudorick): Get rid of InstrumentationOptions.
[email protected]2a684222013-08-01 16:59:22390 return instrumentation_test_options.InstrumentationOptions(
jama47ca85c2014-12-03 18:38:07391 args.tool,
jama47ca85c2014-12-03 18:38:07392 args.annotations,
393 args.exclude_annotations,
394 args.test_filter,
395 args.test_data,
396 args.save_perf_json,
397 args.screenshot_failures,
398 args.wait_for_debugger,
399 args.coverage_dir,
400 args.test_apk,
401 args.test_apk_path,
402 args.test_apk_jar_path,
403 args.test_runner,
404 args.test_support_apk_path,
405 args.device_flags,
davileen98efad12015-01-05 19:48:21406 args.isolate_file_path,
mlliud7f9fe92015-06-15 19:36:56407 args.set_asserts,
408 args.delete_stale_data
[email protected]5e2f3f62014-06-23 12:31:46409 )
[email protected]2a684222013-08-01 16:59:22410
[email protected]fbe29322013-07-09 09:03:26411
jama47ca85c2014-12-03 18:38:07412def AddUIAutomatorTestOptions(parser):
413 """Adds UI Automator test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26414
jama47ca85c2014-12-03 18:38:07415 group = parser.add_argument_group('UIAutomator Test Options')
416 AddJavaTestOptions(group)
417 group.add_argument(
418 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
419 metavar='PACKAGE', help='Package under test.')
420 group.add_argument(
421 '--test-jar', dest='test_jar', required=True,
[email protected]fbe29322013-07-09 09:03:26422 help=('The name of the dexed jar containing the tests (without the '
423 '.dex.jar extension). Alternatively, this can be a full path '
424 'to the jar.'))
425
jama47ca85c2014-12-03 18:38:07426 AddCommonOptions(parser)
427 AddDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26428
429
jama47ca85c2014-12-03 18:38:07430def ProcessUIAutomatorOptions(args):
[email protected]2a684222013-08-01 16:59:22431 """Processes UIAutomator options/arguments.
432
433 Args:
jama47ca85c2014-12-03 18:38:07434 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22435
436 Returns:
437 A UIAutomatorOptions named tuple which contains all options relevant to
[email protected]3dbdfa42013-08-08 01:08:14438 uiautomator tests.
[email protected]2a684222013-08-01 16:59:22439 """
[email protected]fbe29322013-07-09 09:03:26440
jama47ca85c2014-12-03 18:38:07441 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26442
jama47ca85c2014-12-03 18:38:07443 if os.path.exists(args.test_jar):
[email protected]fbe29322013-07-09 09:03:26444 # The dexed JAR is fully qualified, assume the info JAR lives along side.
jama47ca85c2014-12-03 18:38:07445 args.uiautomator_jar = args.test_jar
[email protected]fbe29322013-07-09 09:03:26446 else:
jama47ca85c2014-12-03 18:38:07447 args.uiautomator_jar = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15448 constants.GetOutDirectory(),
449 constants.SDK_BUILD_JAVALIB_DIR,
jama47ca85c2014-12-03 18:38:07450 '%s.dex.jar' % args.test_jar)
451 args.uiautomator_info_jar = (
452 args.uiautomator_jar[:args.uiautomator_jar.find('.dex.jar')] +
[email protected]fbe29322013-07-09 09:03:26453 '_java.jar')
454
[email protected]2a684222013-08-01 16:59:22455 return uiautomator_test_options.UIAutomatorOptions(
jama47ca85c2014-12-03 18:38:07456 args.tool,
jama47ca85c2014-12-03 18:38:07457 args.annotations,
458 args.exclude_annotations,
459 args.test_filter,
460 args.test_data,
461 args.save_perf_json,
462 args.screenshot_failures,
463 args.uiautomator_jar,
464 args.uiautomator_info_jar,
davileen98efad12015-01-05 19:48:21465 args.package,
466 args.set_asserts)
[email protected]2a684222013-08-01 16:59:22467
[email protected]fbe29322013-07-09 09:03:26468
jama47ca85c2014-12-03 18:38:07469def AddJUnitTestOptions(parser):
470 """Adds junit test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07471
jama47ca85c2014-12-03 18:38:07472 group = parser.add_argument_group('JUnit Test Options')
473 group.add_argument(
474 '-s', '--test-suite', dest='test_suite', required=True,
jbudorick9a6b7b332014-09-20 00:01:07475 help=('JUnit test suite to run.'))
jama47ca85c2014-12-03 18:38:07476 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07477 '-f', '--test-filter', dest='test_filter',
478 help='Filters tests googletest-style.')
jama47ca85c2014-12-03 18:38:07479 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07480 '--package-filter', dest='package_filter',
481 help='Filters tests by package.')
jama47ca85c2014-12-03 18:38:07482 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07483 '--runner-filter', dest='runner_filter',
484 help='Filters tests by runner class. Must be fully qualified.')
jama47ca85c2014-12-03 18:38:07485 group.add_argument(
486 '--sdk-version', dest='sdk_version', type=int,
jbudorick9a6b7b332014-09-20 00:01:07487 help='The Android SDK version.')
jama47ca85c2014-12-03 18:38:07488 AddCommonOptions(parser)
jbudorick9a6b7b332014-09-20 00:01:07489
490
jama47ca85c2014-12-03 18:38:07491def AddMonkeyTestOptions(parser):
492 """Adds monkey test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07493
jama47ca85c2014-12-03 18:38:07494 group = parser.add_argument_group('Monkey Test Options')
495 group.add_argument(
496 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
497 metavar='PACKAGE', help='Package under test.')
498 group.add_argument(
499 '--event-count', default=10000, type=int,
500 help='Number of events to generate (default: %(default)s).')
501 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14502 '--category', default='',
[email protected]fb81b982013-08-09 00:07:12503 help='A list of allowed categories.')
jama47ca85c2014-12-03 18:38:07504 group.add_argument(
505 '--throttle', default=100, type=int,
506 help='Delay between events (ms) (default: %(default)s). ')
507 group.add_argument(
508 '--seed', type=int,
[email protected]3dbdfa42013-08-08 01:08:14509 help=('Seed value for pseudo-random generator. Same seed value generates '
510 'the same sequence of events. Seed is randomized by default.'))
jama47ca85c2014-12-03 18:38:07511 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14512 '--extra-args', default='',
jama47ca85c2014-12-03 18:38:07513 help=('String of other args to pass to the command verbatim.'))
[email protected]3dbdfa42013-08-08 01:08:14514
jama47ca85c2014-12-03 18:38:07515 AddCommonOptions(parser)
516 AddDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14517
jama47ca85c2014-12-03 18:38:07518def ProcessMonkeyTestOptions(args):
[email protected]3dbdfa42013-08-08 01:08:14519 """Processes all monkey test options.
520
521 Args:
jama47ca85c2014-12-03 18:38:07522 args: argparse.Namespace object.
[email protected]3dbdfa42013-08-08 01:08:14523
524 Returns:
525 A MonkeyOptions named tuple which contains all options relevant to
526 monkey tests.
527 """
jama47ca85c2014-12-03 18:38:07528 # TODO(jbudorick): Handle this directly in argparse with nargs='+'
529 category = args.category
[email protected]3dbdfa42013-08-08 01:08:14530 if category:
jama47ca85c2014-12-03 18:38:07531 category = args.category.split(',')
[email protected]3dbdfa42013-08-08 01:08:14532
jama47ca85c2014-12-03 18:38:07533 # TODO(jbudorick): Get rid of MonkeyOptions.
[email protected]3dbdfa42013-08-08 01:08:14534 return monkey_test_options.MonkeyOptions(
jama47ca85c2014-12-03 18:38:07535 args.verbose_count,
536 args.package,
537 args.event_count,
[email protected]3dbdfa42013-08-08 01:08:14538 category,
jama47ca85c2014-12-03 18:38:07539 args.throttle,
540 args.seed,
541 args.extra_args)
[email protected]3dbdfa42013-08-08 01:08:14542
rnephew5c499782014-12-12 19:08:55543def AddUirobotTestOptions(parser):
544 """Adds uirobot test options to |option_parser|."""
545 group = parser.add_argument_group('Uirobot Test Options')
546
rnephewefe44b42015-02-04 04:45:15547 group.add_argument('--app-under-test', required=True,
548 help='APK to run tests on.')
rnephew5c499782014-12-12 19:08:55549 group.add_argument(
550 '--minutes', default=5, type=int,
jbudorick676b1202015-02-06 22:02:27551 help='Number of minutes to run uirobot test [default: %(default)s].')
rnephew5c499782014-12-12 19:08:55552
553 AddCommonOptions(parser)
554 AddDeviceOptions(parser)
555 AddRemoteDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14556
jama47ca85c2014-12-03 18:38:07557def AddPerfTestOptions(parser):
558 """Adds perf test options to |parser|."""
[email protected]ec3170b2013-08-14 14:39:47559
jama47ca85c2014-12-03 18:38:07560 group = parser.add_argument_group('Perf Test Options')
[email protected]ec3170b2013-08-14 14:39:47561
jama47ca85c2014-12-03 18:38:07562 class SingleStepAction(argparse.Action):
563 def __call__(self, parser, namespace, values, option_string=None):
564 if values and not namespace.single_step:
565 parser.error('single step command provided, '
566 'but --single-step not specified.')
567 elif namespace.single_step and not values:
568 parser.error('--single-step specified, '
569 'but no single step command provided.')
570 setattr(namespace, self.dest, values)
571
572 step_group = group.add_mutually_exclusive_group(required=True)
573 # TODO(jbudorick): Revise --single-step to use argparse.REMAINDER.
574 # This requires removing "--" from client calls.
575 step_group.add_argument(
576 '--single-step', action='store_true',
[email protected]def4bce2013-11-12 12:59:52577 help='Execute the given command with retries, but only print the result '
578 'for the "most successful" round.')
jama47ca85c2014-12-03 18:38:07579 step_group.add_argument(
[email protected]181a5c92013-09-06 17:11:46580 '--steps',
[email protected]def4bce2013-11-12 12:59:52581 help='JSON file containing the list of commands to run.')
jama47ca85c2014-12-03 18:38:07582 step_group.add_argument(
583 '--print-step',
584 help='The name of a previously executed perf step to print.')
585
586 group.add_argument(
peterbd4e73d2014-12-03 15:47:36587 '--output-json-list',
588 help='Write a simple list of names from --steps into the given file.')
jama47ca85c2014-12-03 18:38:07589 group.add_argument(
peterbd4e73d2014-12-03 15:47:36590 '--collect-chartjson-data',
591 action='store_true',
592 help='Cache the chartjson output from each step for later use.')
jama47ca85c2014-12-03 18:38:07593 group.add_argument(
peterbd4e73d2014-12-03 15:47:36594 '--output-chartjson-data',
595 default='',
596 help='Write out chartjson into the given file.')
jama47ca85c2014-12-03 18:38:07597 group.add_argument(
598 '--flaky-steps',
599 help=('A JSON file containing steps that are flaky '
600 'and will have its exit code ignored.'))
601 group.add_argument(
[email protected]181a5c92013-09-06 17:11:46602 '--no-timeout', action='store_true',
603 help=('Do not impose a timeout. Each perf step is responsible for '
604 'implementing the timeout logic.'))
jama47ca85c2014-12-03 18:38:07605 group.add_argument(
[email protected]650487c2013-09-30 11:40:49606 '-f', '--test-filter',
607 help=('Test filter (will match against the names listed in --steps).'))
jama47ca85c2014-12-03 18:38:07608 group.add_argument(
609 '--dry-run', action='store_true',
[email protected]650487c2013-09-30 11:40:49610 help='Just print the steps without executing.')
jbudorick5cfff872015-07-01 18:46:13611 # Uses 0.1 degrees C because that's what Android does.
612 group.add_argument(
613 '--max-battery-temp', type=int,
614 help='Only start tests when the battery is at or below the given '
615 'temperature (0.1 C)')
jama47ca85c2014-12-03 18:38:07616 group.add_argument('single_step_command', nargs='*', action=SingleStepAction,
617 help='If --single-step is specified, the command to run.')
rnephewdde05da82015-07-09 20:31:01618 group.add_argument('--min-battery-level', type=int,
619 help='Only starts tests when the battery is charged above '
620 'given level.')
jama47ca85c2014-12-03 18:38:07621 AddCommonOptions(parser)
622 AddDeviceOptions(parser)
[email protected]ec3170b2013-08-14 14:39:47623
624
jama47ca85c2014-12-03 18:38:07625def ProcessPerfTestOptions(args):
[email protected]ec3170b2013-08-14 14:39:47626 """Processes all perf test options.
627
628 Args:
jama47ca85c2014-12-03 18:38:07629 args: argparse.Namespace object.
[email protected]ec3170b2013-08-14 14:39:47630
631 Returns:
632 A PerfOptions named tuple which contains all options relevant to
633 perf tests.
634 """
jama47ca85c2014-12-03 18:38:07635 # TODO(jbudorick): Move single_step handling down into the perf tests.
636 if args.single_step:
637 args.single_step = ' '.join(args.single_step_command)
638 # TODO(jbudorick): Get rid of PerfOptions.
[email protected]ec3170b2013-08-14 14:39:47639 return perf_test_options.PerfOptions(
jama47ca85c2014-12-03 18:38:07640 args.steps, args.flaky_steps, args.output_json_list,
641 args.print_step, args.no_timeout, args.test_filter,
642 args.dry_run, args.single_step, args.collect_chartjson_data,
rnephewdde05da82015-07-09 20:31:01643 args.output_chartjson_data, args.max_battery_temp, args.min_battery_level)
[email protected]ec3170b2013-08-14 14:39:47644
645
jama47ca85c2014-12-03 18:38:07646def AddPythonTestOptions(parser):
647 group = parser.add_argument_group('Python Test Options')
648 group.add_argument(
649 '-s', '--suite', dest='suite_name', metavar='SUITE_NAME',
650 choices=constants.PYTHON_UNIT_TEST_SUITES.keys(),
651 help='Name of the test suite to run.')
652 AddCommonOptions(parser)
jbudorick256fd532014-10-24 01:50:13653
654
jama47ca85c2014-12-03 18:38:07655def _RunGTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37656 """Subcommand of RunTestsCommands which runs gtests."""
[email protected]6bc1bda22013-07-19 22:08:37657 exit_code = 0
jama47ca85c2014-12-03 18:38:07658 for suite_name in args.suite_name:
659 # TODO(jbudorick): Either deprecate multi-suite or move its handling down
660 # into the gtest code.
[email protected]2a684222013-08-01 16:59:22661 gtest_options = gtest_test_options.GTestOptions(
jama47ca85c2014-12-03 18:38:07662 args.tool,
jama47ca85c2014-12-03 18:38:07663 args.test_filter,
664 args.run_disabled,
665 args.test_arguments,
666 args.timeout,
667 args.isolate_file_path,
jbudorick5ee45892015-06-10 18:46:22668 suite_name,
669 args.app_data_files,
mlliud7f9fe92015-06-15 19:36:56670 args.app_data_file_dir,
671 args.delete_stale_data)
[email protected]f7148dd42013-08-20 14:24:57672 runner_factory, tests = gtest_setup.Setup(gtest_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37673
674 results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57675 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07676 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37677
678 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
679 exit_code = test_exit_code
680
681 report_results.LogFull(
682 results=results,
683 test_type='Unit test',
684 test_package=suite_name,
jama47ca85c2014-12-03 18:38:07685 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37686
jama47ca85c2014-12-03 18:38:07687 if args.json_results_file:
688 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54689
[email protected]6bc1bda22013-07-19 22:08:37690 return exit_code
691
692
jama47ca85c2014-12-03 18:38:07693def _RunLinkerTests(args, devices):
[email protected]6b6abac6d2013-10-03 11:56:38694 """Subcommand of RunTestsCommands which runs linker tests."""
jama47ca85c2014-12-03 18:38:07695 runner_factory, tests = linker_setup.Setup(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38696
697 results, exit_code = test_dispatcher.RunTests(
698 tests, runner_factory, devices, shard=True, test_timeout=60,
jama47ca85c2014-12-03 18:38:07699 num_retries=args.num_retries)
[email protected]6b6abac6d2013-10-03 11:56:38700
701 report_results.LogFull(
702 results=results,
703 test_type='Linker test',
[email protected]93c9f9b2014-02-10 16:19:22704 test_package='ChromiumLinkerTest')
[email protected]6b6abac6d2013-10-03 11:56:38705
jama47ca85c2014-12-03 18:38:07706 if args.json_results_file:
707 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54708
[email protected]6b6abac6d2013-10-03 11:56:38709 return exit_code
710
711
jama47ca85c2014-12-03 18:38:07712def _RunInstrumentationTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37713 """Subcommand of RunTestsCommands which runs instrumentation tests."""
jbudorick58b4d362015-09-08 16:44:59714 logging.info('_RunInstrumentationTests(%s, %s)', str(args), str(devices))
[email protected]6bc1bda22013-07-19 22:08:37715
jama47ca85c2014-12-03 18:38:07716 instrumentation_options = ProcessInstrumentationOptions(args)
717
718 if len(devices) > 1 and args.wait_for_debugger:
[email protected]f7148dd42013-08-20 14:24:57719 logging.warning('Debugger can not be sharded, using first available device')
720 devices = devices[:1]
721
[email protected]6bc1bda22013-07-19 22:08:37722 results = base_test_result.TestRunResults()
723 exit_code = 0
724
jama47ca85c2014-12-03 18:38:07725 if args.run_java_tests:
mikecase526d68e2014-11-19 20:02:05726 runner_factory, tests = instrumentation_setup.Setup(
727 instrumentation_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37728
729 test_results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57730 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07731 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37732
733 results.AddTestRunResults(test_results)
734
jama47ca85c2014-12-03 18:38:07735 if args.run_python_tests:
[email protected]37ee0c792013-08-06 19:10:13736 runner_factory, tests = host_driven_setup.InstrumentationSetup(
jama47ca85c2014-12-03 18:38:07737 args.host_driven_root, args.official_build,
[email protected]37ee0c792013-08-06 19:10:13738 instrumentation_options)
739
[email protected]34020022013-08-06 23:35:34740 if tests:
741 test_results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57742 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07743 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37744
[email protected]34020022013-08-06 23:35:34745 results.AddTestRunResults(test_results)
[email protected]6bc1bda22013-07-19 22:08:37746
[email protected]34020022013-08-06 23:35:34747 # Only allow exit code escalation
748 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
749 exit_code = test_exit_code
[email protected]6bc1bda22013-07-19 22:08:37750
jama47ca85c2014-12-03 18:38:07751 if args.device_flags:
752 args.device_flags = os.path.join(constants.DIR_SOURCE_ROOT,
753 args.device_flags)
[email protected]4f777ca2014-08-08 01:45:59754
[email protected]6bc1bda22013-07-19 22:08:37755 report_results.LogFull(
756 results=results,
757 test_type='Instrumentation',
jama47ca85c2014-12-03 18:38:07758 test_package=os.path.basename(args.test_apk),
759 annotation=args.annotations,
760 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37761
jama47ca85c2014-12-03 18:38:07762 if args.json_results_file:
763 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54764
[email protected]6bc1bda22013-07-19 22:08:37765 return exit_code
766
767
jama47ca85c2014-12-03 18:38:07768def _RunUIAutomatorTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37769 """Subcommand of RunTestsCommands which runs uiautomator tests."""
jama47ca85c2014-12-03 18:38:07770 uiautomator_options = ProcessUIAutomatorOptions(args)
[email protected]6bc1bda22013-07-19 22:08:37771
jbudorickdde688fb2015-08-27 03:00:17772 runner_factory, tests = uiautomator_setup.Setup(uiautomator_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37773
[email protected]37ee0c792013-08-06 19:10:13774 results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57775 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07776 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37777
778 report_results.LogFull(
779 results=results,
780 test_type='UIAutomator',
jama47ca85c2014-12-03 18:38:07781 test_package=os.path.basename(args.test_jar),
782 annotation=args.annotations,
783 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37784
jama47ca85c2014-12-03 18:38:07785 if args.json_results_file:
786 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54787
[email protected]6bc1bda22013-07-19 22:08:37788 return exit_code
789
790
jama47ca85c2014-12-03 18:38:07791def _RunJUnitTests(args):
jbudorick9a6b7b332014-09-20 00:01:07792 """Subcommand of RunTestsCommand which runs junit tests."""
jama47ca85c2014-12-03 18:38:07793 runner_factory, tests = junit_setup.Setup(args)
mikecasec638a072015-04-01 16:35:35794 results, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
795
796 report_results.LogFull(
797 results=results,
798 test_type='JUnit',
799 test_package=args.test_suite)
800
mikecase572401b2015-04-09 02:28:57801 if args.json_results_file:
802 json_results.GenerateJsonResultsFile(results, args.json_results_file)
803
jbudorick9a6b7b332014-09-20 00:01:07804 return exit_code
805
806
jama47ca85c2014-12-03 18:38:07807def _RunMonkeyTests(args, devices):
[email protected]3dbdfa42013-08-08 01:08:14808 """Subcommand of RunTestsCommands which runs monkey tests."""
jama47ca85c2014-12-03 18:38:07809 monkey_options = ProcessMonkeyTestOptions(args)
[email protected]3dbdfa42013-08-08 01:08:14810
811 runner_factory, tests = monkey_setup.Setup(monkey_options)
812
813 results, exit_code = test_dispatcher.RunTests(
[email protected]181a5c92013-09-06 17:11:46814 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07815 num_retries=args.num_retries)
[email protected]3dbdfa42013-08-08 01:08:14816
817 report_results.LogFull(
818 results=results,
819 test_type='Monkey',
[email protected]14b3b1202013-08-15 22:25:28820 test_package='Monkey')
[email protected]3dbdfa42013-08-08 01:08:14821
jama47ca85c2014-12-03 18:38:07822 if args.json_results_file:
823 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54824
[email protected]3dbdfa42013-08-08 01:08:14825 return exit_code
826
827
jbudorickdde688fb2015-08-27 03:00:17828def _RunPerfTests(args, active_devices):
[email protected]ec3170b2013-08-14 14:39:47829 """Subcommand of RunTestsCommands which runs perf tests."""
jama47ca85c2014-12-03 18:38:07830 perf_options = ProcessPerfTestOptions(args)
[email protected]61487ed2014-06-09 12:33:56831
832 # Just save a simple json with a list of test names.
833 if perf_options.output_json_list:
834 return perf_test_runner.OutputJsonList(
835 perf_options.steps, perf_options.output_json_list)
836
[email protected]ad32f312013-11-13 04:03:29837 # Just print the results from a single previously executed step.
[email protected]ec3170b2013-08-14 14:39:47838 if perf_options.print_step:
simonhatch9b9256d2015-01-07 18:03:42839 return perf_test_runner.PrintTestOutput(
840 perf_options.print_step, perf_options.output_chartjson_data)
[email protected]ec3170b2013-08-14 14:39:47841
jbudorickdde688fb2015-08-27 03:00:17842 runner_factory, tests, devices = perf_setup.Setup(
843 perf_options, active_devices)
[email protected]ec3170b2013-08-14 14:39:47844
[email protected]a72f0752014-06-03 23:52:34845 # shard=False means that each device will get the full list of tests
846 # and then each one will decide their own affinity.
847 # shard=True means each device will pop the next test available from a queue,
848 # which increases throughput but have no affinity.
[email protected]86184c7b2013-08-15 15:06:57849 results, _ = test_dispatcher.RunTests(
[email protected]a72f0752014-06-03 23:52:34850 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07851 num_retries=args.num_retries)
[email protected]ec3170b2013-08-14 14:39:47852
853 report_results.LogFull(
854 results=results,
855 test_type='Perf',
[email protected]865a47a2013-08-16 14:01:12856 test_package='Perf')
[email protected]def4bce2013-11-12 12:59:52857
jama47ca85c2014-12-03 18:38:07858 if args.json_results_file:
859 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54860
[email protected]def4bce2013-11-12 12:59:52861 if perf_options.single_step:
862 return perf_test_runner.PrintTestOutput('single_step')
863
[email protected]11ce8452014-02-17 10:55:03864 perf_test_runner.PrintSummary(tests)
865
[email protected]86184c7b2013-08-15 15:06:57866 # Always return 0 on the sharding stage. Individual tests exit_code
867 # will be returned on the print_step stage.
868 return 0
[email protected]ec3170b2013-08-14 14:39:47869
[email protected]3dbdfa42013-08-08 01:08:14870
jama47ca85c2014-12-03 18:38:07871def _RunPythonTests(args):
jbudorick256fd532014-10-24 01:50:13872 """Subcommand of RunTestsCommand which runs python unit tests."""
jama47ca85c2014-12-03 18:38:07873 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name]
jbudorick256fd532014-10-24 01:50:13874 suite_path = suite_vars['path']
875 suite_test_modules = suite_vars['test_modules']
876
877 sys.path = [suite_path] + sys.path
878 try:
879 suite = unittest.TestSuite()
880 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
881 for m in suite_test_modules)
jama47ca85c2014-12-03 18:38:07882 runner = unittest.TextTestRunner(verbosity=1+args.verbose_count)
jbudorick256fd532014-10-24 01:50:13883 return 0 if runner.run(suite).wasSuccessful() else 1
884 finally:
885 sys.path = sys.path[1:]
886
887
jbudorickdde688fb2015-08-27 03:00:17888def _GetAttachedDevices(blacklist_file, test_device):
[email protected]f7148dd42013-08-20 14:24:57889 """Get all attached devices.
890
891 Args:
892 test_device: Name of a specific device to use.
893
894 Returns:
895 A list of attached devices.
896 """
jbudoricka583ba32015-09-11 17:23:19897 blacklist = (device_blacklist.Blacklist(blacklist_file)
898 if blacklist_file
899 else None)
jbudorickdde688fb2015-08-27 03:00:17900
jbudorickdde688fb2015-08-27 03:00:17901 attached_devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
aberent6a02a6182015-04-29 11:07:55902 if test_device:
jbudorick4551d0dc2015-04-29 16:07:06903 test_device = [d for d in attached_devices if d == test_device]
904 if not test_device:
905 raise device_errors.DeviceUnreachableError(
906 'Did not find device %s among attached device. Attached devices: %s'
907 % (test_device, ', '.join(attached_devices)))
908 return test_device
aberent6a02a6182015-04-29 11:07:55909
jbudorick4551d0dc2015-04-29 16:07:06910 else:
911 if not attached_devices:
912 raise device_errors.NoDevicesError()
913 return sorted(attached_devices)
[email protected]f7148dd42013-08-20 14:24:57914
915
jbudorick58b4d362015-09-08 16:44:59916def RunTestsCommand(args, parser): # pylint: disable=too-many-return-statements
[email protected]fbe29322013-07-09 09:03:26917 """Checks test type and dispatches to the appropriate function.
918
919 Args:
jama47ca85c2014-12-03 18:38:07920 args: argparse.Namespace object.
921 parser: argparse.ArgumentParser object.
[email protected]fbe29322013-07-09 09:03:26922
923 Returns:
924 Integer indicated exit code.
[email protected]b3873892013-07-10 04:57:10925
926 Raises:
927 Exception: Unknown command name passed in, or an exception from an
928 individual test runner.
[email protected]fbe29322013-07-09 09:03:26929 """
jama47ca85c2014-12-03 18:38:07930 command = args.command
[email protected]fbe29322013-07-09 09:03:26931
jama47ca85c2014-12-03 18:38:07932 ProcessCommonOptions(args)
[email protected]d82f0252013-07-12 23:22:57933
jama47ca85c2014-12-03 18:38:07934 if args.enable_platform_mode:
rnephew5c499782014-12-12 19:08:55935 return RunTestsInPlatformMode(args, parser)
jbudorick66dc3722014-11-06 21:33:51936
937 if command in constants.LOCAL_MACHINE_TESTS:
jbudorick256fd532014-10-24 01:50:13938 devices = []
939 else:
jbudorickdde688fb2015-08-27 03:00:17940 devices = _GetAttachedDevices(args.blacklist_file, args.test_device)
[email protected]f7148dd42013-08-20 14:24:57941
[email protected]c0662e092013-11-12 11:51:25942 forwarder.Forwarder.RemoveHostLog()
[email protected]6b11583b2013-11-21 16:18:40943 if not ports.ResetTestServerPortAllocation():
944 raise Exception('Failed to reset test server port.')
[email protected]c0662e092013-11-12 11:51:25945
[email protected]fbe29322013-07-09 09:03:26946 if command == 'gtest':
jbudorick590a3d72015-06-12 23:53:31947 if args.suite_name[0] in gtest_test_instance.BROWSER_TEST_SUITES:
948 return RunTestsInPlatformMode(args, parser)
jama47ca85c2014-12-03 18:38:07949 return _RunGTests(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38950 elif command == 'linker':
jama47ca85c2014-12-03 18:38:07951 return _RunLinkerTests(args, devices)
[email protected]fbe29322013-07-09 09:03:26952 elif command == 'instrumentation':
jama47ca85c2014-12-03 18:38:07953 return _RunInstrumentationTests(args, devices)
[email protected]fbe29322013-07-09 09:03:26954 elif command == 'uiautomator':
jama47ca85c2014-12-03 18:38:07955 return _RunUIAutomatorTests(args, devices)
jbudorick9a6b7b332014-09-20 00:01:07956 elif command == 'junit':
jama47ca85c2014-12-03 18:38:07957 return _RunJUnitTests(args)
[email protected]3dbdfa42013-08-08 01:08:14958 elif command == 'monkey':
jama47ca85c2014-12-03 18:38:07959 return _RunMonkeyTests(args, devices)
[email protected]ec3170b2013-08-14 14:39:47960 elif command == 'perf':
jbudorickdde688fb2015-08-27 03:00:17961 return _RunPerfTests(args, devices)
jbudorick256fd532014-10-24 01:50:13962 elif command == 'python':
jama47ca85c2014-12-03 18:38:07963 return _RunPythonTests(args)
[email protected]fbe29322013-07-09 09:03:26964 else:
[email protected]6bc1bda22013-07-19 22:08:37965 raise Exception('Unknown test type.')
[email protected]fbe29322013-07-09 09:03:26966
[email protected]fbe29322013-07-09 09:03:26967
jbudorick66dc3722014-11-06 21:33:51968_SUPPORTED_IN_PLATFORM_MODE = [
969 # TODO(jbudorick): Add support for more test types.
jbudorick911be58d2015-01-13 02:51:06970 'gtest',
971 'instrumentation',
972 'uirobot',
jbudorick66dc3722014-11-06 21:33:51973]
974
975
jama47ca85c2014-12-03 18:38:07976def RunTestsInPlatformMode(args, parser):
jbudorick66dc3722014-11-06 21:33:51977
jama47ca85c2014-12-03 18:38:07978 if args.command not in _SUPPORTED_IN_PLATFORM_MODE:
979 parser.error('%s is not yet supported in platform mode' % args.command)
jbudorick66dc3722014-11-06 21:33:51980
jama47ca85c2014-12-03 18:38:07981 with environment_factory.CreateEnvironment(args, parser.error) as env:
982 with test_instance_factory.CreateTestInstance(args, parser.error) as test:
jbudorick66dc3722014-11-06 21:33:51983 with test_run_factory.CreateTestRun(
jama47ca85c2014-12-03 18:38:07984 args, env, test, parser.error) as test_run:
jbudorick66dc3722014-11-06 21:33:51985 results = test_run.RunTests()
986
jbudorick911be58d2015-01-13 02:51:06987 if args.environment == 'remote_device' and args.trigger:
rnephew5c499782014-12-12 19:08:55988 return 0 # Not returning results, only triggering.
989
jbudorick66dc3722014-11-06 21:33:51990 report_results.LogFull(
991 results=results,
992 test_type=test.TestType(),
993 test_package=test_run.TestPackage(),
jbudorickf9543672014-12-08 22:36:33994 annotation=getattr(args, 'annotations', None),
995 flakiness_server=getattr(args, 'flakiness_dashboard_server', None))
jbudorick66dc3722014-11-06 21:33:51996
jama47ca85c2014-12-03 18:38:07997 if args.json_results_file:
jbudorickb8c42072014-12-01 18:07:54998 json_results.GenerateJsonResultsFile(
jama47ca85c2014-12-03 18:38:07999 results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:541000
mikecasee74051022015-02-26 23:08:221001 return 0 if results.DidRunPass() else constants.ERROR_EXIT_CODE
jbudorick66dc3722014-11-06 21:33:511002
1003
jama47ca85c2014-12-03 18:38:071004CommandConfigTuple = collections.namedtuple(
1005 'CommandConfigTuple',
1006 ['add_options_func', 'help_txt'])
[email protected]fbe29322013-07-09 09:03:261007VALID_COMMANDS = {
jama47ca85c2014-12-03 18:38:071008 'gtest': CommandConfigTuple(
1009 AddGTestOptions,
1010 'googletest-based C++ tests'),
1011 'instrumentation': CommandConfigTuple(
1012 AddInstrumentationTestOptions,
1013 'InstrumentationTestCase-based Java tests'),
1014 'uiautomator': CommandConfigTuple(
1015 AddUIAutomatorTestOptions,
1016 "Tests that run via Android's uiautomator command"),
1017 'junit': CommandConfigTuple(
1018 AddJUnitTestOptions,
1019 'JUnit4-based Java tests'),
1020 'monkey': CommandConfigTuple(
1021 AddMonkeyTestOptions,
1022 "Tests based on Android's monkey"),
1023 'perf': CommandConfigTuple(
1024 AddPerfTestOptions,
1025 'Performance tests'),
1026 'python': CommandConfigTuple(
1027 AddPythonTestOptions,
1028 'Python tests based on unittest.TestCase'),
1029 'linker': CommandConfigTuple(
1030 AddLinkerTestOptions,
1031 'Linker tests'),
rnephew5c499782014-12-12 19:08:551032 'uirobot': CommandConfigTuple(
1033 AddUirobotTestOptions,
1034 'Uirobot test'),
jama47ca85c2014-12-03 18:38:071035}
[email protected]fbe29322013-07-09 09:03:261036
1037
[email protected]7c53a602014-03-24 16:21:441038def DumpThreadStacks(_signal, _frame):
[email protected]71aec4b2013-11-20 00:35:241039 for thread in threading.enumerate():
1040 reraiser_thread.LogThreadStack(thread)
[email protected]83bb8152013-11-19 15:02:211041
1042
[email protected]7c53a602014-03-24 16:21:441043def main():
[email protected]83bb8152013-11-19 15:02:211044 signal.signal(signal.SIGUSR1, DumpThreadStacks)
jama47ca85c2014-12-03 18:38:071045
1046 parser = argparse.ArgumentParser()
1047 command_parsers = parser.add_subparsers(title='test types',
1048 dest='command')
1049
1050 for test_type, config in sorted(VALID_COMMANDS.iteritems(),
1051 key=lambda x: x[0]):
1052 subparser = command_parsers.add_parser(
1053 test_type, usage='%(prog)s [options]', help=config.help_txt)
1054 config.add_options_func(subparser)
1055
1056 args = parser.parse_args()
mikecasee74051022015-02-26 23:08:221057
1058 try:
1059 return RunTestsCommand(args, parser)
1060 except base_error.BaseError as e:
1061 logging.exception('Error occurred.')
1062 if e.is_infra_error:
1063 return constants.INFRA_EXIT_CODE
mswecce6732015-06-06 00:31:331064 return constants.ERROR_EXIT_CODE
mikecasee74051022015-02-26 23:08:221065 except: # pylint: disable=W0702
1066 logging.exception('Unrecognized error occurred.')
1067 return constants.ERROR_EXIT_CODE
[email protected]fbe29322013-07-09 09:03:261068
[email protected]fbe29322013-07-09 09:03:261069
1070if __name__ == '__main__':
[email protected]7c53a602014-03-24 16:21:441071 sys.exit(main())