Work-around for file pushing in android perf runner.
authormachenbach <machenbach@chromium.org>
Tue, 23 Dec 2014 12:40:32 +0000 (04:40 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 23 Dec 2014 12:40:50 +0000 (12:40 +0000)
Also include the device serial when logging adb commands.

BUG=374740
TBR=ulan@chromium.org
NOTRY=true

Review URL: https://codereview.chromium.org/815003003

Cr-Commit-Position: refs/heads/master@{#25934}

tools/run_perf.py

index 14d67c5..a24627f 100755 (executable)
@@ -529,8 +529,14 @@ class AndroidPlatform(Platform):  # pragma: no cover
     perf.SetDefaultPerfMode()
     self.device.RunShellCommand(["rm", "-rf", AndroidPlatform.DEVICE_DIR])
 
+  def _SendCommand(self, cmd):
+    logging.info("adb -s %s %s" % (str(self.device), cmd))
+    return self.adb.SendCommand(cmd, timeout_time=60)
+
   def _PushFile(self, host_dir, file_name, target_rel="."):
     file_on_host = os.path.join(host_dir, file_name)
+    file_on_device_tmp = os.path.join(
+        AndroidPlatform.DEVICE_DIR, "_tmp_", file_name)
     file_on_device = os.path.join(
         AndroidPlatform.DEVICE_DIR, target_rel, file_name)
 
@@ -540,8 +546,15 @@ class AndroidPlatform(Platform):  # pragma: no cover
     else:
       self.pushed.add(file_on_host)
 
-    logging.info("adb push %s %s" % (file_on_host, file_on_device))
-    self.adb.Push(file_on_host, file_on_device)
+    # Work-around for "text file busy" errors. Push the files to a temporary
+    # location and then move them with a shell command.
+    output = self._SendCommand(
+        "push %s %s" % (file_on_host, file_on_device_tmp))
+    # Success looks like this: "3035 KB/s (12512056 bytes in 4.025s)".
+    # Errors look like this: "failed to copy  ... ".
+    if output and not re.search('^[0-9]', output.splitlines()[-1]):
+      logging.critical('PUSH FAILED: ' + output)
+    self._SendCommand("shell mv %s %s" % (file_on_device_tmp, file_on_device))
 
   def PreTests(self, node, path):
     suite_dir = os.path.abspath(os.path.dirname(path))