Fix run-tests.sh to accept multiple devices in ANDROID_SERIAL

Previously run-tests.sh observes ANDROID_SERIAL, or run tests on
ALL devices detected online (with proper abi/abi2) if ANDROID_SERIAL
is absent.  ANDROID_SERIAL is treated by fastboot/adb to contain
single device, though.

This CL fix run-tests.sh to allow ANDROID_SERIAL to carry multiple devices
(comma-delimited) for testing (instead of all detected)

Change-Id: I18d5a26f1dce9aae0a95618554b9b3990133e9a0
diff --git a/tests/run-tests-all.sh b/tests/run-tests-all.sh
index 03f7ee9..496a054 100755
--- a/tests/run-tests-all.sh
+++ b/tests/run-tests-all.sh
@@ -12,34 +12,44 @@
 DEVICE_x86=
 
 ADB_CMD=`which adb`
-if [ -n $ADB_CMD ] ; then
-    # Get list of online devices, turn ' ' in device into '#'
-    DEVICES=`$ADB_CMD devices | grep -v offline | awk 'NR>1 {gsub(/[ \t]+device$/,""); print;}' | sed '/^$/d' | tr ' ' '#'`
-    for DEVICE in $DEVICES; do
-        # undo previous ' '-to-'#' translation
-        DEVICE=$(echo "$DEVICE" | tr '#' ' ')
-        # get arch
-        ARCH=`$ADB_CMD -s "$DEVICE" shell getprop ro.product.cpu.abi | tr -dc '[:print:]'`
-        case "$ARCH" in
-            armeabi*)
-                    DEVICE_arm=$DEVICE
-                    ;;
-            x86)
-                    DEVICE_x86=$DEVICE
-                    ;;
-            mips*)
-                    DEVICE_mips=$DEVICE
-                    ;;
-            *)
-                    echo "ERROR: Unsupported architecture: $ARCH"
-                    exit 1
-        esac
-    done
-fi
 
-echo "DEVICE_arm=$DEVICE_arm"
-echo "DEVICE_x86=$DEVICE_x86"
-echo "DEVICE_mips=$DEVICE_mips"
+if [ -n "$ANDROID_SERIAL" ] ; then
+    echo ANDROID_SERIAL=$ANDROID_SERIAL
+else
+    if [ -n $ADB_CMD  ] ; then
+        # Get list of online devices, turn ' ' in device into '#'
+        DEVICES=`$ADB_CMD devices | grep -v offline | awk 'NR>1 {gsub(/[ \t]+device$/,""); print;}' | sed '/^$/d' | tr ' ' '#'`
+        for DEVICE in $DEVICES; do
+            # undo previous ' '-to-'#' translation
+            DEVICE=$(echo "$DEVICE" | tr '#' ' ')
+            # get arch
+            ARCH=`$ADB_CMD -s "$DEVICE" shell getprop ro.product.cpu.abi | tr -dc '[:print:]'`
+            case "$ARCH" in
+                armeabi*)
+                        if [ -z "$DEVICE_arm" ]; then
+                            DEVICE_arm=$DEVICE
+                        fi
+                        ;;
+                x86)
+                        if [ -z "$DEVICE_x86" ]; then
+                            DEVICE_x86=$DEVICE
+                        fi
+                        ;;
+                mips*)
+                        if [ -z "$DEVICE_mips" ]; then
+                            DEVICE_mips=$DEVICE
+                        fi
+                        ;;
+                *)
+                        echo "ERROR: Unsupported architecture: $ARCH"
+                        exit 1
+            esac
+        done
+    fi
+    echo "DEVICE_arm=$DEVICE_arm"
+    echo "DEVICE_x86=$DEVICE_x86"
+    echo "DEVICE_mips=$DEVICE_mips"
+fi
 
 #
 # check if we need to also test 32-bit host toolchain
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index dfed27a..42e29ef 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -905,11 +905,16 @@
         else
             ADB_DEVICES="$ADB_DEVICES "
             if [ -n "$ANDROID_SERIAL" ] ; then
-                ADB_SERIAL=$(echo "$ANDROID_SERIAL" | tr ' ' '#')  # turn ' ' into '#'
-                if [ "$ADB_DEVICES" = "${ADB_DEVICES%$ADB_SERIAL *}" ] ; then
-                    dump "WARNING: Device $ANDROID_SERIAL cannot be found or offline!"
-                    SKIP_TESTS=yes
-                else
+                # Expect ANDROID_SERIAL is comma-delimited of one or more devices
+                ANDROID_SERIAL=$(echo "$ANDROID_SERIAL" | tr ' ' '#')  # turn ' ' into '#'
+                ANDROID_SERIAL=$(commas_to_spaces $ANDROID_SERIAL)
+                for SERIAL in $ANDROID_SERIAL; do
+                    if [ "$ADB_DEVICES" = "${ADB_DEVICES%$SERIAL *}" ] ; then
+                        dump "WARNING: Device $SERIAL cannot be found or offline!"
+                        SKIP_TESTS=yes
+                    fi
+                done
+                if [ "$SKIP_TESTS" != "yes" ] ; then
                     ADB_DEVICES="$ANDROID_SERIAL"
                 fi
             fi