The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | # |
| 3 | # Copyright 2008, The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 17 | """Command line utility for running Android tests |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 18 | |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 19 | runtest helps automate the instructions for building and running tests |
| 20 | - It builds the corresponding test package for the code you want to test |
| 21 | - It pushes the test package to your device or emulator |
| 22 | - It launches InstrumentationTestRunner (or similar) to run the tests you |
| 23 | specify. |
| 24 | |
| 25 | runtest supports running tests whose attributes have been pre-defined in |
| 26 | _TEST_FILE_NAME files, (runtest <testname>), or by specifying the file |
| 27 | system path to the test to run (runtest --path <path>). |
| 28 | |
| 29 | Do runtest --help to see full list of options. |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 30 | """ |
| 31 | |
| 32 | # Python imports |
| 33 | import glob |
| 34 | import optparse |
| 35 | import os |
| 36 | from sets import Set |
| 37 | import sys |
| 38 | |
| 39 | # local imports |
| 40 | import adb_interface |
| 41 | import android_build |
| 42 | import coverage |
| 43 | import errors |
| 44 | import logger |
| 45 | import run_command |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 46 | from test_defs import test_defs |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 47 | from test_defs import test_walker |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 48 | |
| 49 | |
| 50 | class TestRunner(object): |
| 51 | """Command line utility class for running pre-defined Android test(s).""" |
| 52 | |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 53 | _TEST_FILE_NAME = "test_defs.xml" |
| 54 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 55 | # file path to android core platform tests, relative to android build root |
| 56 | # TODO move these test data files to another directory |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 57 | _CORE_TEST_PATH = os.path.join("development", "testrunner", |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 58 | _TEST_FILE_NAME) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 59 | |
| 60 | # vendor glob file path patterns to tests, relative to android |
| 61 | # build root |
| 62 | _VENDOR_TEST_PATH = os.path.join("vendor", "*", "tests", "testinfo", |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 63 | _TEST_FILE_NAME) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 64 | |
| 65 | _RUNTEST_USAGE = ( |
| 66 | "usage: runtest.py [options] short-test-name[s]\n\n" |
| 67 | "The runtest script works in two ways. You can query it " |
| 68 | "for a list of tests, or you can launch one or more tests.") |
| 69 | |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 70 | # default value for make -jX |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 71 | _DEFAULT_JOBS = 4 |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 72 | |
Brett Chabot | 72731f3 | 2009-03-31 11:14:05 -0700 | [diff] [blame] | 73 | def __init__(self): |
| 74 | # disable logging of timestamp |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 75 | self._root_path = android_build.GetTop() |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 76 | logger.SetTimestampLogging(False) |
Brett Chabot | 3ae5f8a | 2009-06-28 12:00:47 -0700 | [diff] [blame] | 77 | self._adb = None |
| 78 | self._known_tests = None |
| 79 | self._options = None |
| 80 | self._test_args = None |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 81 | self._tests_to_run = None |
Brett Chabot | 72731f3 | 2009-03-31 11:14:05 -0700 | [diff] [blame] | 82 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 83 | def _ProcessOptions(self): |
| 84 | """Processes command-line options.""" |
| 85 | # TODO error messages on once-only or mutually-exclusive options. |
| 86 | user_test_default = os.path.join(os.environ.get("HOME"), ".android", |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 87 | self._TEST_FILE_NAME) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 88 | |
| 89 | parser = optparse.OptionParser(usage=self._RUNTEST_USAGE) |
| 90 | |
| 91 | parser.add_option("-l", "--list-tests", dest="only_list_tests", |
| 92 | default=False, action="store_true", |
| 93 | help="To view the list of tests") |
| 94 | parser.add_option("-b", "--skip-build", dest="skip_build", default=False, |
| 95 | action="store_true", help="Skip build - just launch") |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 96 | parser.add_option("-j", "--jobs", dest="make_jobs", |
| 97 | metavar="X", default=self._DEFAULT_JOBS, |
| 98 | help="Number of make jobs to use when building") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 99 | parser.add_option("-n", "--skip_execute", dest="preview", default=False, |
| 100 | action="store_true", |
| 101 | help="Do not execute, just preview commands") |
| 102 | parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False, |
| 103 | action="store_true", |
| 104 | help="Raw mode (for output to other tools)") |
| 105 | parser.add_option("-a", "--suite-assign", dest="suite_assign_mode", |
| 106 | default=False, action="store_true", |
| 107 | help="Suite assignment (for details & usage see " |
| 108 | "InstrumentationTestRunner)") |
| 109 | parser.add_option("-v", "--verbose", dest="verbose", default=False, |
| 110 | action="store_true", |
| 111 | help="Increase verbosity of %s" % sys.argv[0]) |
| 112 | parser.add_option("-w", "--wait-for-debugger", dest="wait_for_debugger", |
| 113 | default=False, action="store_true", |
| 114 | help="Wait for debugger before launching tests") |
| 115 | parser.add_option("-c", "--test-class", dest="test_class", |
| 116 | help="Restrict test to a specific class") |
| 117 | parser.add_option("-m", "--test-method", dest="test_method", |
| 118 | help="Restrict test to a specific method") |
Brett Chabot | 8a101cb | 2009-05-05 12:56:39 -0700 | [diff] [blame] | 119 | parser.add_option("-p", "--test-package", dest="test_package", |
| 120 | help="Restrict test to a specific java package") |
| 121 | parser.add_option("-z", "--size", dest="test_size", |
| 122 | help="Restrict test to a specific test size") |
Brett Chabot | c061154 | 2010-02-20 20:09:58 -0800 | [diff] [blame] | 123 | parser.add_option("--annotation", dest="test_annotation", |
| 124 | help="Include only those tests tagged with a specific" |
| 125 | " annotation") |
| 126 | parser.add_option("--not-annotation", dest="test_not_annotation", |
Brett Chabot | 2e16fbc | 2010-02-23 12:28:27 -0800 | [diff] [blame] | 127 | help="Exclude any tests tagged with a specific" |
Brett Chabot | c061154 | 2010-02-20 20:09:58 -0800 | [diff] [blame] | 128 | " annotation") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 129 | parser.add_option("-u", "--user-tests-file", dest="user_tests_file", |
| 130 | metavar="FILE", default=user_test_default, |
| 131 | help="Alternate source of user test definitions") |
| 132 | parser.add_option("-o", "--coverage", dest="coverage", |
| 133 | default=False, action="store_true", |
| 134 | help="Generate code coverage metrics for test(s)") |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 135 | parser.add_option("-x", "--path", dest="test_path", |
| 136 | help="Run test(s) at given file system path") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 137 | parser.add_option("-t", "--all-tests", dest="all_tests", |
| 138 | default=False, action="store_true", |
| 139 | help="Run all defined tests") |
| 140 | parser.add_option("--continuous", dest="continuous_tests", |
| 141 | default=False, action="store_true", |
| 142 | help="Run all tests defined as part of the continuous " |
| 143 | "test set") |
Wei-Ta Chen | 97752d4 | 2009-05-21 16:24:04 -0700 | [diff] [blame] | 144 | parser.add_option("--timeout", dest="timeout", |
| 145 | default=300, help="Set a timeout limit (in sec) for " |
| 146 | "running native tests on a device (default: 300 secs)") |
Brett Chabot | 4a5d9f1 | 2010-02-18 20:01:11 -0800 | [diff] [blame] | 147 | parser.add_option("--suite", dest="suite", |
Brett Chabot | 49b7711 | 2009-06-02 11:46:04 -0700 | [diff] [blame] | 148 | help="Run all tests defined as part of the " |
Brett Chabot | 4a5d9f1 | 2010-02-18 20:01:11 -0800 | [diff] [blame] | 149 | "the given test suite") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 150 | group = optparse.OptionGroup( |
| 151 | parser, "Targets", "Use these options to direct tests to a specific " |
| 152 | "Android target") |
| 153 | group.add_option("-e", "--emulator", dest="emulator", default=False, |
| 154 | action="store_true", help="use emulator") |
| 155 | group.add_option("-d", "--device", dest="device", default=False, |
| 156 | action="store_true", help="use device") |
| 157 | group.add_option("-s", "--serial", dest="serial", |
| 158 | help="use specific serial") |
| 159 | parser.add_option_group(group) |
| 160 | |
| 161 | self._options, self._test_args = parser.parse_args() |
| 162 | |
Brett Chabot | 49b7711 | 2009-06-02 11:46:04 -0700 | [diff] [blame] | 163 | if (not self._options.only_list_tests |
| 164 | and not self._options.all_tests |
| 165 | and not self._options.continuous_tests |
Brett Chabot | 4a5d9f1 | 2010-02-18 20:01:11 -0800 | [diff] [blame] | 166 | and not self._options.suite |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 167 | and not self._options.test_path |
Brett Chabot | 49b7711 | 2009-06-02 11:46:04 -0700 | [diff] [blame] | 168 | and len(self._test_args) < 1): |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 169 | parser.print_help() |
| 170 | logger.SilentLog("at least one test name must be specified") |
| 171 | raise errors.AbortError |
| 172 | |
| 173 | self._adb = adb_interface.AdbInterface() |
| 174 | if self._options.emulator: |
| 175 | self._adb.SetEmulatorTarget() |
| 176 | elif self._options.device: |
| 177 | self._adb.SetDeviceTarget() |
| 178 | elif self._options.serial is not None: |
| 179 | self._adb.SetTargetSerial(self._options.serial) |
| 180 | |
| 181 | if self._options.verbose: |
| 182 | logger.SetVerbose(True) |
| 183 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 184 | self._known_tests = self._ReadTests() |
| 185 | |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 186 | self._options.host_lib_path = android_build.GetHostLibraryPath() |
| 187 | self._options.test_data_path = android_build.GetTestAppPath() |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 188 | |
| 189 | def _ReadTests(self): |
| 190 | """Parses the set of test definition data. |
| 191 | |
| 192 | Returns: |
| 193 | A TestDefinitions object that contains the set of parsed tests. |
| 194 | Raises: |
| 195 | AbortError: If a fatal error occurred when parsing the tests. |
| 196 | """ |
| 197 | core_test_path = os.path.join(self._root_path, self._CORE_TEST_PATH) |
| 198 | try: |
| 199 | known_tests = test_defs.TestDefinitions() |
| 200 | known_tests.Parse(core_test_path) |
Brett Chabot | 2d85c0e | 2009-03-31 15:19:13 -0700 | [diff] [blame] | 201 | # read all <android root>/vendor/*/tests/testinfo/test_defs.xml paths |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 202 | vendor_tests_pattern = os.path.join(self._root_path, |
| 203 | self._VENDOR_TEST_PATH) |
| 204 | test_file_paths = glob.glob(vendor_tests_pattern) |
| 205 | for test_file_path in test_file_paths: |
| 206 | known_tests.Parse(test_file_path) |
| 207 | if os.path.isfile(self._options.user_tests_file): |
| 208 | known_tests.Parse(self._options.user_tests_file) |
| 209 | return known_tests |
| 210 | except errors.ParseError: |
| 211 | raise errors.AbortError |
| 212 | |
| 213 | def _DumpTests(self): |
| 214 | """Prints out set of defined tests.""" |
Brett Chabot | be659c0 | 2009-09-21 17:48:26 -0700 | [diff] [blame] | 215 | print "The following tests are currently defined:\n" |
| 216 | print "%-25s %-40s %s" % ("name", "build path", "description") |
| 217 | print "-" * 80 |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 218 | for test in self._known_tests: |
Brett Chabot | be659c0 | 2009-09-21 17:48:26 -0700 | [diff] [blame] | 219 | print "%-25s %-40s %s" % (test.GetName(), test.GetBuildPath(), |
| 220 | test.GetDescription()) |
| 221 | print "\nSee %s for more information" % self._TEST_FILE_NAME |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 222 | |
| 223 | def _DoBuild(self): |
| 224 | logger.SilentLog("Building tests...") |
Brett Chabot | 8dc9eb8 | 2010-04-15 15:43:04 -0700 | [diff] [blame^] | 225 | |
| 226 | tests = self._GetTestsToRun() |
| 227 | self._DoFullBuild(tests) |
| 228 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 229 | target_set = Set() |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 230 | extra_args_set = Set() |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 231 | for test_suite in tests: |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 232 | self._AddBuildTarget(test_suite, target_set, extra_args_set) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 233 | |
| 234 | if target_set: |
| 235 | if self._options.coverage: |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 236 | coverage.EnableCoverageBuild() |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 237 | |
Brett Chabot | 8dc9eb8 | 2010-04-15 15:43:04 -0700 | [diff] [blame^] | 238 | target_build_string = ' '.join(list(target_set)) |
| 239 | extra_args_string = ' '.join(list(extra_args_set)) |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 240 | # mmm cannot be used from python, so perform a similar operation using |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 241 | # ONE_SHOT_MAKEFILE |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 242 | cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" files %s' % ( |
| 243 | target_build_string, self._options.make_jobs, self._root_path, |
| 244 | extra_args_string) |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 245 | logger.Log(cmd) |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 246 | |
Brett Chabot | 72731f3 | 2009-03-31 11:14:05 -0700 | [diff] [blame] | 247 | if self._options.preview: |
| 248 | # in preview mode, just display to the user what command would have been |
| 249 | # run |
| 250 | logger.Log("adb sync") |
| 251 | else: |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 252 | run_command.RunCommand(cmd, return_output=False) |
| 253 | logger.Log("Syncing to device...") |
| 254 | self._adb.Sync() |
| 255 | |
Brett Chabot | 8dc9eb8 | 2010-04-15 15:43:04 -0700 | [diff] [blame^] | 256 | def _DoFullBuild(self, tests): |
| 257 | """If necessary, run a full 'make' command for the tests that need it.""" |
| 258 | extra_args_set = Set() |
| 259 | |
| 260 | # hack to build cts dependencies |
| 261 | # TODO: remove this when cts dependencies are removed |
| 262 | if self._IsCtsTests(tests): |
| 263 | # need to use make since these fail building with ONE_SHOT_MAKEFILE |
| 264 | extra_args_set.add('CtsTestStubs') |
| 265 | extra_args_set.add('android.core.tests.runner') |
| 266 | for test in tests: |
| 267 | if test.IsFullMake(): |
| 268 | if test.GetExtraBuildArgs(): |
| 269 | # extra args contains the args to pass to 'make' |
| 270 | extra_args_set.add(test.GetExtraBuildArgs()) |
| 271 | else: |
| 272 | logger.Log("Warning: test %s needs a full build but does not specify" |
| 273 | " extra_build_args" % test.GetName()) |
| 274 | |
| 275 | # check if there is actually any tests that required a full build |
| 276 | if extra_args_set: |
| 277 | cmd = ('make -j%s %s' % (self._options.make_jobs, |
| 278 | ' '.join(list(extra_args_set)))) |
| 279 | logger.Log(cmd) |
| 280 | if not self._options.preview: |
| 281 | old_dir = os.getcwd() |
| 282 | os.chdir(self._root_path) |
| 283 | run_command.RunCommand(cmd, return_output=False) |
| 284 | os.chdir(old_dir) |
| 285 | |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 286 | def _AddBuildTarget(self, test_suite, target_set, extra_args_set): |
Brett Chabot | 8dc9eb8 | 2010-04-15 15:43:04 -0700 | [diff] [blame^] | 287 | if not test_suite.IsFullMake(): |
| 288 | build_dir = test_suite.GetBuildPath() |
| 289 | if self._AddBuildTargetPath(build_dir, target_set): |
| 290 | extra_args_set.add(test_suite.GetExtraBuildArgs()) |
| 291 | for path in test_suite.GetBuildDependencies(self._options): |
| 292 | self._AddBuildTargetPath(path, target_set) |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 293 | |
| 294 | def _AddBuildTargetPath(self, build_dir, target_set): |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 295 | if build_dir is not None: |
| 296 | build_file_path = os.path.join(build_dir, "Android.mk") |
| 297 | if os.path.isfile(os.path.join(self._root_path, build_file_path)): |
| 298 | target_set.add(build_file_path) |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 299 | return True |
Brett Chabot | e00595b | 2009-10-21 20:01:31 -0700 | [diff] [blame] | 300 | else: |
| 301 | logger.Log("%s has no Android.mk, skipping" % build_dir) |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 302 | return False |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 303 | |
| 304 | def _GetTestsToRun(self): |
| 305 | """Get a list of TestSuite objects to run, based on command line args.""" |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 306 | if self._tests_to_run: |
| 307 | return self._tests_to_run |
| 308 | |
| 309 | self._tests_to_run = [] |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 310 | if self._options.all_tests: |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 311 | self._tests_to_run = self._known_tests.GetTests() |
Brett Chabot | 49b7711 | 2009-06-02 11:46:04 -0700 | [diff] [blame] | 312 | elif self._options.continuous_tests: |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 313 | self._tests_to_run = self._known_tests.GetContinuousTests() |
Brett Chabot | 4a5d9f1 | 2010-02-18 20:01:11 -0800 | [diff] [blame] | 314 | elif self._options.suite: |
| 315 | self._tests_to_run = \ |
| 316 | self._known_tests.GetTestsInSuite(self._options.suite) |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 317 | elif self._options.test_path: |
| 318 | walker = test_walker.TestWalker() |
| 319 | self._tests_to_run = walker.FindTests(self._options.test_path) |
| 320 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 321 | for name in self._test_args: |
| 322 | test = self._known_tests.GetTest(name) |
| 323 | if test is None: |
| 324 | logger.Log("Error: Could not find test %s" % name) |
| 325 | self._DumpTests() |
| 326 | raise errors.AbortError |
Brett Chabot | 59b4778 | 2009-10-21 17:23:01 -0700 | [diff] [blame] | 327 | self._tests_to_run.append(test) |
| 328 | return self._tests_to_run |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 329 | |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 330 | def _IsCtsTests(self, test_list): |
| 331 | """Check if any cts tests are included in given list of tests to run.""" |
| 332 | for test in test_list: |
Brett Chabot | 4a5d9f1 | 2010-02-18 20:01:11 -0800 | [diff] [blame] | 333 | if test.GetSuite() == 'cts': |
Brett Chabot | 2477b38 | 2009-09-23 18:05:28 -0700 | [diff] [blame] | 334 | return True |
| 335 | return False |
| 336 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 337 | def RunTests(self): |
| 338 | """Main entry method - executes the tests according to command line args.""" |
| 339 | try: |
| 340 | run_command.SetAbortOnError() |
| 341 | self._ProcessOptions() |
| 342 | if self._options.only_list_tests: |
| 343 | self._DumpTests() |
| 344 | return |
| 345 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 346 | if not self._options.skip_build: |
| 347 | self._DoBuild() |
| 348 | |
| 349 | for test_suite in self._GetTestsToRun(): |
Brett Chabot | 920e9fe | 2010-01-21 17:30:47 -0800 | [diff] [blame] | 350 | try: |
| 351 | test_suite.Run(self._options, self._adb) |
| 352 | except errors.WaitForResponseTimedOutError: |
| 353 | logger.Log("Timed out waiting for response") |
Brett Chabot | 764d3fa | 2009-06-25 17:57:31 -0700 | [diff] [blame] | 354 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 355 | except KeyboardInterrupt: |
| 356 | logger.Log("Exiting...") |
Brett Chabot | 3ae5f8a | 2009-06-28 12:00:47 -0700 | [diff] [blame] | 357 | except errors.AbortError, error: |
| 358 | logger.Log(error.msg) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 359 | logger.SilentLog("Exiting due to AbortError...") |
| 360 | except errors.WaitForResponseTimedOutError: |
| 361 | logger.Log("Timed out waiting for response") |
| 362 | |
| 363 | |
| 364 | def RunTests(): |
| 365 | runner = TestRunner() |
| 366 | runner.RunTests() |
| 367 | |
| 368 | if __name__ == "__main__": |
| 369 | RunTests() |