Add musl handling in run-on-host.sh.

Bug: None
Test: ./tests/run-on-host.sh glibc
Test: ./tests/run-on-host.sh musl
Change-Id: I4f85310750402e1187358aeb4a585f26092b97ac
diff --git a/README.md b/README.md
index 113ffd7..aafbcff 100644
--- a/README.md
+++ b/README.md
@@ -374,6 +374,19 @@
 
     $ ./tests/run-on-host.sh glibc
 
+### Against musl
+
+Another way to verify test behavior is to run against musl on the host. glibc
+musl don't always match, so this can be a good way to find the more complicated
+corners of the spec. If they *do* match, bionic probably should too!
+
+    $ OUT_DIR=$(ANDROID_BUILD_TOP)/musl-out ./tests/run-on-host.sh musl
+
+Note: the alternate OUT_DIR is used to avoid causing excessive rebuilding when
+switching between glibc and musl. The first musl test run will be expensive
+because it will not reuse any already built artifacts, but subsequent runs will
+be cheaper than if you hadn't used it.
+
 ## Gathering test coverage
 
 To get test coverage for bionic, use `//bionic/build/coverage.sh`. Before
diff --git a/tests/run-on-host.sh b/tests/run-on-host.sh
index fe2c25a..19bbacf 100755
--- a/tests/run-on-host.sh
+++ b/tests/run-on-host.sh
@@ -2,9 +2,14 @@
 
 . $(dirname $0)/../build/run-on-host.sh
 
-if [ "$1" = glibc ]; then
+if [ "$1" = glibc -o "$1" = musl ]; then
+  if [ "$1" = musl ]; then
+    BUILD_ARGS=USE_HOST_MUSL=true
+  else
+    BUILD_ARGS=
+  fi
   shift
-  m -j bionic-unit-tests-glibc
+  m -j $BUILD_ARGS bionic-unit-tests-glibc
   (
     cd ${ANDROID_BUILD_TOP}
     export ANDROID_DATA=${TARGET_OUT_DATA}
@@ -13,7 +18,7 @@
   )
   exit 0
 elif [ "$1" != 32 -a "$1" != 64 ]; then
-  echo "Usage: $0 [ 32 | 64 | glibc ] [gtest flags]"
+  echo "Usage: $0 [ 32 | 64 | glibc | musl ] [gtest flags]"
   exit 1
 fi