am 8f7e926c: Merge change 3202 into donut
Merge commit '8f7e926c115ece3b9c8972ae9d03113850220bcb'
* commit '8f7e926c115ece3b9c8972ae9d03113850220bcb':
Make runtest wait for instrumentation install before running test.
diff --git a/testrunner/adb_interface.py b/testrunner/adb_interface.py
index b1e3757..429bc27 100755
--- a/testrunner/adb_interface.py
+++ b/testrunner/adb_interface.py
@@ -317,7 +317,44 @@
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.
diff --git a/testrunner/runtest.py b/testrunner/runtest.py
index e66b8de..03eddbf 100755
--- a/testrunner/runtest.py
+++ b/testrunner/runtest.py
@@ -287,6 +287,8 @@
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 @@
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(),