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