Fix log syntax.

And add better error message when instrumentation test is not
present.

Change-Id: I381421e59a3b667a5c3090ccd49e38fe99d680c5
This commit is contained in:
Brett Chabot
2012-09-11 12:57:31 -07:00
parent 39e3b7fe23
commit 81c475e4ac
3 changed files with 25 additions and 28 deletions

View File

@@ -336,29 +336,16 @@ class AdbInterface:
raise errors.WaitForResponseTimedOutError(
"Package manager did not respond after %s seconds" % wait_time)
def WaitForInstrumentation(self, package_name, runner_name, wait_time=120):
"""Waits for given instrumentation to be present on device
Args:
wait_time: time in seconds to wait
Raises:
WaitForResponseTimedOutError if wait_time elapses and instrumentation
still not present.
"""
def IsInstrumentationInstalled(self, package_name, runner_name):
"""Checks if instrumentation is present on device."""
instrumentation_path = "%s/%s" % (package_name, runner_name)
logger.Log("Waiting for instrumentation to be present")
# Query the package manager
try:
command = "pm list instrumentation | grep %s" % instrumentation_path
self._WaitForShellCommandContents(command, "instrumentation:", wait_time,
raise_abort=False)
except errors.WaitForResponseTimedOutError :
logger.Log(
"Could not find instrumentation %s on device. Does the "
"instrumentation in test's AndroidManifest.xml match definition"
"in test_defs.xml?" % instrumentation_path)
raise
try:
output = self.SendShellCommand(command)
return output.startswith("instrumentation:")
except errors.AbortError:
# command can return error code on failure
return False
def WaitForProcess(self, name, wait_time=120):
"""Wait until a process is running on the device.

View File

@@ -294,7 +294,7 @@ class TestRunner(object):
if m:
remote_path = m.group(1)
abs_install_path = os.path.join(self._root_path, install_path)
logger.Log("adb push %s %s", abs_install_path, remote_path)
logger.Log("adb push %s %s" % (abs_install_path, remote_path))
self._adb.Push(abs_install_path, remote_path)
else:
logger.Log("Error: Failed to recognize path of file to install %s" % install_path)

View File

@@ -140,6 +140,7 @@ class InstrumentationTestSuite(test_suite.AbstractTestSuite):
logger.Log(adb_cmd)
elif options.coverage:
coverage_gen = coverage.CoverageGenerator(adb)
self._CheckInstrumentationInstalled(adb)
# need to parse test output to determine path to coverage file
logger.Log("Running in coverage mode, suppressing test output")
try:
@@ -160,12 +161,22 @@ class InstrumentationTestSuite(test_suite.AbstractTestSuite):
self, device_coverage_path, test_qualifier=options.test_size)
if coverage_file is not None:
logger.Log("Coverage report generated at %s" % coverage_file)
else:
adb.StartInstrumentationNoResults(
package_name=self.GetPackageName(),
self._CheckInstrumentationInstalled(adb)
adb.StartInstrumentationNoResults(package_name=self.GetPackageName(),
runner_name=self.GetRunnerName(),
raw_mode=options.raw_mode,
instrumentation_args=instrumentation_args)
instrumentation_args=
instrumentation_args)
def _CheckInstrumentationInstalled(self, adb):
if not adb.IsInstrumentationInstalled(self.GetPackageName(),
self.GetRunnerName()):
msg=("Could not find instrumentation %s/%s on device. Try forcing a "
"rebuild by updating a source file, and re-executing runtest." %
(self.GetPackageName(), self.GetRunnerName()))
raise errors.AbortError(msg=msg)
def _PrintTestResults(self, test_results):
"""Prints a summary of test result data to stdout.
@@ -189,7 +200,6 @@ class InstrumentationTestSuite(test_suite.AbstractTestSuite):
logger.Log("Tests run: %d, Failures: %d, Errors: %d" %
(total_count, fail_count, error_count))
def HasInstrumentationTest(path):
"""Determine if given path defines an instrumentation test.