diff options
author | Oliver Smith <osmith@sysmocom.de> | 2024-04-03 12:21:14 +0200 |
---|---|---|
committer | osmith <osmith@sysmocom.de> | 2024-04-03 12:41:11 +0000 |
commit | 5a48bfbe24e3809699a22445c07c9da3d37322ff (patch) | |
tree | 59272a31b9fa861ea6b3c42e7be4f0fb639a9662 | |
parent | 10e6a00476d7b4d9f118c34ddfffd9efb7825b6f (diff) |
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
-rw-r--r-- | jenkins-common.sh | 23 | ||||
-rwxr-xr-x | scripts/kernel-test/prepare.sh | 15 | ||||
-rwxr-xr-x | scripts/kernel-test/smoke-test.sh | 13 |
3 files changed, 32 insertions, 19 deletions
diff --git a/jenkins-common.sh b/jenkins-common.sh index f22158b..eae0473 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 1f1d1d5..a93a93d 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 0000000..b0570dd --- /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 |