Change in docker-playground[master]: kernel-test: don't try to use KVM if not available

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Fri Feb 26 16:18:26 UTC 2021


osmith has submitted this change. ( https://gerrit.osmocom.org/c/docker-playground/+/23123 )

Change subject: kernel-test: don't try to use KVM if not available
......................................................................

kernel-test: don't try to use KVM if not available

Disable KVM if /dev/kvm is missing, as it is apparently the case on our
jenkins nodes. This makes the tests run a bit slower, but not much. Add
kernel_test_wait_for_vm to sleep until the VM is booted up (~5s instead
of ~1s without KVM), so the first test in the testsuite does not fail
when using KVM.

The variable is useful to test the non-KVM code path even if KVM is
available on the host.

Related: OS#3208
Change-Id: I1f337af1e2de6db05b22636bc31a535404235559
---
M README.md
M jenkins-common.sh
M scripts/kernel-test/initrd-init.sh
M scripts/kernel-test/run-qemu.sh
M ttcn3-ggsn-test/jenkins.sh
5 files changed, 54 insertions(+), 3 deletions(-)

Approvals:
  osmith: Looks good to me, approved; Verified



diff --git a/README.md b/README.md
index 27a589e..6a9f4b9 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,7 @@
 
 Environment variables:
 * `KERNEL_TEST`: set to 1 to run the SUT in QEMU
+* `KERNEL_TEST_KVM`: set to 0 to disable KVM acceleration
 * `KERNEL_BUILD`: set to 1 to build the kernel instead of using the
   pre-built one
 * `KERNEL_REMOTE_NAME`: git remote name (to add multiple git
diff --git a/jenkins-common.sh b/jenkins-common.sh
index 6c54109..25d5426 100644
--- a/jenkins-common.sh
+++ b/jenkins-common.sh
@@ -194,6 +194,12 @@
 	trap clean_up_common EXIT INT TERM 0
 }
 
+docker_kvm_param() {
+	if [ "$KERNEL_TEST_KVM" != 0 ]; then
+		echo "--device /dev/kvm:/dev/kvm"
+	fi
+}
+
 # Generate the initrd, and optionally build a kernel, for tests that involve
 # kernel modules. Boot the kernel once in QEMU inside docker to verify that it
 # works. See README.md for description of the KERNEL_* environment variables.
@@ -212,6 +218,15 @@
 	local docker_image="$4"
 	shift 4
 
+	# Store KVM availibility in global KERNEL_TEST_KVM
+	if [ -z "$KERNEL_TEST_KVM" ]; then
+		if [ -e "/dev/kvm" ]; then
+			KERNEL_TEST_KVM=1
+		else
+			KERNEL_TEST_KVM=0
+		fi
+	fi
+
 	mkdir -p "$CACHE_DIR/kernel-test"
 
 	cp "$kernel_config_fragment" \
@@ -221,7 +236,7 @@
 
 	docker run \
 		--cap-add=NET_ADMIN \
-		--device /dev/kvm:/dev/kvm \
+		$(docker_kvm_param) \
 		--device /dev/net/tun:/dev/net/tun \
 		-v "$CACHE_DIR:/cache" \
 		-v "$KERNEL_TEST_DIR:/kernel-test:ro" \
@@ -235,6 +250,31 @@
 		"/kernel-test/prepare.sh"
 }
 
+# Wait until the linux kernel is booted inside QEMU inside docker, and the
+# initrd is right before running the project-specific commands (e.g. starting
+# osmo-ggsn). This may take a few seconds if running without KVM.
+# $1: path to the VM's log file
+kernel_test_wait_for_vm() {
+	local log="$1"
+	local i
+
+	if [ "$KERNEL_TEST" != 1 ]; then
+		return
+	fi
+
+	for i in $(seq 1 10); do
+		sleep 1
+
+		if grep -q KERNEL_TEST_VM_IS_READY "$log"; then
+			return
+		fi
+	done
+
+	# Let clean_up_common kill the VM
+	echo "Timeout while waiting for kernel test VM"
+	exit 1
+}
+
 set -x
 
 # non-jenkins execution: assume local user name
diff --git a/scripts/kernel-test/initrd-init.sh b/scripts/kernel-test/initrd-init.sh
index 1c198b8..c2d936a 100755
--- a/scripts/kernel-test/initrd-init.sh
+++ b/scripts/kernel-test/initrd-init.sh
@@ -22,6 +22,8 @@
 ip link set lo up
 ip link set eth0 up
 
+echo "KERNEL_TEST_VM_IS_READY"
+
 if grep -q SMOKE_TEST /proc/cmdline; then
 	# Called from scripts/kernel-test/prepare.sh:kernel_smoke_test() to
 	# verify that the kernel + initramfs boot up properly. Output this
diff --git a/scripts/kernel-test/run-qemu.sh b/scripts/kernel-test/run-qemu.sh
index 0a1824f..1873af4 100755
--- a/scripts/kernel-test/run-qemu.sh
+++ b/scripts/kernel-test/run-qemu.sh
@@ -13,8 +13,14 @@
 	$@
 "
 
+if [ -e /dev/kvm ]; then
+	MACHINE_ARG="-machine pc,accel=kvm"
+else
+	MACHINE_ARG="-machine pc"
+fi
+
 qemu-system-x86_64 \
-	-machine pc,accel=kvm \
+	$MACHINE_ARG \
 	-smp 1 \
 	-m 512M \
 	-nodefconfig -no-user-config -nodefaults -display none \
diff --git a/ttcn3-ggsn-test/jenkins.sh b/ttcn3-ggsn-test/jenkins.sh
index c6ea729..ba5e76d 100755
--- a/ttcn3-ggsn-test/jenkins.sh
+++ b/ttcn3-ggsn-test/jenkins.sh
@@ -41,7 +41,7 @@
 	GGSN_CMD="/kernel-test/run-qemu.sh"
 	GGSN_DOCKER_ARGS="
 		$(docker_network_params $SUBNET 200)
-		--device /dev/kvm:/dev/kvm
+		$(docker_kvm_param)
 		-v "$KERNEL_TEST_DIR:/kernel-test:ro"
 		-v "$CACHE_DIR:/cache"
 		"
@@ -64,6 +64,8 @@
 		$REPO_USER/osmo-ggsn-$IMAGE_SUFFIX \
 		/bin/sh -c "$GGSN_CMD >/data/osmo-ggsn.log 2>&1"
 
+kernel_test_wait_for_vm "$VOL_BASE_DIR/ggsn/osmo-ggsn.log"
+
 # start docker container with testsuite in foreground
 docker run	--rm \
 		--sysctl net.ipv6.conf.all.disable_ipv6=0 \

-- 
To view, visit https://gerrit.osmocom.org/c/docker-playground/+/23123
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: docker-playground
Gerrit-Branch: master
Gerrit-Change-Id: I1f337af1e2de6db05b22636bc31a535404235559
Gerrit-Change-Number: 23123
Gerrit-PatchSet: 5
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210226/d3c3e961/attachment.htm>


More information about the gerrit-log mailing list