Merge change 3202 into donut

* changes:
  Make runtest wait for instrumentation install before running test.
This commit is contained in:
Android (Google) Code Review
2009-06-04 18:54:50 -07:00
2 changed files with 42 additions and 1 deletions

View File

@@ -317,7 +317,44 @@ class AdbInterface:
if not pm_found:
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.
"""
instrumentation_path = "%s/%s" % (package_name, runner_name)
logger.Log("Waiting for instrumentation to be present")
# Query the package manager
inst_found = False
attempts = 0
wait_period = 5
while not inst_found and (attempts*wait_period) < wait_time:
# assume the 'adb shell pm list instrumentation'
# return 'instrumentation: something' in the success case
try:
output = self.SendShellCommand("pm list instrumentation | grep %s"
% instrumentation_path, retry_count=1)
if "instrumentation:" in output:
inst_found = True
except errors.AbortError, e:
# ignore
pass
if not inst_found:
time.sleep(wait_period)
attempts += 1
if not inst_found:
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 errors.WaitForResponseTimedOutError()
def Sync(self, retry_count=3):
"""Perform a adb sync.

View File

@@ -287,6 +287,8 @@ class TestRunner(object):
instrumentation_args=instrumentation_args)
logger.Log(adb_cmd)
elif self._options.coverage:
self._adb.WaitForInstrumentation(test_suite.GetPackageName(),
test_suite.GetRunnerName())
# need to parse test output to determine path to coverage file
logger.Log("Running in coverage mode, suppressing test output")
try:
@@ -306,6 +308,8 @@ class TestRunner(object):
if coverage_file is not None:
logger.Log("Coverage report generated at %s" % coverage_file)
else:
self._adb.WaitForInstrumentation(test_suite.GetPackageName(),
test_suite.GetRunnerName())
self._adb.StartInstrumentationNoResults(
package_name=test_suite.GetPackageName(),
runner_name=test_suite.GetRunnerName(),