blob: c54ed28d324054eae3c5aee72aa1442d80bf1f36 [file] [log] [blame]
[email protected]fbe29322013-07-09 09:03:261#!/usr/bin/env python
2#
3# Copyright 2013 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
[email protected]181a5c92013-09-06 17:11:467"""Runs all types of tests from one unified interface."""
[email protected]fbe29322013-07-09 09:03:268
jama47ca85c2014-12-03 18:38:079import argparse
[email protected]fbe29322013-07-09 09:03:2610import collections
[email protected]f7148dd42013-08-20 14:24:5711import logging
[email protected]fbe29322013-07-09 09:03:2612import os
[email protected]6bc1bda22013-07-19 22:08:3713import shutil
[email protected]83bb8152013-11-19 15:02:2114import signal
[email protected]fbe29322013-07-09 09:03:2615import sys
[email protected]83bb8152013-11-19 15:02:2116import threading
jbudorick256fd532014-10-24 01:50:1317import unittest
[email protected]fbe29322013-07-09 09:03:2618
[email protected]f7148dd42013-08-20 14:24:5719from pylib import android_commands
[email protected]fbe29322013-07-09 09:03:2620from pylib import constants
[email protected]c0662e092013-11-12 11:51:2521from pylib import forwarder
[email protected]fbe29322013-07-09 09:03:2622from pylib import ports
23from pylib.base import base_test_result
jbudorick66dc3722014-11-06 21:33:5124from pylib.base import environment_factory
[email protected]6bc1bda22013-07-19 22:08:3725from pylib.base import test_dispatcher
jbudorick66dc3722014-11-06 21:33:5126from pylib.base import test_instance_factory
27from pylib.base import test_run_factory
[email protected]6bc1bda22013-07-19 22:08:3728from pylib.gtest import gtest_config
[email protected]2a684222013-08-01 16:59:2229from pylib.gtest import setup as gtest_setup
30from pylib.gtest import test_options as gtest_test_options
[email protected]6b6abac6d2013-10-03 11:56:3831from pylib.linker import setup as linker_setup
[email protected]37ee0c792013-08-06 19:10:1332from pylib.host_driven import setup as host_driven_setup
[email protected]6bc1bda22013-07-19 22:08:3733from pylib.instrumentation import setup as instrumentation_setup
[email protected]2a684222013-08-01 16:59:2234from pylib.instrumentation import test_options as instrumentation_test_options
jbudorick9a6b7b332014-09-20 00:01:0735from pylib.junit import setup as junit_setup
36from pylib.junit import test_dispatcher as junit_dispatcher
[email protected]3dbdfa42013-08-08 01:08:1437from pylib.monkey import setup as monkey_setup
38from pylib.monkey import test_options as monkey_test_options
[email protected]ec3170b2013-08-14 14:39:4739from pylib.perf import setup as perf_setup
40from pylib.perf import test_options as perf_test_options
41from pylib.perf import test_runner as perf_test_runner
jbudorickb8c42072014-12-01 18:07:5442from pylib.results import json_results
43from pylib.results import report_results
[email protected]6bc1bda22013-07-19 22:08:3744from pylib.uiautomator import setup as uiautomator_setup
[email protected]2a684222013-08-01 16:59:2245from pylib.uiautomator import test_options as uiautomator_test_options
[email protected]2eea4872014-07-28 23:06:1746from pylib.utils import apk_helper
mikecasee74051022015-02-26 23:08:2247from pylib.utils import base_error
[email protected]71aec4b2013-11-20 00:35:2448from pylib.utils import reraiser_thread
[email protected]6bc1bda22013-07-19 22:08:3749from pylib.utils import run_tests_helper
[email protected]fbe29322013-07-09 09:03:2650
51
jama47ca85c2014-12-03 18:38:0752def AddCommonOptions(parser):
53 """Adds all common options to |parser|."""
[email protected]fbe29322013-07-09 09:03:2654
jama47ca85c2014-12-03 18:38:0755 group = parser.add_argument_group('Common Options')
56
[email protected]dfffbcbc2013-09-17 22:06:0157 default_build_type = os.environ.get('BUILDTYPE', 'Debug')
jama47ca85c2014-12-03 18:38:0758
59 debug_or_release_group = group.add_mutually_exclusive_group()
60 debug_or_release_group.add_argument(
61 '--debug', action='store_const', const='Debug', dest='build_type',
62 default=default_build_type,
63 help=('If set, run test suites under out/Debug. '
64 'Default is env var BUILDTYPE or Debug.'))
65 debug_or_release_group.add_argument(
66 '--release', action='store_const', const='Release', dest='build_type',
67 help=('If set, run test suites under out/Release. '
68 'Default is env var BUILDTYPE or Debug.'))
69
70 group.add_argument('--build-directory', dest='build_directory',
71 help=('Path to the directory in which build files are'
72 ' located (should not include build type)'))
73 group.add_argument('--output-directory', dest='output_directory',
74 help=('Path to the directory in which build files are'
75 ' located (must include build type). This will take'
76 ' precedence over --debug, --release and'
77 ' --build-directory'))
78 group.add_argument('--num_retries', dest='num_retries', type=int, default=2,
79 help=('Number of retries for a test before '
80 'giving up (default: %(default)s).'))
81 group.add_argument('-v',
82 '--verbose',
83 dest='verbose_count',
84 default=0,
85 action='count',
86 help='Verbose level (multiple times for more)')
87 group.add_argument('--flakiness-dashboard-server',
88 dest='flakiness_dashboard_server',
89 help=('Address of the server that is hosting the '
90 'Chrome for Android flakiness dashboard.'))
91 group.add_argument('--enable-platform-mode', action='store_true',
92 help=('Run the test scripts in platform mode, which '
93 'conceptually separates the test runner from the '
94 '"device" (local or remote, real or emulated) on '
95 'which the tests are running. [experimental]'))
96 group.add_argument('-e', '--environment', default='local',
97 choices=constants.VALID_ENVIRONMENTS,
98 help='Test environment to run in (default: %(default)s).')
99 group.add_argument('--adb-path',
100 help=('Specify the absolute path of the adb binary that '
101 'should be used.'))
102 group.add_argument('--json-results-file', dest='json_results_file',
103 help='If set, will dump results in JSON form '
104 'to specified file.')
[email protected]fbe29322013-07-09 09:03:26105
jama47ca85c2014-12-03 18:38:07106def ProcessCommonOptions(args):
[email protected]fbe29322013-07-09 09:03:26107 """Processes and handles all common options."""
jama47ca85c2014-12-03 18:38:07108 run_tests_helper.SetLogLevel(args.verbose_count)
109 constants.SetBuildType(args.build_type)
110 if args.build_directory:
111 constants.SetBuildDirectory(args.build_directory)
112 if args.output_directory:
113 constants.SetOutputDirectort(args.output_directory)
114 if args.adb_path:
115 constants.SetAdbPath(args.adb_path)
mikecase48e16bf2014-11-19 22:46:45116 # Some things such as Forwarder require ADB to be in the environment path.
117 adb_dir = os.path.dirname(constants.GetAdbPath())
118 if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep):
119 os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH']
[email protected]fbe29322013-07-09 09:03:26120
121
rnephew5c499782014-12-12 19:08:55122def AddRemoteDeviceOptions(parser):
123 group = parser.add_argument_group('Remote Device Options')
124
rnephewefe44b42015-02-04 04:45:15125 group.add_argument('--trigger',
jbudoricke6c560152015-01-13 23:49:28126 help=('Only triggers the test if set. Stores test_run_id '
127 'in given file path. '))
rnephewefe44b42015-02-04 04:45:15128 group.add_argument('--collect',
jbudoricke6c560152015-01-13 23:49:28129 help=('Only collects the test results if set. '
130 'Gets test_run_id from given file path.'))
rnephewefe44b42015-02-04 04:45:15131 group.add_argument('--remote-device', action='append',
jbudoricke6c560152015-01-13 23:49:28132 help='Device type to run test on.')
rnephewefe44b42015-02-04 04:45:15133 group.add_argument('--results-path',
jbudoricke6c560152015-01-13 23:49:28134 help='File path to download results to.')
rnephew7f1e2052014-12-12 23:00:11135 group.add_argument('--api-protocol',
jbudoricke6c560152015-01-13 23:49:28136 help='HTTP protocol to use. (http or https)')
rnephewefe44b42015-02-04 04:45:15137 group.add_argument('--api-address',
138 help='Address to send HTTP requests.')
139 group.add_argument('--api-port',
140 help='Port to send HTTP requests to.')
141 group.add_argument('--runner-type',
jbudoricke6c560152015-01-13 23:49:28142 help='Type of test to run as.')
rnephewefe44b42015-02-04 04:45:15143 group.add_argument('--runner-package',
144 help='Package name of test.')
145 group.add_argument('--device-type',
rnephewa46fc562015-01-23 16:00:14146 choices=constants.VALID_DEVICE_TYPES,
147 help=('Type of device to run on. iOS or android'))
rnephewefe44b42015-02-04 04:45:15148 group.add_argument('--device-oem', action='append',
149 help='Device OEM to run on.')
150 group.add_argument('--remote-device-file',
151 help=('File with JSON to select remote device. '
152 'Overrides all other flags.'))
rnephewc9ae8f52015-02-13 03:02:55153 group.add_argument('--remote-device-timeout', type=int,
154 help='Times to retry finding remote device')
mikecase520cbbb52015-04-21 18:51:18155 group.add_argument('--network-config', type=int,
156 help='Integer that specifies the network environment '
157 'that the tests will be run in.')
rnephewefe44b42015-02-04 04:45:15158
159 device_os_group = group.add_mutually_exclusive_group()
160 device_os_group.add_argument('--remote-device-minimum-os',
161 help='Minimum OS on device.')
162 device_os_group.add_argument('--remote-device-os', action='append',
163 help='OS to have on the device.')
rnephew5c499782014-12-12 19:08:55164
165 api_secret_group = group.add_mutually_exclusive_group()
166 api_secret_group.add_argument('--api-secret', default='',
jbudoricke6c560152015-01-13 23:49:28167 help='API secret for remote devices.')
rnephew5c499782014-12-12 19:08:55168 api_secret_group.add_argument('--api-secret-file', default='',
jbudoricke6c560152015-01-13 23:49:28169 help='Path to file that contains API secret.')
rnephew5c499782014-12-12 19:08:55170
171 api_key_group = group.add_mutually_exclusive_group()
172 api_key_group.add_argument('--api-key', default='',
jbudoricke6c560152015-01-13 23:49:28173 help='API key for remote devices.')
rnephew5c499782014-12-12 19:08:55174 api_key_group.add_argument('--api-key-file', default='',
jbudoricke6c560152015-01-13 23:49:28175 help='Path to file that contains API key.')
rnephew5c499782014-12-12 19:08:55176
177
jama47ca85c2014-12-03 18:38:07178def AddDeviceOptions(parser):
179 """Adds device options to |parser|."""
180 group = parser.add_argument_group(title='Device Options')
jama47ca85c2014-12-03 18:38:07181 group.add_argument('--tool',
182 dest='tool',
183 help=('Run the test under a tool '
184 '(use --tool help to list them)'))
185 group.add_argument('-d', '--device', dest='test_device',
186 help=('Target device for the test suite '
187 'to run on.'))
jbudorick256fd532014-10-24 01:50:13188
189
jama47ca85c2014-12-03 18:38:07190def AddGTestOptions(parser):
191 """Adds gtest options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26192
jama47ca85c2014-12-03 18:38:07193 gtest_suites = list(gtest_config.STABLE_TEST_SUITES
194 + gtest_config.EXPERIMENTAL_TEST_SUITES)
[email protected]fbe29322013-07-09 09:03:26195
jama47ca85c2014-12-03 18:38:07196 group = parser.add_argument_group('GTest Options')
jbudorick15cdcd52014-12-03 19:58:49197 group.add_argument('-s', '--suite', dest='suite_name',
jama47ca85c2014-12-03 18:38:07198 nargs='+', metavar='SUITE_NAME', required=True,
jbudorick15cdcd52014-12-03 19:58:49199 help=('Executable name of the test suite to run. '
200 'Available suites include (but are not limited to): '
201 '%s' % ', '.join('"%s"' % s for s in gtest_suites)))
jama47ca85c2014-12-03 18:38:07202 group.add_argument('--gtest_also_run_disabled_tests',
203 '--gtest-also-run-disabled-tests',
204 dest='run_disabled', action='store_true',
205 help='Also run disabled tests if applicable.')
206 group.add_argument('-a', '--test-arguments', dest='test_arguments',
207 default='',
208 help='Additional arguments to pass to the test.')
209 group.add_argument('-t', dest='timeout', type=int, default=60,
210 help='Timeout to wait for each test '
211 '(default: %(default)s).')
212 group.add_argument('--isolate_file_path',
213 '--isolate-file-path',
214 dest='isolate_file_path',
215 help='.isolate file path to override the default '
216 'path')
jbudorick442a6932015-02-03 03:01:15217
218 filter_group = group.add_mutually_exclusive_group()
219 filter_group.add_argument('-f', '--gtest_filter', '--gtest-filter',
220 dest='test_filter',
221 help='googletest-style filter string.')
222 filter_group.add_argument('--gtest-filter-file', dest='test_filter_file',
223 help='Path to file that contains googletest-style '
224 'filter strings. (Lines will be joined with '
225 '":" to create a single filter string.)')
226
jama47ca85c2014-12-03 18:38:07227 AddDeviceOptions(parser)
228 AddCommonOptions(parser)
rnephew5c499782014-12-12 19:08:55229 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26230
231
jama47ca85c2014-12-03 18:38:07232def AddLinkerTestOptions(parser):
233 group = parser.add_argument_group('Linker Test Options')
234 group.add_argument('-f', '--gtest-filter', dest='test_filter',
235 help='googletest-style filter string.')
236 AddCommonOptions(parser)
237 AddDeviceOptions(parser)
[email protected]6b6abac6d2013-10-03 11:56:38238
239
jama47ca85c2014-12-03 18:38:07240def AddJavaTestOptions(argument_group):
[email protected]fbe29322013-07-09 09:03:26241 """Adds the Java test options to |option_parser|."""
242
jama47ca85c2014-12-03 18:38:07243 argument_group.add_argument(
244 '-f', '--test-filter', dest='test_filter',
245 help=('Test filter (if not fully qualified, will run all matches).'))
246 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26247 '-A', '--annotation', dest='annotation_str',
248 help=('Comma-separated list of annotations. Run only tests with any of '
249 'the given annotations. An annotation can be either a key or a '
250 'key-values pair. A test that has no annotation is considered '
251 '"SmallTest".'))
jama47ca85c2014-12-03 18:38:07252 argument_group.add_argument(
[email protected]fbe29322013-07-09 09:03:26253 '-E', '--exclude-annotation', dest='exclude_annotation_str',
254 help=('Comma-separated list of annotations. Exclude tests with these '
255 'annotations.'))
jama47ca85c2014-12-03 18:38:07256 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59257 '--screenshot', dest='screenshot_failures', action='store_true',
258 help='Capture screenshots of test failures')
jama47ca85c2014-12-03 18:38:07259 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59260 '--save-perf-json', action='store_true',
261 help='Saves the JSON file for each UI Perf test.')
jama47ca85c2014-12-03 18:38:07262 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59263 '--official-build', action='store_true', help='Run official build tests.')
jama47ca85c2014-12-03 18:38:07264 argument_group.add_argument(
jbudorickcbcc115d2014-09-18 17:50:59265 '--test_data', '--test-data', action='append', default=[],
266 help=('Each instance defines a directory of test data that should be '
267 'copied to the target(s) before running the tests. The argument '
268 'should be of the form <target>:<source>, <target> is relative to '
269 'the device data directory, and <source> is relative to the '
270 'chromium build directory.'))
davileen98efad12015-01-05 19:48:21271 argument_group.add_argument(
272 '--disable-dalvik-asserts', dest='set_asserts', action='store_false',
273 default=True, help='Removes the dalvik.vm.enableassertions property')
274
[email protected]fbe29322013-07-09 09:03:26275
276
jama47ca85c2014-12-03 18:38:07277def ProcessJavaTestOptions(args):
[email protected]fbe29322013-07-09 09:03:26278 """Processes options/arguments and populates |options| with defaults."""
279
jama47ca85c2014-12-03 18:38:07280 # TODO(jbudorick): Handle most of this function in argparse.
281 if args.annotation_str:
282 args.annotations = args.annotation_str.split(',')
283 elif args.test_filter:
284 args.annotations = []
[email protected]fbe29322013-07-09 09:03:26285 else:
jama47ca85c2014-12-03 18:38:07286 args.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
287 'EnormousTest', 'IntegrationTest']
[email protected]fbe29322013-07-09 09:03:26288
jama47ca85c2014-12-03 18:38:07289 if args.exclude_annotation_str:
290 args.exclude_annotations = args.exclude_annotation_str.split(',')
[email protected]fbe29322013-07-09 09:03:26291 else:
jama47ca85c2014-12-03 18:38:07292 args.exclude_annotations = []
[email protected]fbe29322013-07-09 09:03:26293
[email protected]fbe29322013-07-09 09:03:26294
jama47ca85c2014-12-03 18:38:07295def AddInstrumentationTestOptions(parser):
296 """Adds Instrumentation test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26297
jama47ca85c2014-12-03 18:38:07298 parser.usage = '%(prog)s [options]'
[email protected]fbe29322013-07-09 09:03:26299
jama47ca85c2014-12-03 18:38:07300 group = parser.add_argument_group('Instrumentation Test Options')
301 AddJavaTestOptions(group)
[email protected]fbe29322013-07-09 09:03:26302
jama47ca85c2014-12-03 18:38:07303 java_or_python_group = group.add_mutually_exclusive_group()
304 java_or_python_group.add_argument(
305 '-j', '--java-only', action='store_false',
306 dest='run_python_tests', default=True, help='Run only the Java tests.')
307 java_or_python_group.add_argument(
308 '-p', '--python-only', action='store_false',
309 dest='run_java_tests', default=True,
310 help='Run only the host-driven tests.')
311
312 group.add_argument('--host-driven-root',
313 help='Root of the host-driven tests.')
314 group.add_argument('-w', '--wait_debugger', dest='wait_for_debugger',
315 action='store_true',
316 help='Wait for debugger.')
jbudorick911be58d2015-01-13 02:51:06317 group.add_argument('--apk-under-test', dest='apk_under_test',
318 help=('the name of the apk under test.'))
jama47ca85c2014-12-03 18:38:07319 group.add_argument('--test-apk', dest='test_apk', required=True,
320 help=('The name of the apk containing the tests '
321 '(without the .apk extension; '
322 'e.g. "ContentShellTest").'))
323 group.add_argument('--coverage-dir',
324 help=('Directory in which to place all generated '
325 'EMMA coverage files.'))
326 group.add_argument('--device-flags', dest='device_flags', default='',
327 help='The relative filepath to a file containing '
328 'command-line flags to set on the device')
jbudorick911be58d2015-01-13 02:51:06329 group.add_argument('--device-flags-file', default='',
330 help='The relative filepath to a file containing '
331 'command-line flags to set on the device')
jama47ca85c2014-12-03 18:38:07332 group.add_argument('--isolate_file_path',
333 '--isolate-file-path',
334 dest='isolate_file_path',
335 help='.isolate file path to override the default '
336 'path')
337
338 AddCommonOptions(parser)
339 AddDeviceOptions(parser)
rnephewe416dff2015-01-21 21:26:37340 AddRemoteDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26341
342
jama47ca85c2014-12-03 18:38:07343def ProcessInstrumentationOptions(args):
[email protected]2a684222013-08-01 16:59:22344 """Processes options/arguments and populate |options| with defaults.
345
346 Args:
jama47ca85c2014-12-03 18:38:07347 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22348
349 Returns:
350 An InstrumentationOptions named tuple which contains all options relevant to
351 instrumentation tests.
352 """
[email protected]fbe29322013-07-09 09:03:26353
jama47ca85c2014-12-03 18:38:07354 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26355
jama47ca85c2014-12-03 18:38:07356 if not args.host_driven_root:
357 args.run_python_tests = False
[email protected]37ee0c792013-08-06 19:10:13358
jama47ca85c2014-12-03 18:38:07359 args.test_apk_path = os.path.join(
[email protected]2eea4872014-07-28 23:06:17360 constants.GetOutDirectory(),
361 constants.SDK_BUILD_APKS_DIR,
jama47ca85c2014-12-03 18:38:07362 '%s.apk' % args.test_apk)
363 args.test_apk_jar_path = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15364 constants.GetOutDirectory(),
365 constants.SDK_BUILD_TEST_JAVALIB_DIR,
jama47ca85c2014-12-03 18:38:07366 '%s.jar' % args.test_apk)
367 args.test_support_apk_path = '%sSupport%s' % (
368 os.path.splitext(args.test_apk_path))
[email protected]5e2f3f62014-06-23 12:31:46369
jama47ca85c2014-12-03 18:38:07370 args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path)
[email protected]5e2f3f62014-06-23 12:31:46371
jama47ca85c2014-12-03 18:38:07372 # TODO(jbudorick): Get rid of InstrumentationOptions.
[email protected]2a684222013-08-01 16:59:22373 return instrumentation_test_options.InstrumentationOptions(
jama47ca85c2014-12-03 18:38:07374 args.tool,
jama47ca85c2014-12-03 18:38:07375 args.annotations,
376 args.exclude_annotations,
377 args.test_filter,
378 args.test_data,
379 args.save_perf_json,
380 args.screenshot_failures,
381 args.wait_for_debugger,
382 args.coverage_dir,
383 args.test_apk,
384 args.test_apk_path,
385 args.test_apk_jar_path,
386 args.test_runner,
387 args.test_support_apk_path,
388 args.device_flags,
davileen98efad12015-01-05 19:48:21389 args.isolate_file_path,
390 args.set_asserts
[email protected]5e2f3f62014-06-23 12:31:46391 )
[email protected]2a684222013-08-01 16:59:22392
[email protected]fbe29322013-07-09 09:03:26393
jama47ca85c2014-12-03 18:38:07394def AddUIAutomatorTestOptions(parser):
395 """Adds UI Automator test options to |parser|."""
[email protected]fbe29322013-07-09 09:03:26396
jama47ca85c2014-12-03 18:38:07397 group = parser.add_argument_group('UIAutomator Test Options')
398 AddJavaTestOptions(group)
399 group.add_argument(
400 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
401 metavar='PACKAGE', help='Package under test.')
402 group.add_argument(
403 '--test-jar', dest='test_jar', required=True,
[email protected]fbe29322013-07-09 09:03:26404 help=('The name of the dexed jar containing the tests (without the '
405 '.dex.jar extension). Alternatively, this can be a full path '
406 'to the jar.'))
407
jama47ca85c2014-12-03 18:38:07408 AddCommonOptions(parser)
409 AddDeviceOptions(parser)
[email protected]fbe29322013-07-09 09:03:26410
411
jama47ca85c2014-12-03 18:38:07412def ProcessUIAutomatorOptions(args):
[email protected]2a684222013-08-01 16:59:22413 """Processes UIAutomator options/arguments.
414
415 Args:
jama47ca85c2014-12-03 18:38:07416 args: argparse.Namespace object.
[email protected]2a684222013-08-01 16:59:22417
418 Returns:
419 A UIAutomatorOptions named tuple which contains all options relevant to
[email protected]3dbdfa42013-08-08 01:08:14420 uiautomator tests.
[email protected]2a684222013-08-01 16:59:22421 """
[email protected]fbe29322013-07-09 09:03:26422
jama47ca85c2014-12-03 18:38:07423 ProcessJavaTestOptions(args)
[email protected]fbe29322013-07-09 09:03:26424
jama47ca85c2014-12-03 18:38:07425 if os.path.exists(args.test_jar):
[email protected]fbe29322013-07-09 09:03:26426 # The dexed JAR is fully qualified, assume the info JAR lives along side.
jama47ca85c2014-12-03 18:38:07427 args.uiautomator_jar = args.test_jar
[email protected]fbe29322013-07-09 09:03:26428 else:
jama47ca85c2014-12-03 18:38:07429 args.uiautomator_jar = os.path.join(
[email protected]ae68d4a2013-09-24 21:57:15430 constants.GetOutDirectory(),
431 constants.SDK_BUILD_JAVALIB_DIR,
jama47ca85c2014-12-03 18:38:07432 '%s.dex.jar' % args.test_jar)
433 args.uiautomator_info_jar = (
434 args.uiautomator_jar[:args.uiautomator_jar.find('.dex.jar')] +
[email protected]fbe29322013-07-09 09:03:26435 '_java.jar')
436
[email protected]2a684222013-08-01 16:59:22437 return uiautomator_test_options.UIAutomatorOptions(
jama47ca85c2014-12-03 18:38:07438 args.tool,
jama47ca85c2014-12-03 18:38:07439 args.annotations,
440 args.exclude_annotations,
441 args.test_filter,
442 args.test_data,
443 args.save_perf_json,
444 args.screenshot_failures,
445 args.uiautomator_jar,
446 args.uiautomator_info_jar,
davileen98efad12015-01-05 19:48:21447 args.package,
448 args.set_asserts)
[email protected]2a684222013-08-01 16:59:22449
[email protected]fbe29322013-07-09 09:03:26450
jama47ca85c2014-12-03 18:38:07451def AddJUnitTestOptions(parser):
452 """Adds junit test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07453
jama47ca85c2014-12-03 18:38:07454 group = parser.add_argument_group('JUnit Test Options')
455 group.add_argument(
456 '-s', '--test-suite', dest='test_suite', required=True,
jbudorick9a6b7b332014-09-20 00:01:07457 help=('JUnit test suite to run.'))
jama47ca85c2014-12-03 18:38:07458 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07459 '-f', '--test-filter', dest='test_filter',
460 help='Filters tests googletest-style.')
jama47ca85c2014-12-03 18:38:07461 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07462 '--package-filter', dest='package_filter',
463 help='Filters tests by package.')
jama47ca85c2014-12-03 18:38:07464 group.add_argument(
jbudorick9a6b7b332014-09-20 00:01:07465 '--runner-filter', dest='runner_filter',
466 help='Filters tests by runner class. Must be fully qualified.')
jama47ca85c2014-12-03 18:38:07467 group.add_argument(
468 '--sdk-version', dest='sdk_version', type=int,
jbudorick9a6b7b332014-09-20 00:01:07469 help='The Android SDK version.')
jama47ca85c2014-12-03 18:38:07470 AddCommonOptions(parser)
jbudorick9a6b7b332014-09-20 00:01:07471
472
jama47ca85c2014-12-03 18:38:07473def AddMonkeyTestOptions(parser):
474 """Adds monkey test options to |parser|."""
jbudorick9a6b7b332014-09-20 00:01:07475
jama47ca85c2014-12-03 18:38:07476 group = parser.add_argument_group('Monkey Test Options')
477 group.add_argument(
478 '--package', required=True, choices=constants.PACKAGE_INFO.keys(),
479 metavar='PACKAGE', help='Package under test.')
480 group.add_argument(
481 '--event-count', default=10000, type=int,
482 help='Number of events to generate (default: %(default)s).')
483 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14484 '--category', default='',
[email protected]fb81b982013-08-09 00:07:12485 help='A list of allowed categories.')
jama47ca85c2014-12-03 18:38:07486 group.add_argument(
487 '--throttle', default=100, type=int,
488 help='Delay between events (ms) (default: %(default)s). ')
489 group.add_argument(
490 '--seed', type=int,
[email protected]3dbdfa42013-08-08 01:08:14491 help=('Seed value for pseudo-random generator. Same seed value generates '
492 'the same sequence of events. Seed is randomized by default.'))
jama47ca85c2014-12-03 18:38:07493 group.add_argument(
[email protected]3dbdfa42013-08-08 01:08:14494 '--extra-args', default='',
jama47ca85c2014-12-03 18:38:07495 help=('String of other args to pass to the command verbatim.'))
[email protected]3dbdfa42013-08-08 01:08:14496
jama47ca85c2014-12-03 18:38:07497 AddCommonOptions(parser)
498 AddDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14499
jama47ca85c2014-12-03 18:38:07500def ProcessMonkeyTestOptions(args):
[email protected]3dbdfa42013-08-08 01:08:14501 """Processes all monkey test options.
502
503 Args:
jama47ca85c2014-12-03 18:38:07504 args: argparse.Namespace object.
[email protected]3dbdfa42013-08-08 01:08:14505
506 Returns:
507 A MonkeyOptions named tuple which contains all options relevant to
508 monkey tests.
509 """
jama47ca85c2014-12-03 18:38:07510 # TODO(jbudorick): Handle this directly in argparse with nargs='+'
511 category = args.category
[email protected]3dbdfa42013-08-08 01:08:14512 if category:
jama47ca85c2014-12-03 18:38:07513 category = args.category.split(',')
[email protected]3dbdfa42013-08-08 01:08:14514
jama47ca85c2014-12-03 18:38:07515 # TODO(jbudorick): Get rid of MonkeyOptions.
[email protected]3dbdfa42013-08-08 01:08:14516 return monkey_test_options.MonkeyOptions(
jama47ca85c2014-12-03 18:38:07517 args.verbose_count,
518 args.package,
519 args.event_count,
[email protected]3dbdfa42013-08-08 01:08:14520 category,
jama47ca85c2014-12-03 18:38:07521 args.throttle,
522 args.seed,
523 args.extra_args)
[email protected]3dbdfa42013-08-08 01:08:14524
rnephew5c499782014-12-12 19:08:55525def AddUirobotTestOptions(parser):
526 """Adds uirobot test options to |option_parser|."""
527 group = parser.add_argument_group('Uirobot Test Options')
528
rnephewefe44b42015-02-04 04:45:15529 group.add_argument('--app-under-test', required=True,
530 help='APK to run tests on.')
rnephew5c499782014-12-12 19:08:55531 group.add_argument(
532 '--minutes', default=5, type=int,
jbudorick676b1202015-02-06 22:02:27533 help='Number of minutes to run uirobot test [default: %(default)s].')
rnephew5c499782014-12-12 19:08:55534
535 AddCommonOptions(parser)
536 AddDeviceOptions(parser)
537 AddRemoteDeviceOptions(parser)
[email protected]3dbdfa42013-08-08 01:08:14538
jama47ca85c2014-12-03 18:38:07539def AddPerfTestOptions(parser):
540 """Adds perf test options to |parser|."""
[email protected]ec3170b2013-08-14 14:39:47541
jama47ca85c2014-12-03 18:38:07542 group = parser.add_argument_group('Perf Test Options')
[email protected]ec3170b2013-08-14 14:39:47543
jama47ca85c2014-12-03 18:38:07544 class SingleStepAction(argparse.Action):
545 def __call__(self, parser, namespace, values, option_string=None):
546 if values and not namespace.single_step:
547 parser.error('single step command provided, '
548 'but --single-step not specified.')
549 elif namespace.single_step and not values:
550 parser.error('--single-step specified, '
551 'but no single step command provided.')
552 setattr(namespace, self.dest, values)
553
554 step_group = group.add_mutually_exclusive_group(required=True)
555 # TODO(jbudorick): Revise --single-step to use argparse.REMAINDER.
556 # This requires removing "--" from client calls.
557 step_group.add_argument(
558 '--single-step', action='store_true',
[email protected]def4bce2013-11-12 12:59:52559 help='Execute the given command with retries, but only print the result '
560 'for the "most successful" round.')
jama47ca85c2014-12-03 18:38:07561 step_group.add_argument(
[email protected]181a5c92013-09-06 17:11:46562 '--steps',
[email protected]def4bce2013-11-12 12:59:52563 help='JSON file containing the list of commands to run.')
jama47ca85c2014-12-03 18:38:07564 step_group.add_argument(
565 '--print-step',
566 help='The name of a previously executed perf step to print.')
567
568 group.add_argument(
peterbd4e73d2014-12-03 15:47:36569 '--output-json-list',
570 help='Write a simple list of names from --steps into the given file.')
jama47ca85c2014-12-03 18:38:07571 group.add_argument(
peterbd4e73d2014-12-03 15:47:36572 '--collect-chartjson-data',
573 action='store_true',
574 help='Cache the chartjson output from each step for later use.')
jama47ca85c2014-12-03 18:38:07575 group.add_argument(
peterbd4e73d2014-12-03 15:47:36576 '--output-chartjson-data',
577 default='',
578 help='Write out chartjson into the given file.')
jama47ca85c2014-12-03 18:38:07579 group.add_argument(
580 '--flaky-steps',
581 help=('A JSON file containing steps that are flaky '
582 'and will have its exit code ignored.'))
583 group.add_argument(
[email protected]181a5c92013-09-06 17:11:46584 '--no-timeout', action='store_true',
585 help=('Do not impose a timeout. Each perf step is responsible for '
586 'implementing the timeout logic.'))
jama47ca85c2014-12-03 18:38:07587 group.add_argument(
[email protected]650487c2013-09-30 11:40:49588 '-f', '--test-filter',
589 help=('Test filter (will match against the names listed in --steps).'))
jama47ca85c2014-12-03 18:38:07590 group.add_argument(
591 '--dry-run', action='store_true',
[email protected]650487c2013-09-30 11:40:49592 help='Just print the steps without executing.')
jama47ca85c2014-12-03 18:38:07593 group.add_argument('single_step_command', nargs='*', action=SingleStepAction,
594 help='If --single-step is specified, the command to run.')
595 AddCommonOptions(parser)
596 AddDeviceOptions(parser)
[email protected]ec3170b2013-08-14 14:39:47597
598
jama47ca85c2014-12-03 18:38:07599def ProcessPerfTestOptions(args):
[email protected]ec3170b2013-08-14 14:39:47600 """Processes all perf test options.
601
602 Args:
jama47ca85c2014-12-03 18:38:07603 args: argparse.Namespace object.
[email protected]ec3170b2013-08-14 14:39:47604
605 Returns:
606 A PerfOptions named tuple which contains all options relevant to
607 perf tests.
608 """
jama47ca85c2014-12-03 18:38:07609 # TODO(jbudorick): Move single_step handling down into the perf tests.
610 if args.single_step:
611 args.single_step = ' '.join(args.single_step_command)
612 # TODO(jbudorick): Get rid of PerfOptions.
[email protected]ec3170b2013-08-14 14:39:47613 return perf_test_options.PerfOptions(
jama47ca85c2014-12-03 18:38:07614 args.steps, args.flaky_steps, args.output_json_list,
615 args.print_step, args.no_timeout, args.test_filter,
616 args.dry_run, args.single_step, args.collect_chartjson_data,
617 args.output_chartjson_data)
[email protected]ec3170b2013-08-14 14:39:47618
619
jama47ca85c2014-12-03 18:38:07620def AddPythonTestOptions(parser):
621 group = parser.add_argument_group('Python Test Options')
622 group.add_argument(
623 '-s', '--suite', dest='suite_name', metavar='SUITE_NAME',
624 choices=constants.PYTHON_UNIT_TEST_SUITES.keys(),
625 help='Name of the test suite to run.')
626 AddCommonOptions(parser)
jbudorick256fd532014-10-24 01:50:13627
628
jama47ca85c2014-12-03 18:38:07629def _RunGTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37630 """Subcommand of RunTestsCommands which runs gtests."""
[email protected]6bc1bda22013-07-19 22:08:37631 exit_code = 0
jama47ca85c2014-12-03 18:38:07632 for suite_name in args.suite_name:
633 # TODO(jbudorick): Either deprecate multi-suite or move its handling down
634 # into the gtest code.
[email protected]2a684222013-08-01 16:59:22635 gtest_options = gtest_test_options.GTestOptions(
jama47ca85c2014-12-03 18:38:07636 args.tool,
jama47ca85c2014-12-03 18:38:07637 args.test_filter,
638 args.run_disabled,
639 args.test_arguments,
640 args.timeout,
641 args.isolate_file_path,
[email protected]2a684222013-08-01 16:59:22642 suite_name)
[email protected]f7148dd42013-08-20 14:24:57643 runner_factory, tests = gtest_setup.Setup(gtest_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37644
645 results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57646 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07647 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37648
649 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
650 exit_code = test_exit_code
651
652 report_results.LogFull(
653 results=results,
654 test_type='Unit test',
655 test_package=suite_name,
jama47ca85c2014-12-03 18:38:07656 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37657
jama47ca85c2014-12-03 18:38:07658 if args.json_results_file:
659 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54660
[email protected]6bc1bda22013-07-19 22:08:37661 if os.path.isdir(constants.ISOLATE_DEPS_DIR):
662 shutil.rmtree(constants.ISOLATE_DEPS_DIR)
663
664 return exit_code
665
666
jama47ca85c2014-12-03 18:38:07667def _RunLinkerTests(args, devices):
[email protected]6b6abac6d2013-10-03 11:56:38668 """Subcommand of RunTestsCommands which runs linker tests."""
jama47ca85c2014-12-03 18:38:07669 runner_factory, tests = linker_setup.Setup(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38670
671 results, exit_code = test_dispatcher.RunTests(
672 tests, runner_factory, devices, shard=True, test_timeout=60,
jama47ca85c2014-12-03 18:38:07673 num_retries=args.num_retries)
[email protected]6b6abac6d2013-10-03 11:56:38674
675 report_results.LogFull(
676 results=results,
677 test_type='Linker test',
[email protected]93c9f9b2014-02-10 16:19:22678 test_package='ChromiumLinkerTest')
[email protected]6b6abac6d2013-10-03 11:56:38679
jama47ca85c2014-12-03 18:38:07680 if args.json_results_file:
681 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54682
[email protected]6b6abac6d2013-10-03 11:56:38683 return exit_code
684
685
jama47ca85c2014-12-03 18:38:07686def _RunInstrumentationTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37687 """Subcommand of RunTestsCommands which runs instrumentation tests."""
jama47ca85c2014-12-03 18:38:07688 logging.info('_RunInstrumentationTests(%s, %s)' % (str(args), str(devices)))
[email protected]6bc1bda22013-07-19 22:08:37689
jama47ca85c2014-12-03 18:38:07690 instrumentation_options = ProcessInstrumentationOptions(args)
691
692 if len(devices) > 1 and args.wait_for_debugger:
[email protected]f7148dd42013-08-20 14:24:57693 logging.warning('Debugger can not be sharded, using first available device')
694 devices = devices[:1]
695
[email protected]6bc1bda22013-07-19 22:08:37696 results = base_test_result.TestRunResults()
697 exit_code = 0
698
jama47ca85c2014-12-03 18:38:07699 if args.run_java_tests:
mikecase526d68e2014-11-19 20:02:05700 runner_factory, tests = instrumentation_setup.Setup(
701 instrumentation_options, devices)
[email protected]6bc1bda22013-07-19 22:08:37702
703 test_results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57704 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07705 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37706
707 results.AddTestRunResults(test_results)
708
jama47ca85c2014-12-03 18:38:07709 if args.run_python_tests:
[email protected]37ee0c792013-08-06 19:10:13710 runner_factory, tests = host_driven_setup.InstrumentationSetup(
jama47ca85c2014-12-03 18:38:07711 args.host_driven_root, args.official_build,
[email protected]37ee0c792013-08-06 19:10:13712 instrumentation_options)
713
[email protected]34020022013-08-06 23:35:34714 if tests:
715 test_results, test_exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57716 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07717 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37718
[email protected]34020022013-08-06 23:35:34719 results.AddTestRunResults(test_results)
[email protected]6bc1bda22013-07-19 22:08:37720
[email protected]34020022013-08-06 23:35:34721 # Only allow exit code escalation
722 if test_exit_code and exit_code != constants.ERROR_EXIT_CODE:
723 exit_code = test_exit_code
[email protected]6bc1bda22013-07-19 22:08:37724
jama47ca85c2014-12-03 18:38:07725 if args.device_flags:
726 args.device_flags = os.path.join(constants.DIR_SOURCE_ROOT,
727 args.device_flags)
[email protected]4f777ca2014-08-08 01:45:59728
[email protected]6bc1bda22013-07-19 22:08:37729 report_results.LogFull(
730 results=results,
731 test_type='Instrumentation',
jama47ca85c2014-12-03 18:38:07732 test_package=os.path.basename(args.test_apk),
733 annotation=args.annotations,
734 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37735
jama47ca85c2014-12-03 18:38:07736 if args.json_results_file:
737 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54738
[email protected]6bc1bda22013-07-19 22:08:37739 return exit_code
740
741
jama47ca85c2014-12-03 18:38:07742def _RunUIAutomatorTests(args, devices):
[email protected]6bc1bda22013-07-19 22:08:37743 """Subcommand of RunTestsCommands which runs uiautomator tests."""
jama47ca85c2014-12-03 18:38:07744 uiautomator_options = ProcessUIAutomatorOptions(args)
[email protected]6bc1bda22013-07-19 22:08:37745
[email protected]37ee0c792013-08-06 19:10:13746 runner_factory, tests = uiautomator_setup.Setup(uiautomator_options)
[email protected]6bc1bda22013-07-19 22:08:37747
[email protected]37ee0c792013-08-06 19:10:13748 results, exit_code = test_dispatcher.RunTests(
[email protected]f7148dd42013-08-20 14:24:57749 tests, runner_factory, devices, shard=True, test_timeout=None,
jama47ca85c2014-12-03 18:38:07750 num_retries=args.num_retries)
[email protected]6bc1bda22013-07-19 22:08:37751
752 report_results.LogFull(
753 results=results,
754 test_type='UIAutomator',
jama47ca85c2014-12-03 18:38:07755 test_package=os.path.basename(args.test_jar),
756 annotation=args.annotations,
757 flakiness_server=args.flakiness_dashboard_server)
[email protected]6bc1bda22013-07-19 22:08:37758
jama47ca85c2014-12-03 18:38:07759 if args.json_results_file:
760 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54761
[email protected]6bc1bda22013-07-19 22:08:37762 return exit_code
763
764
jama47ca85c2014-12-03 18:38:07765def _RunJUnitTests(args):
jbudorick9a6b7b332014-09-20 00:01:07766 """Subcommand of RunTestsCommand which runs junit tests."""
jama47ca85c2014-12-03 18:38:07767 runner_factory, tests = junit_setup.Setup(args)
mikecasec638a072015-04-01 16:35:35768 results, exit_code = junit_dispatcher.RunTests(tests, runner_factory)
769
770 report_results.LogFull(
771 results=results,
772 test_type='JUnit',
773 test_package=args.test_suite)
774
mikecase572401b2015-04-09 02:28:57775 if args.json_results_file:
776 json_results.GenerateJsonResultsFile(results, args.json_results_file)
777
jbudorick9a6b7b332014-09-20 00:01:07778 return exit_code
779
780
jama47ca85c2014-12-03 18:38:07781def _RunMonkeyTests(args, devices):
[email protected]3dbdfa42013-08-08 01:08:14782 """Subcommand of RunTestsCommands which runs monkey tests."""
jama47ca85c2014-12-03 18:38:07783 monkey_options = ProcessMonkeyTestOptions(args)
[email protected]3dbdfa42013-08-08 01:08:14784
785 runner_factory, tests = monkey_setup.Setup(monkey_options)
786
787 results, exit_code = test_dispatcher.RunTests(
[email protected]181a5c92013-09-06 17:11:46788 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07789 num_retries=args.num_retries)
[email protected]3dbdfa42013-08-08 01:08:14790
791 report_results.LogFull(
792 results=results,
793 test_type='Monkey',
[email protected]14b3b1202013-08-15 22:25:28794 test_package='Monkey')
[email protected]3dbdfa42013-08-08 01:08:14795
jama47ca85c2014-12-03 18:38:07796 if args.json_results_file:
797 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54798
[email protected]3dbdfa42013-08-08 01:08:14799 return exit_code
800
801
jama47ca85c2014-12-03 18:38:07802def _RunPerfTests(args):
[email protected]ec3170b2013-08-14 14:39:47803 """Subcommand of RunTestsCommands which runs perf tests."""
jama47ca85c2014-12-03 18:38:07804 perf_options = ProcessPerfTestOptions(args)
[email protected]61487ed2014-06-09 12:33:56805
806 # Just save a simple json with a list of test names.
807 if perf_options.output_json_list:
808 return perf_test_runner.OutputJsonList(
809 perf_options.steps, perf_options.output_json_list)
810
[email protected]ad32f312013-11-13 04:03:29811 # Just print the results from a single previously executed step.
[email protected]ec3170b2013-08-14 14:39:47812 if perf_options.print_step:
simonhatch9b9256d2015-01-07 18:03:42813 return perf_test_runner.PrintTestOutput(
814 perf_options.print_step, perf_options.output_chartjson_data)
[email protected]ec3170b2013-08-14 14:39:47815
[email protected]a72f0752014-06-03 23:52:34816 runner_factory, tests, devices = perf_setup.Setup(perf_options)
[email protected]ec3170b2013-08-14 14:39:47817
[email protected]a72f0752014-06-03 23:52:34818 # shard=False means that each device will get the full list of tests
819 # and then each one will decide their own affinity.
820 # shard=True means each device will pop the next test available from a queue,
821 # which increases throughput but have no affinity.
[email protected]86184c7b2013-08-15 15:06:57822 results, _ = test_dispatcher.RunTests(
[email protected]a72f0752014-06-03 23:52:34823 tests, runner_factory, devices, shard=False, test_timeout=None,
jama47ca85c2014-12-03 18:38:07824 num_retries=args.num_retries)
[email protected]ec3170b2013-08-14 14:39:47825
826 report_results.LogFull(
827 results=results,
828 test_type='Perf',
[email protected]865a47a2013-08-16 14:01:12829 test_package='Perf')
[email protected]def4bce2013-11-12 12:59:52830
jama47ca85c2014-12-03 18:38:07831 if args.json_results_file:
832 json_results.GenerateJsonResultsFile(results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54833
[email protected]def4bce2013-11-12 12:59:52834 if perf_options.single_step:
835 return perf_test_runner.PrintTestOutput('single_step')
836
[email protected]11ce8452014-02-17 10:55:03837 perf_test_runner.PrintSummary(tests)
838
[email protected]86184c7b2013-08-15 15:06:57839 # Always return 0 on the sharding stage. Individual tests exit_code
840 # will be returned on the print_step stage.
841 return 0
[email protected]ec3170b2013-08-14 14:39:47842
[email protected]3dbdfa42013-08-08 01:08:14843
jama47ca85c2014-12-03 18:38:07844def _RunPythonTests(args):
jbudorick256fd532014-10-24 01:50:13845 """Subcommand of RunTestsCommand which runs python unit tests."""
jama47ca85c2014-12-03 18:38:07846 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name]
jbudorick256fd532014-10-24 01:50:13847 suite_path = suite_vars['path']
848 suite_test_modules = suite_vars['test_modules']
849
850 sys.path = [suite_path] + sys.path
851 try:
852 suite = unittest.TestSuite()
853 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m)
854 for m in suite_test_modules)
jama47ca85c2014-12-03 18:38:07855 runner = unittest.TextTestRunner(verbosity=1+args.verbose_count)
jbudorick256fd532014-10-24 01:50:13856 return 0 if runner.run(suite).wasSuccessful() else 1
857 finally:
858 sys.path = sys.path[1:]
859
860
[email protected]f7148dd42013-08-20 14:24:57861def _GetAttachedDevices(test_device=None):
862 """Get all attached devices.
863
864 Args:
865 test_device: Name of a specific device to use.
866
867 Returns:
868 A list of attached devices.
869 """
870 attached_devices = []
871
872 attached_devices = android_commands.GetAttachedDevices()
873 if test_device:
874 assert test_device in attached_devices, (
875 'Did not find device %s among attached device. Attached devices: %s'
876 % (test_device, ', '.join(attached_devices)))
877 attached_devices = [test_device]
878
879 assert attached_devices, 'No devices attached.'
880
881 return sorted(attached_devices)
882
883
jama47ca85c2014-12-03 18:38:07884def RunTestsCommand(args, parser):
[email protected]fbe29322013-07-09 09:03:26885 """Checks test type and dispatches to the appropriate function.
886
887 Args:
jama47ca85c2014-12-03 18:38:07888 args: argparse.Namespace object.
889 parser: argparse.ArgumentParser object.
[email protected]fbe29322013-07-09 09:03:26890
891 Returns:
892 Integer indicated exit code.
[email protected]b3873892013-07-10 04:57:10893
894 Raises:
895 Exception: Unknown command name passed in, or an exception from an
896 individual test runner.
[email protected]fbe29322013-07-09 09:03:26897 """
jama47ca85c2014-12-03 18:38:07898 command = args.command
[email protected]fbe29322013-07-09 09:03:26899
jama47ca85c2014-12-03 18:38:07900 ProcessCommonOptions(args)
[email protected]d82f0252013-07-12 23:22:57901
jama47ca85c2014-12-03 18:38:07902 if args.enable_platform_mode:
rnephew5c499782014-12-12 19:08:55903 return RunTestsInPlatformMode(args, parser)
jbudorick66dc3722014-11-06 21:33:51904
905 if command in constants.LOCAL_MACHINE_TESTS:
jbudorick256fd532014-10-24 01:50:13906 devices = []
907 else:
jama47ca85c2014-12-03 18:38:07908 devices = _GetAttachedDevices(args.test_device)
[email protected]f7148dd42013-08-20 14:24:57909
[email protected]c0662e092013-11-12 11:51:25910 forwarder.Forwarder.RemoveHostLog()
[email protected]6b11583b2013-11-21 16:18:40911 if not ports.ResetTestServerPortAllocation():
912 raise Exception('Failed to reset test server port.')
[email protected]c0662e092013-11-12 11:51:25913
[email protected]fbe29322013-07-09 09:03:26914 if command == 'gtest':
jama47ca85c2014-12-03 18:38:07915 return _RunGTests(args, devices)
[email protected]6b6abac6d2013-10-03 11:56:38916 elif command == 'linker':
jama47ca85c2014-12-03 18:38:07917 return _RunLinkerTests(args, devices)
[email protected]fbe29322013-07-09 09:03:26918 elif command == 'instrumentation':
jama47ca85c2014-12-03 18:38:07919 return _RunInstrumentationTests(args, devices)
[email protected]fbe29322013-07-09 09:03:26920 elif command == 'uiautomator':
jama47ca85c2014-12-03 18:38:07921 return _RunUIAutomatorTests(args, devices)
jbudorick9a6b7b332014-09-20 00:01:07922 elif command == 'junit':
jama47ca85c2014-12-03 18:38:07923 return _RunJUnitTests(args)
[email protected]3dbdfa42013-08-08 01:08:14924 elif command == 'monkey':
jama47ca85c2014-12-03 18:38:07925 return _RunMonkeyTests(args, devices)
[email protected]ec3170b2013-08-14 14:39:47926 elif command == 'perf':
jama47ca85c2014-12-03 18:38:07927 return _RunPerfTests(args)
jbudorick256fd532014-10-24 01:50:13928 elif command == 'python':
jama47ca85c2014-12-03 18:38:07929 return _RunPythonTests(args)
[email protected]fbe29322013-07-09 09:03:26930 else:
[email protected]6bc1bda22013-07-19 22:08:37931 raise Exception('Unknown test type.')
[email protected]fbe29322013-07-09 09:03:26932
[email protected]fbe29322013-07-09 09:03:26933
jbudorick66dc3722014-11-06 21:33:51934_SUPPORTED_IN_PLATFORM_MODE = [
935 # TODO(jbudorick): Add support for more test types.
jbudorick911be58d2015-01-13 02:51:06936 'gtest',
937 'instrumentation',
938 'uirobot',
jbudorick66dc3722014-11-06 21:33:51939]
940
941
jama47ca85c2014-12-03 18:38:07942def RunTestsInPlatformMode(args, parser):
jbudorick66dc3722014-11-06 21:33:51943
jama47ca85c2014-12-03 18:38:07944 if args.command not in _SUPPORTED_IN_PLATFORM_MODE:
945 parser.error('%s is not yet supported in platform mode' % args.command)
jbudorick66dc3722014-11-06 21:33:51946
jama47ca85c2014-12-03 18:38:07947 with environment_factory.CreateEnvironment(args, parser.error) as env:
948 with test_instance_factory.CreateTestInstance(args, parser.error) as test:
jbudorick66dc3722014-11-06 21:33:51949 with test_run_factory.CreateTestRun(
jama47ca85c2014-12-03 18:38:07950 args, env, test, parser.error) as test_run:
jbudorick66dc3722014-11-06 21:33:51951 results = test_run.RunTests()
952
jbudorick911be58d2015-01-13 02:51:06953 if args.environment == 'remote_device' and args.trigger:
rnephew5c499782014-12-12 19:08:55954 return 0 # Not returning results, only triggering.
955
jbudorick66dc3722014-11-06 21:33:51956 report_results.LogFull(
957 results=results,
958 test_type=test.TestType(),
959 test_package=test_run.TestPackage(),
jbudorickf9543672014-12-08 22:36:33960 annotation=getattr(args, 'annotations', None),
961 flakiness_server=getattr(args, 'flakiness_dashboard_server', None))
jbudorick66dc3722014-11-06 21:33:51962
jama47ca85c2014-12-03 18:38:07963 if args.json_results_file:
jbudorickb8c42072014-12-01 18:07:54964 json_results.GenerateJsonResultsFile(
jama47ca85c2014-12-03 18:38:07965 results, args.json_results_file)
jbudorickb8c42072014-12-01 18:07:54966
mikecasee74051022015-02-26 23:08:22967 return 0 if results.DidRunPass() else constants.ERROR_EXIT_CODE
jbudorick66dc3722014-11-06 21:33:51968
969
jama47ca85c2014-12-03 18:38:07970CommandConfigTuple = collections.namedtuple(
971 'CommandConfigTuple',
972 ['add_options_func', 'help_txt'])
[email protected]fbe29322013-07-09 09:03:26973VALID_COMMANDS = {
jama47ca85c2014-12-03 18:38:07974 'gtest': CommandConfigTuple(
975 AddGTestOptions,
976 'googletest-based C++ tests'),
977 'instrumentation': CommandConfigTuple(
978 AddInstrumentationTestOptions,
979 'InstrumentationTestCase-based Java tests'),
980 'uiautomator': CommandConfigTuple(
981 AddUIAutomatorTestOptions,
982 "Tests that run via Android's uiautomator command"),
983 'junit': CommandConfigTuple(
984 AddJUnitTestOptions,
985 'JUnit4-based Java tests'),
986 'monkey': CommandConfigTuple(
987 AddMonkeyTestOptions,
988 "Tests based on Android's monkey"),
989 'perf': CommandConfigTuple(
990 AddPerfTestOptions,
991 'Performance tests'),
992 'python': CommandConfigTuple(
993 AddPythonTestOptions,
994 'Python tests based on unittest.TestCase'),
995 'linker': CommandConfigTuple(
996 AddLinkerTestOptions,
997 'Linker tests'),
rnephew5c499782014-12-12 19:08:55998 'uirobot': CommandConfigTuple(
999 AddUirobotTestOptions,
1000 'Uirobot test'),
jama47ca85c2014-12-03 18:38:071001}
[email protected]fbe29322013-07-09 09:03:261002
1003
[email protected]7c53a602014-03-24 16:21:441004def DumpThreadStacks(_signal, _frame):
[email protected]71aec4b2013-11-20 00:35:241005 for thread in threading.enumerate():
1006 reraiser_thread.LogThreadStack(thread)
[email protected]83bb8152013-11-19 15:02:211007
1008
[email protected]7c53a602014-03-24 16:21:441009def main():
[email protected]83bb8152013-11-19 15:02:211010 signal.signal(signal.SIGUSR1, DumpThreadStacks)
jama47ca85c2014-12-03 18:38:071011
1012 parser = argparse.ArgumentParser()
1013 command_parsers = parser.add_subparsers(title='test types',
1014 dest='command')
1015
1016 for test_type, config in sorted(VALID_COMMANDS.iteritems(),
1017 key=lambda x: x[0]):
1018 subparser = command_parsers.add_parser(
1019 test_type, usage='%(prog)s [options]', help=config.help_txt)
1020 config.add_options_func(subparser)
1021
1022 args = parser.parse_args()
mikecasee74051022015-02-26 23:08:221023
1024 try:
1025 return RunTestsCommand(args, parser)
1026 except base_error.BaseError as e:
1027 logging.exception('Error occurred.')
1028 if e.is_infra_error:
1029 return constants.INFRA_EXIT_CODE
1030 else:
1031 return constants.ERROR_EXIT_CODE
1032 except: # pylint: disable=W0702
1033 logging.exception('Unrecognized error occurred.')
1034 return constants.ERROR_EXIT_CODE
[email protected]fbe29322013-07-09 09:03:261035
[email protected]fbe29322013-07-09 09:03:261036
1037if __name__ == '__main__':
[email protected]7c53a602014-03-24 16:21:441038 sys.exit(main())