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