blob: 470dc423bb91b26fab90435ec47202262a186e51 [file] [log] [blame]
Geremy Condra01844b12012-09-11 15:24:25 -07001#!/usr/bin/env python
The Android Open Source Project6ffae012009-03-18 17:39:43 -07002#
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
Brett Chabot8ac51182012-09-19 07:35:35 -070044from coverage import coverage
The Android Open Source Project6ffae012009-03-18 17:39:43 -070045import errors
46import logger
Brett Chabot8ac51182012-09-19 07:35:35 -070047import make_tree
The Android Open Source Project6ffae012009-03-18 17:39:43 -070048import run_command
Brett Chabot764d3fa2009-06-25 17:57:31 -070049from test_defs import test_defs
Brett Chabot59b47782009-10-21 17:23:01 -070050from test_defs import test_walker
The Android Open Source Project6ffae012009-03-18 17:39:43 -070051
52
53class TestRunner(object):
54 """Command line utility class for running pre-defined Android test(s)."""
55
Brett Chabotf61f43e2009-04-02 11:52:48 -070056 _TEST_FILE_NAME = "test_defs.xml"
57
The Android Open Source Project6ffae012009-03-18 17:39:43 -070058 # file path to android core platform tests, relative to android build root
59 # TODO move these test data files to another directory
Nicolas Catania97b24c42009-04-22 11:08:32 -070060 _CORE_TEST_PATH = os.path.join("development", "testrunner",
Brett Chabotf61f43e2009-04-02 11:52:48 -070061 _TEST_FILE_NAME)
The Android Open Source Project6ffae012009-03-18 17:39:43 -070062
63 # vendor glob file path patterns to tests, relative to android
64 # build root
65 _VENDOR_TEST_PATH = os.path.join("vendor", "*", "tests", "testinfo",
Brett Chabotf61f43e2009-04-02 11:52:48 -070066 _TEST_FILE_NAME)
The Android Open Source Project6ffae012009-03-18 17:39:43 -070067
68 _RUNTEST_USAGE = (
69 "usage: runtest.py [options] short-test-name[s]\n\n"
70 "The runtest script works in two ways. You can query it "
71 "for a list of tests, or you can launch one or more tests.")
72
Brett Chabot2477b382009-09-23 18:05:28 -070073 # default value for make -jX
Brett Chabot12db4362012-01-17 16:03:49 -080074 _DEFAULT_JOBS = 16
Brett Chabot2477b382009-09-23 18:05:28 -070075
Brett Chabotccae47d2010-06-14 15:19:25 -070076 _DALVIK_VERIFIER_OFF_PROP = "dalvik.vm.dexopt-flags = v=n"
77
Brett Chabot74541712012-08-31 18:39:00 -070078 # regular expression to match install: statements in make output
79 _RE_MAKE_INSTALL = re.compile(r'Install:\s(.+)')
80
Brett Chabot74541712012-08-31 18:39:00 -070081
Brett Chabot72731f32009-03-31 11:14:05 -070082 def __init__(self):
83 # disable logging of timestamp
Niko Catania2e990b92009-04-02 16:52:26 -070084 self._root_path = android_build.GetTop()
JP Abgrallf38107c2013-07-11 17:39:16 -070085 out_base_name = os.path.basename(android_build.GetOutDir())
86 # regular expression to find remote device path from a file path relative
87 # to build root
88 pattern = r'' + out_base_name + r'\/target\/product\/\w+\/(.+)$'
89 self._re_make_install_path = re.compile(pattern)
Nicolas Catania97b24c42009-04-22 11:08:32 -070090 logger.SetTimestampLogging(False)
Brett Chabot3ae5f8a2009-06-28 12:00:47 -070091 self._adb = None
92 self._known_tests = None
93 self._options = None
94 self._test_args = None
Brett Chabot59b47782009-10-21 17:23:01 -070095 self._tests_to_run = None
Brett Chabot72731f32009-03-31 11:14:05 -070096
The Android Open Source Project6ffae012009-03-18 17:39:43 -070097 def _ProcessOptions(self):
98 """Processes command-line options."""
99 # TODO error messages on once-only or mutually-exclusive options.
100 user_test_default = os.path.join(os.environ.get("HOME"), ".android",
Brett Chabotf61f43e2009-04-02 11:52:48 -0700101 self._TEST_FILE_NAME)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700102
103 parser = optparse.OptionParser(usage=self._RUNTEST_USAGE)
104
105 parser.add_option("-l", "--list-tests", dest="only_list_tests",
106 default=False, action="store_true",
107 help="To view the list of tests")
108 parser.add_option("-b", "--skip-build", dest="skip_build", default=False,
109 action="store_true", help="Skip build - just launch")
Brett Chabot2477b382009-09-23 18:05:28 -0700110 parser.add_option("-j", "--jobs", dest="make_jobs",
111 metavar="X", default=self._DEFAULT_JOBS,
112 help="Number of make jobs to use when building")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700113 parser.add_option("-n", "--skip_execute", dest="preview", default=False,
114 action="store_true",
115 help="Do not execute, just preview commands")
116 parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False,
117 action="store_true",
118 help="Raw mode (for output to other tools)")
119 parser.add_option("-a", "--suite-assign", dest="suite_assign_mode",
120 default=False, action="store_true",
121 help="Suite assignment (for details & usage see "
122 "InstrumentationTestRunner)")
123 parser.add_option("-v", "--verbose", dest="verbose", default=False,
124 action="store_true",
125 help="Increase verbosity of %s" % sys.argv[0])
126 parser.add_option("-w", "--wait-for-debugger", dest="wait_for_debugger",
127 default=False, action="store_true",
128 help="Wait for debugger before launching tests")
129 parser.add_option("-c", "--test-class", dest="test_class",
130 help="Restrict test to a specific class")
131 parser.add_option("-m", "--test-method", dest="test_method",
132 help="Restrict test to a specific method")
Brett Chabot8a101cb2009-05-05 12:56:39 -0700133 parser.add_option("-p", "--test-package", dest="test_package",
134 help="Restrict test to a specific java package")
135 parser.add_option("-z", "--size", dest="test_size",
136 help="Restrict test to a specific test size")
Brett Chabotc0611542010-02-20 20:09:58 -0800137 parser.add_option("--annotation", dest="test_annotation",
138 help="Include only those tests tagged with a specific"
139 " annotation")
140 parser.add_option("--not-annotation", dest="test_not_annotation",
Brett Chabot2e16fbc2010-02-23 12:28:27 -0800141 help="Exclude any tests tagged with a specific"
Brett Chabotc0611542010-02-20 20:09:58 -0800142 " annotation")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700143 parser.add_option("-u", "--user-tests-file", dest="user_tests_file",
144 metavar="FILE", default=user_test_default,
145 help="Alternate source of user test definitions")
146 parser.add_option("-o", "--coverage", dest="coverage",
147 default=False, action="store_true",
148 help="Generate code coverage metrics for test(s)")
Brett Chabot8ac51182012-09-19 07:35:35 -0700149 parser.add_option("--coverage-target", dest="coverage_target_path",
150 default=None,
151 help="Path to app to collect code coverage target data for.")
Brett Chabot59b47782009-10-21 17:23:01 -0700152 parser.add_option("-x", "--path", dest="test_path",
153 help="Run test(s) at given file system path")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700154 parser.add_option("-t", "--all-tests", dest="all_tests",
155 default=False, action="store_true",
156 help="Run all defined tests")
157 parser.add_option("--continuous", dest="continuous_tests",
158 default=False, action="store_true",
159 help="Run all tests defined as part of the continuous "
160 "test set")
Wei-Ta Chen97752d42009-05-21 16:24:04 -0700161 parser.add_option("--timeout", dest="timeout",
162 default=300, help="Set a timeout limit (in sec) for "
163 "running native tests on a device (default: 300 secs)")
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800164 parser.add_option("--suite", dest="suite",
Brett Chabot49b77112009-06-02 11:46:04 -0700165 help="Run all tests defined as part of the "
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800166 "the given test suite")
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700167 group = optparse.OptionGroup(
168 parser, "Targets", "Use these options to direct tests to a specific "
169 "Android target")
170 group.add_option("-e", "--emulator", dest="emulator", default=False,
171 action="store_true", help="use emulator")
172 group.add_option("-d", "--device", dest="device", default=False,
173 action="store_true", help="use device")
174 group.add_option("-s", "--serial", dest="serial",
175 help="use specific serial")
176 parser.add_option_group(group)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700177 self._options, self._test_args = parser.parse_args()
178
Brett Chabot49b77112009-06-02 11:46:04 -0700179 if (not self._options.only_list_tests
180 and not self._options.all_tests
181 and not self._options.continuous_tests
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800182 and not self._options.suite
Brett Chabot59b47782009-10-21 17:23:01 -0700183 and not self._options.test_path
Brett Chabot49b77112009-06-02 11:46:04 -0700184 and len(self._test_args) < 1):
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700185 parser.print_help()
186 logger.SilentLog("at least one test name must be specified")
187 raise errors.AbortError
188
189 self._adb = adb_interface.AdbInterface()
190 if self._options.emulator:
191 self._adb.SetEmulatorTarget()
192 elif self._options.device:
193 self._adb.SetDeviceTarget()
194 elif self._options.serial is not None:
195 self._adb.SetTargetSerial(self._options.serial)
196
197 if self._options.verbose:
198 logger.SetVerbose(True)
199
Brett Chabot8ac51182012-09-19 07:35:35 -0700200 if self._options.coverage_target_path:
201 self._options.coverage = True
202
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700203 self._known_tests = self._ReadTests()
204
Brett Chabot764d3fa2009-06-25 17:57:31 -0700205 self._options.host_lib_path = android_build.GetHostLibraryPath()
206 self._options.test_data_path = android_build.GetTestAppPath()
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700207
208 def _ReadTests(self):
209 """Parses the set of test definition data.
210
211 Returns:
212 A TestDefinitions object that contains the set of parsed tests.
213 Raises:
214 AbortError: If a fatal error occurred when parsing the tests.
215 """
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700216 try:
217 known_tests = test_defs.TestDefinitions()
Brett Chabot3c9cefc2011-06-06 20:53:56 -0700218 # only read tests when not in path mode
219 if not self._options.test_path:
220 core_test_path = os.path.join(self._root_path, self._CORE_TEST_PATH)
221 if os.path.isfile(core_test_path):
222 known_tests.Parse(core_test_path)
223 # read all <android root>/vendor/*/tests/testinfo/test_defs.xml paths
224 vendor_tests_pattern = os.path.join(self._root_path,
225 self._VENDOR_TEST_PATH)
226 test_file_paths = glob.glob(vendor_tests_pattern)
227 for test_file_path in test_file_paths:
228 known_tests.Parse(test_file_path)
229 if os.path.isfile(self._options.user_tests_file):
230 known_tests.Parse(self._options.user_tests_file)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700231 return known_tests
232 except errors.ParseError:
233 raise errors.AbortError
234
235 def _DumpTests(self):
236 """Prints out set of defined tests."""
Brett Chabotbe659c02009-09-21 17:48:26 -0700237 print "The following tests are currently defined:\n"
238 print "%-25s %-40s %s" % ("name", "build path", "description")
239 print "-" * 80
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700240 for test in self._known_tests:
Brett Chabotbe659c02009-09-21 17:48:26 -0700241 print "%-25s %-40s %s" % (test.GetName(), test.GetBuildPath(),
242 test.GetDescription())
243 print "\nSee %s for more information" % self._TEST_FILE_NAME
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700244
245 def _DoBuild(self):
246 logger.SilentLog("Building tests...")
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700247
248 tests = self._GetTestsToRun()
Brett Chabotb1eb5d22010-06-15 11:18:42 -0700249 # turn off dalvik verifier if necessary
250 self._TurnOffVerifier(tests)
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700251 self._DoFullBuild(tests)
252
Brett Chabot8ac51182012-09-19 07:35:35 -0700253 target_tree = make_tree.MakeTree()
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800254
255 extra_args_set = []
Brett Chabot2477b382009-09-23 18:05:28 -0700256 for test_suite in tests:
Brett Chabot8ac51182012-09-19 07:35:35 -0700257 self._AddBuildTarget(test_suite, target_tree, extra_args_set)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700258
Brett Chabotccae47d2010-06-14 15:19:25 -0700259 if not self._options.preview:
260 self._adb.EnableAdbRoot()
261 else:
262 logger.Log("adb root")
Brett Chabot8ac51182012-09-19 07:35:35 -0700263
264 if not target_tree.IsEmpty():
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700265 if self._options.coverage:
Brett Chabot764d3fa2009-06-25 17:57:31 -0700266 coverage.EnableCoverageBuild()
Brett Chabot8ac51182012-09-19 07:35:35 -0700267 target_tree.AddPath("external/emma")
Brett Chabot2477b382009-09-23 18:05:28 -0700268
Brett Chabot8ac51182012-09-19 07:35:35 -0700269 target_list = target_tree.GetPrunedMakeList()
270 target_build_string = " ".join(target_list)
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800271 extra_args_string = " ".join(extra_args_set)
Brett Chabotb1eb5d22010-06-15 11:18:42 -0700272
Brett Chabot764d3fa2009-06-25 17:57:31 -0700273 # mmm cannot be used from python, so perform a similar operation using
Brett Chabot2b6643b2009-04-07 18:35:27 -0700274 # ONE_SHOT_MAKEFILE
Brett Chabot546a3282011-06-07 19:19:30 -0700275 cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" all_modules %s' % (
Brett Chabot2477b382009-09-23 18:05:28 -0700276 target_build_string, self._options.make_jobs, self._root_path,
277 extra_args_string)
Brett Chabot764d3fa2009-06-25 17:57:31 -0700278 logger.Log(cmd)
Brett Chabot74541712012-08-31 18:39:00 -0700279 if not self._options.preview:
280 output = run_command.RunCommand(cmd, return_output=True, timeout_time=600)
281 self._DoInstall(output)
Niko Cataniaa6dc2ab2009-04-03 14:12:46 -0700282
Brett Chabot74541712012-08-31 18:39:00 -0700283 def _DoInstall(self, make_output):
284 """Install artifacts from build onto device.
285
286 Looks for 'install:' text from make output to find artifacts to install.
287
288 Args:
289 make_output: stdout from make command
290 """
291 for line in make_output.split("\n"):
292 m = self._RE_MAKE_INSTALL.match(line)
293 if m:
294 install_path = m.group(1)
295 if install_path.endswith(".apk"):
296 abs_install_path = os.path.join(self._root_path, install_path)
297 logger.Log("adb install -r %s" % abs_install_path)
298 logger.Log(self._adb.Install(abs_install_path))
299 else:
300 self._PushInstallFileToDevice(install_path)
301
302 def _PushInstallFileToDevice(self, install_path):
JP Abgrallf38107c2013-07-11 17:39:16 -0700303 m = self._re_make_install_path.match(install_path)
Brett Chabot74541712012-08-31 18:39:00 -0700304 if m:
305 remote_path = m.group(1)
Brett Chabote607d3a2013-05-16 23:00:43 -0700306 remote_dir = os.path.dirname(remote_path)
307 logger.Log("adb shell mkdir -p %s" % remote_dir)
308 self._adb.SendShellCommand("mkdir -p %s" % remote_dir)
Brett Chabot74541712012-08-31 18:39:00 -0700309 abs_install_path = os.path.join(self._root_path, install_path)
Brett Chabot81c475e2012-09-11 12:57:31 -0700310 logger.Log("adb push %s %s" % (abs_install_path, remote_path))
Brett Chabot74541712012-08-31 18:39:00 -0700311 self._adb.Push(abs_install_path, remote_path)
312 else:
313 logger.Log("Error: Failed to recognize path of file to install %s" % install_path)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700314
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700315 def _DoFullBuild(self, tests):
316 """If necessary, run a full 'make' command for the tests that need it."""
317 extra_args_set = Set()
318
319 # hack to build cts dependencies
320 # TODO: remove this when cts dependencies are removed
321 if self._IsCtsTests(tests):
322 # need to use make since these fail building with ONE_SHOT_MAKEFILE
323 extra_args_set.add('CtsTestStubs')
324 extra_args_set.add('android.core.tests.runner')
325 for test in tests:
326 if test.IsFullMake():
327 if test.GetExtraBuildArgs():
328 # extra args contains the args to pass to 'make'
329 extra_args_set.add(test.GetExtraBuildArgs())
330 else:
331 logger.Log("Warning: test %s needs a full build but does not specify"
332 " extra_build_args" % test.GetName())
333
334 # check if there is actually any tests that required a full build
335 if extra_args_set:
336 cmd = ('make -j%s %s' % (self._options.make_jobs,
337 ' '.join(list(extra_args_set))))
338 logger.Log(cmd)
339 if not self._options.preview:
340 old_dir = os.getcwd()
341 os.chdir(self._root_path)
Brett Chabotb0b8c782012-09-19 08:32:56 -0700342 output = run_command.RunCommand(cmd, return_output=True)
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700343 os.chdir(old_dir)
Brett Chabot74541712012-08-31 18:39:00 -0700344 self._DoInstall(output)
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700345
Brett Chabot8ac51182012-09-19 07:35:35 -0700346 def _AddBuildTarget(self, test_suite, target_tree, extra_args_set):
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700347 if not test_suite.IsFullMake():
348 build_dir = test_suite.GetBuildPath()
Brett Chabot8ac51182012-09-19 07:35:35 -0700349 if self._AddBuildTargetPath(build_dir, target_tree):
Brian Muramatsu95cbc9e2012-01-10 12:06:12 -0800350 extra_args_set.append(test_suite.GetExtraBuildArgs())
Brett Chabot8dc9eb82010-04-15 15:43:04 -0700351 for path in test_suite.GetBuildDependencies(self._options):
Brett Chabot8ac51182012-09-19 07:35:35 -0700352 self._AddBuildTargetPath(path, target_tree)
Brett Chabot2b6643b2009-04-07 18:35:27 -0700353
Brett Chabot8ac51182012-09-19 07:35:35 -0700354 def _AddBuildTargetPath(self, build_dir, target_tree):
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700355 if build_dir is not None:
Brett Chabot8ac51182012-09-19 07:35:35 -0700356 target_tree.AddPath(build_dir)
357 return True
Brett Chabot2b6643b2009-04-07 18:35:27 -0700358 return False
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700359
360 def _GetTestsToRun(self):
361 """Get a list of TestSuite objects to run, based on command line args."""
Brett Chabot59b47782009-10-21 17:23:01 -0700362 if self._tests_to_run:
363 return self._tests_to_run
364
365 self._tests_to_run = []
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700366 if self._options.all_tests:
Brett Chabot59b47782009-10-21 17:23:01 -0700367 self._tests_to_run = self._known_tests.GetTests()
Brett Chabot49b77112009-06-02 11:46:04 -0700368 elif self._options.continuous_tests:
Brett Chabot59b47782009-10-21 17:23:01 -0700369 self._tests_to_run = self._known_tests.GetContinuousTests()
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800370 elif self._options.suite:
371 self._tests_to_run = \
372 self._known_tests.GetTestsInSuite(self._options.suite)
Brett Chabot59b47782009-10-21 17:23:01 -0700373 elif self._options.test_path:
374 walker = test_walker.TestWalker()
375 self._tests_to_run = walker.FindTests(self._options.test_path)
376
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700377 for name in self._test_args:
378 test = self._known_tests.GetTest(name)
379 if test is None:
380 logger.Log("Error: Could not find test %s" % name)
381 self._DumpTests()
382 raise errors.AbortError
Brett Chabot59b47782009-10-21 17:23:01 -0700383 self._tests_to_run.append(test)
384 return self._tests_to_run
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700385
Brett Chabot2477b382009-09-23 18:05:28 -0700386 def _IsCtsTests(self, test_list):
387 """Check if any cts tests are included in given list of tests to run."""
388 for test in test_list:
Brett Chabot4a5d9f12010-02-18 20:01:11 -0800389 if test.GetSuite() == 'cts':
Brett Chabot2477b382009-09-23 18:05:28 -0700390 return True
391 return False
392
Brett Chabotccae47d2010-06-14 15:19:25 -0700393 def _TurnOffVerifier(self, test_list):
394 """Turn off the dalvik verifier if needed by given tests.
395
396 If one or more tests needs dalvik verifier off, and it is not already off,
397 turns off verifier and reboots device to allow change to take effect.
398 """
Brett Chabot74541712012-08-31 18:39:00 -0700399 # hack to check if these are frameworks/base tests. If so, turn off verifier
Brett Chabotccae47d2010-06-14 15:19:25 -0700400 # to allow framework tests to access package-private framework api
401 framework_test = False
402 for test in test_list:
403 if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]):
404 framework_test = True
405 if framework_test:
406 # check if verifier is off already - to avoid the reboot if not
407 # necessary
408 output = self._adb.SendShellCommand("cat /data/local.prop")
409 if not self._DALVIK_VERIFIER_OFF_PROP in output:
410 if self._options.preview:
411 logger.Log("adb shell \"echo %s >> /data/local.prop\""
412 % self._DALVIK_VERIFIER_OFF_PROP)
Brett Chabot25dfd792012-02-16 15:51:43 -0800413 logger.Log("adb shell chmod 644 /data/local.prop")
Brett Chabotccae47d2010-06-14 15:19:25 -0700414 logger.Log("adb reboot")
415 logger.Log("adb wait-for-device")
416 else:
417 logger.Log("Turning off dalvik verifier and rebooting")
418 self._adb.SendShellCommand("\"echo %s >> /data/local.prop\""
419 % self._DALVIK_VERIFIER_OFF_PROP)
Brett Chabot25dfd792012-02-16 15:51:43 -0800420
421 self._ChmodReboot()
422 elif not self._options.preview:
423 # check the permissions on the file
424 permout = self._adb.SendShellCommand("ls -l /data/local.prop")
425 if not "-rw-r--r--" in permout:
426 logger.Log("Fixing permissions on /data/local.prop and rebooting")
427 self._ChmodReboot()
428
429 def _ChmodReboot(self):
430 """Perform a chmod of /data/local.prop and reboot.
431 """
432 self._adb.SendShellCommand("chmod 644 /data/local.prop")
433 self._adb.SendCommand("reboot")
434 # wait for device to go offline
435 time.sleep(10)
436 self._adb.SendCommand("wait-for-device", timeout_time=60,
437 retry_count=3)
438 self._adb.EnableAdbRoot()
439
Brett Chabotccae47d2010-06-14 15:19:25 -0700440
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700441 def RunTests(self):
442 """Main entry method - executes the tests according to command line args."""
443 try:
444 run_command.SetAbortOnError()
445 self._ProcessOptions()
446 if self._options.only_list_tests:
447 self._DumpTests()
448 return
449
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700450 if not self._options.skip_build:
451 self._DoBuild()
452
453 for test_suite in self._GetTestsToRun():
Brett Chabot920e9fe2010-01-21 17:30:47 -0800454 try:
455 test_suite.Run(self._options, self._adb)
456 except errors.WaitForResponseTimedOutError:
457 logger.Log("Timed out waiting for response")
Brett Chabot764d3fa2009-06-25 17:57:31 -0700458
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700459 except KeyboardInterrupt:
460 logger.Log("Exiting...")
Brett Chabot3ae5f8a2009-06-28 12:00:47 -0700461 except errors.AbortError, error:
462 logger.Log(error.msg)
The Android Open Source Project6ffae012009-03-18 17:39:43 -0700463 logger.SilentLog("Exiting due to AbortError...")
464 except errors.WaitForResponseTimedOutError:
465 logger.Log("Timed out waiting for response")
466
467
468def RunTests():
469 runner = TestRunner()
470 runner.RunTests()
471
472if __name__ == "__main__":
473 RunTests()