diff options
author | james.wei@intel.com <james.wei@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-11 03:30:04 +0000 |
---|---|---|
committer | james.wei@intel.com <james.wei@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-11 03:30:04 +0000 |
commit | a9bd5a3bfcf649dbf7ccb92a62a25850f4d46145 (patch) | |
tree | 908d975e5a35f2220b707c8e02704166a4ac6001 | |
parent | c44e5c806fcd975c383c32ee46aa3f8156ca3dd3 (diff) | |
download | chromium_src-a9bd5a3bfcf649dbf7ccb92a62a25850f4d46145.zip chromium_src-a9bd5a3bfcf649dbf7ccb92a62a25850f4d46145.tar.gz chromium_src-a9bd5a3bfcf649dbf7ccb92a62a25850f4d46145.tar.bz2 |
fix test broken issue when using --use-emulator
BUG=136474
TEST=./build/android/run_tests.py -s out/Release/base_unittests_apk/base_unittests-debug.apk -e 1
Review URL: https://chromiumcodereview.appspot.com/10692132
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146045 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | build/android/emulator.py | 5 | ||||
-rw-r--r-- | build/android/pylib/single_test_runner.py | 3 | ||||
-rwxr-xr-x | build/android/run_tests.py | 4 | ||||
-rw-r--r-- | third_party/android_testrunner/README.chromium | 5 | ||||
-rw-r--r-- | third_party/android_testrunner/adb_interface.py | 48 |
5 files changed, 57 insertions, 8 deletions
diff --git a/build/android/emulator.py b/build/android/emulator.py index e08b760..18f190e 100755 --- a/build/android/emulator.py +++ b/build/android/emulator.py @@ -221,11 +221,8 @@ class Emulator(object): if wait_for_boot: # Now that we checked for obvious problems, wait for a boot complete. # Waiting for the package manager is sometimes problematic. - # TODO(jrg): for reasons I don't understand, sometimes this - # gives an "error: device not found" which is only fixed with an - # 'adb kill-server' command. Fix. a.Adb().SetTargetSerial(self.device) - a.Adb().WaitForBootComplete(self._WAITFORBOOT_TIMEOUT) + a.Adb().WaitForSystemBootCompleted(self._WAITFORBOOT_TIMEOUT) def Shutdown(self): """Shuts down the process started by launch.""" diff --git a/build/android/pylib/single_test_runner.py b/build/android/pylib/single_test_runner.py index c7648eb..46cfa91 100644 --- a/build/android/pylib/single_test_runner.py +++ b/build/android/pylib/single_test_runner.py @@ -311,6 +311,9 @@ class SingleTestRunner(BaseTestRunner): """Sets up necessary test enviroment for the test suite.""" super(SingleTestRunner, self).SetUp() self.adb.ClearApplicationState(constants.CHROME_PACKAGE) + # Sometimes adb server lost connection to the emulator, which will break the + # test, so restart the adb server before the test. + self.adb.Adb().RestartAdbServer() if self.test_package.performance_test: self.adb.SetupPerformanceTest() if self.dump_debug_info: diff --git a/build/android/run_tests.py b/build/android/run_tests.py index 90bfe6b..b2314db 100755 --- a/build/android/run_tests.py +++ b/build/android/run_tests.py @@ -340,8 +340,8 @@ def _RunATestSuite(options): t.Stop() buildbot_emulators.append(buildbot_emulator) attached_devices.append(buildbot_emulator.device) - # Wait for all emulators to become available. - map(lambda buildbot_emulator:buildbot_emulator.ConfirmLaunch(), + # Wait for all emulators to boot completed. + map(lambda buildbot_emulator:buildbot_emulator.ConfirmLaunch(True), buildbot_emulators) elif options.test_device: attached_devices = [options.test_device] diff --git a/third_party/android_testrunner/README.chromium b/third_party/android_testrunner/README.chromium index c8a97fa..a2e76f0 100644 --- a/third_party/android_testrunner/README.chromium +++ b/third_party/android_testrunner/README.chromium @@ -9,8 +9,9 @@ This package is the scripts used to run the unit test for Android and from Android Gingerbread. Local Modifications: -This are no local modifications, all files were copied from -<android_gingerbread_tree>/development/testrunner/ +1. Added functions to start/kill/restart the adb server. +2. Added function of WaitForSystemBootCompleted to wait for the flag of +sys.boot_completed to be set. Here is the detail steps 1. Checkout Android source code diff --git a/third_party/android_testrunner/adb_interface.py b/third_party/android_testrunner/adb_interface.py index 1928c73..9109916 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. |