runtest: Update to work with emulator and to build dependencies

* Combine dalvik.vm.dexopt-flags with existing to disable verification
* Always do a runtime reset (stop;start) instead of rebooting device
* Build dependencies (mma) if regular build fails (mm)

Change-Id: I5e9fcebeea052c3314d1f4146b074637c329c0a0
This commit is contained in:
Igor Murashkin
2014-01-22 16:22:50 -08:00
parent 0305f64106
commit a0afc8cfb2
2 changed files with 101 additions and 28 deletions

View File

@@ -506,3 +506,34 @@ class AdbInterface:
def GetSerialNumber(self): def GetSerialNumber(self):
"""Returns the serial number of the targeted device.""" """Returns the serial number of the targeted device."""
return self.SendCommand("get-serialno").strip() return self.SendCommand("get-serialno").strip()
def RuntimeReset(self, disable_keyguard=False, retry_count=3, preview_only=False):
"""
Resets the Android runtime (does *not* reboot the kernel).
Blocks until the reset is complete and the package manager
is available.
Args:
disable_keyguard: if True, presses the MENU key to disable
key guard, after reset is finished
retry_count: number of times to retry reset before failing
Raises:
WaitForResponseTimedOutError if package manager does not respond
AbortError if unrecoverable error occurred
"""
logger.Log("adb shell stop")
logger.Log("adb shell start")
if not preview_only:
self.SendShellCommand("stop", retry_count=retry_count)
self.SendShellCommand("start", retry_count=retry_count)
self.WaitForDevicePm()
if disable_keyguard:
logger.Log("input keyevent 82 ## disable keyguard")
if not preview_only:
self.SendShellCommand("input keyevent 82", retry_count=retry_count)

View File

