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