[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1 | #!/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] | 181a5c9 | 2013-09-06 17:11:46 | [diff] [blame] | 7 | """Runs all types of tests from one unified interface.""" |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 8 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 9 | import argparse |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 10 | import collections |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 11 | import itertools |
[email protected] | f7148dd4 | 2013-08-20 14:24:57 | [diff] [blame] | 12 | import logging |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 13 | import os |
[email protected] | 83bb815 | 2013-11-19 15:02:21 | [diff] [blame] | 14 | import signal |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 15 | import sys |
[email protected] | 83bb815 | 2013-11-19 15:02:21 | [diff] [blame] | 16 | import threading |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 17 | import unittest |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 18 | |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 19 | import devil_chromium |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 20 | from devil import base_error |
jbudorick | e29693be | 2015-12-07 15:53:23 | [diff] [blame] | 21 | from devil import devil_env |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 22 | from devil.android import apk_helper |
| 23 | from devil.android import device_blacklist |
| 24 | from devil.android import device_errors |
| 25 | from devil.android import device_utils |
jbudorick | d645efe8 | 2015-12-11 19:09:59 | [diff] [blame] | 26 | from devil.android import forwarder |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 27 | from devil.android import ports |
| 28 | from devil.utils import reraiser_thread |
| 29 | from devil.utils import run_tests_helper |
| 30 | |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 31 | from pylib import constants |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 32 | from pylib.constants import host_paths |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 33 | from pylib.base import base_test_result |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 34 | from pylib.base import environment_factory |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 35 | from pylib.base import test_dispatcher |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 36 | from pylib.base import test_instance_factory |
| 37 | from pylib.base import test_run_factory |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 38 | from pylib.linker import setup as linker_setup |
[email protected] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 39 | from pylib.host_driven import setup as host_driven_setup |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 40 | from pylib.instrumentation import setup as instrumentation_setup |
[email protected] | 2a68422 | 2013-08-01 16:59:22 | [diff] [blame] | 41 | from pylib.instrumentation import test_options as instrumentation_test_options |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 42 | from pylib.junit import setup as junit_setup |
| 43 | from pylib.junit import test_dispatcher as junit_dispatcher |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 44 | from pylib.monkey import setup as monkey_setup |
| 45 | from pylib.monkey import test_options as monkey_test_options |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 46 | from pylib.perf import setup as perf_setup |
| 47 | from pylib.perf import test_options as perf_test_options |
| 48 | from pylib.perf import test_runner as perf_test_runner |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 49 | from pylib.results import json_results |
| 50 | from pylib.results import report_results |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 51 | |
| 52 | |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 53 | _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 54 | host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 55 | |
| 56 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 57 | def AddCommonOptions(parser): |
| 58 | """Adds all common options to |parser|.""" |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 59 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 60 | group = parser.add_argument_group('Common Options') |
| 61 | |
[email protected] | dfffbcbc | 2013-09-17 22:06:01 | [diff] [blame] | 62 | default_build_type = os.environ.get('BUILDTYPE', 'Debug') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 63 | |
| 64 | debug_or_release_group = group.add_mutually_exclusive_group() |
| 65 | debug_or_release_group.add_argument( |
| 66 | '--debug', action='store_const', const='Debug', dest='build_type', |
| 67 | default=default_build_type, |
| 68 | help=('If set, run test suites under out/Debug. ' |
| 69 | 'Default is env var BUILDTYPE or Debug.')) |
| 70 | debug_or_release_group.add_argument( |
| 71 | '--release', action='store_const', const='Release', dest='build_type', |
| 72 | help=('If set, run test suites under out/Release. ' |
| 73 | 'Default is env var BUILDTYPE or Debug.')) |
| 74 | |
| 75 | group.add_argument('--build-directory', dest='build_directory', |
| 76 | help=('Path to the directory in which build files are' |
| 77 | ' located (should not include build type)')) |
| 78 | group.add_argument('--output-directory', dest='output_directory', |
| 79 | help=('Path to the directory in which build files are' |
| 80 | ' located (must include build type). This will take' |
| 81 | ' precedence over --debug, --release and' |
| 82 | ' --build-directory')) |
agrieve | ddb11f1 | 2015-10-23 17:03:43 | [diff] [blame] | 83 | group.add_argument('--num_retries', '--num-retries', dest='num_retries', |
| 84 | type=int, default=2, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 85 | help=('Number of retries for a test before ' |
| 86 | 'giving up (default: %(default)s).')) |
| 87 | group.add_argument('-v', |
| 88 | '--verbose', |
| 89 | dest='verbose_count', |
| 90 | default=0, |
| 91 | action='count', |
| 92 | help='Verbose level (multiple times for more)') |
| 93 | group.add_argument('--flakiness-dashboard-server', |
| 94 | dest='flakiness_dashboard_server', |
| 95 | help=('Address of the server that is hosting the ' |
| 96 | 'Chrome for Android flakiness dashboard.')) |
| 97 | group.add_argument('--enable-platform-mode', action='store_true', |
| 98 | help=('Run the test scripts in platform mode, which ' |
| 99 | 'conceptually separates the test runner from the ' |
| 100 | '"device" (local or remote, real or emulated) on ' |
| 101 | 'which the tests are running. [experimental]')) |
| 102 | group.add_argument('-e', '--environment', default='local', |
| 103 | choices=constants.VALID_ENVIRONMENTS, |
| 104 | help='Test environment to run in (default: %(default)s).') |
| 105 | group.add_argument('--adb-path', |
| 106 | help=('Specify the absolute path of the adb binary that ' |
| 107 | 'should be used.')) |
stip | a5733b5 | 2015-12-02 08:17:19 | [diff] [blame] | 108 | group.add_argument('--json-results-file', '--test-launcher-summary-output', |
| 109 | dest='json_results_file', |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 110 | help='If set, will dump results in JSON form ' |
| 111 | 'to specified file.') |
mikecase | b0bafb0 | 2016-02-09 04:24:44 | [diff] [blame] | 112 | |
| 113 | logcat_output_group = group.add_mutually_exclusive_group() |
| 114 | logcat_output_group.add_argument( |
| 115 | '--logcat-output-dir', |
| 116 | help='If set, will dump logcats recorded during test run to directory. ' |
| 117 | 'File names will be the device ids with timestamps.') |
| 118 | logcat_output_group.add_argument( |
| 119 | '--logcat-output-file', |
| 120 | help='If set, will merge logcats recorded during test run and dump them ' |
| 121 | 'to the specified file.') |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 122 | |
agrieve | 7acf04a | 2016-02-09 18:36:38 | [diff] [blame] | 123 | class FastLocalDevAction(argparse.Action): |
| 124 | def __call__(self, parser, namespace, values, option_string=None): |
| 125 | namespace.verbose_count = max(namespace.verbose_count, 1) |
| 126 | namespace.num_retries = 0 |
| 127 | namespace.enable_device_cache = True |
agrieve | 2e802760 | 2016-02-10 22:26:22 | [diff] [blame] | 128 | namespace.enable_concurrent_adb = True |
agrieve | 7acf04a | 2016-02-09 18:36:38 | [diff] [blame] | 129 | namespace.skip_clear_data = True |
| 130 | namespace.extract_test_list_from_filter = True |
| 131 | |
| 132 | group.add_argument('--fast-local-dev', type=bool, nargs=0, |
| 133 | action=FastLocalDevAction, |
| 134 | help='Alias for: --verbose --num-retries=0 ' |
agrieve | 2e802760 | 2016-02-10 22:26:22 | [diff] [blame] | 135 | '--enable-device-cache --enable-concurrent-adb ' |
| 136 | '--skip-clear-data --extract-test-list-from-filter') |
agrieve | 7acf04a | 2016-02-09 18:36:38 | [diff] [blame] | 137 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 138 | def ProcessCommonOptions(args): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 139 | """Processes and handles all common options.""" |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 140 | run_tests_helper.SetLogLevel(args.verbose_count) |
| 141 | constants.SetBuildType(args.build_type) |
| 142 | if args.build_directory: |
| 143 | constants.SetBuildDirectory(args.build_directory) |
| 144 | if args.output_directory: |
mikecase | 0aea9c5 | 2015-04-30 00:12:33 | [diff] [blame] | 145 | constants.SetOutputDirectory(args.output_directory) |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 146 | |
| 147 | devil_custom_deps = None |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 148 | if args.adb_path: |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 149 | devil_custom_deps = { |
| 150 | 'adb': { |
jbudorick | e29693be | 2015-12-07 15:53:23 | [diff] [blame] | 151 | devil_env.GetPlatform(): [args.adb_path] |
jbudorick | 0c2a94a | 2015-12-04 14:27:43 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | devil_chromium.Initialize( |
| 156 | output_directory=constants.GetOutDirectory(), |
| 157 | custom_deps=devil_custom_deps) |
| 158 | |
mikecase | 48e16bf | 2014-11-19 22:46:45 | [diff] [blame] | 159 | # Some things such as Forwarder require ADB to be in the environment path. |
| 160 | adb_dir = os.path.dirname(constants.GetAdbPath()) |
| 161 | if adb_dir and adb_dir not in os.environ['PATH'].split(os.pathsep): |
| 162 | os.environ['PATH'] = adb_dir + os.pathsep + os.environ['PATH'] |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 163 | |
| 164 | |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 165 | def AddRemoteDeviceOptions(parser): |
| 166 | group = parser.add_argument_group('Remote Device Options') |
| 167 | |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 168 | group.add_argument('--trigger', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 169 | help=('Only triggers the test if set. Stores test_run_id ' |
| 170 | 'in given file path. ')) |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 171 | group.add_argument('--collect', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 172 | help=('Only collects the test results if set. ' |
| 173 | 'Gets test_run_id from given file path.')) |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 174 | group.add_argument('--remote-device', action='append', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 175 | help='Device type to run test on.') |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 176 | group.add_argument('--results-path', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 177 | help='File path to download results to.') |
rnephew | 7f1e205 | 2014-12-12 23:00:11 | [diff] [blame] | 178 | group.add_argument('--api-protocol', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 179 | help='HTTP protocol to use. (http or https)') |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 180 | group.add_argument('--api-address', |
| 181 | help='Address to send HTTP requests.') |
| 182 | group.add_argument('--api-port', |
| 183 | help='Port to send HTTP requests to.') |
| 184 | group.add_argument('--runner-type', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 185 | help='Type of test to run as.') |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 186 | group.add_argument('--runner-package', |
| 187 | help='Package name of test.') |
| 188 | group.add_argument('--device-type', |
rnephew | a46fc56 | 2015-01-23 16:00:14 | [diff] [blame] | 189 | choices=constants.VALID_DEVICE_TYPES, |
| 190 | help=('Type of device to run on. iOS or android')) |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 191 | group.add_argument('--device-oem', action='append', |
| 192 | help='Device OEM to run on.') |
| 193 | group.add_argument('--remote-device-file', |
| 194 | help=('File with JSON to select remote device. ' |
| 195 | 'Overrides all other flags.')) |
rnephew | c9ae8f5 | 2015-02-13 03:02:55 | [diff] [blame] | 196 | group.add_argument('--remote-device-timeout', type=int, |
| 197 | help='Times to retry finding remote device') |
mikecase | 520cbbb5 | 2015-04-21 18:51:18 | [diff] [blame] | 198 | group.add_argument('--network-config', type=int, |
| 199 | help='Integer that specifies the network environment ' |
| 200 | 'that the tests will be run in.') |
mikecase | ddfa35d | 2015-10-28 01:14:27 | [diff] [blame] | 201 | group.add_argument('--test-timeout', type=int, |
| 202 | help='Test run timeout in seconds.') |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 203 | |
| 204 | device_os_group = group.add_mutually_exclusive_group() |
| 205 | device_os_group.add_argument('--remote-device-minimum-os', |
| 206 | help='Minimum OS on device.') |
| 207 | device_os_group.add_argument('--remote-device-os', action='append', |
| 208 | help='OS to have on the device.') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 209 | |
| 210 | api_secret_group = group.add_mutually_exclusive_group() |
| 211 | api_secret_group.add_argument('--api-secret', default='', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 212 | help='API secret for remote devices.') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 213 | api_secret_group.add_argument('--api-secret-file', default='', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 214 | help='Path to file that contains API secret.') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 215 | |
| 216 | api_key_group = group.add_mutually_exclusive_group() |
| 217 | api_key_group.add_argument('--api-key', default='', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 218 | help='API key for remote devices.') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 219 | api_key_group.add_argument('--api-key-file', default='', |
jbudorick | e6c56015 | 2015-01-13 23:49:28 | [diff] [blame] | 220 | help='Path to file that contains API key.') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 221 | |
| 222 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 223 | def AddDeviceOptions(parser): |
| 224 | """Adds device options to |parser|.""" |
| 225 | group = parser.add_argument_group(title='Device Options') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 226 | group.add_argument('--tool', |
| 227 | dest='tool', |
| 228 | help=('Run the test under a tool ' |
| 229 | '(use --tool help to list them)')) |
| 230 | group.add_argument('-d', '--device', dest='test_device', |
| 231 | help=('Target device for the test suite ' |
| 232 | 'to run on.')) |
jbudorick | dde688fb | 2015-08-27 03:00:17 | [diff] [blame] | 233 | group.add_argument('--blacklist-file', help='Device blacklist file.') |
agrieve | a538a14 | 2015-10-09 15:45:56 | [diff] [blame] | 234 | group.add_argument('--enable-device-cache', action='store_true', |
| 235 | help='Cache device state to disk between runs') |
agrieve | 8bcb52e | 2015-10-20 19:38:33 | [diff] [blame] | 236 | group.add_argument('--enable-concurrent-adb', action='store_true', |
| 237 | help='Run multiple adb commands at the same time, even ' |
| 238 | 'for the same device.') |
agrieve | cd243a2 | 2016-02-08 23:25:14 | [diff] [blame] | 239 | group.add_argument('--skip-clear-data', action='store_true', |
| 240 | help='Do not wipe app data between tests. Use this to ' |
| 241 | 'speed up local development and never on bots ' |
| 242 | '(increases flakiness)') |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 243 | |
| 244 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 245 | def AddGTestOptions(parser): |
| 246 | """Adds gtest options to |parser|.""" |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 247 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 248 | group = parser.add_argument_group('GTest Options') |
jbudorick | 15cdcd5 | 2014-12-03 19:58:49 | [diff] [blame] | 249 | group.add_argument('-s', '--suite', dest='suite_name', |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 250 | nargs='+', metavar='SUITE_NAME', required=True, |
jbudorick | 277f231 | 2015-09-24 16:37:43 | [diff] [blame] | 251 | help='Executable name of the test suite to run.') |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 252 | group.add_argument('--executable-dist-dir', |
| 253 | help="Path to executable's dist directory for native" |
| 254 | " (non-apk) tests.") |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 255 | group.add_argument('--test-apk-incremental-install-script', |
| 256 | help='Path to install script for the test apk.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 257 | group.add_argument('--gtest_also_run_disabled_tests', |
| 258 | '--gtest-also-run-disabled-tests', |
| 259 | dest='run_disabled', action='store_true', |
| 260 | help='Also run disabled tests if applicable.') |
| 261 | group.add_argument('-a', '--test-arguments', dest='test_arguments', |
| 262 | default='', |
| 263 | help='Additional arguments to pass to the test.') |
jbudorick | 24616eb | 2015-10-06 02:40:57 | [diff] [blame] | 264 | group.add_argument('-t', '--shard-timeout', |
mikecase | 68bcfc8 | 2016-01-22 20:14:38 | [diff] [blame] | 265 | dest='shard_timeout', type=int, default=120, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 266 | help='Timeout to wait for each test ' |
| 267 | '(default: %(default)s).') |
| 268 | group.add_argument('--isolate_file_path', |
| 269 | '--isolate-file-path', |
| 270 | dest='isolate_file_path', |
| 271 | help='.isolate file path to override the default ' |
| 272 | 'path') |
jbudorick | 5ee4589 | 2015-06-10 18:46:22 | [diff] [blame] | 273 | group.add_argument('--app-data-file', action='append', dest='app_data_files', |
| 274 | help='A file path relative to the app data directory ' |
| 275 | 'that should be saved to the host.') |
| 276 | group.add_argument('--app-data-file-dir', |
| 277 | help='Host directory to which app data files will be' |
| 278 | ' saved. Used with --app-data-file.') |
mlliu | d7f9fe9 | 2015-06-15 19:36:56 | [diff] [blame] | 279 | group.add_argument('--delete-stale-data', dest='delete_stale_data', |
| 280 | action='store_true', |
| 281 | help='Delete stale test data on the device.') |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 282 | group.add_argument('--repeat', '--gtest_repeat', '--gtest-repeat', |
| 283 | dest='repeat', type=int, default=0, |
| 284 | help='Number of times to repeat the specified set of ' |
| 285 | 'tests.') |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 286 | group.add_argument('--break-on-failure', '--break_on_failure', |
| 287 | dest='break_on_failure', action='store_true', |
| 288 | help='Whether to break on failure.') |
agrieve | 0f5e53e | 2016-02-04 03:47:37 | [diff] [blame] | 289 | group.add_argument('--extract-test-list-from-filter', |
| 290 | action='store_true', |
| 291 | help='When a test filter is specified, and the list of ' |
| 292 | 'tests can be determined from it, skip querying the ' |
| 293 | 'device for the list of all tests. Speeds up local ' |
| 294 | 'development, but is not safe to use on bots (' |
| 295 | 'http://crbug.com/549214') |
jbudorick | 442a693 | 2015-02-03 03:01:15 | [diff] [blame] | 296 | |
| 297 | filter_group = group.add_mutually_exclusive_group() |
| 298 | filter_group.add_argument('-f', '--gtest_filter', '--gtest-filter', |
| 299 | dest='test_filter', |
| 300 | help='googletest-style filter string.') |
| 301 | filter_group.add_argument('--gtest-filter-file', dest='test_filter_file', |
| 302 | help='Path to file that contains googletest-style ' |
| 303 | 'filter strings. (Lines will be joined with ' |
| 304 | '":" to create a single filter string.)') |
| 305 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 306 | AddDeviceOptions(parser) |
| 307 | AddCommonOptions(parser) |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 308 | AddRemoteDeviceOptions(parser) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 309 | |
| 310 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 311 | def AddLinkerTestOptions(parser): |
| 312 | group = parser.add_argument_group('Linker Test Options') |
| 313 | group.add_argument('-f', '--gtest-filter', dest='test_filter', |
| 314 | help='googletest-style filter string.') |
| 315 | AddCommonOptions(parser) |
| 316 | AddDeviceOptions(parser) |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 317 | |
| 318 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 319 | def AddJavaTestOptions(argument_group): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 320 | """Adds the Java test options to |option_parser|.""" |
| 321 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 322 | argument_group.add_argument( |
| 323 | '-f', '--test-filter', dest='test_filter', |
| 324 | help=('Test filter (if not fully qualified, will run all matches).')) |
| 325 | argument_group.add_argument( |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 326 | '--repeat', dest='repeat', type=int, default=0, |
| 327 | help='Number of times to repeat the specified set of tests.') |
| 328 | argument_group.add_argument( |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 329 | '--break-on-failure', '--break_on_failure', |
| 330 | dest='break_on_failure', action='store_true', |
| 331 | help='Whether to break on failure.') |
| 332 | argument_group.add_argument( |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 333 | '-A', '--annotation', dest='annotation_str', |
| 334 | help=('Comma-separated list of annotations. Run only tests with any of ' |
| 335 | 'the given annotations. An annotation can be either a key or a ' |
| 336 | 'key-values pair. A test that has no annotation is considered ' |
| 337 | '"SmallTest".')) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 338 | argument_group.add_argument( |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 339 | '-E', '--exclude-annotation', dest='exclude_annotation_str', |
| 340 | help=('Comma-separated list of annotations. Exclude tests with these ' |
| 341 | 'annotations.')) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 342 | argument_group.add_argument( |
jbudorick | cbcc115d | 2014-09-18 17:50:59 | [diff] [blame] | 343 | '--screenshot', dest='screenshot_failures', action='store_true', |
| 344 | help='Capture screenshots of test failures') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 345 | argument_group.add_argument( |
jbudorick | cbcc115d | 2014-09-18 17:50:59 | [diff] [blame] | 346 | '--save-perf-json', action='store_true', |
| 347 | help='Saves the JSON file for each UI Perf test.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 348 | argument_group.add_argument( |
jbudorick | cbcc115d | 2014-09-18 17:50:59 | [diff] [blame] | 349 | '--official-build', action='store_true', help='Run official build tests.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 350 | argument_group.add_argument( |
jbudorick | cbcc115d | 2014-09-18 17:50:59 | [diff] [blame] | 351 | '--test_data', '--test-data', action='append', default=[], |
| 352 | help=('Each instance defines a directory of test data that should be ' |
| 353 | 'copied to the target(s) before running the tests. The argument ' |
| 354 | 'should be of the form <target>:<source>, <target> is relative to ' |
| 355 | 'the device data directory, and <source> is relative to the ' |
| 356 | 'chromium build directory.')) |
davileen | 98efad1 | 2015-01-05 19:48:21 | [diff] [blame] | 357 | argument_group.add_argument( |
| 358 | '--disable-dalvik-asserts', dest='set_asserts', action='store_false', |
| 359 | default=True, help='Removes the dalvik.vm.enableassertions property') |
| 360 | |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 361 | |
| 362 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 363 | def ProcessJavaTestOptions(args): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 364 | """Processes options/arguments and populates |options| with defaults.""" |
| 365 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 366 | # TODO(jbudorick): Handle most of this function in argparse. |
| 367 | if args.annotation_str: |
| 368 | args.annotations = args.annotation_str.split(',') |
| 369 | elif args.test_filter: |
| 370 | args.annotations = [] |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 371 | else: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 372 | args.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', |
| 373 | 'EnormousTest', 'IntegrationTest'] |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 374 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 375 | if args.exclude_annotation_str: |
| 376 | args.exclude_annotations = args.exclude_annotation_str.split(',') |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 377 | else: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 378 | args.exclude_annotations = [] |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 379 | |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 380 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 381 | def AddInstrumentationTestOptions(parser): |
| 382 | """Adds Instrumentation test options to |parser|.""" |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 383 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 384 | parser.usage = '%(prog)s [options]' |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 385 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 386 | group = parser.add_argument_group('Instrumentation Test Options') |
| 387 | AddJavaTestOptions(group) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 388 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 389 | java_or_python_group = group.add_mutually_exclusive_group() |
| 390 | java_or_python_group.add_argument( |
| 391 | '-j', '--java-only', action='store_false', |
| 392 | dest='run_python_tests', default=True, help='Run only the Java tests.') |
| 393 | java_or_python_group.add_argument( |
| 394 | '-p', '--python-only', action='store_false', |
| 395 | dest='run_java_tests', default=True, |
| 396 | help='Run only the host-driven tests.') |
| 397 | |
| 398 | group.add_argument('--host-driven-root', |
| 399 | help='Root of the host-driven tests.') |
| 400 | group.add_argument('-w', '--wait_debugger', dest='wait_for_debugger', |
| 401 | action='store_true', |
| 402 | help='Wait for debugger.') |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 403 | group.add_argument('--apk-under-test', |
| 404 | help='Path or name of the apk under test.') |
| 405 | group.add_argument('--apk-under-test-incremental-install-script', |
| 406 | help='Path to install script for the --apk-under-test.') |
| 407 | group.add_argument('--test-apk', required=True, |
| 408 | help='Path or name of the apk containing the tests ' |
| 409 | '(name is without the .apk extension; ' |
| 410 | 'e.g. "ContentShellTest").') |
| 411 | group.add_argument('--test-apk-incremental-install-script', |
| 412 | help='Path to install script for the --test-apk.') |
mikecase | e725862 | 2015-09-29 13:47:35 | [diff] [blame] | 413 | group.add_argument('--additional-apk', action='append', |
mikecase | 8c4ab30 | 2015-09-29 17:03:29 | [diff] [blame] | 414 | dest='additional_apks', default=[], |
mikecase | e725862 | 2015-09-29 13:47:35 | [diff] [blame] | 415 | help='Additional apk that must be installed on ' |
| 416 | 'the device when the tests are run') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 417 | group.add_argument('--coverage-dir', |
| 418 | help=('Directory in which to place all generated ' |
| 419 | 'EMMA coverage files.')) |
| 420 | group.add_argument('--device-flags', dest='device_flags', default='', |
| 421 | help='The relative filepath to a file containing ' |
| 422 | 'command-line flags to set on the device') |
jbudorick | 911be58d | 2015-01-13 02:51:06 | [diff] [blame] | 423 | group.add_argument('--device-flags-file', default='', |
| 424 | help='The relative filepath to a file containing ' |
| 425 | 'command-line flags to set on the device') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 426 | group.add_argument('--isolate_file_path', |
| 427 | '--isolate-file-path', |
| 428 | dest='isolate_file_path', |
| 429 | help='.isolate file path to override the default ' |
| 430 | 'path') |
mlliu | d7f9fe9 | 2015-06-15 19:36:56 | [diff] [blame] | 431 | group.add_argument('--delete-stale-data', dest='delete_stale_data', |
| 432 | action='store_true', |
| 433 | help='Delete stale test data on the device.') |
jbudorick | ede4972 | 2015-11-25 05:16:34 | [diff] [blame] | 434 | group.add_argument('--timeout-scale', type=float, |
| 435 | help='Factor by which timeouts should be scaled.') |
wnwen | 1d20289 | 2016-02-02 20:22:58 | [diff] [blame] | 436 | group.add_argument('--strict-mode', dest='strict_mode', default='testing', |
wnwen | 2b56c15 | 2016-01-12 16:40:10 | [diff] [blame] | 437 | help='StrictMode command-line flag set on the device, ' |
| 438 | 'death/testing to kill the process, off to stop ' |
| 439 | 'checking, flash to flash only. Default testing.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 440 | |
| 441 | AddCommonOptions(parser) |
| 442 | AddDeviceOptions(parser) |
rnephew | e416dff | 2015-01-21 21:26:37 | [diff] [blame] | 443 | AddRemoteDeviceOptions(parser) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 444 | |
| 445 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 446 | def ProcessInstrumentationOptions(args): |
[email protected] | 2a68422 | 2013-08-01 16:59:22 | [diff] [blame] | 447 | """Processes options/arguments and populate |options| with defaults. |
| 448 | |
| 449 | Args: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 450 | args: argparse.Namespace object. |
[email protected] | 2a68422 | 2013-08-01 16:59:22 | [diff] [blame] | 451 | |
| 452 | Returns: |
| 453 | An InstrumentationOptions named tuple which contains all options relevant to |
| 454 | instrumentation tests. |
| 455 | """ |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 456 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 457 | ProcessJavaTestOptions(args) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 458 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 459 | if not args.host_driven_root: |
| 460 | args.run_python_tests = False |
[email protected] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 461 | |
jbudorick | 9ef3f955 | 2015-10-20 22:58:33 | [diff] [blame] | 462 | if os.path.exists(args.test_apk): |
| 463 | args.test_apk_path = args.test_apk |
| 464 | args.test_apk, _ = os.path.splitext(os.path.basename(args.test_apk)) |
| 465 | else: |
| 466 | args.test_apk_path = os.path.join( |
| 467 | constants.GetOutDirectory(), |
| 468 | constants.SDK_BUILD_APKS_DIR, |
| 469 | '%s.apk' % args.test_apk) |
| 470 | |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 471 | jar_basename = args.test_apk |
| 472 | if jar_basename.endswith('_incremental'): |
| 473 | jar_basename = jar_basename[:-len('_incremental')] |
| 474 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 475 | args.test_apk_jar_path = os.path.join( |
[email protected] | ae68d4a | 2013-09-24 21:57:15 | [diff] [blame] | 476 | constants.GetOutDirectory(), |
| 477 | constants.SDK_BUILD_TEST_JAVALIB_DIR, |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 478 | '%s.jar' % jar_basename) |
yusufo | 72c598c0 | 2015-07-16 23:40:20 | [diff] [blame] | 479 | args.test_support_apk_path = '%sSupport%s' % ( |
| 480 | os.path.splitext(args.test_apk_path)) |
[email protected] | 5e2f3f6 | 2014-06-23 12:31:46 | [diff] [blame] | 481 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 482 | args.test_runner = apk_helper.GetInstrumentationName(args.test_apk_path) |
[email protected] | 5e2f3f6 | 2014-06-23 12:31:46 | [diff] [blame] | 483 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 484 | # TODO(jbudorick): Get rid of InstrumentationOptions. |
[email protected] | 2a68422 | 2013-08-01 16:59:22 | [diff] [blame] | 485 | return instrumentation_test_options.InstrumentationOptions( |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 486 | args.tool, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 487 | args.annotations, |
| 488 | args.exclude_annotations, |
| 489 | args.test_filter, |
| 490 | args.test_data, |
| 491 | args.save_perf_json, |
| 492 | args.screenshot_failures, |
| 493 | args.wait_for_debugger, |
| 494 | args.coverage_dir, |
| 495 | args.test_apk, |
| 496 | args.test_apk_path, |
| 497 | args.test_apk_jar_path, |
| 498 | args.test_runner, |
| 499 | args.test_support_apk_path, |
| 500 | args.device_flags, |
davileen | 98efad1 | 2015-01-05 19:48:21 | [diff] [blame] | 501 | args.isolate_file_path, |
mlliu | d7f9fe9 | 2015-06-15 19:36:56 | [diff] [blame] | 502 | args.set_asserts, |
jbudorick | ede4972 | 2015-11-25 05:16:34 | [diff] [blame] | 503 | args.delete_stale_data, |
jbudorick | 248e31a | 2016-01-06 16:28:11 | [diff] [blame] | 504 | args.timeout_scale, |
| 505 | args.apk_under_test, |
wnwen | 2b56c15 | 2016-01-12 16:40:10 | [diff] [blame] | 506 | args.additional_apks, |
agrieve | cd243a2 | 2016-02-08 23:25:14 | [diff] [blame] | 507 | args.strict_mode, |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 508 | args.skip_clear_data, |
| 509 | args.test_apk_incremental_install_script, |
| 510 | args.apk_under_test_incremental_install_script) |
[email protected] | 2a68422 | 2013-08-01 16:59:22 | [diff] [blame] | 511 | |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 512 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 513 | def AddUIAutomatorTestOptions(parser): |
| 514 | """Adds UI Automator test options to |parser|.""" |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 515 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 516 | group = parser.add_argument_group('UIAutomator Test Options') |
| 517 | AddJavaTestOptions(group) |
| 518 | group.add_argument( |
| 519 | '--package', required=True, choices=constants.PACKAGE_INFO.keys(), |
| 520 | metavar='PACKAGE', help='Package under test.') |
| 521 | group.add_argument( |
| 522 | '--test-jar', dest='test_jar', required=True, |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 523 | help=('The name of the dexed jar containing the tests (without the ' |
| 524 | '.dex.jar extension). Alternatively, this can be a full path ' |
| 525 | 'to the jar.')) |
| 526 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 527 | AddCommonOptions(parser) |
| 528 | AddDeviceOptions(parser) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 529 | |
| 530 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 531 | def AddJUnitTestOptions(parser): |
| 532 | """Adds junit test options to |parser|.""" |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 533 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 534 | group = parser.add_argument_group('JUnit Test Options') |
| 535 | group.add_argument( |
| 536 | '-s', '--test-suite', dest='test_suite', required=True, |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 537 | help=('JUnit test suite to run.')) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 538 | group.add_argument( |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 539 | '-f', '--test-filter', dest='test_filter', |
| 540 | help='Filters tests googletest-style.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 541 | group.add_argument( |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 542 | '--package-filter', dest='package_filter', |
| 543 | help='Filters tests by package.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 544 | group.add_argument( |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 545 | '--runner-filter', dest='runner_filter', |
| 546 | help='Filters tests by runner class. Must be fully qualified.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 547 | group.add_argument( |
| 548 | '--sdk-version', dest='sdk_version', type=int, |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 549 | help='The Android SDK version.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 550 | AddCommonOptions(parser) |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 551 | |
| 552 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 553 | def AddMonkeyTestOptions(parser): |
| 554 | """Adds monkey test options to |parser|.""" |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 555 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 556 | group = parser.add_argument_group('Monkey Test Options') |
| 557 | group.add_argument( |
| 558 | '--package', required=True, choices=constants.PACKAGE_INFO.keys(), |
| 559 | metavar='PACKAGE', help='Package under test.') |
| 560 | group.add_argument( |
| 561 | '--event-count', default=10000, type=int, |
| 562 | help='Number of events to generate (default: %(default)s).') |
| 563 | group.add_argument( |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 564 | '--category', default='', |
[email protected] | fb81b98 | 2013-08-09 00:07:12 | [diff] [blame] | 565 | help='A list of allowed categories.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 566 | group.add_argument( |
| 567 | '--throttle', default=100, type=int, |
| 568 | help='Delay between events (ms) (default: %(default)s). ') |
| 569 | group.add_argument( |
| 570 | '--seed', type=int, |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 571 | help=('Seed value for pseudo-random generator. Same seed value generates ' |
| 572 | 'the same sequence of events. Seed is randomized by default.')) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 573 | group.add_argument( |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 574 | '--extra-args', default='', |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 575 | help=('String of other args to pass to the command verbatim.')) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 576 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 577 | AddCommonOptions(parser) |
| 578 | AddDeviceOptions(parser) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 579 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 580 | def ProcessMonkeyTestOptions(args): |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 581 | """Processes all monkey test options. |
| 582 | |
| 583 | Args: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 584 | args: argparse.Namespace object. |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 585 | |
| 586 | Returns: |
| 587 | A MonkeyOptions named tuple which contains all options relevant to |
| 588 | monkey tests. |
| 589 | """ |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 590 | # TODO(jbudorick): Handle this directly in argparse with nargs='+' |
| 591 | category = args.category |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 592 | if category: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 593 | category = args.category.split(',') |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 594 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 595 | # TODO(jbudorick): Get rid of MonkeyOptions. |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 596 | return monkey_test_options.MonkeyOptions( |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 597 | args.verbose_count, |
| 598 | args.package, |
| 599 | args.event_count, |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 600 | category, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 601 | args.throttle, |
| 602 | args.seed, |
| 603 | args.extra_args) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 604 | |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 605 | def AddUirobotTestOptions(parser): |
| 606 | """Adds uirobot test options to |option_parser|.""" |
| 607 | group = parser.add_argument_group('Uirobot Test Options') |
| 608 | |
rnephew | efe44b4 | 2015-02-04 04:45:15 | [diff] [blame] | 609 | group.add_argument('--app-under-test', required=True, |
| 610 | help='APK to run tests on.') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 611 | group.add_argument( |
mikecase | afa4384 | 2015-10-19 23:04:12 | [diff] [blame] | 612 | '--repeat', dest='repeat', type=int, default=0, |
| 613 | help='Number of times to repeat the uirobot test.') |
| 614 | group.add_argument( |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 615 | '--minutes', default=5, type=int, |
jbudorick | 676b120 | 2015-02-06 22:02:27 | [diff] [blame] | 616 | help='Number of minutes to run uirobot test [default: %(default)s].') |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 617 | |
| 618 | AddCommonOptions(parser) |
| 619 | AddDeviceOptions(parser) |
| 620 | AddRemoteDeviceOptions(parser) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 621 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 622 | def AddPerfTestOptions(parser): |
| 623 | """Adds perf test options to |parser|.""" |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 624 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 625 | group = parser.add_argument_group('Perf Test Options') |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 626 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 627 | class SingleStepAction(argparse.Action): |
| 628 | def __call__(self, parser, namespace, values, option_string=None): |
| 629 | if values and not namespace.single_step: |
| 630 | parser.error('single step command provided, ' |
| 631 | 'but --single-step not specified.') |
| 632 | elif namespace.single_step and not values: |
| 633 | parser.error('--single-step specified, ' |
| 634 | 'but no single step command provided.') |
| 635 | setattr(namespace, self.dest, values) |
| 636 | |
| 637 | step_group = group.add_mutually_exclusive_group(required=True) |
| 638 | # TODO(jbudorick): Revise --single-step to use argparse.REMAINDER. |
| 639 | # This requires removing "--" from client calls. |
| 640 | step_group.add_argument( |
| 641 | '--single-step', action='store_true', |
[email protected] | def4bce | 2013-11-12 12:59:52 | [diff] [blame] | 642 | help='Execute the given command with retries, but only print the result ' |
| 643 | 'for the "most successful" round.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 644 | step_group.add_argument( |
[email protected] | 181a5c9 | 2013-09-06 17:11:46 | [diff] [blame] | 645 | '--steps', |
[email protected] | def4bce | 2013-11-12 12:59:52 | [diff] [blame] | 646 | help='JSON file containing the list of commands to run.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 647 | step_group.add_argument( |
| 648 | '--print-step', |
| 649 | help='The name of a previously executed perf step to print.') |
| 650 | |
| 651 | group.add_argument( |
peter | bd4e73d | 2014-12-03 15:47:36 | [diff] [blame] | 652 | '--output-json-list', |
| 653 | help='Write a simple list of names from --steps into the given file.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 654 | group.add_argument( |
peter | bd4e73d | 2014-12-03 15:47:36 | [diff] [blame] | 655 | '--collect-chartjson-data', |
| 656 | action='store_true', |
| 657 | help='Cache the chartjson output from each step for later use.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 658 | group.add_argument( |
peter | bd4e73d | 2014-12-03 15:47:36 | [diff] [blame] | 659 | '--output-chartjson-data', |
| 660 | default='', |
| 661 | help='Write out chartjson into the given file.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 662 | group.add_argument( |
perezju | 67cf7f1 | 2015-09-29 11:39:05 | [diff] [blame] | 663 | '--get-output-dir-archive', metavar='FILENAME', |
| 664 | help='Write the chached output directory archived by a step into the' |
| 665 | ' given ZIP file.') |
| 666 | group.add_argument( |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 667 | '--flaky-steps', |
| 668 | help=('A JSON file containing steps that are flaky ' |
| 669 | 'and will have its exit code ignored.')) |
| 670 | group.add_argument( |
[email protected] | 181a5c9 | 2013-09-06 17:11:46 | [diff] [blame] | 671 | '--no-timeout', action='store_true', |
| 672 | help=('Do not impose a timeout. Each perf step is responsible for ' |
| 673 | 'implementing the timeout logic.')) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 674 | group.add_argument( |
[email protected] | 650487c | 2013-09-30 11:40:49 | [diff] [blame] | 675 | '-f', '--test-filter', |
| 676 | help=('Test filter (will match against the names listed in --steps).')) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 677 | group.add_argument( |
| 678 | '--dry-run', action='store_true', |
[email protected] | 650487c | 2013-09-30 11:40:49 | [diff] [blame] | 679 | help='Just print the steps without executing.') |
jbudorick | 5cfff87 | 2015-07-01 18:46:13 | [diff] [blame] | 680 | # Uses 0.1 degrees C because that's what Android does. |
| 681 | group.add_argument( |
| 682 | '--max-battery-temp', type=int, |
| 683 | help='Only start tests when the battery is at or below the given ' |
| 684 | 'temperature (0.1 C)') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 685 | group.add_argument('single_step_command', nargs='*', action=SingleStepAction, |
| 686 | help='If --single-step is specified, the command to run.') |
rnephew | dde05da8 | 2015-07-09 20:31:01 | [diff] [blame] | 687 | group.add_argument('--min-battery-level', type=int, |
| 688 | help='Only starts tests when the battery is charged above ' |
| 689 | 'given level.') |
rnephew | a66f5999 | 2016-02-26 18:29:05 | [diff] [blame] | 690 | group.add_argument('--known-devices-file', help='Path to known device list.') |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 691 | AddCommonOptions(parser) |
| 692 | AddDeviceOptions(parser) |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 693 | |
| 694 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 695 | def ProcessPerfTestOptions(args): |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 696 | """Processes all perf test options. |
| 697 | |
| 698 | Args: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 699 | args: argparse.Namespace object. |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 700 | |
| 701 | Returns: |
| 702 | A PerfOptions named tuple which contains all options relevant to |
| 703 | perf tests. |
| 704 | """ |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 705 | # TODO(jbudorick): Move single_step handling down into the perf tests. |
| 706 | if args.single_step: |
| 707 | args.single_step = ' '.join(args.single_step_command) |
| 708 | # TODO(jbudorick): Get rid of PerfOptions. |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 709 | return perf_test_options.PerfOptions( |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 710 | args.steps, args.flaky_steps, args.output_json_list, |
| 711 | args.print_step, args.no_timeout, args.test_filter, |
| 712 | args.dry_run, args.single_step, args.collect_chartjson_data, |
perezju | 67cf7f1 | 2015-09-29 11:39:05 | [diff] [blame] | 713 | args.output_chartjson_data, args.get_output_dir_archive, |
rnephew | a66f5999 | 2016-02-26 18:29:05 | [diff] [blame] | 714 | args.max_battery_temp, args.min_battery_level, |
| 715 | args.known_devices_file) |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 716 | |
| 717 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 718 | def AddPythonTestOptions(parser): |
| 719 | group = parser.add_argument_group('Python Test Options') |
| 720 | group.add_argument( |
| 721 | '-s', '--suite', dest='suite_name', metavar='SUITE_NAME', |
| 722 | choices=constants.PYTHON_UNIT_TEST_SUITES.keys(), |
| 723 | help='Name of the test suite to run.') |
| 724 | AddCommonOptions(parser) |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 725 | |
| 726 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 727 | def _RunLinkerTests(args, devices): |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 728 | """Subcommand of RunTestsCommands which runs linker tests.""" |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 729 | runner_factory, tests = linker_setup.Setup(args, devices) |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 730 | |
| 731 | results, exit_code = test_dispatcher.RunTests( |
| 732 | tests, runner_factory, devices, shard=True, test_timeout=60, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 733 | num_retries=args.num_retries) |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 734 | |
| 735 | report_results.LogFull( |
| 736 | results=results, |
| 737 | test_type='Linker test', |
[email protected] | 93c9f9b | 2014-02-10 16:19:22 | [diff] [blame] | 738 | test_package='ChromiumLinkerTest') |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 739 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 740 | if args.json_results_file: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 741 | json_results.GenerateJsonResultsFile([results], args.json_results_file) |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 742 | |
[email protected] | 6b6abac6d | 2013-10-03 11:56:38 | [diff] [blame] | 743 | return exit_code |
| 744 | |
| 745 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 746 | def _RunInstrumentationTests(args, devices): |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 747 | """Subcommand of RunTestsCommands which runs instrumentation tests.""" |
jbudorick | 58b4d36 | 2015-09-08 16:44:59 | [diff] [blame] | 748 | logging.info('_RunInstrumentationTests(%s, %s)', str(args), str(devices)) |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 749 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 750 | instrumentation_options = ProcessInstrumentationOptions(args) |
| 751 | |
| 752 | if len(devices) > 1 and args.wait_for_debugger: |
[email protected] | f7148dd4 | 2013-08-20 14:24:57 | [diff] [blame] | 753 | logging.warning('Debugger can not be sharded, using first available device') |
| 754 | devices = devices[:1] |
| 755 | |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 756 | results = base_test_result.TestRunResults() |
| 757 | exit_code = 0 |
| 758 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 759 | if args.run_java_tests: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 760 | java_runner_factory, java_tests = instrumentation_setup.Setup( |
mikecase | 526d68e | 2014-11-19 20:02:05 | [diff] [blame] | 761 | instrumentation_options, devices) |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 762 | else: |
| 763 | java_runner_factory = None |
| 764 | java_tests = None |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 765 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 766 | if args.run_python_tests: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 767 | py_runner_factory, py_tests = host_driven_setup.InstrumentationSetup( |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 768 | args.host_driven_root, args.official_build, |
[email protected] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 769 | instrumentation_options) |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 770 | else: |
| 771 | py_runner_factory = None |
| 772 | py_tests = None |
[email protected] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 773 | |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 774 | results = [] |
| 775 | repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 |
| 776 | else itertools.count()) |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 777 | |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 778 | code_counts = {constants.INFRA_EXIT_CODE: 0, |
| 779 | constants.ERROR_EXIT_CODE: 0, |
| 780 | constants.WARNING_EXIT_CODE: 0, |
| 781 | 0: 0} |
| 782 | |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 783 | def _escalate_code(old, new): |
| 784 | for x in (constants.INFRA_EXIT_CODE, |
| 785 | constants.ERROR_EXIT_CODE, |
| 786 | constants.WARNING_EXIT_CODE): |
| 787 | if x in (old, new): |
| 788 | return x |
| 789 | return 0 |
| 790 | |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 791 | for _ in repetitions: |
| 792 | iteration_results = base_test_result.TestRunResults() |
| 793 | if java_tests: |
[email protected] | 3402002 | 2013-08-06 23:35:34 | [diff] [blame] | 794 | test_results, test_exit_code = test_dispatcher.RunTests( |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 795 | java_tests, java_runner_factory, devices, shard=True, |
| 796 | test_timeout=None, num_retries=args.num_retries) |
| 797 | iteration_results.AddTestRunResults(test_results) |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 798 | |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 799 | code_counts[test_exit_code] += 1 |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 800 | exit_code = _escalate_code(exit_code, test_exit_code) |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 801 | |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 802 | if py_tests: |
| 803 | test_results, test_exit_code = test_dispatcher.RunTests( |
| 804 | py_tests, py_runner_factory, devices, shard=True, test_timeout=None, |
| 805 | num_retries=args.num_retries) |
| 806 | iteration_results.AddTestRunResults(test_results) |
[email protected] | 4f777ca | 2014-08-08 01:45:59 | [diff] [blame] | 807 | |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 808 | code_counts[test_exit_code] += 1 |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 809 | exit_code = _escalate_code(exit_code, test_exit_code) |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 810 | |
| 811 | results.append(iteration_results) |
| 812 | report_results.LogFull( |
| 813 | results=iteration_results, |
| 814 | test_type='Instrumentation', |
| 815 | test_package=os.path.basename(args.test_apk), |
| 816 | annotation=args.annotations, |
| 817 | flakiness_server=args.flakiness_dashboard_server) |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 818 | |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 819 | |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 820 | if args.break_on_failure and exit_code in (constants.ERROR_EXIT_CODE, |
| 821 | constants.INFRA_EXIT_CODE): |
| 822 | break |
| 823 | |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 824 | logging.critical('Instr tests: %s success, %s infra, %s errors, %s warnings', |
| 825 | str(code_counts[0]), |
| 826 | str(code_counts[constants.INFRA_EXIT_CODE]), |
| 827 | str(code_counts[constants.ERROR_EXIT_CODE]), |
| 828 | str(code_counts[constants.WARNING_EXIT_CODE])) |
| 829 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 830 | if args.json_results_file: |
| 831 | json_results.GenerateJsonResultsFile(results, args.json_results_file) |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 832 | |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 833 | return exit_code |
| 834 | |
| 835 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 836 | def _RunJUnitTests(args): |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 837 | """Subcommand of RunTestsCommand which runs junit tests.""" |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 838 | runner_factory, tests = junit_setup.Setup(args) |
mikecase | c638a07 | 2015-04-01 16:35:35 | [diff] [blame] | 839 | results, exit_code = junit_dispatcher.RunTests(tests, runner_factory) |
| 840 | |
| 841 | report_results.LogFull( |
| 842 | results=results, |
| 843 | test_type='JUnit', |
| 844 | test_package=args.test_suite) |
| 845 | |
mikecase | 572401b | 2015-04-09 02:28:57 | [diff] [blame] | 846 | if args.json_results_file: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 847 | json_results.GenerateJsonResultsFile([results], args.json_results_file) |
mikecase | 572401b | 2015-04-09 02:28:57 | [diff] [blame] | 848 | |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 849 | return exit_code |
| 850 | |
| 851 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 852 | def _RunMonkeyTests(args, devices): |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 853 | """Subcommand of RunTestsCommands which runs monkey tests.""" |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 854 | monkey_options = ProcessMonkeyTestOptions(args) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 855 | |
| 856 | runner_factory, tests = monkey_setup.Setup(monkey_options) |
| 857 | |
| 858 | results, exit_code = test_dispatcher.RunTests( |
[email protected] | 181a5c9 | 2013-09-06 17:11:46 | [diff] [blame] | 859 | tests, runner_factory, devices, shard=False, test_timeout=None, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 860 | num_retries=args.num_retries) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 861 | |
| 862 | report_results.LogFull( |
| 863 | results=results, |
| 864 | test_type='Monkey', |
[email protected] | 14b3b120 | 2013-08-15 22:25:28 | [diff] [blame] | 865 | test_package='Monkey') |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 866 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 867 | if args.json_results_file: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 868 | json_results.GenerateJsonResultsFile([results], args.json_results_file) |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 869 | |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 870 | return exit_code |
| 871 | |
| 872 | |
jbudorick | dde688fb | 2015-08-27 03:00:17 | [diff] [blame] | 873 | def _RunPerfTests(args, active_devices): |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 874 | """Subcommand of RunTestsCommands which runs perf tests.""" |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 875 | perf_options = ProcessPerfTestOptions(args) |
[email protected] | 61487ed | 2014-06-09 12:33:56 | [diff] [blame] | 876 | |
| 877 | # Just save a simple json with a list of test names. |
| 878 | if perf_options.output_json_list: |
| 879 | return perf_test_runner.OutputJsonList( |
| 880 | perf_options.steps, perf_options.output_json_list) |
| 881 | |
[email protected] | ad32f31 | 2013-11-13 04:03:29 | [diff] [blame] | 882 | # Just print the results from a single previously executed step. |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 883 | if perf_options.print_step: |
simonhatch | 9b9256d | 2015-01-07 18:03:42 | [diff] [blame] | 884 | return perf_test_runner.PrintTestOutput( |
perezju | 67cf7f1 | 2015-09-29 11:39:05 | [diff] [blame] | 885 | perf_options.print_step, perf_options.output_chartjson_data, |
| 886 | perf_options.get_output_dir_archive) |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 887 | |
jbudorick | dde688fb | 2015-08-27 03:00:17 | [diff] [blame] | 888 | runner_factory, tests, devices = perf_setup.Setup( |
| 889 | perf_options, active_devices) |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 890 | |
[email protected] | a72f075 | 2014-06-03 23:52:34 | [diff] [blame] | 891 | # shard=False means that each device will get the full list of tests |
| 892 | # and then each one will decide their own affinity. |
| 893 | # shard=True means each device will pop the next test available from a queue, |
| 894 | # which increases throughput but have no affinity. |
[email protected] | 86184c7b | 2013-08-15 15:06:57 | [diff] [blame] | 895 | results, _ = test_dispatcher.RunTests( |
[email protected] | a72f075 | 2014-06-03 23:52:34 | [diff] [blame] | 896 | tests, runner_factory, devices, shard=False, test_timeout=None, |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 897 | num_retries=args.num_retries) |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 898 | |
| 899 | report_results.LogFull( |
| 900 | results=results, |
| 901 | test_type='Perf', |
[email protected] | 865a47a | 2013-08-16 14:01:12 | [diff] [blame] | 902 | test_package='Perf') |
[email protected] | def4bce | 2013-11-12 12:59:52 | [diff] [blame] | 903 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 904 | if args.json_results_file: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 905 | json_results.GenerateJsonResultsFile([results], args.json_results_file) |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 906 | |
[email protected] | def4bce | 2013-11-12 12:59:52 | [diff] [blame] | 907 | if perf_options.single_step: |
| 908 | return perf_test_runner.PrintTestOutput('single_step') |
| 909 | |
[email protected] | 11ce845 | 2014-02-17 10:55:03 | [diff] [blame] | 910 | perf_test_runner.PrintSummary(tests) |
| 911 | |
[email protected] | 86184c7b | 2013-08-15 15:06:57 | [diff] [blame] | 912 | # Always return 0 on the sharding stage. Individual tests exit_code |
| 913 | # will be returned on the print_step stage. |
| 914 | return 0 |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 915 | |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 916 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 917 | def _RunPythonTests(args): |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 918 | """Subcommand of RunTestsCommand which runs python unit tests.""" |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 919 | suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name] |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 920 | suite_path = suite_vars['path'] |
| 921 | suite_test_modules = suite_vars['test_modules'] |
| 922 | |
| 923 | sys.path = [suite_path] + sys.path |
| 924 | try: |
| 925 | suite = unittest.TestSuite() |
| 926 | suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m) |
| 927 | for m in suite_test_modules) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 928 | runner = unittest.TextTestRunner(verbosity=1+args.verbose_count) |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 929 | return 0 if runner.run(suite).wasSuccessful() else 1 |
| 930 | finally: |
| 931 | sys.path = sys.path[1:] |
| 932 | |
| 933 | |
agrieve | ebc6bfa | 2016-04-05 19:29:25 | [diff] [blame] | 934 | def _GetAttachedDevices(blacklist_file, test_device, enable_cache, num_retries): |
[email protected] | f7148dd4 | 2013-08-20 14:24:57 | [diff] [blame] | 935 | """Get all attached devices. |
| 936 | |
| 937 | Args: |
agrieve | a538a14 | 2015-10-09 15:45:56 | [diff] [blame] | 938 | blacklist_file: Path to device blacklist. |
[email protected] | f7148dd4 | 2013-08-20 14:24:57 | [diff] [blame] | 939 | test_device: Name of a specific device to use. |
agrieve | a538a14 | 2015-10-09 15:45:56 | [diff] [blame] | 940 | enable_cache: Whether to enable checksum caching. |
[email protected] | f7148dd4 | 2013-08-20 14:24:57 | [diff] [blame] | 941 | |
| 942 | Returns: |
| 943 | A list of attached devices. |
| 944 | """ |
jbudorick | a583ba3 | 2015-09-11 17:23:19 | [diff] [blame] | 945 | blacklist = (device_blacklist.Blacklist(blacklist_file) |
| 946 | if blacklist_file |
| 947 | else None) |
jbudorick | dde688fb | 2015-08-27 03:00:17 | [diff] [blame] | 948 | |
agrieve | a538a14 | 2015-10-09 15:45:56 | [diff] [blame] | 949 | attached_devices = device_utils.DeviceUtils.HealthyDevices( |
agrieve | ebc6bfa | 2016-04-05 19:29:25 | [diff] [blame] | 950 | blacklist, enable_device_files_cache=enable_cache, |
| 951 | default_retries=num_retries) |
aberent | 6a02a618 | 2015-04-29 11:07:55 | [diff] [blame] | 952 | if test_device: |
jbudorick | 4551d0dc | 2015-04-29 16:07:06 | [diff] [blame] | 953 | test_device = [d for d in attached_devices if d == test_device] |
| 954 | if not test_device: |
| 955 | raise device_errors.DeviceUnreachableError( |
| 956 | 'Did not find device %s among attached device. Attached devices: %s' |
| 957 | % (test_device, ', '.join(attached_devices))) |
| 958 | return test_device |
aberent | 6a02a618 | 2015-04-29 11:07:55 | [diff] [blame] | 959 | |
jbudorick | 4551d0dc | 2015-04-29 16:07:06 | [diff] [blame] | 960 | else: |
| 961 | if not attached_devices: |
| 962 | raise device_errors.NoDevicesError() |
| 963 | return sorted(attached_devices) |
[email protected] | f7148dd4 | 2013-08-20 14:24:57 | [diff] [blame] | 964 | |
| 965 | |
agrieve | 63d2078 | 2016-02-04 17:47:26 | [diff] [blame] | 966 | def RunTestsCommand(args): # pylint: disable=too-many-return-statements |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 967 | """Checks test type and dispatches to the appropriate function. |
| 968 | |
| 969 | Args: |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 970 | args: argparse.Namespace object. |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 971 | |
| 972 | Returns: |
| 973 | Integer indicated exit code. |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 974 | |
| 975 | Raises: |
| 976 | Exception: Unknown command name passed in, or an exception from an |
| 977 | individual test runner. |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 978 | """ |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 979 | command = args.command |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 980 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 981 | ProcessCommonOptions(args) |
jbudorick | 2be28ee | 2016-02-16 15:53:23 | [diff] [blame] | 982 | logging.info('command: %s', ' '.join(sys.argv)) |
[email protected] | d82f025 | 2013-07-12 23:22:57 | [diff] [blame] | 983 | |
jbudorick | b71170d0 | 2016-03-30 01:32:08 | [diff] [blame] | 984 | if args.enable_platform_mode or command in ('gtest', 'instrumentation'): |
agrieve | 63d2078 | 2016-02-04 17:47:26 | [diff] [blame] | 985 | return RunTestsInPlatformMode(args) |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 986 | |
[email protected] | c0662e09 | 2013-11-12 11:51:25 | [diff] [blame] | 987 | forwarder.Forwarder.RemoveHostLog() |
[email protected] | 6b11583b | 2013-11-21 16:18:40 | [diff] [blame] | 988 | if not ports.ResetTestServerPortAllocation(): |
| 989 | raise Exception('Failed to reset test server port.') |
[email protected] | c0662e09 | 2013-11-12 11:51:25 | [diff] [blame] | 990 | |
agrieve | 18930bd | 2015-10-09 17:41:42 | [diff] [blame] | 991 | def get_devices(): |
| 992 | return _GetAttachedDevices(args.blacklist_file, args.test_device, |
agrieve | ebc6bfa | 2016-04-05 19:29:25 | [diff] [blame] | 993 | args.enable_device_cache, args.num_retries) |
agrieve | 18930bd | 2015-10-09 17:41:42 | [diff] [blame] | 994 | |
jbudorick | b71170d0 | 2016-03-30 01:32:08 | [diff] [blame] | 995 | if command == 'linker': |
agrieve | 18930bd | 2015-10-09 17:41:42 | [diff] [blame] | 996 | return _RunLinkerTests(args, get_devices()) |
jbudorick | 9a6b7b33 | 2014-09-20 00:01:07 | [diff] [blame] | 997 | elif command == 'junit': |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 998 | return _RunJUnitTests(args) |
[email protected] | 3dbdfa4 | 2013-08-08 01:08:14 | [diff] [blame] | 999 | elif command == 'monkey': |
agrieve | 18930bd | 2015-10-09 17:41:42 | [diff] [blame] | 1000 | return _RunMonkeyTests(args, get_devices()) |
[email protected] | ec3170b | 2013-08-14 14:39:47 | [diff] [blame] | 1001 | elif command == 'perf': |
agrieve | 18930bd | 2015-10-09 17:41:42 | [diff] [blame] | 1002 | return _RunPerfTests(args, get_devices()) |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 1003 | elif command == 'python': |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1004 | return _RunPythonTests(args) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1005 | else: |
[email protected] | 6bc1bda2 | 2013-07-19 22:08:37 | [diff] [blame] | 1006 | raise Exception('Unknown test type.') |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1007 | |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1008 | |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 1009 | _SUPPORTED_IN_PLATFORM_MODE = [ |
| 1010 | # TODO(jbudorick): Add support for more test types. |
jbudorick | 911be58d | 2015-01-13 02:51:06 | [diff] [blame] | 1011 | 'gtest', |
| 1012 | 'instrumentation', |
| 1013 | 'uirobot', |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 1014 | ] |
| 1015 | |
| 1016 | |
agrieve | 63d2078 | 2016-02-04 17:47:26 | [diff] [blame] | 1017 | def RunTestsInPlatformMode(args): |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 1018 | |
jbudorick | 566592ab | 2015-09-21 15:32:47 | [diff] [blame] | 1019 | def infra_error(message): |
agrieve | 63d2078 | 2016-02-04 17:47:26 | [diff] [blame] | 1020 | logging.fatal(message) |
| 1021 | sys.exit(constants.INFRA_EXIT_CODE) |
jbudorick | b9b0ada | 2015-09-17 22:52:58 | [diff] [blame] | 1022 | |
jbudorick | 566592ab | 2015-09-21 15:32:47 | [diff] [blame] | 1023 | if args.command not in _SUPPORTED_IN_PLATFORM_MODE: |
| 1024 | infra_error('%s is not yet supported in platform mode' % args.command) |
| 1025 | |
| 1026 | with environment_factory.CreateEnvironment(args, infra_error) as env: |
| 1027 | with test_instance_factory.CreateTestInstance(args, infra_error) as test: |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 1028 | with test_run_factory.CreateTestRun( |
jbudorick | 566592ab | 2015-09-21 15:32:47 | [diff] [blame] | 1029 | args, env, test, infra_error) as test_run: |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 1030 | results = [] |
| 1031 | repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 |
| 1032 | else itertools.count()) |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 1033 | result_counts = collections.defaultdict( |
| 1034 | lambda: collections.defaultdict(int)) |
| 1035 | iteration_count = 0 |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 1036 | for _ in repetitions: |
| 1037 | iteration_results = test_run.RunTests() |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 1038 | if iteration_results is not None: |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 1039 | iteration_count += 1 |
jbudorick | d4f7798 | 2015-09-28 21:09:18 | [diff] [blame] | 1040 | results.append(iteration_results) |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 1041 | for r in iteration_results.GetAll(): |
| 1042 | result_counts[r.GetName()][r.GetType()] += 1 |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 1043 | report_results.LogFull( |
| 1044 | results=iteration_results, |
| 1045 | test_type=test.TestType(), |
| 1046 | test_package=test_run.TestPackage(), |
| 1047 | annotation=getattr(args, 'annotations', None), |
| 1048 | flakiness_server=getattr(args, 'flakiness_dashboard_server', |
| 1049 | None)) |
alexandermont | a3f03bf | 2015-12-02 18:56:45 | [diff] [blame] | 1050 | if args.break_on_failure and not iteration_results.DidRunPass(): |
| 1051 | break |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 1052 | |
alexandermont | e2cbe02 | 2015-12-16 04:58:58 | [diff] [blame] | 1053 | if iteration_count > 1: |
| 1054 | # display summary results |
| 1055 | # only display results for a test if at least one test did not pass |
| 1056 | all_pass = 0 |
| 1057 | tot_tests = 0 |
| 1058 | for test_name in result_counts: |
| 1059 | tot_tests += 1 |
| 1060 | if any(result_counts[test_name][x] for x in ( |
| 1061 | base_test_result.ResultType.FAIL, |
| 1062 | base_test_result.ResultType.CRASH, |
| 1063 | base_test_result.ResultType.TIMEOUT, |
| 1064 | base_test_result.ResultType.UNKNOWN)): |
| 1065 | logging.critical( |
| 1066 | '%s: %s', |
| 1067 | test_name, |
| 1068 | ', '.join('%s %s' % (str(result_counts[test_name][i]), i) |
| 1069 | for i in base_test_result.ResultType.GetTypes())) |
| 1070 | else: |
| 1071 | all_pass += 1 |
| 1072 | |
| 1073 | logging.critical('%s of %s tests passed in all %s runs', |
| 1074 | str(all_pass), |
| 1075 | str(tot_tests), |
| 1076 | str(iteration_count)) |
| 1077 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1078 | if args.json_results_file: |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 1079 | json_results.GenerateJsonResultsFile( |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1080 | results, args.json_results_file) |
jbudorick | b8c4207 | 2014-12-01 18:07:54 | [diff] [blame] | 1081 | |
jbudorick | eb7ea71c | 2015-09-28 16:40:20 | [diff] [blame] | 1082 | return (0 if all(r.DidRunPass() for r in results) |
| 1083 | else constants.ERROR_EXIT_CODE) |
jbudorick | 66dc372 | 2014-11-06 21:33:51 | [diff] [blame] | 1084 | |
| 1085 | |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1086 | CommandConfigTuple = collections.namedtuple( |
| 1087 | 'CommandConfigTuple', |
| 1088 | ['add_options_func', 'help_txt']) |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1089 | VALID_COMMANDS = { |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1090 | 'gtest': CommandConfigTuple( |
| 1091 | AddGTestOptions, |
| 1092 | 'googletest-based C++ tests'), |
| 1093 | 'instrumentation': CommandConfigTuple( |
| 1094 | AddInstrumentationTestOptions, |
| 1095 | 'InstrumentationTestCase-based Java tests'), |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1096 | 'junit': CommandConfigTuple( |
| 1097 | AddJUnitTestOptions, |
| 1098 | 'JUnit4-based Java tests'), |
| 1099 | 'monkey': CommandConfigTuple( |
| 1100 | AddMonkeyTestOptions, |
| 1101 | "Tests based on Android's monkey"), |
| 1102 | 'perf': CommandConfigTuple( |
| 1103 | AddPerfTestOptions, |
| 1104 | 'Performance tests'), |
| 1105 | 'python': CommandConfigTuple( |
| 1106 | AddPythonTestOptions, |
| 1107 | 'Python tests based on unittest.TestCase'), |
| 1108 | 'linker': CommandConfigTuple( |
| 1109 | AddLinkerTestOptions, |
| 1110 | 'Linker tests'), |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 1111 | 'uirobot': CommandConfigTuple( |
| 1112 | AddUirobotTestOptions, |
| 1113 | 'Uirobot test'), |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1114 | } |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1115 | |
| 1116 | |
[email protected] | 7c53a60 | 2014-03-24 16:21:44 | [diff] [blame] | 1117 | def DumpThreadStacks(_signal, _frame): |
[email protected] | 71aec4b | 2013-11-20 00:35:24 | [diff] [blame] | 1118 | for thread in threading.enumerate(): |
| 1119 | reraiser_thread.LogThreadStack(thread) |
[email protected] | 83bb815 | 2013-11-19 15:02:21 | [diff] [blame] | 1120 | |
| 1121 | |
[email protected] | 7c53a60 | 2014-03-24 16:21:44 | [diff] [blame] | 1122 | def main(): |
[email protected] | 83bb815 | 2013-11-19 15:02:21 | [diff] [blame] | 1123 | signal.signal(signal.SIGUSR1, DumpThreadStacks) |
jam | a47ca85c | 2014-12-03 18:38:07 | [diff] [blame] | 1124 | |
| 1125 | parser = argparse.ArgumentParser() |
| 1126 | command_parsers = parser.add_subparsers(title='test types', |
| 1127 | dest='command') |
| 1128 | |
| 1129 | for test_type, config in sorted(VALID_COMMANDS.iteritems(), |
| 1130 | key=lambda x: x[0]): |
| 1131 | subparser = command_parsers.add_parser( |
| 1132 | test_type, usage='%(prog)s [options]', help=config.help_txt) |
| 1133 | config.add_options_func(subparser) |
| 1134 | |
| 1135 | args = parser.parse_args() |
mikecase | e7405102 | 2015-02-26 23:08:22 | [diff] [blame] | 1136 | |
| 1137 | try: |
agrieve | 63d2078 | 2016-02-04 17:47:26 | [diff] [blame] | 1138 | return RunTestsCommand(args) |
mikecase | e7405102 | 2015-02-26 23:08:22 | [diff] [blame] | 1139 | except base_error.BaseError as e: |
| 1140 | logging.exception('Error occurred.') |
| 1141 | if e.is_infra_error: |
| 1142 | return constants.INFRA_EXIT_CODE |
msw | ecce673 | 2015-06-06 00:31:33 | [diff] [blame] | 1143 | return constants.ERROR_EXIT_CODE |
mikecase | e7405102 | 2015-02-26 23:08:22 | [diff] [blame] | 1144 | except: # pylint: disable=W0702 |
| 1145 | logging.exception('Unrecognized error occurred.') |
| 1146 | return constants.ERROR_EXIT_CODE |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1147 | |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 1148 | |
| 1149 | if __name__ == '__main__': |
[email protected] | 7c53a60 | 2014-03-24 16:21:44 | [diff] [blame] | 1150 | sys.exit(main()) |