@@ -73,11 +73,12 @@ class TestRunner(object):
# default value for make -jX # default value for make -jX
_DEFAULT_JOBS = 16 _DEFAULT_JOBS = 16
_DALVIK_VERIFIER_OFF_PROP = "dalvik.vm.dexopt-flags = v=n" _DALVIK_VERIFIER_PROP = "dalvik.vm.dexopt-flags"
_DALVIK_VERIFIER_OFF_VALUE = "v=n"
_DALVIK_VERIFIER_OFF_PROP = "%s = %s" %(_DALVIK_VERIFIER_PROP, _DALVIK_VERIFIER_OFF_VALUE)
# regular expression to match path to artifacts to install in make output # regular expression to match path to artifacts to install in make output
_RE_MAKE_INSTALL = re.compile(r'INSTALL-PATH:\s(.+)\s(.+)') _RE_MAKE_INSTALL = re.compile(r'INSTALL-PATH:\s([^\s]+)\s(.*)$')
def __init__(self): def __init__(self):
# disable logging of timestamp # disable logging of timestamp
@@ -193,7 +194,6 @@ class TestRunner(object):
self._adb.SetDeviceTarget() self._adb.SetDeviceTarget()
elif self._options.serial is not None: elif self._options.serial is not None:
self._adb.SetTargetSerial(self._options.serial) self._adb.SetTargetSerial(self._options.serial)
if self._options.verbose: if self._options.verbose:
logger.SetVerbose(True) logger.SetVerbose(True)
@@ -267,7 +267,9 @@ class TestRunner(object):
target_tree.AddPath("external/emma") target_tree.AddPath("external/emma")
target_list = target_tree.GetPrunedMakeList() target_list = target_tree.GetPrunedMakeList()
target_dir_list = [re.sub(r'Android[.]mk$', r'', i) for i in target_list]
target_build_string = " ".join(target_list) target_build_string = " ".join(target_list)
target_dir_build_string = " ".join(target_dir_list)
extra_args_string = " ".join(extra_args_set) extra_args_string = " ".join(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
@@ -275,9 +277,24 @@ class TestRunner(object):
cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" GET-INSTALL-PATH all_modules %s' % ( cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" GET-INSTALL-PATH all_modules %s' % (
target_build_string, self._options.make_jobs, self._root_path, target_build_string, self._options.make_jobs, self._root_path,
extra_args_string) extra_args_string)
# mmma equivalent, used when regular mmm fails
alt_cmd = 'make -j%s -C "%s" -f build/core/main.mk %s all_modules BUILD_MODULES_IN_PATHS="%s"' % (
self._options.make_jobs, self._root_path, extra_args_string, target_dir_build_string)
logger.Log(cmd) logger.Log(cmd)
if not self._options.preview: if not self._options.preview:
run_command.SetAbortOnError()
try:
output = run_command.RunCommand(cmd, return_output=True, timeout_time=600) output = run_command.RunCommand(cmd, return_output=True, timeout_time=600)
## Chances are this failed because it didn't build the dependencies
except errors.AbortError:
logger.Log("make failed. Trying to rebuild all dependencies.")
logger.Log("mmma -j%s %s" %(self._options.make_jobs, target_dir_build_string))
# Try again with mma equivalent, which will build the dependencies
run_command.RunCommand(alt_cmd, return_output=False, timeout_time=600)
# Run mmm again to get the install paths only
output = run_command.RunCommand(cmd, return_output=True, timeout_time=600)
run_command.SetAbortOnError(False)
logger.SilentLog(output) logger.SilentLog(output)
self._DoInstall(output) self._DoInstall(output)
@@ -286,13 +303,19 @@ class TestRunner(object):
Looks for 'install:' text from make output to find artifacts to install. Looks for 'install:' text from make output to find artifacts to install.
Files with the .apk extension get 'adb install'ed, all other files
get 'adb push'ed onto the device.
Args: Args:
make_output: stdout from make command make_output: stdout from make command
""" """
for line in make_output.split("\n"): for line in make_output.split("\n"):
m = self._RE_MAKE_INSTALL.match(line) m = self._RE_MAKE_INSTALL.match(line)
if m: if m:
install_path = m.group(2) # strip the 'INSTALL: <name>' from the left hand side
# the remaining string is a space-separated list of build-generated files
install_paths = m.group(2)
for install_path in re.split(r'\s+', install_paths):
if install_path.endswith(".apk"): if install_path.endswith(".apk"):
abs_install_path = os.path.join(self._root_path, install_path) abs_install_path = os.path.join(self._root_path, install_path)
logger.Log("adb install -r %s" % abs_install_path) logger.Log("adb install -r %s" % abs_install_path)
@@ -406,7 +429,7 @@ class TestRunner(object):
turns off verifier and reboots device to allow change to take effect. turns off verifier and reboots device to allow change to take effect.
""" """
# hack to check if these are frameworks/base tests. If so, turn off verifier # hack to check if these are frameworks/base tests. If so, turn off verifier
# to allow framework tests to access package-private framework api # to allow framework tests to access private/protected/package-private framework api
framework_test = False framework_test = False
for test in test_list: for test in test_list:
if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]): if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]):
@@ -416,34 +439,53 @@ class TestRunner(object):
# necessary # necessary
output = self._adb.SendShellCommand("cat /data/local.prop") output = self._adb.SendShellCommand("cat /data/local.prop")
if not self._DALVIK_VERIFIER_OFF_PROP in output: if not self._DALVIK_VERIFIER_OFF_PROP in output:
# Read the existing dalvik verifier flags.
old_prop_value = self._adb.SendShellCommand("getprop %s" \
%(self._DALVIK_VERIFIER_PROP))
old_prop_value = old_prop_value.strip() if old_prop_value else ""
# Append our verifier flags to existing flags
new_prop_value = "%s %s" %(self._DALVIK_VERIFIER_OFF_VALUE, old_prop_value)
# Update property now, as /data/local.prop is not read until reboot
logger.Log("adb shell setprop %s '%s'" \
%(self._DALVIK_VERIFIER_PROP, new_prop_value))
if not self._options.preview:
self._adb.SendShellCommand("setprop %s '%s'" \
%(self._DALVIK_VERIFIER_PROP, new_prop_value))
# Write prop to /data/local.prop
# Every time device is booted, it will pick up this value
new_prop_assignment = "%s = %s" %(self._DALVIK_VERIFIER_PROP, new_prop_value)
if self._options.preview: if self._options.preview:
logger.Log("adb shell \"echo %s >> /data/local.prop\"" logger.Log("adb shell \"echo %s >> /data/local.prop\""
% self._DALVIK_VERIFIER_OFF_PROP) % new_prop_assignment)
logger.Log("adb shell chmod 644 /data/local.prop") logger.Log("adb shell chmod 644 /data/local.prop")
logger.Log("adb reboot")
logger.Log("adb wait-for-device")
else: else:
logger.Log("Turning off dalvik verifier and rebooting") logger.Log("Turning off dalvik verifier and rebooting")
self._adb.SendShellCommand("\"echo %s >> /data/local.prop\"" self._adb.SendShellCommand("\"echo %s >> /data/local.prop\""
% self._DALVIK_VERIFIER_OFF_PROP) % new_prop_assignment)
self._ChmodReboot() # Reset runtime so that dalvik picks up new verifier flags from prop
self._ChmodRuntimeReset()
elif not self._options.preview: elif not self._options.preview:
# check the permissions on the file # check the permissions on the file
permout = self._adb.SendShellCommand("ls -l /data/local.prop") permout = self._adb.SendShellCommand("ls -l /data/local.prop")
if not "-rw-r--r--" in permout: if not "-rw-r--r--" in permout:
logger.Log("Fixing permissions on /data/local.prop and rebooting") logger.Log("Fixing permissions on /data/local.prop and rebooting")
self._ChmodReboot() self._ChmodRuntimeReset()
def _ChmodReboot(self): def _ChmodRuntimeReset(self):
"""Perform a chmod of /data/local.prop and reboot. """Perform a chmod of /data/local.prop and reset the runtime.
""" """
logger.Log("adb shell chmod 644 /data/local.prop ## u+w,a+r")
if not self._options.preview:
self._adb.SendShellCommand("chmod 644 /data/local.prop") self._adb.SendShellCommand("chmod 644 /data/local.prop")
self._adb.SendCommand("reboot")
# wait for device to go offline self._adb.RuntimeReset(preview_only=self._options.preview)
time.sleep(10)
self._adb.SendCommand("wait-for-device", timeout_time=60, if not self._options.preview:
retry_count=3)
self._adb.EnableAdbRoot() self._adb.EnableAdbRoot()