Splitting up wait_for_device into two pieces
authorkjlubick <kjlubick@google.com>
Fri, 25 Mar 2016 12:22:40 +0000 (05:22 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 25 Mar 2016 12:22:40 +0000 (05:22 -0700)
BUG=skia:5111
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1829753004

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

infra/bots/flavor/android_flavor.py
platform_tools/android/bin/adb_wait_for_charge [new file with mode: 0755]
platform_tools/android/bin/adb_wait_for_device

index 5a30079951dc6c21c740950ef746c9cd46366fbd..754e23ca3072f9f48d4a946c8c9d0412ed41df6e 100644 (file)
@@ -31,6 +31,12 @@ class _ADBWrapper(object):
     ]
     self._android_flavor._bot_info.run(
         cmd, env=self._android_flavor._default_env)
+    cmd = [
+        os.path.join(self._android_flavor.android_bin, 'adb_wait_for_charge'),
+        '-s', self._serial,
+    ]
+    self._android_flavor._bot_info.run(
+        cmd, env=self._android_flavor._default_env)
 
   def maybe_wait_for_device(self):
     """Run 'adb wait-for-device' if it hasn't already been run."""
diff --git a/platform_tools/android/bin/adb_wait_for_charge b/platform_tools/android/bin/adb_wait_for_charge
new file mode 100755 (executable)
index 0000000..43e70bc
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/bash
+#
+# Wait for the device to be charged enough for testing.
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+source $SCRIPT_DIR/android_setup.sh
+source $SCRIPT_DIR/utils/setup_adb.sh
+
+# Helper function used by get_battery_level. Parses the battery level from
+# dumpsys output.
+function _parse_battery_level {
+  SPLIT=( $@ )
+
+  HAS_BATTERY=1
+  LEVEL=""
+
+  for i in "${!SPLIT[@]}"; do
+    if [ "${SPLIT[$i]}" = "level:" ]; then
+      LEVEL="${SPLIT[$i+1]}"
+    fi
+    if [ "${SPLIT[$i]}" = "present:" ]; then
+      PRESENT="$(echo "${SPLIT[$i+1]}" | tr -d '\r')"
+      if [ "$PRESENT" = "0" ]; then
+        HAS_BATTERY=0
+      fi
+      if [ "$PRESENT" = "false" ]; then
+        HAS_BATTERY=0
+      fi
+    fi
+  done
+
+  if [ "$HAS_BATTERY" = "1" ]; then
+    echo "$LEVEL" | tr -d '\r'
+    return
+  fi
+  # If there's no battery, report a full battery.
+  echo "Device has no battery." 1>&2
+  echo "100"
+}
+
+# Echo the battery level percentage of the attached Android device.
+function get_battery_level {
+  STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)"
+  SPLIT=( $STATS )
+  RV="$(_parse_battery_level ${SPLIT[@]})"
+  if [ -n "$RV" ]; then
+    echo "$RV"
+    return
+  fi
+
+  echo "Battery level fallback..." 1>&2
+
+  STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)"
+  SPLIT=( $STATS )
+  RV="$(_parse_battery_level ${SPLIT[@]})"
+  if [ "$RV" != "-1" ]; then
+    echo "$RV"
+    return
+  fi
+
+  echo "Could not determine battery level!" 1>&2
+  # Just exit to prevent hanging forever or failing the build.
+  echo "0"
+}
+
+# Wait for battery charge.
+DESIRED_BATTERY_LEVEL=80
+CURRENT_BATTERY_LEVEL="$(get_battery_level)"
+while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do
+  echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRED_BATTERY_LEVEL}"
+  sleep 5
+  CURRENT_BATTERY_LEVEL="$(get_battery_level)"
+done
+
+echo "Charged!"
\ No newline at end of file
index a1f8c1645e1b2053b5370ed3fdf51f5348425a02..32a517b691fc89666a0907dda8df56a9f735e82f 100755 (executable)
@@ -1,68 +1,11 @@
 #!/bin/bash
 #
-# Wait for the device to be ready to run tests.
+# Wait for the device to be connected.
 
 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 source $SCRIPT_DIR/android_setup.sh
 source $SCRIPT_DIR/utils/setup_adb.sh
 
-# Helper function used by get_battery_level. Parses the battery level from
-# dumpsys output.
-function _parse_battery_level {
-  SPLIT=( $@ )
-
-  HAS_BATTERY=1
-  LEVEL=""
-
-  for i in "${!SPLIT[@]}"; do
-    if [ "${SPLIT[$i]}" = "level:" ]; then
-      LEVEL="${SPLIT[$i+1]}"
-    fi
-    if [ "${SPLIT[$i]}" = "present:" ]; then
-      PRESENT="$(echo "${SPLIT[$i+1]}" | tr -d '\r')"
-      if [ "$PRESENT" = "0" ]; then
-        HAS_BATTERY=0
-      fi
-      if [ "$PRESENT" = "false" ]; then
-        HAS_BATTERY=0
-      fi
-    fi
-  done
-
-  if [ "$HAS_BATTERY" = "1" ]; then
-    echo "$LEVEL" | tr -d '\r'
-    return
-  fi
-  # If there's no battery, report a full battery.
-  echo "Device has no battery." 1>&2
-  echo "100"
-}
-
-# Echo the battery level percentage of the attached Android device.
-function get_battery_level {
-  STATS="$($ADB $DEVICE_SERIAL shell dumpsys batteryproperties)"
-  SPLIT=( $STATS )
-  RV="$(_parse_battery_level ${SPLIT[@]})"
-  if [ -n "$RV" ]; then
-    echo "$RV"
-    return
-  fi
-
-  echo "Battery level fallback..." 1>&2
-
-  STATS="$($ADB $DEVICE_SERIAL shell dumpsys battery)"
-  SPLIT=( $STATS )
-  RV="$(_parse_battery_level ${SPLIT[@]})"
-  if [ "$RV" != "-1" ]; then
-    echo "$RV"
-    return
-  fi
-
-  echo "Could not determine battery level!" 1>&2
-  # Just exit to prevent hanging forever or failing the build.
-  echo "0"
-}
-
 set -e
 
 # Wait for the device to be connected and fully booted.
@@ -71,13 +14,4 @@ while [ "$($ADB $DEVICE_SERIAL shell getprop sys.boot_completed | tr -d '\r')" !
   sleep 5
 done
 
-# Wait for battery charge.
-DESIRED_BATTERY_LEVEL=80
-CURRENT_BATTERY_LEVEL="$(get_battery_level)"
-while [ "${CURRENT_BATTERY_LEVEL}" -lt "${DESIRED_BATTERY_LEVEL}" ]; do
-  echo "Battery level is ${CURRENT_BATTERY_LEVEL}; waiting to charge to ${DESIRED_BATTERY_LEVEL}"
-  sleep 5
-  CURRENT_BATTERY_LEVEL="$(get_battery_level)"
-done
-
-echo "Ready!"
+echo "Connected!"