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
This commit is contained in:
parent
5a31e0adc8
commit
cb2a8326c1
|
@ -35,6 +35,7 @@ be used for other testsuites in the future.
|
|||
|
||||
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
|
||||
|
|
|
@ -194,6 +194,12 @@ set_clean_up_trap() {
|
|||
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 @@ kernel_test_prepare() {
|
|||
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 @@ kernel_test_prepare() {
|
|||
|
||||
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() {
|
|||
"/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
|
||||
|
|
|
@ -22,6 +22,8 @@ fi
|
|||
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
|
||||
|
|
|
@ -13,8 +13,14 @@ KERNEL_CMDLINE="
|
|||
$@
|
||||
"
|
||||
|
||||
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 \
|
||||
|
|
|
@ -41,7 +41,7 @@ if [ "$KERNEL_TEST" = "1" ]; then
|
|||
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 @@ docker run --cap-add=NET_ADMIN \
|
|||
$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 \
|
||||
|
|
Loading…
Reference in New Issue