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