]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: allow use of nested KVM
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 26 Sep 2019 21:29:38 +0000 (23:29 +0200)
committerFilipe Brandenburger <filbranden@gmail.com>
Fri, 27 Sep 2019 22:42:38 +0000 (15:42 -0700)
Introduce TEST_NESTED_KVM variable, which allows use of nested KVM for
QEMU VMs (which is disabled by default by KVM autodetection).

test/README.testsuite
test/test-functions

index 7ff148e1300d58147f9f28fc449fa74ae0ff3944..2753ed6e3a6e64f0c36c172a63508bdfffd07ecc 100644 (file)
@@ -54,6 +54,11 @@ TEST_NO_KVM=1
     Disable QEMU KVM autodetection (may be necessary when you're trying to run the
     *vanilla* QEMU and have both qemu and qemu-kvm installed)
 
+TEST_NESTED_KVM=1
+    Allow tests to run with nested KVM. By default, the testsuite disables
+    nested KVM if the host machine already runs under KVM. Setting this
+    variable disables such checks
+
 QEMU_MEM=512M
     Configure amount of memory for QEMU VMs (defaults to 512M)
 
index a8b527b5a6257eaeac6535b400f43f2744ffeecd..2254bda467ae9fb7b1e7fff108ecc085c7d12815 100644 (file)
@@ -17,6 +17,17 @@ UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
 EFI_MOUNT="$(bootctl -x 2>/dev/null || echo /boot)"
 QEMU_MEM="${QEMU_MEM:-512M}"
 
+# Decide if we can (and want to) run QEMU with KVM acceleration.
+# Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not,
+# check if it's not explicitly disabled (TEST_NO_KVM) and we're not already
+# running under KVM. If these conditions are met, enable KVM (and possibly
+# nested KVM), otherwise disable it.
+if [[ -n "$TEST_NESTED_KVM" || ( -z "$TEST_NO_KVM" && $(systemd-detect-virt -v) != kvm ) ]]; then
+    QEMU_KVM=yes
+else
+    QEMU_KVM=no
+fi
+
 if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
     echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
     ROOTLIBDIR=/usr/lib/systemd
@@ -86,9 +97,7 @@ fi
 
 function find_qemu_bin() {
     # SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.
-    # Either way, only use this version if we aren't running in KVM, because
-    # nested KVM is flaky still.
-    if [[ $(systemd-detect-virt -v) != kvm && -z $TEST_NO_KVM ]] ; then
+    if [[ $QEMU_KVM == "yes" ]]; then
         [ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
     fi
 
@@ -220,8 +229,8 @@ $QEMU_OPTIONS \
         QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
     fi
 
-    # Let's use KVM if it is available, but let's avoid using nested KVM as that is still flaky
-    if [[ -c /dev/kvm && $(systemd-detect-virt -v) != kvm && -z $TEST_NO_KVM ]] ; then
+    # Let's use KVM if possible
+    if [[ -c /dev/kvm && $QEMU_KVM == "yes" ]]; then
         QEMU_OPTIONS="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
     fi