Check in my Android test-running script.

Also update the documentation in Android.mk.

Bug: N/A
Test: ran tests
Change-Id: Id986221f274101fff4d42b2a538bf39cd4956e06
diff --git a/Android.mk b/Android.mk
index a2cfe5f..26fe2a3 100644
--- a/Android.mk
+++ b/Android.mk
@@ -17,21 +17,29 @@
 LOCAL_PATH := $(call my-dir)
 
 #
-# To update:
+# To sync with upstream:
 #
 
+#  # Update.
 #  git remote add toybox https://github.com/landley/toybox.git
 #  git fetch toybox
 #  git merge toybox/master
+
+#  # Regenerate generated files.
+#  make
+
+#  # Make any necessary Android.mk changes and rebuild.
 #  mm -j32
-#  # (Make any necessary Android.mk changes and test the new toybox.)
-#  repo upload .
+
+#  # Run tests.
+#  ./run-tests-on-android.sh
+#  # Run a single test.
+#  ./run-tests-on-android.sh wc
+
+#  # Upload changes.
+#  git commit -a --amend
 #  git push aosp HEAD:refs/for/master  # Push to gerrit for review.
 #  git push aosp HEAD:master  # Push directly, avoiding gerrit.
-#
-#  # Now commit any necessary Android.mk changes like normal:
-#  repo start post-sync .
-#  git commit -a
 
 
 #
diff --git a/run-tests-on-android.sh b/run-tests-on-android.sh
new file mode 100755
index 0000000..aefbdc0
--- /dev/null
+++ b/run-tests-on-android.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# Copy the toybox tests across.
+adb shell mkdir /data/local/tmp/toybox-tests/
+adb push tests/ /data/local/tmp/toybox-tests/
+adb push scripts/runtest.sh /data/local/tmp/toybox-tests/
+
+# Make a temporary directory on the device.
+tmp_dir=`adb shell TMPDIR=/data/local/tmp mktemp --directory`
+
+test_toy() {
+  toy=$1
+
+  echo
+
+  location=$(adb shell "which $toy")
+  if [ $? -ne 0 ]; then
+    echo "-- $toy not present"
+    return
+  fi
+
+  echo "-- $toy"
+
+  implementation=$(adb shell "realpath $location")
+  if [ "$implementation" != "/system/bin/toybox" ]; then
+    echo "-- note: $toy is non-toybox implementation"
+  fi
+
+  adb shell -t "export FILES=/data/local/tmp/toybox-tests/tests/files/ ; \
+                export VERBOSE=1 ; \
+                export CMDNAME=$toy; \
+                export C=$toy; \
+                export LANG=en_US.UTF-8; \
+                cd $tmp_dir ; \
+                source /data/local/tmp/toybox-tests/runtest.sh ; \
+                source /data/local/tmp/toybox-tests/tests/$toy.test"
+}
+
+if [ "$#" -eq 0 ]; then
+  # Run all the tests.
+  for t in tests/*.test; do
+    toy=`echo $t | sed 's|tests/||' | sed 's|\.test||'`
+    test_toy $toy
+  done
+else
+  # Just run the tests for the given toys.
+  for toy in "$@"; do
+    test_toy $toy
+  done
+fi