From 5a48bfbe24e3809699a22445c07c9da3d37322ff Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 3 Apr 2024 12:21:14 +0200 Subject: [PATCH] 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 --- jenkins-common.sh | 23 +++++++++++++++++++---- scripts/kernel-test/prepare.sh | 15 --------------- scripts/kernel-test/smoke-test.sh | 13 +++++++++++++ 3 files changed, 32 insertions(+), 19 deletions(-) create mode 100755 scripts/kernel-test/smoke-test.sh diff --git a/jenkins-common.sh b/jenkins-common.sh index f22158b5..eae04735 100644 --- a/jenkins-common.sh +++ b/jenkins-common.sh @@ -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 diff --git a/scripts/kernel-test/prepare.sh b/scripts/kernel-test/prepare.sh index 1f1d1d56..a93a93dc 100755 --- a/scripts/kernel-test/prepare.sh +++ b/scripts/kernel-test/prepare.sh @@ -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 diff --git a/scripts/kernel-test/smoke-test.sh b/scripts/kernel-test/smoke-test.sh new file mode 100755 index 00000000..b0570dd2 --- /dev/null +++ b/scripts/kernel-test/smoke-test.sh @@ -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