[PATCH 07/18] selftests/liveupdate: Support kernel modules in vmtest.sh

From: David Matlack

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


Add TEST_MODULES to vmtest.sh test definitions. vmtest.sh builds the
modules in the Makefile's TEST_GEN_MODS_DIR against the test kernel,
and places the listed modules at the root of both kernels' initrds,
where the test binary can load them.

The modules are built with MO= so that their build output goes into the
workspace rather than the source tree. The kernel's own modules are
built too, since external modules need Module.symvers.

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

diff --git a/tools/testing/selftests/liveupdate/vmtest.sh b/tools/testing/selftests/liveupdate/vmtest.sh
index 797190d4b47c..937f10fc9592 100755
--- a/tools/testing/selftests/liveupdate/vmtest.sh
+++ b/tools/testing/selftests/liveupdate/vmtest.sh
@@ -21,10 +21,13 @@ KEEP_WORKSPACE=0
# TEST_BINARY Test binary to run, as named in the Makefile
# (default: the test name)
# TEST_ARGS Arguments for the test binary in both stages
+# TEST_MODULES Kernel modules to place at /<module>.ko in the
+# initrd, built from the Makefile's TEST_GEN_MODS_DIR
# TEST_QEMU_ARGS Extra QEMU arguments
# TEST_TIMEOUT Timeout for the QEMU run
# test_check() Host-side check, run after the test passes in the VM
TEST_ARGS=()
+TEST_MODULES=()
TEST_QEMU_ARGS=()
TEST_TIMEOUT="30s"

@@ -152,6 +155,11 @@ function build_kernel() {

$make_cmd "$kimage"
$make_cmd headers_install INSTALL_HDR_PATH="$headers_dir"
+
+ # External modules need Module.symvers
+ if [ ${#TEST_MODULES[@]} -gt 0 ]; then
+ $make_cmd modules
+ fi
}

function mkinitrd() {
@@ -161,12 +169,26 @@ function mkinitrd() {
local output="$workspace_dir/build"
local init="$output/init"
local test_binary="$output/$TEST_BINARY"
+ local extra_files="$workspace_dir/cpio_list_extra"
+ local module ko

# 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"

+ # Build the test modules against the test kernel, and place the ones
+ # the test needs in both initrds
+ : > "$extra_files"
+ if [ ${#TEST_MODULES[@]} -gt 0 ]; then
+ $make_cmd -C "$test_dir" KDIR="$build_dir" MO="$output/modules" gen_mods_dir
+ fi
+ for module in "${TEST_MODULES[@]}"; do
+ ko="$output/modules/$module.ko"
+ [ -f "$ko" ] || fail "Module $module was not built"
+ echo "file /$module.ko $ko 0644 0 0" >> "$extra_files"
+ done
+
# init passes these to the test binary in both stages
echo "${TEST_ARGS[*]}" > "$workspace_dir/test_args"

@@ -179,6 +201,7 @@ file /init $init 0755 0 0
file /test_binary $test_binary 0755 0 0
file /test_args $workspace_dir/test_args 0644 0 0
EOF
+ cat "$extra_files" >> "$workspace_dir/cpio_list_inner"

# Generate inner_initrd.cpio
"$build_dir/scripts/gen_init_cpio" "$workspace_dir/cpio_list_inner" > "$workspace_dir/inner_initrd.cpio"
@@ -194,6 +217,7 @@ file /test_binary $test_binary 0755 0 0
file /test_args $workspace_dir/test_args 0644 0 0
file /initrd.img $workspace_dir/inner_initrd.cpio 0644 0 0
EOF
+ cat "$extra_files" >> "$workspace_dir/cpio_list"

# Generate the final initrd
"$build_dir/scripts/gen_init_cpio" "$workspace_dir/cpio_list" > "$initrd"
--
2.56.1.911.g883d8bcb20-goog