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