[smoke test] Add non-KVM tests on all test machines

Previously the tests were always run with whatever the test machine
provided, which typically always have KVM support. This now forces
tests to be run on a non-KVM emulator as well, to ensure that DFv2
is tested properly in all configurations. Enabling/disabling KVM
causes the PCI device enumeration to be different, so we want to
cover all cases in our tests.

Change-Id: I00cc0c8bc0fc0d8ea04b1abfa3bf9c85a9c9441e
Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-samples/drivers/+/769151
Commit-Queue: Wayne Piekarski <waynepie@google.com>
Reviewed-by: Renato Mangini Dias <mangini@google.com>
diff --git a/scripts/smoke_test.sh b/scripts/smoke_test.sh
index a21d735..d095cc8 100755
--- a/scripts/smoke_test.sh
+++ b/scripts/smoke_test.sh
@@ -35,23 +35,21 @@
   echo
 }
 
-no_kvm() {
-  [[ "$(uname -s)" == "Linux" && ! -w /dev/kvm ]] && return 0
-  return 1
-}
-
 main() {
   trap 'failure $LINENO' ERR
   local keep_emu=0
   local skip_clean=0
+  local only_kvm=0
   while [[ $# -gt 0 ]]; do
     if [[ "$1" == "--keep" ]]; then
       keep_emu=1
     elif [[ "$1" == "--no-clean" ]]; then
       skip_clean=1
+    elif [[ "$1" == "--only-kvm" ]]; then
+      only_kvm=1
     else
       echo >&2 "Invalid argument: $1"
-      echo >&2 "Syntax: $0 [--keep] [--no-clean]"
+      echo >&2 "Syntax: $0 [--keep] [--no-clean] [--only-kvm]"
       return 1
     fi
     shift
@@ -83,11 +81,30 @@
   print_and_run tools/ffx product-bundle get "$pb_name" --repository "$repo_name" --force-repo
   stop_emu
 
-  emu_options=""
+  # If KVM is available, then run emulator tests with default flags that will use KVM
+  if [[ "$(uname -s)" != "Linux" || -w /dev/kvm ]]; then
+    run_emulator_tests 0
+  elif [[ ${only_kvm} -eq 1 ]]; then
+    echo "Virtualization not available, but --only-kvm selected so no tests would run"
+    exit 1
+  fi
+  # Run the emulator tests again with extra flags to support disabled KVM
+  if [[ ${only_kvm} -eq 0 ]]; then
+    stop_emu
+    run_emulator_tests 1
+  fi
+}
+
+run_emulator_tests() {
+  local disable_kvm="$1"
+  local emu_options=""
   # If KVM is not available, need to fall back to an alternative emulator that works fxbug.dev/113237
   # otherwise it fails to start up properly, and ffx emu does not handle this yet.
-  if no_kvm; then
+  if [[ ${disable_kvm} -eq 1 ]]; then
+    echo "Running emulator tests with KVM disabled"
     emu_options="--engine qemu --startup-timeout 720 --accel none --device qemu-x64-emu-min"
+  else
+    echo "Running emulator tests with default KVM"
   fi
   print_and_run tools/ffx emu start "$pb_name" --headless --name $emu_name $emu_options \
       --kernel-args "devmgr.enable-ephemeral=true" \
@@ -139,7 +156,7 @@
   print_and_run tools/ffx component show qemu_edu.cm | check_output "Moniker:  /bootstrap/universe-pkg-drivers:root.sys.platform.pt.PCI0.bus."
   print_and_run tools/ffx driver list-devices | check_output "root.sys.platform.pt.PCI0.bus."
   # The PCI id changes depending if /dev/kvm is available
-  if no_kvm; then
+  if [[ ${disable_kvm} -eq 1 ]]; then
     print_and_run tools/ffx driver list-devices root.sys.platform.pt.PCI0.bus.00_05_0_ --verbose | check_output "Name     : 00_05_0_"
   else
     print_and_run tools/ffx driver list-devices root.sys.platform.pt.PCI0.bus.00_06_0_ --verbose | check_output "Name     : 00_06_0_"
@@ -167,6 +184,7 @@
 stop_emu() {
   # stop the emulator
   if tools/ffx emu show $emu_name >/dev/null 2>&1; then
+    echo "Stopping emulator"
     tools/ffx emu stop $emu_name || true
   fi
   if [[ -n "${current_target}" ]]; then
diff --git a/scripts/sshconfig.local b/scripts/sshconfig.local
index 3f43104..243bc3b 100644
--- a/scripts/sshconfig.local
+++ b/scripts/sshconfig.local
@@ -20,8 +20,8 @@
 ForwardAgent no
 ForwardX11 no
 
-# Connection timeout in seconds
-ConnectTimeout=10
+# Connection timeout in seconds, needs to be high enough for non-KVM emulators
+ConnectTimeout=20
 
 # Check for server alive in seconds, max count before disconnecting
 ServerAliveInterval 1