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