scripts/kernel-test: build initrd+kernel as user

Refactor code to build the initramfs and kernel as user, instead of
running related code as root. Put the smoke_test.log into /tmp instead
of the cache dir, so we don't write as root into the cache dir. We cat
it on error anyway, so we don't need to have it in the workspace.

Change-Id: I1670dd86f2670f42eb99e4527d483965d8222402
This commit is contained in:
Oliver Smith 2024-04-03 12:21:14 +02:00 committed by osmith
parent 10e6a00476
commit 5a48bfbe24
3 changed files with 32 additions and 19 deletions

View File

@ -467,11 +467,12 @@ kernel_test_prepare() {
cp "$initrd_project_script" \
"$CACHE_DIR/kernel-test/initrd-project-script.sh"
fix_perms
# Build kernel and initramfs
docker run \
--rm \
--cap-add=NET_ADMIN \
$(docker_kvm_param) \
--device /dev/net/tun:/dev/net/tun \
--user "build" \
-v "$CACHE_DIR:/cache" \
-v "$KERNEL_TEST_DIR:/kernel-test:ro" \
-e "KERNEL_BRANCH=$KERNEL_BRANCH" \
@ -480,11 +481,25 @@ kernel_test_prepare() {
-e "KERNEL_REMOTE_NAME=$KERNEL_REMOTE_NAME" \
-e "KERNEL_URL=$KERNEL_URL" \
-e "KERNEL_SKIP_REBUILD=$KERNEL_SKIP_REBUILD" \
-e "KERNEL_SKIP_SMOKE_TEST=$KERNEL_SKIP_SMOKE_TEST" \
$DOCKER_ARGS \
"$@" \
"$docker_image" \
"/kernel-test/prepare.sh"
# Smoke test
if [ "$KERNEL_SKIP_SMOKE_TEST" != 1 ]; then
docker run \
--rm \
--cap-add=NET_ADMIN \
$(docker_kvm_param) \
--device /dev/net/tun:/dev/net/tun \
-v "$CACHE_DIR:/cache" \
-v "$KERNEL_TEST_DIR:/kernel-test:ro" \
$DOCKER_ARGS \
"$@" \
"$docker_image" \
"/kernel-test/smoke-test.sh"
fi
}
# Wait until the linux kernel is booted inside QEMU inside docker, and the

View File

@ -1,17 +1,6 @@
#!/bin/sh -ex
KERNEL_BUILD="${KERNEL_BUILD:-0}"
# Test if the kernel boots up, and initd code runs through without error
kernel_smoke_test() {
local log=/cache/kernel-test/smoke_test.log
/kernel-test/run-qemu.sh SMOKE_TEST > "$log" 2>&1 || true
if ! grep -q SMOKE_TEST_SUCCESS "$log"; then
cat "$log"
echo "ERROR: failed to boot the kernel and initrd in QEMU!"
exit 1
fi
}
/kernel-test/initrd-build.sh
if [ "$KERNEL_BUILD" = 1 ]; then
@ -19,7 +8,3 @@ if [ "$KERNEL_BUILD" = 1 ]; then
else
cp /boot/vmlinuz-* /cache/kernel-test/linux
fi
if [ "$KERNEL_SKIP_SMOKE_TEST" != 1 ]; then
kernel_smoke_test
fi

View File

@ -0,0 +1,13 @@
#!/bin/sh -ex
# Test if the kernel boots up, and initd code runs through without error
LOG=/tmp/smoke_test.log
/kernel-test/run-qemu.sh SMOKE_TEST > "$LOG" 2>&1 || true
if ! grep -q SMOKE_TEST_SUCCESS "$LOG"; then
cat "$LOG"
set +x
echo "ERROR: failed to boot the kernel and initrd in QEMU!"
exit 1
fi