[PATCH 05/18] selftests/liveupdate: Build vmtest.sh's binaries with the Makefile

From: David Matlack

Date: Tue Dec 01 2026 - 19:40:27 EST


Build the test binary and the init process for vmtest.sh's initrds with
the liveupdate selftests Makefile in NOLIBC=1 mode, rather than with
separate compiler invocations in vmtest.sh. The build output goes into
the workspace.

This leaves a single description of how the tests are built, so that
any test added to the Makefile can also be run with vmtest.sh,
including tests built from multiple source files.

Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
tools/testing/selftests/liveupdate/vmtest.sh | 32 ++++++++------------
1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/liveupdate/vmtest.sh b/tools/testing/selftests/liveupdate/vmtest.sh
index 6cbee44cd27e..b24a8bb774ca 100755
--- a/tools/testing/selftests/liveupdate/vmtest.sh
+++ b/tools/testing/selftests/liveupdate/vmtest.sh
@@ -139,29 +139,23 @@ function mkinitrd() {
local build_dir=$1
local kernel_path=$2
local test_name=$3
+ local make_cmd=$4
+ local output="$workspace_dir/build"
+ local init="$output/init"
+ local test_binary="$output/$test_name"

- # Compile the test binary and the init process
- "$CROSS_COMPILE"gcc -static -O2 -nostdinc -nostdlib \
- -I "$headers_dir/include" \
- -I "$kernel_dir/tools/include/nolibc" \
- -I "$test_dir/lib/include" \
- -o "$workspace_dir/test_binary" \
- "$test_dir/$test_name.c" "$test_dir/lib/lu_utils.c"
-
- "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -nostdlib \
- -fno-asynchronous-unwind-tables -fno-ident \
- -fno-stack-protector \
- -I "$headers_dir/include" \
- -I "$kernel_dir/tools/include/nolibc" \
- -o "$workspace_dir/init" "$test_dir/init.c"
+ # Build the test binary and the init process
+ mkdir -p "$output"
+ $make_cmd -C "$test_dir" NOLIBC=1 OUTPUT="$output" \
+ KHDR_INCLUDES="-I$headers_dir/include" "$init" "$test_binary"

cat > "$workspace_dir/cpio_list_inner" <<EOF
dir /dev 0755 0 0
dir /proc 0755 0 0
dir /debugfs 0755 0 0
nod /dev/console 0600 0 0 c 5 1
-file /init $workspace_dir/init 0755 0 0
-file /test_binary $workspace_dir/test_binary 0755 0 0
+file /init $init 0755 0 0
+file /test_binary $test_binary 0755 0 0
EOF

# Generate inner_initrd.cpio
@@ -172,9 +166,9 @@ dir /dev 0755 0 0
dir /proc 0755 0 0
dir /debugfs 0755 0 0
nod /dev/console 0600 0 0 c 5 1
-file /init $workspace_dir/init 0755 0 0
+file /init $init 0755 0 0
file /kernel $kernel_path 0644 0 0
-file /test_binary $workspace_dir/test_binary 0755 0 0
+file /test_binary $test_binary 0755 0 0
file /initrd.img $workspace_dir/inner_initrd.cpio 0644 0 0
EOF

@@ -268,7 +262,7 @@ function main() {
build_kernel "$build_dir" "$make_cmd_build" "$KERNEL_IMAGE" "$target"

local final_kernel="$build_dir/arch/$arch/boot/$KERNEL_IMAGE"
- mkinitrd "$build_dir" "$final_kernel" "$test_name"
+ mkinitrd "$build_dir" "$final_kernel" "$test_name" "$make_cmd"

run_qemu "$QEMU_CMD" "$KERNEL_CMDLINE" "$final_kernel"
ktap_test_pass "$test_name succeeded"
--
2.56.1.911.g883d8bcb20-goog