Merge "Fix log syntax." into jb-mr1-dev
diff --git a/testrunner/adb_interface.py b/testrunner/adb_interface.py
index 5191340..1f1e3c6 100755
--- a/testrunner/adb_interface.py
+++ b/testrunner/adb_interface.py
@@ -336,29 +336,16 @@
       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.
-    """
+  def IsInstrumentationInstalled(self, package_name, runner_name):
+    """Checks if instrumentation is present on device."""
     instrumentation_path = "%s/%s" % (package_name, runner_name)
-    logger.Log("Waiting for instrumentation to be present")
-    # Query the package manager
+    command = "pm list instrumentation | grep %s" % instrumentation_path
     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
+      output = self.SendShellCommand(command)
+      return output.startswith("instrumentation:")
+    except errors.AbortError:
+      # command can return error code on failure
+      return False
 
   def WaitForProcess(self, name, wait_time=120):
     """Wait until a process is running on the device.
diff --git a/testrunner/runtest.py b/testrunner/runtest.py
index 9082d79..1c11e27 100755
--- a/testrunner/runtest.py
+++ b/testrunner/runtest.py
@@ -294,7 +294,7 @@
     if m:
       remote_path = m.group(1)
       abs_install_path = os.path.join(self._root_path, install_path)
-      logger.Log("adb push %s %s", abs_install_path, remote_path)
+      logger.Log("adb push %s %s" % (abs_install_path, remote_path))
       self._adb.Push(abs_install_path, remote_path)
     else:
       logger.Log("Error: Failed to recognize path of file to install %s" % install_path)
diff --git a/testrunner/test_defs/instrumentation_test.py b/testrunner/test_defs/instrumentation_test.py
index 12633b2..c87fffd 100644
--- a/testrunner/test_defs/instrumentation_test.py
+++ b/testrunner/test_defs/instrumentation_test.py
@@ -140,6 +140,7 @@
       logger.Log(adb_cmd)
     elif options.coverage:
       coverage_gen = coverage.CoverageGenerator(adb)
+      self._CheckInstrumentationInstalled(adb)
       # need to parse test output to determine path to coverage file
       logger.Log("Running in coverage mode, suppressing test output")
       try:
@@ -160,12 +161,22 @@
           self, device_coverage_path, test_qualifier=options.test_size)
       if coverage_file is not None:
         logger.Log("Coverage report generated at %s" % coverage_file)
+
     else:
-      adb.StartInstrumentationNoResults(
-          package_name=self.GetPackageName(),
-          runner_name=self.GetRunnerName(),
-          raw_mode=options.raw_mode,
-          instrumentation_args=instrumentation_args)
+      self._CheckInstrumentationInstalled(adb)
+      adb.StartInstrumentationNoResults(package_name=self.GetPackageName(),
+                                        runner_name=self.GetRunnerName(),
+                                        raw_mode=options.raw_mode,
+                                        instrumentation_args=
+                                        instrumentation_args)
+
+  def _CheckInstrumentationInstalled(self, adb):
+    if not adb.IsInstrumentationInstalled(self.GetPackageName(),    
+                                          self.GetRunnerName()):
+      msg=("Could not find instrumentation %s/%s on device. Try forcing a "
+           "rebuild by updating a source file, and re-executing runtest." % 
+           (self.GetPackageName(), self.GetRunnerName()))
+      raise errors.AbortError(msg=msg)
 
   def _PrintTestResults(self, test_results):
     """Prints a summary of test result data to stdout.
@@ -189,7 +200,6 @@
     logger.Log("Tests run: %d, Failures: %d, Errors: %d" %
                (total_count, fail_count, error_count))
 
-
 def HasInstrumentationTest(path):
   """Determine if given path defines an instrumentation test.