Test team touch fw update script.

Script for the test team to run while verifying a new touch firmware.
Supply a host ip and two builds (one with old firmware and one with new).
During test:
- Image the DUT to a build with the old firmware (by calling cros flash).
- Check for firmware updater errors (by calling test_that) new -> old.
- Image the DUT to a build with the new firmware.
- Check for firmware updater errors old -> new.
- Repeat above N times.

TEST=have used at my desk with no problems, test has found bugs in the past
BUG=None

Change-Id: Ic1e3147cc32d0a5a4851b8f2506c64cd96c53263
Reviewed-on: https://chromium-review.googlesource.com/290410
Reviewed-by: Katherine Threlkeld <kathrelkeld@chromium.org>
Commit-Queue: Katherine Threlkeld <kathrelkeld@chromium.org>
Tested-by: Katherine Threlkeld <kathrelkeld@chromium.org>
diff --git a/provingground/loop_touch_fw_update.sh b/provingground/loop_touch_fw_update.sh
new file mode 100755
index 0000000..ced93de
--- /dev/null
+++ b/provingground/loop_touch_fw_update.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+
+# Copyright 2015 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Script to run on a test image DUT (HOST) and test firmware updates.
+# Supply a build with one firmware (FROM_BUILD) and a build with a second
+# (TO_BUILD).  This script will install the first, check the firmware, install
+# the second, check the firmware, repeat.
+
+USAGE_STRING='loop_touch_fw_update.sh HOST FROM_BUILD TO_BUILD COUNT(OPTIONAL)'
+# HOST: IP of DUT
+# FROM_BUILD: path to .bin file of older test image
+# TO_BUILD: path to .bin file for newer test image
+# COUNT: number of times to loop the test (default 50)
+
+# Test Setup
+ERRORS_FOUND=0
+i=0
+
+if [ -z "$1" ] ||  [ -z "$2" ] || [ -z "$3" ]
+then
+  echo "Required inputs HOST, FROM_BUILD, and/or TO_BUILD not set!"
+  echo $USAGE_STRING
+  exit 1
+fi
+HOST="$1"
+FROM_BUILD="$2"
+TO_BUILD="$3"
+
+if ! [ -f "$FROM_BUILD" ] || ! [ -f "$TO_BUILD" ]
+then
+  echo "$FROM_BUILD and/or $TO_BUILD do not exist!"
+  exit 1
+fi
+
+if [ -z "$4" ]
+then
+  LIMIT=50
+else
+  LIMIT="$4"
+fi
+
+echo "Running touch_update test script."
+echo "HOST: $HOST"
+echo "FROM_BUILD: $FROM_BUILD"
+echo "TO_BUILD: $TO_BUILD"
+echo "COUNT: $LIMIT"
+
+
+function check_firmware {
+  # Run touch update autotest and check for pass/fail.
+  test_that $HOST --board=link touch_UpdateErrors
+  count=`grep "FAIL" /tmp/test_that_latest/results*/status* | wc -l`
+  if [ $count -gt 0 ]
+  then
+    ERRORS_FOUND=$((ERRORS_FOUND+1))
+    echo "Found errors!"
+    grep "touch-firmware" /tmp/test_that_latest/results*/sysinfo/messages
+  else
+    echo "No problems found during touch firmware update."
+  fi
+}
+
+function load_build {
+  # Run cros flash to apply the next build to the DUT.
+  echo "FLASHING "$nextbuild
+  cros flash $HOST $nextbuild
+}
+
+
+echo "Starting Test!"
+while [ $ERRORS_FOUND -eq 0 ] && [ $i -lt $LIMIT ]
+do
+  echo "LOOP "$i":"
+  i=$((i+1))
+  nextbuild=$FROM_BUILD
+  load_build
+  check_firmware
+  nextbuild=$TO_BUILD
+  load_build
+  check_firmware
+done
+
+if [ $ERRORS_FOUND -gt 0 ]
+then
+  echo "Found ERROR after $i tries!"
+else
+  echo "Completed test.  No problems found."
+fi