am 0e968fa2: Merge "Workaround for package-private framework tests in runtest." into gingerbread

Merge commit '0e968fa2eec9dcdbb0ab075be9489cc9e4ad9c99' into gingerbread-plus-aosp

* commit '0e968fa2eec9dcdbb0ab075be9489cc9e4ad9c99':
  Workaround for package-private framework tests in runtest.
This commit is contained in:
Brett Chabot
2010-06-15 10:49:09 -07:00
committed by Android Git Automerger
2 changed files with 51 additions and 0 deletions

View File

@@ -148,6 +148,19 @@ class AdbInterface:
return False return False
return True return True
def EnableAdbRoot(self):
"""Enable adb root on device."""
output = self.SendCommand("root")
if "adbd is already running as root" in output:
return True
elif "restarting adbd as root" in output:
# device will disappear from adb, wait for it to come back
self.SendCommand("wait-for-device")
return True
else:
logger.Log("Unrecognized output from adb root: %s" % output)
return False
def StartInstrumentationForPackage( def StartInstrumentationForPackage(
self, package_name, runner_name, timeout_time=60*10, self, package_name, runner_name, timeout_time=60*10,
no_window_animation=False, instrumentation_args={}): no_window_animation=False, instrumentation_args={}):

View File

@@ -70,6 +70,8 @@ class TestRunner(object):
# default value for make -jX # default value for make -jX
_DEFAULT_JOBS = 4 _DEFAULT_JOBS = 4
_DALVIK_VERIFIER_OFF_PROP = "dalvik.vm.dexopt-flags = v=n"
def __init__(self): def __init__(self):
# disable logging of timestamp # disable logging of timestamp
self._root_path = android_build.GetTop() self._root_path = android_build.GetTop()
@@ -227,6 +229,10 @@ class TestRunner(object):
for test_suite in tests: for test_suite in tests:
self._AddBuildTarget(test_suite, target_set, extra_args_set) self._AddBuildTarget(test_suite, target_set, extra_args_set)
if not self._options.preview:
self._adb.EnableAdbRoot()
else:
logger.Log("adb root")
rebuild_libcore = False rebuild_libcore = False
if target_set: if target_set:
if self._options.coverage: if self._options.coverage:
@@ -258,6 +264,8 @@ class TestRunner(object):
os.chdir(self._root_path) os.chdir(self._root_path)
run_command.RunCommand(cmd, return_output=False) run_command.RunCommand(cmd, return_output=False)
os.chdir(old_dir) os.chdir(old_dir)
# turn off dalvik verifier if necessary
self._TurnOffVerifier(tests)
target_build_string = " ".join(list(target_set)) target_build_string = " ".join(list(target_set))
extra_args_string = " ".join(list(extra_args_set)) extra_args_string = " ".join(list(extra_args_set))
# mmm cannot be used from python, so perform a similar operation using # mmm cannot be used from python, so perform a similar operation using
@@ -328,6 +336,36 @@ class TestRunner(object):
return True return True
return False return False
def _TurnOffVerifier(self, test_list):
"""Turn off the dalvik verifier if needed by given tests.
If one or more tests needs dalvik verifier off, and it is not already off,
turns off verifier and reboots device to allow change to take effect.
"""
# hack to check if these are framework/base tests. If so, turn off verifier
# to allow framework tests to access package-private framework api
framework_test = False
for test in test_list:
if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]):
framework_test = True
if framework_test:
# check if verifier is off already - to avoid the reboot if not
# necessary
output = self._adb.SendShellCommand("cat /data/local.prop")
if not self._DALVIK_VERIFIER_OFF_PROP in output:
if self._options.preview:
logger.Log("adb shell \"echo %s >> /data/local.prop\""
% self._DALVIK_VERIFIER_OFF_PROP)
logger.Log("adb reboot")
logger.Log("adb wait-for-device")
else:
logger.Log("Turning off dalvik verifier and rebooting")
self._adb.SendShellCommand("\"echo %s >> /data/local.prop\""
% self._DALVIK_VERIFIER_OFF_PROP)
self._adb.SendCommand("reboot")
self._adb.SendCommand("wait-for-device", timeout_time=60,
retry_count=3)
def RunTests(self): def RunTests(self):
"""Main entry method - executes the tests according to command line args.""" """Main entry method - executes the tests according to command line args."""
try: try: