diff options
| author | Jean-Baptiste Queru <jbq@google.com> | 2010-10-10 17:46:49 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2010-10-10 17:46:49 -0700 |
| commit | a4d6fb39075e86cc7d2c19be5d863c9adfbb70d0 (patch) | |
| tree | f4f45762368f3657cef0e5d7f643be9038fe445c /testrunner | |
| parent | 25597814241f8b6f870bf54c1d9512feabaaad04 (diff) | |
| parent | 4ceead6ba01a938499726809c90154cb0e8c1e22 (diff) | |
| download | android_development-a4d6fb39075e86cc7d2c19be5d863c9adfbb70d0.tar.gz android_development-a4d6fb39075e86cc7d2c19be5d863c9adfbb70d0.tar.bz2 android_development-a4d6fb39075e86cc7d2c19be5d863c9adfbb70d0.zip | |
am 4ceead6b: am e73f0dfc: Merge "Added adb_interface.WaitForProcess and WaitForProcessEnd."
Merge commit '4ceead6ba01a938499726809c90154cb0e8c1e22'
* commit '4ceead6ba01a938499726809c90154cb0e8c1e22':
Added adb_interface.WaitForProcess and WaitForProcessEnd.
Diffstat (limited to 'testrunner')
| -rwxr-xr-x | testrunner/adb_interface.py | 109 |
1 files changed, 80 insertions, 29 deletions
diff --git a/testrunner/adb_interface.py b/testrunner/adb_interface.py index 451d04644..1928c73a8 100755 --- a/testrunner/adb_interface.py +++ b/testrunner/adb_interface.py @@ -315,19 +315,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) @@ -344,28 +335,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 WaitForBootComplete(self, wait_time=120): |
