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