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 | |
| 17 | """Command line utility for running a pre-defined test. |
| 18 | |
| 19 | Based on previous <androidroot>/development/tools/runtest shell script. |
| 20 | """ |
| 21 | |
| 22 | # Python imports |
| 23 | import glob |
| 24 | import optparse |
| 25 | import os |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 26 | import re |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 27 | from sets import Set |
| 28 | import sys |
| 29 | |
| 30 | # local imports |
| 31 | import adb_interface |
| 32 | import android_build |
| 33 | import coverage |
| 34 | import errors |
| 35 | import logger |
| 36 | import run_command |
| 37 | import test_defs |
| 38 | |
| 39 | |
| 40 | class TestRunner(object): |
| 41 | """Command line utility class for running pre-defined Android test(s).""" |
| 42 | |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 43 | _TEST_FILE_NAME = "test_defs.xml" |
| 44 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 45 | # file path to android core platform tests, relative to android build root |
| 46 | # TODO move these test data files to another directory |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 47 | _CORE_TEST_PATH = os.path.join("development", "testrunner", |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 48 | _TEST_FILE_NAME) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 49 | |
| 50 | # vendor glob file path patterns to tests, relative to android |
| 51 | # build root |
| 52 | _VENDOR_TEST_PATH = os.path.join("vendor", "*", "tests", "testinfo", |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 53 | _TEST_FILE_NAME) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 54 | |
| 55 | _RUNTEST_USAGE = ( |
| 56 | "usage: runtest.py [options] short-test-name[s]\n\n" |
| 57 | "The runtest script works in two ways. You can query it " |
| 58 | "for a list of tests, or you can launch one or more tests.") |
| 59 | |
Brett Chabot | 72731f3 | 2009-03-31 11:14:05 -0700 | [diff] [blame] | 60 | def __init__(self): |
| 61 | # disable logging of timestamp |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 62 | self._root_path = android_build.GetTop() |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 63 | logger.SetTimestampLogging(False) |
Brett Chabot | 72731f3 | 2009-03-31 11:14:05 -0700 | [diff] [blame] | 64 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 65 | def _ProcessOptions(self): |
| 66 | """Processes command-line options.""" |
| 67 | # TODO error messages on once-only or mutually-exclusive options. |
| 68 | user_test_default = os.path.join(os.environ.get("HOME"), ".android", |
Brett Chabot | f61f43e | 2009-04-02 11:52:48 -0700 | [diff] [blame] | 69 | self._TEST_FILE_NAME) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 70 | |
| 71 | parser = optparse.OptionParser(usage=self._RUNTEST_USAGE) |
| 72 | |
| 73 | parser.add_option("-l", "--list-tests", dest="only_list_tests", |
| 74 | default=False, action="store_true", |
| 75 | help="To view the list of tests") |
| 76 | parser.add_option("-b", "--skip-build", dest="skip_build", default=False, |
| 77 | action="store_true", help="Skip build - just launch") |
| 78 | parser.add_option("-n", "--skip_execute", dest="preview", default=False, |
| 79 | action="store_true", |
| 80 | help="Do not execute, just preview commands") |
| 81 | parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False, |
| 82 | action="store_true", |
| 83 | help="Raw mode (for output to other tools)") |
| 84 | parser.add_option("-a", "--suite-assign", dest="suite_assign_mode", |
| 85 | default=False, action="store_true", |
| 86 | help="Suite assignment (for details & usage see " |
| 87 | "InstrumentationTestRunner)") |
| 88 | parser.add_option("-v", "--verbose", dest="verbose", default=False, |
| 89 | action="store_true", |
| 90 | help="Increase verbosity of %s" % sys.argv[0]) |
| 91 | parser.add_option("-w", "--wait-for-debugger", dest="wait_for_debugger", |
| 92 | default=False, action="store_true", |
| 93 | help="Wait for debugger before launching tests") |
| 94 | parser.add_option("-c", "--test-class", dest="test_class", |
| 95 | help="Restrict test to a specific class") |
| 96 | parser.add_option("-m", "--test-method", dest="test_method", |
| 97 | help="Restrict test to a specific method") |
Brett Chabot | 8a101cb | 2009-05-05 12:56:39 -0700 | [diff] [blame] | 98 | parser.add_option("-p", "--test-package", dest="test_package", |
| 99 | help="Restrict test to a specific java package") |
| 100 | parser.add_option("-z", "--size", dest="test_size", |
| 101 | help="Restrict test to a specific test size") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 102 | parser.add_option("-u", "--user-tests-file", dest="user_tests_file", |
| 103 | metavar="FILE", default=user_test_default, |
| 104 | help="Alternate source of user test definitions") |
| 105 | parser.add_option("-o", "--coverage", dest="coverage", |
| 106 | default=False, action="store_true", |
| 107 | help="Generate code coverage metrics for test(s)") |
| 108 | parser.add_option("-t", "--all-tests", dest="all_tests", |
| 109 | default=False, action="store_true", |
| 110 | help="Run all defined tests") |
| 111 | parser.add_option("--continuous", dest="continuous_tests", |
| 112 | default=False, action="store_true", |
| 113 | help="Run all tests defined as part of the continuous " |
| 114 | "test set") |
Wei-Ta Chen | 97752d4 | 2009-05-21 16:24:04 -0700 | [diff] [blame^] | 115 | parser.add_option("--timeout", dest="timeout", |
| 116 | default=300, help="Set a timeout limit (in sec) for " |
| 117 | "running native tests on a device (default: 300 secs)") |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 118 | |
| 119 | group = optparse.OptionGroup( |
| 120 | parser, "Targets", "Use these options to direct tests to a specific " |
| 121 | "Android target") |
| 122 | group.add_option("-e", "--emulator", dest="emulator", default=False, |
| 123 | action="store_true", help="use emulator") |
| 124 | group.add_option("-d", "--device", dest="device", default=False, |
| 125 | action="store_true", help="use device") |
| 126 | group.add_option("-s", "--serial", dest="serial", |
| 127 | help="use specific serial") |
| 128 | parser.add_option_group(group) |
| 129 | |
| 130 | self._options, self._test_args = parser.parse_args() |
| 131 | |
| 132 | if (not self._options.only_list_tests and not self._options.all_tests |
| 133 | and not self._options.continuous_tests and len(self._test_args) < 1): |
| 134 | parser.print_help() |
| 135 | logger.SilentLog("at least one test name must be specified") |
| 136 | raise errors.AbortError |
| 137 | |
| 138 | self._adb = adb_interface.AdbInterface() |
| 139 | if self._options.emulator: |
| 140 | self._adb.SetEmulatorTarget() |
| 141 | elif self._options.device: |
| 142 | self._adb.SetDeviceTarget() |
| 143 | elif self._options.serial is not None: |
| 144 | self._adb.SetTargetSerial(self._options.serial) |
| 145 | |
| 146 | if self._options.verbose: |
| 147 | logger.SetVerbose(True) |
| 148 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 149 | self._known_tests = self._ReadTests() |
| 150 | |
| 151 | self._coverage_gen = coverage.CoverageGenerator( |
| 152 | android_root_path=self._root_path, adb_interface=self._adb) |
| 153 | |
| 154 | def _ReadTests(self): |
| 155 | """Parses the set of test definition data. |
| 156 | |
| 157 | Returns: |
| 158 | A TestDefinitions object that contains the set of parsed tests. |
| 159 | Raises: |
| 160 | AbortError: If a fatal error occurred when parsing the tests. |
| 161 | """ |
| 162 | core_test_path = os.path.join(self._root_path, self._CORE_TEST_PATH) |
| 163 | try: |
| 164 | known_tests = test_defs.TestDefinitions() |
| 165 | known_tests.Parse(core_test_path) |
Brett Chabot | 2d85c0e | 2009-03-31 15:19:13 -0700 | [diff] [blame] | 166 | # 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] | 167 | vendor_tests_pattern = os.path.join(self._root_path, |
| 168 | self._VENDOR_TEST_PATH) |
| 169 | test_file_paths = glob.glob(vendor_tests_pattern) |
| 170 | for test_file_path in test_file_paths: |
| 171 | known_tests.Parse(test_file_path) |
| 172 | if os.path.isfile(self._options.user_tests_file): |
| 173 | known_tests.Parse(self._options.user_tests_file) |
| 174 | return known_tests |
| 175 | except errors.ParseError: |
| 176 | raise errors.AbortError |
| 177 | |
| 178 | def _DumpTests(self): |
| 179 | """Prints out set of defined tests.""" |
| 180 | print "The following tests are currently defined:" |
| 181 | for test in self._known_tests: |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 182 | print "%-15s %s" % (test.GetName(), test.GetDescription()) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 183 | |
| 184 | def _DoBuild(self): |
| 185 | logger.SilentLog("Building tests...") |
| 186 | target_set = Set() |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 187 | extra_args_set = Set() |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 188 | for test_suite in self._GetTestsToRun(): |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 189 | self._AddBuildTarget(test_suite, target_set, extra_args_set) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 190 | |
| 191 | if target_set: |
| 192 | if self._options.coverage: |
| 193 | self._coverage_gen.EnableCoverageBuild() |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 194 | self._AddBuildTargetPath(self._coverage_gen.GetEmmaBuildPath(), |
| 195 | target_set) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 196 | target_build_string = " ".join(list(target_set)) |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 197 | extra_args_string = " ".join(list(extra_args_set)) |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 198 | # log the user-friendly equivalent make command, so developers can |
| 199 | # replicate this step |
| 200 | logger.Log("mmm %s %s" % (target_build_string, extra_args_string)) |
| 201 | # mmm cannot be used from python, so perform a similiar operation using |
| 202 | # ONE_SHOT_MAKEFILE |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 203 | cmd = 'ONE_SHOT_MAKEFILE="%s" make -C "%s" files %s' % ( |
| 204 | target_build_string, self._root_path, extra_args_string) |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 205 | |
Brett Chabot | 72731f3 | 2009-03-31 11:14:05 -0700 | [diff] [blame] | 206 | if self._options.preview: |
| 207 | # in preview mode, just display to the user what command would have been |
| 208 | # run |
| 209 | logger.Log("adb sync") |
| 210 | else: |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 211 | run_command.RunCommand(cmd, return_output=False) |
| 212 | logger.Log("Syncing to device...") |
| 213 | self._adb.Sync() |
| 214 | |
Niko Catania | a6dc2ab | 2009-04-03 14:12:46 -0700 | [diff] [blame] | 215 | def _AddBuildTarget(self, test_suite, target_set, extra_args_set): |
| 216 | build_dir = test_suite.GetBuildPath() |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 217 | if self._AddBuildTargetPath(build_dir, target_set): |
| 218 | extra_args_set.add(test_suite.GetExtraMakeArgs()) |
| 219 | |
| 220 | def _AddBuildTargetPath(self, build_dir, target_set): |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 221 | if build_dir is not None: |
| 222 | build_file_path = os.path.join(build_dir, "Android.mk") |
| 223 | if os.path.isfile(os.path.join(self._root_path, build_file_path)): |
| 224 | target_set.add(build_file_path) |
Brett Chabot | 2b6643b | 2009-04-07 18:35:27 -0700 | [diff] [blame] | 225 | return True |
| 226 | return False |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 227 | |
| 228 | def _GetTestsToRun(self): |
| 229 | """Get a list of TestSuite objects to run, based on command line args.""" |
| 230 | if self._options.all_tests: |
| 231 | return self._known_tests.GetTests() |
| 232 | if self._options.continuous_tests: |
| 233 | return self._known_tests.GetContinuousTests() |
| 234 | tests = [] |
| 235 | for name in self._test_args: |
| 236 | test = self._known_tests.GetTest(name) |
| 237 | if test is None: |
| 238 | logger.Log("Error: Could not find test %s" % name) |
| 239 | self._DumpTests() |
| 240 | raise errors.AbortError |
| 241 | tests.append(test) |
| 242 | return tests |
| 243 | |
| 244 | def _RunTest(self, test_suite): |
| 245 | """Run the provided test suite. |
| 246 | |
| 247 | Builds up an adb instrument command using provided input arguments. |
| 248 | |
| 249 | Args: |
| 250 | test_suite: TestSuite to run |
| 251 | """ |
| 252 | |
| 253 | test_class = test_suite.GetClassName() |
| 254 | if self._options.test_class is not None: |
Brett Chabot | 292df41 | 2009-05-07 11:09:40 -0700 | [diff] [blame] | 255 | test_class = self._options.test_class.lstrip() |
| 256 | if test_class.startswith("."): |
| 257 | test_class = test_suite.GetPackageName() + test_class |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 258 | if self._options.test_method is not None: |
| 259 | test_class = "%s#%s" % (test_class, self._options.test_method) |
| 260 | |
| 261 | instrumentation_args = {} |
| 262 | if test_class is not None: |
| 263 | instrumentation_args["class"] = test_class |
Brett Chabot | 8a101cb | 2009-05-05 12:56:39 -0700 | [diff] [blame] | 264 | if self._options.test_package: |
| 265 | instrumentation_args["package"] = self._options.test_package |
| 266 | if self._options.test_size: |
| 267 | instrumentation_args["size"] = self._options.test_size |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 268 | if self._options.wait_for_debugger: |
| 269 | instrumentation_args["debug"] = "true" |
| 270 | if self._options.suite_assign_mode: |
| 271 | instrumentation_args["suiteAssignment"] = "true" |
| 272 | if self._options.coverage: |
| 273 | instrumentation_args["coverage"] = "true" |
| 274 | if self._options.preview: |
| 275 | adb_cmd = self._adb.PreviewInstrumentationCommand( |
| 276 | package_name=test_suite.GetPackageName(), |
| 277 | runner_name=test_suite.GetRunnerName(), |
| 278 | raw_mode=self._options.raw_mode, |
| 279 | instrumentation_args=instrumentation_args) |
| 280 | logger.Log(adb_cmd) |
| 281 | else: |
| 282 | self._adb.StartInstrumentationNoResults( |
| 283 | package_name=test_suite.GetPackageName(), |
| 284 | runner_name=test_suite.GetRunnerName(), |
| 285 | raw_mode=self._options.raw_mode, |
| 286 | instrumentation_args=instrumentation_args) |
| 287 | if self._options.coverage and test_suite.GetTargetName() is not None: |
| 288 | coverage_file = self._coverage_gen.ExtractReport(test_suite) |
| 289 | if coverage_file is not None: |
| 290 | logger.Log("Coverage report generated at %s" % coverage_file) |
| 291 | |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 292 | def _CollectTestSources(self, test_list, dirname, files): |
| 293 | """For each directory, find tests source file and add them to the list. |
| 294 | |
| 295 | Test files must match one of the following pattern: |
| 296 | - test_*.[cc|cpp] |
| 297 | - *_test.[cc|cpp] |
| 298 | - *_unittest.[cc|cpp] |
| 299 | |
| 300 | This method is a callback for os.path.walk. |
| 301 | |
| 302 | Args: |
| 303 | test_list: Where new tests should be inserted. |
| 304 | dirname: Current directory. |
| 305 | files: List of files in the current directory. |
| 306 | """ |
| 307 | for f in files: |
| 308 | (name, ext) = os.path.splitext(f) |
| 309 | if ext == ".cc" or ext == ".cpp": |
| 310 | if re.search("_test$|_test_$|_unittest$|_unittest_$|^test_", name): |
| 311 | logger.SilentLog("Found %s" % f) |
| 312 | test_list.append(str(os.path.join(dirname, f))) |
| 313 | |
| 314 | def _FilterOutMissing(self, path, sources): |
| 315 | """Filter out from the sources list missing tests. |
| 316 | |
| 317 | Sometimes some test source are not built for the target, i.e there |
| 318 | is no binary corresponding to the source file. We need to filter |
| 319 | these out. |
| 320 | |
| 321 | Args: |
| 322 | path: Where the binaries should be. |
| 323 | sources: List of tests source path. |
| 324 | Returns: |
| 325 | A list of test binaries built from the sources. |
| 326 | """ |
| 327 | binaries = [] |
| 328 | for f in sources: |
| 329 | binary = os.path.basename(f) |
| 330 | binary = os.path.splitext(binary)[0] |
| 331 | full_path = os.path.join(path, binary) |
| 332 | if os.path.exists(full_path): |
| 333 | binaries.append(binary) |
| 334 | return binaries |
| 335 | |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 336 | def _RunNativeTest(self, test_suite): |
| 337 | """Run the provided *native* test suite. |
| 338 | |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 339 | The test_suite must contain a build path where the native test |
| 340 | files are. Subdirectories are automatically scanned as well. |
| 341 | |
| 342 | Each test's name must have a .cc or .cpp extension and match one |
| 343 | of the following patterns: |
| 344 | - test_* |
| 345 | - *_test.[cc|cpp] |
| 346 | - *_unittest.[cc|cpp] |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 347 | A successful test must return 0. Any other value will be considered |
| 348 | as an error. |
| 349 | |
| 350 | Args: |
| 351 | test_suite: TestSuite to run |
| 352 | """ |
| 353 | # find all test files, convert unicode names to ascii, take the basename |
| 354 | # and drop the .cc/.cpp extension. |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 355 | source_list = [] |
| 356 | build_path = test_suite.GetBuildPath() |
| 357 | os.path.walk(build_path, self._CollectTestSources, source_list) |
| 358 | logger.SilentLog("Tests source %s" % source_list) |
| 359 | |
| 360 | # Host tests are under out/host/<os>-<arch>/bin. |
| 361 | host_list = self._FilterOutMissing(android_build.GetHostBin(), source_list) |
| 362 | logger.SilentLog("Host tests %s" % host_list) |
| 363 | |
| 364 | # Target tests are under $ANDROID_PRODUCT_OUT/system/bin. |
| 365 | target_list = self._FilterOutMissing(android_build.GetTargetSystemBin(), |
| 366 | source_list) |
| 367 | logger.SilentLog("Target tests %s" % target_list) |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 368 | |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 369 | # Run on the host |
| 370 | logger.Log("\nRunning on host") |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 371 | for f in host_list: |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 372 | if run_command.RunHostCommand(f) != 0: |
| 373 | logger.Log("%s... failed" % f) |
| 374 | else: |
Nicolas Catania | bcd93dc | 2009-05-14 12:25:23 -0700 | [diff] [blame] | 375 | if run_command.HasValgrind(): |
| 376 | if run_command.RunHostCommand(f, valgrind=True) == 0: |
| 377 | logger.Log("%s... ok\t\t[valgrind: ok]" % f) |
| 378 | else: |
| 379 | logger.Log("%s... ok\t\t[valgrind: failed]" % f) |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 380 | else: |
Nicolas Catania | bcd93dc | 2009-05-14 12:25:23 -0700 | [diff] [blame] | 381 | logger.Log("%s... ok\t\t[valgrind: missing]" % f) |
Nicolas Catania | 97b24c4 | 2009-04-22 11:08:32 -0700 | [diff] [blame] | 382 | |
| 383 | # Run on the device |
| 384 | logger.Log("\nRunning on target") |
Nicolas Catania | ff096c1 | 2009-05-01 11:55:36 -0700 | [diff] [blame] | 385 | for f in target_list: |
| 386 | full_path = os.path.join(os.sep, "system", "bin", f) |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 387 | |
Niko Catania | fa14bd5 | 2009-04-09 16:50:54 -0700 | [diff] [blame] | 388 | # Single quotes are needed to prevent the shell splitting it. |
Nicolas Catania | bcd93dc | 2009-05-14 12:25:23 -0700 | [diff] [blame] | 389 | output = self._adb.SendShellCommand("'%s 2>&1;echo -n exit code:$?'" % |
Wei-Ta Chen | 97752d4 | 2009-05-21 16:24:04 -0700 | [diff] [blame^] | 390 | full_path, |
| 391 | int(self._options.timeout)) |
Nicolas Catania | bcd93dc | 2009-05-14 12:25:23 -0700 | [diff] [blame] | 392 | success = output.endswith("exit code:0") |
| 393 | logger.Log("%s... %s" % (f, success and "ok" or "failed")) |
| 394 | # Print the captured output when the test failed. |
| 395 | if not success or self._options.verbose: |
| 396 | pos = output.rfind("exit code") |
| 397 | output = output[0:pos] |
| 398 | logger.Log(output) |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 399 | |
| 400 | # Cleanup |
| 401 | self._adb.SendShellCommand("rm %s" % full_path) |
| 402 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 403 | def RunTests(self): |
| 404 | """Main entry method - executes the tests according to command line args.""" |
| 405 | try: |
| 406 | run_command.SetAbortOnError() |
| 407 | self._ProcessOptions() |
| 408 | if self._options.only_list_tests: |
| 409 | self._DumpTests() |
| 410 | return |
| 411 | |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 412 | if not self._options.skip_build: |
| 413 | self._DoBuild() |
| 414 | |
| 415 | for test_suite in self._GetTestsToRun(): |
Niko Catania | 2e990b9 | 2009-04-02 16:52:26 -0700 | [diff] [blame] | 416 | if test_suite.IsNative(): |
| 417 | self._RunNativeTest(test_suite) |
| 418 | else: |
| 419 | self._RunTest(test_suite) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 420 | except KeyboardInterrupt: |
| 421 | logger.Log("Exiting...") |
Brett Chabot | 8a101cb | 2009-05-05 12:56:39 -0700 | [diff] [blame] | 422 | except errors.AbortError, e: |
| 423 | logger.Log(e.msg) |
The Android Open Source Project | 6ffae01 | 2009-03-18 17:39:43 -0700 | [diff] [blame] | 424 | logger.SilentLog("Exiting due to AbortError...") |
| 425 | except errors.WaitForResponseTimedOutError: |
| 426 | logger.Log("Timed out waiting for response") |
| 427 | |
| 428 | |
| 429 | def RunTests(): |
| 430 | runner = TestRunner() |
| 431 | runner.RunTests() |
| 432 | |
| 433 | if __name__ == "__main__": |
| 434 | RunTests() |