Add support for running ART tests on a Linux virtual machine.

Test: setup a local VM and run ART tests on it:
  lunch aosp_arm64-userdebug

  export ART_TEST_SSH_USER=ubuntu
  export ART_TEST_SSH_HOST=localhost
  export ART_TEST_SSH_PORT=10001
  export ART_TEST_ON_VM=true

  . art/tools/buildbot-utils.sh
  art/tools/buildbot-build.sh --target

  # Create, boot and configure the VM.
  art/tools/buildbot-vm.sh create
  art/tools/buildbot-vm.sh boot
  art/tools/buildbot-vm.sh setup-ssh  # password: 'ubuntu'

  art/tools/buildbot-cleanup-device.sh
  art/tools/buildbot-setup-device.sh
  art/tools/buildbot-sync.sh

  art/test.py --target -r 001-HelloWorld
  art/tools/run-gtests.sh

Test: check that non-VM testing still works:
  lunch aosp_arm32-userdebug

  . art/tools/buildbot-utils.sh
  art/tools/buildbot-build.sh --target

  export ART_TEST_CHROOT=/data/local/art-test-chroot

  art/tools/buildbot-cleanup-device.sh
  art/tools/buildbot-setup-device.sh
  art/tools/buildbot-sync.sh

  art/test.py --target -r --32 001-HelloWorld

Change-Id: I1393f8132b0b5d6ad10e291504550a5e7751f8e2
diff --git a/tools/run-gtests.sh b/tools/run-gtests.sh
index 21064c1..0f333f6 100755
--- a/tools/run-gtests.sh
+++ b/tools/run-gtests.sh
@@ -59,9 +59,17 @@
 
 options="$@"
 
+run_in_chroot() {
+  if [ -n $ART_TEST_ON_VM ]; then
+    $ART_SSH_CMD $ART_CHROOT_CMD $@
+  else
+    "$adb" shell chroot "$ART_TEST_CHROOT" $@
+  fi
+}
+
 if [[ ${#tests[@]} -eq 0 ]]; then
   # Search for executables under the `bin/art` directory of the ART APEX.
-  readarray -t tests <<<$("$adb" shell chroot "$ART_TEST_CHROOT" \
+  readarray -t tests <<<$(run_in_chroot \
     find "$android_art_root/bin/art" -type f -perm /ugo+x | sort)
 fi
 
@@ -69,7 +77,7 @@
 
 for t in ${tests[@]}; do
   echo "$t"
-  "$adb" shell chroot "$ART_TEST_CHROOT" \
+  run_in_chroot \
     env ANDROID_ART_ROOT="$android_art_root" \
         ANDROID_I18N_ROOT="$android_i18n_root" \
         ANDROID_TZDATA_ROOT="$android_tzdata_root" \