Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1459)

Unified Diff: third_party/android_testrunner/adb_interface.py

Issue 10692132: fix test broken issue when using --use-emulator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/android_testrunner/README.chromium ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/android_testrunner/adb_interface.py
diff --git a/third_party/android_testrunner/adb_interface.py b/third_party/android_testrunner/adb_interface.py
index 1928c73a8e6ba7c41c4a725d1988f6044dfe0829..9109916e116223169e47ace61cfc82f45897c176 100644
--- a/third_party/android_testrunner/adb_interface.py
+++ b/third_party/android_testrunner/adb_interface.py
@@ -51,6 +51,21 @@ class AdbInterface:
"""Direct all future commands to Android target with the given serial."""
self._target_arg = "-s %s" % serial
+ def RestartAdbServer(self):
+ """Restart the adb server."""
+ self.KillAdbServer()
+ self.StartAdbServer()
+
+ def KillAdbServer(self):
+ """Kill adb server."""
+ adb_cmd = "adb kill-server"
+ return run_command.RunCommand(adb_cmd)
+
+ def StartAdbServer(self):
+ """Start adb server."""
+ adb_cmd = "adb start-server"
+ return run_command.RunCommand(adb_cmd)
+
def SendCommand(self, command_string, timeout_time=20, retry_count=3):
"""Send a command via adb.
@@ -419,6 +434,39 @@ class AdbInterface:
if not success:
raise errors.WaitForResponseTimedOutError()
+ def WaitForSystemBootCompleted(self, wait_time=120):
+ """Waits for targeted system's boot_completed flag to be set.
+
+ Args:
+ wait_time: time in seconds to wait
+
+ Raises:
+ WaitForResponseTimedOutError if wait_time elapses and flag still not
+ set.
+ """
+ logger.Log("Waiting for system boot completed...")
+ self.SendCommand("wait-for-device")
+ # Now the device is there, but system not boot completed.
+ # Query the sys.boot_completed flag with a basic command
+ boot_completed = False
+ attempts = 0
+ wait_period = 5
+ while not boot_completed and (attempts*wait_period) < wait_time:
+ output = self.SendShellCommand("getprop sys.boot_completed", retry_count=1)
+ output = output.strip()
+ if output == "1":
+ boot_completed = True
+ else:
+ # If 'error: xxx' returned when querying the flag, it means
+ # adb server lost the connection to the emulator, so restart the adb server.
+ if "error:" in output:
+ self.RestartAdbServer()
+ time.sleep(wait_period)
+ attempts += 1
+ if not boot_completed:
+ raise errors.WaitForResponseTimedOutError(
+ "sys.boot_completed flag was not set after %s seconds" % wait_time)
+
def WaitForBootComplete(self, wait_time=120):
"""Waits for targeted device's bootcomplete flag to be set.
« no previous file with comments | « third_party/android_testrunner/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698