Merge changes Ia8070804,I3033b442,I5e9fcebe

* changes:
  runtest: add an extra pattern for gtest file names (*Tests.[c|cpp])
  runtest: add --build-install-only/-i flag to skip test execution
  runtest: Update to work with emulator and to build dependencies
This commit is contained in:
Igor Murashkin
2014-01-25 00:32:08 +00:00
committed by Android (Google) Code Review
3 changed files with 111 additions and 29 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
@@ -113,6 +114,9 @@ class TestRunner(object):
parser.add_option("-n", "--skip_execute", dest="preview", default=False, parser.add_option("-n", "--skip_execute", dest="preview", default=False,
action="store_true", action="store_true",
help="Do not execute, just preview commands") help="Do not execute, just preview commands")
parser.add_option("-i", "--build-install-only", dest="build_install_only", default=False,
action="store_true",
help="Do not execute, build tests and install to device only")
parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False, parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False,
action="store_true", action="store_true",
help="Raw mode (for output to other tools)") help="Raw mode (for output to other tools)")
@@ -193,7 +197,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 +270,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 +280,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 +306,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 +432,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 +442,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()
@@ -459,6 +504,10 @@ class TestRunner(object):
if not self._options.skip_build: if not self._options.skip_build:
self._DoBuild() self._DoBuild()
if self._options.build_install_only:
logger.Log("Skipping test execution (due to --build-install-only flag)")
return
for test_suite in self._GetTestsToRun(): for test_suite in self._GetTestsToRun():
try: try:
test_suite.Run(self._options, self._adb) test_suite.Run(self._options, self._adb)

View File

@@ -73,6 +73,7 @@ class GTestFactory(test_suite.AbstractTestFactory):
- test_*.[c|cc|cpp] - test_*.[c|cc|cpp]
- *_test.[c|cc|cpp] - *_test.[c|cc|cpp]
- *_unittest.[c|cc|cpp] - *_unittest.[c|cc|cpp]
- *Tests.[cc|cpp]
""" """
if not sub_tests_path: if not sub_tests_path:
@@ -101,6 +102,7 @@ class GTestFactory(test_suite.AbstractTestFactory):
- test_*.[cc|cpp] - test_*.[cc|cpp]
- *_test.[cc|cpp] - *_test.[cc|cpp]
- *_unittest.[cc|cpp] - *_unittest.[cc|cpp]
- *Tests.[cc|cpp]
This method is a callback for os.path.walk. This method is a callback for os.path.walk.
@@ -115,6 +117,6 @@ class GTestFactory(test_suite.AbstractTestFactory):
def _EvaluateFile(self, test_list, file): def _EvaluateFile(self, test_list, file):
(name, ext) = os.path.splitext(file) (name, ext) = os.path.splitext(file)
if ext == ".cc" or ext == ".cpp" or ext == ".c": if ext == ".cc" or ext == ".cpp" or ext == ".c":
if re.search("_test$|_test_$|_unittest$|_unittest_$|^test_", name): if re.search("_test$|_test_$|_unittest$|_unittest_$|^test_|Tests$", name):
logger.SilentLog("Found native test file %s" % file) logger.SilentLog("Found native test file %s" % file)
test_list.append(name) test_list.append(name)