summaryrefslogtreecommitdiffstats
path: root/testrunner
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2010-10-08 13:43:42 -0700
committerAndroid Code Review <code-review@android.com>2010-10-08 13:43:42 -0700
commite73f0dfc64a55dcdcac92a2cab93de677042fb07 (patch)
tree5331d864efd6f22d8c232ad7c6133a7c2a6525ac /testrunner
parent682ec293359cf4ac8c61df25bb05519b604b17eb (diff)
parent9290dd9c7d6286906ef0f1fc9706e67ca0bb4bf4 (diff)
downloadandroid_development-e73f0dfc64a55dcdcac92a2cab93de677042fb07.tar.gz
android_development-e73f0dfc64a55dcdcac92a2cab93de677042fb07.tar.bz2
android_development-e73f0dfc64a55dcdcac92a2cab93de677042fb07.zip
Merge "Added adb_interface.WaitForProcess and WaitForProcessEnd."
Diffstat (limited to 'testrunner')
-rwxr-xr-xtestrunner/adb_interface.py109
1 files changed, 80 insertions, 29 deletions
diff --git a/testrunner/adb_interface.py b/testrunner/adb_interface.py
index 698ea8bc0..ad31fb232 100755
--- a/testrunner/adb_interface.py
+++ b/testrunner/adb_interface.py
@@ -302,19 +302,10 @@ class AdbInterface:
self.SendCommand("wait-for-device")
# Now the device is there, but may not be running.
# Query the package manager with a basic command
- pm_found = False
- attempts = 0
- wait_period = 5
- while not pm_found and (attempts*wait_period) < wait_time:
- # assume the 'adb shell pm path android' command will always
- # return 'package: something' in the success case
- output = self.SendShellCommand("pm path android", retry_count=1)
- if "package:" in output:
- pm_found = True
- else:
- time.sleep(wait_period)
- attempts += 1
- if not pm_found:
+ try:
+ self._WaitForShellCommandContents("pm path android", "package:",
+ wait_time)
+ except errors.WaitForResponseTimedOutError:
raise errors.WaitForResponseTimedOutError(
"Package manager did not respond after %s seconds" % wait_time)
@@ -331,28 +322,88 @@ class AdbInterface:
instrumentation_path = "%s/%s" % (package_name, runner_name)
logger.Log("Waiting for instrumentation to be present")
# Query the package manager
- inst_found = False
+ 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
+
+ def WaitForProcess(self, name, wait_time=120):
+ """Wait until a process is running on the device.
+
+ Args:
+ name: the process name as it appears in `ps`
+ wait_time: time in seconds to wait
+
+ Raises:
+ WaitForResponseTimedOutError if wait_time elapses and the process is
+ still not running
+ """
+ logger.Log("Waiting for process %s" % name)
+ self.SendCommand("wait-for-device")
+ self._WaitForShellCommandContents("ps", name, wait_time)
+
+ def WaitForProcessEnd(self, name, wait_time=120):
+ """Wait until a process is no longer running on the device.
+
+ Args:
+ name: the process name as it appears in `ps`
+ wait_time: time in seconds to wait
+
+ Raises:
+ WaitForResponseTimedOutError if wait_time elapses and the process is
+ still running
+ """
+ logger.Log("Waiting for process %s to end" % name)
+ self._WaitForShellCommandContents("ps", name, wait_time, invert=True)
+
+ def _WaitForShellCommandContents(self, command, expected, wait_time,
+ raise_abort=True, invert=False):
+ """Wait until the response to a command contains a given output.
+
+ Assumes that a only successful execution of "adb shell <command>" contains
+ the substring expected. Assumes that a device is present.
+
+ Args:
+ command: adb shell command to execute
+ expected: the string that should appear to consider the
+ command successful.
+ wait_time: time in seconds to wait
+ raise_abort: if False, retry when executing the command raises an
+ AbortError, rather than failing.
+ invert: if True, wait until the command output no longer contains the
+ expected contents.
+
+ Raises:
+ WaitForResponseTimedOutError: If wait_time elapses and the command has not
+ returned an output containing expected yet.
+ """
+ # Query the device with the command
+ success = 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
+ while not success and (attempts*wait_period) < wait_time:
+ # assume the command will always contain expected 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
+ output = self.SendShellCommand(command, retry_count=1)
+ if ((not invert and expected in output)
+ or (invert and expected not in output)):
+ success = True
except errors.AbortError, e:
- # ignore
- pass
- if not inst_found:
+ if raise_abort:
+ raise
+ # ignore otherwise
+
+ if not success:
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)
+
+ if not success:
raise errors.WaitForResponseTimedOutError()
def Sync(self, retry_count=3):