blob: 9082d79e2b551f16df6a703b7f8cf42da2040362 [file] [log] [blame]
The Android Open Source Project6ffae012009-03-18 17:39:43 -07001#!/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 Chabot59b47782009-10-21 17:23:01 -070017"""Command line utility for running Android tests
The Android Open Source Project6ffae012009-03-18 17:39:43 -070018
Brett Chabot59b47782009-10-21 17:23:01 -070019runtest 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
23specify.
24
25runtest supports running tests whose attributes have been pre-defined in
26_TEST_FILE_NAME files, (runtest <testname>), or by specifying the file
27system path to the test to run (runtest --path <path>).
28
29Do runtest --help to see full list of options.
The Android Open Source Project6ffae012009-03-18 17:39:43 -070030"""
31
32# Python imports
33import glob
34import optparse
35import os
Brett Chabot74541712012-08-31 18:39:00 -070036import re
The Android Open Source Project6ffae012009-03-18 17:39:43 -070037from sets import Set
38import sys
Brett Chabotcdfaae12011-06-07 10:10:38 -070039import time
The Android Open Source Project6ffae012009-03-18 17:39:43 -070040
41# local imports
42import adb_interface
43import android_build
44import coverage
45import errors
46import logger
47import run_command
Brett Chabot764d3fa2009-06-25 17:57:31 -070048from test_defs import test_defs
Brett Chabot59b47782009-10-21 17:23:01 -070049from test_defs import test_walker
The Android Open Source Project6ffae012009-03-18 17:39:43 -070050
51
52class TestRunner(object):
53 """Command line utility class for running pre-defined Android test(s)."""
54
Brett Chabotf61f43e2009-04-02 11:52:48 -070055 _TEST_FILE_NAME = "test_defs.xml"
56
The Android Open Source Project6ffae012009-03-18 17:39:43 -070057 # file path to android core platform tests, relative to android build root
58 # TODO move these test data files to another directory
Nicolas Catania97b24c42009-04-22 11:08:32 -070059 _CORE_TEST_PATH = os.path.join("development", "testrunner",
Brett Chabotf61f43e2009-04-02 11:52:48 -070060 _TEST_FILE_NAME)
The Android Open Source Project6ffae012009-03-18 17:39:43 -070061
62 # vendor glob file path patterns to tests, relative to android
63 # build root
64 _VENDOR_TEST_PATH = os.path.join("vendor", "*", "tests", "testinfo",
Brett Chabotf61f43e2009-04-02 11:52:48 -070065 _TEST_FILE_NAME)
The Android Open Source Project6ffae012009-03-18 17:39:43 -070066
67 _RUNTEST_USAGE = (
68 "usage: runtest.py [options] short-test-name[s]\n\n"
69 "The runtest script works in two ways. You can query it "
70 "for a list of tests, or you can launch one or more tests.")
71
Brett Chabot2477b382009-09-23 18:05:28 -070072 # default value for make -jX
Brett Chabot12db4362012-01-17 16:03:49 -080073 _DEFAULT_JOBS = 16
Brett Chabot2477b382009-09-23 18:05:28 -070074
Brett Chabotccae47d2010-06-14 15:19:25 -070075 _DALVIK_VERIFIER_OFF_PROP = "dalvik.vm.dexopt-flags = v=n"
76
Brett Chabot74541712012-08-31 18:39:00 -070077 # regular expression to match install: statements in make output
78 _RE_MAKE_INSTALL = re.compile(r'Install:\s(.+)')
79
80 # regular expression to find remote device path from a file path relative
81 # to build root
82 _RE_MAKE_INSTALL_PATH = re.compile(r'out\/target\/product\/\w+\/(.+)$')
83
Brett Chabot72731f32009-03-31 11:14:05 -070084 def __init__(self):
85 # disable logging of timestamp
Niko Catania2e990b92009-04-02 16:52:26 -070086 self._root_path = android_build.GetTop()
Nicolas Catania97b24c42009-04-22 11:08:32 -070087 logger.SetTimestampLogging(False)
Brett Chabot3ae5f8a2009-06-28 12:00:47 -070088 self._adb = None
89 self._known_tests = None
90 self._options = None
91 self._test_args = None
Brett Chabot59b47782009-10-21 17:23:01 -070092 self._tests_to_run = None
Brett Chabot72731f32009-03-31 11:14:05 -070093
The Android Open Source Project6ffae012009-03-18 17:39:43 -070094 def _ProcessOptions(self):
95 """Processes command-line options."""
96 # TODO error messages on once-only or mutually-exclusive options.
97 user_test_default = os.path.join(os.environ.get("HOME"), ".android",
Brett Chabotf61f43e2009-04-02 11:52:48 -070098 self._TEST_FILE_NAME)
The Android Open Source Project6ffae012009-03-18 17:39:43 -070099
100 parser = optparse.OptionParser(usage=self._RUNTEST_USAGE)
101
102 parser.add_option("-l", "--list-tests", dest="only_list_tests",
103 default=False, action="store_true",
104 help="To view the list of tests")
105 parser.add_option("-b", "--skip-build", dest="skip_build", default=False,
106 action="store_true", help="Skip build - just launch")
Brett Chabot2477b382009-09-23 18:05:28 -0700107 parser.add_option("-j", "--jobs", dest="make_jobs",
108 metavar="X", default=self._DEFAULT_JOBS,
109 help="Number of make jobs to use when building")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700110 parser.add_option("-n", "--skip_execute", dest="preview", default=False,
111 action="store_true",
112 help="Do not execute, just preview commands")
113 parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False,
114 action="store_true",
115 help="Raw mode (for output to other tools)")
116 parser.add_option("-a", "--suite-assign", dest="suite_assign_mode",
117 default=False, action="store_true",
118 help="Suite assignment (for details & usage see "
119 "InstrumentationTestRunner)")
120 parser.add_option("-v", "--verbose", dest="verbose", default=False,
121 action="store_true",
122 help="Increase verbosity of %s" % sys.argv[0])
123 parser.add_option("-w", "--wait-for-debugger", dest="wait_for_debugger",
124 default=False, action="store_true",
125 help="Wait for debugger before launching tests")
126 parser.add_option("-c", "--test-class", dest="test_class",
127 help="Restrict test to a specific class")
128 parser.add_option("-m", "--test-method", dest="test_method",
129 help="Restrict test to a specific method")
Brett Chabot8a101cb2009-05-05 12:56:39 -0700130 parser.add_option("-p", "--test-package", dest="test_package",
131 help="Restrict test to a specific java package")
132 parser.add_option("-z", "--size", dest="test_size",
133 help="Restrict test to a specific test size")
Brett Chabotc0611542010-02-20 20:09:58 -0800134 parser.add_option("--annotation", dest="test_annotation",
135 help="Include only those tests tagged with a specific"
136 " annotation")
137 parser.add_option("--not-annotation", dest="test_not_annotation",
Brett Chabot2e16fbc2010-02-23 12:28:27 -0800138 help="Exclude any tests tagged with a specific"
Brett Chabotc0611542010-02-20 20:09:58 -0800139 " annotation")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700140 parser.add_option("-u", "--user-tests-file", dest="user_tests_file",
141 metavar="FILE", default=user_test_default,
142 help="Alternate source of user test definitions")
143 parser.add_option("-o", "--coverage", dest="coverage",
144 default=False, action="store_true",
145 help="Generate code coverage metrics for test(s)")
Brett Chabot59b47782009-10-21 17:23:01 -0700146 parser.add_option("-x", "--path", dest="test_path",
147 help="Run test(s) at given file system path")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700148 parser.add_option("-t", "--all-tests", dest="all_tests",
149 default=False, action="store_true",
150 help="Run all defined tests")
151 parser.add_option("--continuous", dest="continuous_tests",
152 default=False, action="store_true",
153 help="Run all tests defined as part of the continuous "
154 "test set")
Wei-Ta Chen97752d42009-05-21 16:24:04 -0700155 parser.add_option("--timeout", dest="timeout",
156 default=300, help="Set a timeout limit (in sec) for "
157 "running native tests on a device (default: 300 secs)")
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800158 parser.add_option("--suite", dest="suite",
Brett Chabot49b77112009-06-02 11:46:04 -0700159 help="Run all tests defined as part of the "
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800160 "the given test suite")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700161 group = optparse.OptionGroup(
162 parser, "Targets", "Use these options to direct tests to a specific "
163 "Android target")
164 group.add_option("-e", "--emulator", dest="emulator", default=False,
165 action="store_true", help="use emulator")
166 group.add_option("-d", "--device", dest="device", default=False,
167 action="store_true", help="use device")
168 group.add_option("-s", "--serial", dest="serial",
169 help="use specific serial")
170 parser.add_option_group(group)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700171 self._options, self._test_args = parser.parse_args()
172
Brett Chabot49b77112009-06-02 11:46:04 -0700173 if (not self._options.only_list_tests
174 and not self._options.all_tests
175 and not self._options.continuous_tests
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800176 and not self._options.suite
Brett Chabot59b47782009-10-21 17:23:01 -0700177 and not self._options.test_path
Brett Chabot49b77112009-06-02 11:46:04 -0700178 and len(self._test_args) < 1):
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700179 parser.print_help()
180 logger.SilentLog("at least one test name must be specified")
181 raise errors.AbortError
182
183 self._adb = adb_interface.AdbInterface()
184 if self._options.emulator:
185 self._adb.SetEmulatorTarget()
186 elif self._options.device:
187 self._adb.SetDeviceTarget()
188 elif self._options.serial is not None:
189 self._adb.SetTargetSerial(self._options.serial)
190
191 if self._options.verbose:
192 logger.SetVerbose(True)
193
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700194 self._known_tests = self._ReadTests()
195
Brett Chabot764d3fa2009-06-25 17:57:31 -0700196 self._options.host_lib_path = android_build.GetHostLibraryPath()
197 self._options.test_data_path = android_build.GetTestAppPath()
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700198
199 def _ReadTests(self):
200 """Parses the set of test definition data.
201
202 Returns:
203 A TestDefinitions object that contains the set of parsed tests.
204 Raises:
205 AbortError: If a fatal error occurred when parsing the tests.
206 """
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700207 try:
208 known_tests = test_defs.TestDefinitions()
Brett Chabot3c9cefc2011-06-06 20:53:56 -0700209 # only read tests when not in path mode
210 if not self._options.test_path:
211 core_test_path = os.path.join(self._root_path, self._CORE_TEST_PATH)
212 if os.path.isfile(core_test_path):
213 known_tests.Parse(core_test_path)
214 # read all <android root>/vendor/*/tests/testinfo/test_defs.xml paths
215 vendor_tests_pattern = os.path.join(self._root_path,
216 self._VENDOR_TEST_PATH)
217 test_file_paths = glob.glob(vendor_tests_pattern)
218 for test_file_path in test_file_paths:
219 known_tests.Parse(test_file_path)
220 if os.path.isfile(self._options.user_tests_file):
221 known_tests.Parse(self._options.user_tests_file)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700222 return known_tests
223 except errors.ParseError:
224 raise errors.AbortError
225
226 def _DumpTests(self):
227 """Prints out set of defined tests."""
Brett Chabotbe659c02009-09-21 17:48:26 -0700228 print "The following tests are currently defined:\n"
229 print "%-25s %-40s %s" % ("name", "build path", "description")
230 print "-" * 80
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700231 for test in self._known_tests:
Brett Chabotbe659c02009-09-21 17:48:26 -0700232 print "%-25s %-40s %s" % (test.GetName(), test.GetBuildPath(),
233 test.GetDescription())
234 print "\nSee %s for more information" % self._TEST_FILE_NAME
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700235
236 def _DoBuild(self):
237 logger.SilentLog("Building tests...")
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700238
239 tests = self._GetTestsToRun()
Brett Chabotb1eb5d22010-06-15 11:18:42 -0700240 # turn off dalvik verifier if necessary
241 self._TurnOffVerifier(tests)
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700242 self._DoFullBuild(tests)
243
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800244 target_set = []
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800245
246 extra_args_set = []
Brett Chabot2477b382009-09-23 18:05:28 -0700247 for test_suite in tests:
Niko Cataniaa6dc2ab2009-04-03 14:12:46 -0700248 self._AddBuildTarget(test_suite, target_set, extra_args_set)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700249
Brett Chabotccae47d2010-06-14 15:19:25 -0700250 if not self._options.preview:
251 self._adb.EnableAdbRoot()
252 else:
253 logger.Log("adb root")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700254 if target_set:
255 if self._options.coverage:
Brett Chabot764d3fa2009-06-25 17:57:31 -0700256 coverage.EnableCoverageBuild()
Brett Chabot74541712012-08-31 18:39:00 -0700257 target_set.append("external/emma/Android.mk")
258 # TODO: detect if external/emma exists
Brett Chabot2477b382009-09-23 18:05:28 -0700259
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800260 target_build_string = " ".join(target_set)
261 extra_args_string = " ".join(extra_args_set)
Brett Chabotb1eb5d22010-06-15 11:18:42 -0700262
Brett Chabot764d3fa2009-06-25 17:57:31 -0700263 # mmm cannot be used from python, so perform a similar operation using
Brett Chabot2b6643b2009-04-07 18:35:27 -0700264 # ONE_SHOT_MAKEFILE
Brett Chabot546a3282011-06-07 19:19:30 -0700265 cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" all_modules %s' % (
Brett Chabot2477b382009-09-23 18:05:28 -0700266 target_build_string, self._options.make_jobs, self._root_path,
267 extra_args_string)
Brett Chabot764d3fa2009-06-25 17:57:31 -0700268 logger.Log(cmd)
Brett Chabot74541712012-08-31 18:39:00 -0700269 if not self._options.preview:
270 output = run_command.RunCommand(cmd, return_output=True, timeout_time=600)
271 self._DoInstall(output)
Niko Cataniaa6dc2ab2009-04-03 14:12:46 -0700272
Brett Chabot74541712012-08-31 18:39:00 -0700273 def _DoInstall(self, make_output):
274 """Install artifacts from build onto device.
275
276 Looks for 'install:' text from make output to find artifacts to install.
277
278 Args:
279 make_output: stdout from make command
280 """
281 for line in make_output.split("\n"):
282 m = self._RE_MAKE_INSTALL.match(line)
283 if m:
284 install_path = m.group(1)
285 if install_path.endswith(".apk"):
286 abs_install_path = os.path.join(self._root_path, install_path)
287 logger.Log("adb install -r %s" % abs_install_path)
288 logger.Log(self._adb.Install(abs_install_path))
289 else:
290 self._PushInstallFileToDevice(install_path)
291
292 def _PushInstallFileToDevice(self, install_path):
293 m = self._RE_MAKE_INSTALL_PATH.match(install_path)
294 if m:
295 remote_path = m.group(1)
296 abs_install_path = os.path.join(self._root_path, install_path)
297 logger.Log("adb push %s %s", abs_install_path, remote_path)
298 self._adb.Push(abs_install_path, remote_path)
299 else:
300 logger.Log("Error: Failed to recognize path of file to install %s" % install_path)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700301
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700302 def _DoFullBuild(self, tests):
303 """If necessary, run a full 'make' command for the tests that need it."""
304 extra_args_set = Set()
305
306 # hack to build cts dependencies
307 # TODO: remove this when cts dependencies are removed
308 if self._IsCtsTests(tests):
309 # need to use make since these fail building with ONE_SHOT_MAKEFILE
310 extra_args_set.add('CtsTestStubs')
311 extra_args_set.add('android.core.tests.runner')
312 for test in tests:
313 if test.IsFullMake():
314 if test.GetExtraBuildArgs():
315 # extra args contains the args to pass to 'make'
316 extra_args_set.add(test.GetExtraBuildArgs())
317 else:
318 logger.Log("Warning: test %s needs a full build but does not specify"
319 " extra_build_args" % test.GetName())
320
321 # check if there is actually any tests that required a full build
322 if extra_args_set:
323 cmd = ('make -j%s %s' % (self._options.make_jobs,
324 ' '.join(list(extra_args_set))))
325 logger.Log(cmd)
326 if not self._options.preview:
327 old_dir = os.getcwd()
328 os.chdir(self._root_path)
Brett Chabot74541712012-08-31 18:39:00 -0700329 output = run_command.RunCommand(cmd, return_output=False)
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700330 os.chdir(old_dir)
Brett Chabot74541712012-08-31 18:39:00 -0700331 self._DoInstall(output)
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700332
Niko Cataniaa6dc2ab2009-04-03 14:12:46 -0700333 def _AddBuildTarget(self, test_suite, target_set, extra_args_set):
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700334 if not test_suite.IsFullMake():
335 build_dir = test_suite.GetBuildPath()
336 if self._AddBuildTargetPath(build_dir, target_set):
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800337 extra_args_set.append(test_suite.GetExtraBuildArgs())
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700338 for path in test_suite.GetBuildDependencies(self._options):
339 self._AddBuildTargetPath(path, target_set)
Brett Chabot2b6643b2009-04-07 18:35:27 -0700340
341 def _AddBuildTargetPath(self, build_dir, target_set):
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700342 if build_dir is not None:
343 build_file_path = os.path.join(build_dir, "Android.mk")
344 if os.path.isfile(os.path.join(self._root_path, build_file_path)):
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800345 target_set.append(build_file_path)
Brett Chabot2b6643b2009-04-07 18:35:27 -0700346 return True
Brett Chabote00595b2009-10-21 20:01:31 -0700347 else:
348 logger.Log("%s has no Android.mk, skipping" % build_dir)
Brett Chabot2b6643b2009-04-07 18:35:27 -0700349 return False
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700350
351 def _GetTestsToRun(self):
352 """Get a list of TestSuite objects to run, based on command line args."""
Brett Chabot59b47782009-10-21 17:23:01 -0700353 if self._tests_to_run:
354 return self._tests_to_run
355
356 self._tests_to_run = []
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700357 if self._options.all_tests:
Brett Chabot59b47782009-10-21 17:23:01 -0700358 self._tests_to_run = self._known_tests.GetTests()
Brett Chabot49b77112009-06-02 11:46:04 -0700359 elif self._options.continuous_tests:
Brett Chabot59b47782009-10-21 17:23:01 -0700360 self._tests_to_run = self._known_tests.GetContinuousTests()
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800361 elif self._options.suite:
362 self._tests_to_run = \
363 self._known_tests.GetTestsInSuite(self._options.suite)
Brett Chabot59b47782009-10-21 17:23:01 -0700364 elif self._options.test_path:
365 walker = test_walker.TestWalker()
366 self._tests_to_run = walker.FindTests(self._options.test_path)
367
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700368 for name in self._test_args:
369 test = self._known_tests.GetTest(name)
370 if test is None:
371 logger.Log("Error: Could not find test %s" % name)
372 self._DumpTests()
373 raise errors.AbortError
Brett Chabot59b47782009-10-21 17:23:01 -0700374 self._tests_to_run.append(test)
375 return self._tests_to_run
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700376
Brett Chabot2477b382009-09-23 18:05:28 -0700377 def _IsCtsTests(self, test_list):
378 """Check if any cts tests are included in given list of tests to run."""
379 for test in test_list:
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800380 if test.GetSuite() == 'cts':
Brett Chabot2477b382009-09-23 18:05:28 -0700381 return True
382 return False
383
Brett Chabotccae47d2010-06-14 15:19:25 -0700384 def _TurnOffVerifier(self, test_list):
385 """Turn off the dalvik verifier if needed by given tests.
386
387 If one or more tests needs dalvik verifier off, and it is not already off,
388 turns off verifier and reboots device to allow change to take effect.
389 """
Brett Chabot74541712012-08-31 18:39:00 -0700390 # hack to check if these are frameworks/base tests. If so, turn off verifier
Brett Chabotccae47d2010-06-14 15:19:25 -0700391 # to allow framework tests to access package-private framework api
392 framework_test = False
393 for test in test_list:
394 if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]):
395 framework_test = True
396 if framework_test:
397 # check if verifier is off already - to avoid the reboot if not
398 # necessary
399 output = self._adb.SendShellCommand("cat /data/local.prop")
400 if not self._DALVIK_VERIFIER_OFF_PROP in output:
401 if self._options.preview:
402 logger.Log("adb shell \"echo %s >> /data/local.prop\""
403 % self._DALVIK_VERIFIER_OFF_PROP)
Brett Chabot25dfd792012-02-16 15:51:43 -0800404 logger.Log("adb shell chmod 644 /data/local.prop")
Brett Chabotccae47d2010-06-14 15:19:25 -0700405 logger.Log("adb reboot")
406 logger.Log("adb wait-for-device")
407 else:
408 logger.Log("Turning off dalvik verifier and rebooting")
409 self._adb.SendShellCommand("\"echo %s >> /data/local.prop\""
410 % self._DALVIK_VERIFIER_OFF_PROP)
Brett Chabot25dfd792012-02-16 15:51:43 -0800411
412 self._ChmodReboot()
413 elif not self._options.preview:
414 # check the permissions on the file
415 permout = self._adb.SendShellCommand("ls -l /data/local.prop")
416 if not "-rw-r--r--" in permout:
417 logger.Log("Fixing permissions on /data/local.prop and rebooting")
418 self._ChmodReboot()
419
420 def _ChmodReboot(self):
421 """Perform a chmod of /data/local.prop and reboot.
422 """
423 self._adb.SendShellCommand("chmod 644 /data/local.prop")
424 self._adb.SendCommand("reboot")
425 # wait for device to go offline
426 time.sleep(10)
427 self._adb.SendCommand("wait-for-device", timeout_time=60,
428 retry_count=3)
429 self._adb.EnableAdbRoot()
430
Brett Chabotccae47d2010-06-14 15:19:25 -0700431
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700432 def RunTests(self):
433 """Main entry method - executes the tests according to command line args."""
434 try:
435 run_command.SetAbortOnError()
436 self._ProcessOptions()
437 if self._options.only_list_tests:
438 self._DumpTests()
439 return
440
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700441 if not self._options.skip_build:
442 self._DoBuild()
443
444 for test_suite in self._GetTestsToRun():
Brett Chabot920e9fe2010-01-21 17:30:47 -0800445 try:
446 test_suite.Run(self._options, self._adb)
447 except errors.WaitForResponseTimedOutError:
448 logger.Log("Timed out waiting for response")
Brett Chabot764d3fa2009-06-25 17:57:31 -0700449
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700450 except KeyboardInterrupt:
451 logger.Log("Exiting...")
Brett Chabot3ae5f8a2009-06-28 12:00:47 -0700452 except errors.AbortError, error:
453 logger.Log(error.msg)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700454 logger.SilentLog("Exiting due to AbortError...")
455 except errors.WaitForResponseTimedOutError:
456 logger.Log("Timed out waiting for response")
457
458
459def RunTests():
460 runner = TestRunner()
461 runner.RunTests()
462
463if __name__ == "__main__":
464 RunTests()