Skip to content

Commit 501deda

Browse files
mrc0mmandfilbranden
authored andcommitted
test: allow use of nested KVM
Introduce TEST_NESTED_KVM variable, which allows use of nested KVM for QEMU VMs (which is disabled by default by KVM autodetection).
1 parent c4fed80 commit 501deda

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

test/README.testsuite

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ TEST_NO_KVM=1
5454
Disable QEMU KVM autodetection (may be necessary when you're trying to run the
5555
*vanilla* QEMU and have both qemu and qemu-kvm installed)
5656

57+
TEST_NESTED_KVM=1
58+
Allow tests to run with nested KVM. By default, the testsuite disables
59+
nested KVM if the host machine already runs under KVM. Setting this
60+
variable disables such checks
61+
5762
QEMU_MEM=512M
5863
Configure amount of memory for QEMU VMs (defaults to 512M)
5964

test/test-functions

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ UNIFIED_CGROUP_HIERARCHY="${UNIFIED_CGROUP_HIERARCHY:-default}"
1717
EFI_MOUNT="$(bootctl -x 2>/dev/null || echo /boot)"
1818
QEMU_MEM="${QEMU_MEM:-512M}"
1919

20+
# Decide if we can (and want to) run QEMU with KVM acceleration.
21+
# Check if nested KVM is explicitly enabled (TEST_NESTED_KVM). If not,
22+
# check if it's not explicitly disabled (TEST_NO_KVM) and we're not already
23+
# running under KVM. If these conditions are met, enable KVM (and possibly
24+
# nested KVM), otherwise disable it.
25+
if [[ -n "$TEST_NESTED_KVM" || ( -z "$TEST_NO_KVM" && $(systemd-detect-virt -v) != kvm ) ]]; then
26+
QEMU_KVM=yes
27+
else
28+
QEMU_KVM=no
29+
fi
30+
2031
if ! ROOTLIBDIR=$(pkg-config --variable=systemdutildir systemd); then
2132
echo "WARNING! Cannot determine rootlibdir from pkg-config, assuming /usr/lib/systemd" >&2
2233
ROOTLIBDIR=/usr/lib/systemd
@@ -86,9 +97,7 @@ fi
8697

8798
function find_qemu_bin() {
8899
# SUSE and Red Hat call the binary qemu-kvm. Debian and Gentoo call it kvm.
89-
# Either way, only use this version if we aren't running in KVM, because
90-
# nested KVM is flaky still.
91-
if [[ $(systemd-detect-virt -v) != kvm && -z $TEST_NO_KVM ]] ; then
100+
if [[ $QEMU_KVM == "yes" ]]; then
92101
[ "$QEMU_BIN" ] || QEMU_BIN=$(which -a kvm qemu-kvm 2>/dev/null | grep '^/' -m1)
93102
fi
94103

@@ -220,8 +229,8 @@ $QEMU_OPTIONS \
220229
QEMU_OPTIONS="$QEMU_OPTIONS -initrd $INITRD"
221230
fi
222231

223-
# Let's use KVM if it is available, but let's avoid using nested KVM as that is still flaky
224-
if [[ -c /dev/kvm && $(systemd-detect-virt -v) != kvm && -z $TEST_NO_KVM ]] ; then
232+
# Let's use KVM if possible
233+
if [[ -c /dev/kvm && $QEMU_KVM == "yes" ]]; then
225234
QEMU_OPTIONS="$QEMU_OPTIONS -machine accel=kvm -enable-kvm -cpu host"
226235
fi
227236

0 commit comments

Comments
 (0)