[PATCH 04/18] selftests/liveupdate: Support building the kexec tests against nolibc
From: David Matlack
Date: Tue Dec 01 2026 - 19:40:29 EST
Add a NOLIBC=1 mode to the liveupdate selftests Makefile, which builds
the tests that run across kexec, and the init process that runs them in
vmtest.sh's VMs, as static binaries against nolibc.
vmtest.sh builds these binaries with its own compiler invocations
today, and this mode will let it use the Makefile instead. The
liveupdate test is not built in this mode since it uses the kselftest
harness, which requires libc. make clean removes the binaries of both
modes.
Fix two warnings in init.c that show up now that it is built with -Wall:
an unused variable, and status possibly being used uninitialized if
waitpid() fails.
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
tools/testing/selftests/liveupdate/Makefile | 13 +++++++++++++
tools/testing/selftests/liveupdate/init.c | 4 ++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/selftests/liveupdate/Makefile
index 31517a07f531..df0567e8ca15 100644
--- a/tools/testing/selftests/liveupdate/Makefile
+++ b/tools/testing/selftests/liveupdate/Makefile
@@ -1,6 +1,13 @@
# SPDX-License-Identifier: GPL-2.0-only
+# With NOLIBC=1, build the tests that run across kexec, and the init process
+# that runs them, as static binaries against nolibc. vmtest.sh uses this to
+# build the initrds for its VMs.
+ifeq ($(NOLIBC),)
TEST_GEN_PROGS += liveupdate
+else
+TEST_GEN_FILES += init
+endif
TEST_GEN_PROGS_EXTENDED += luo_kexec_simple
TEST_GEN_PROGS_EXTENDED += luo_multi_session
@@ -12,6 +19,9 @@ TEST_FILES += do_kexec.sh
include ../lib.mk
include lib/libliveupdate.mk
+ifneq ($(NOLIBC),)
+CFLAGS += -static -nostdlib -nostdinc -I$(top_srcdir)/tools/include/nolibc
+endif
CFLAGS += $(KHDR_INCLUDES)
CFLAGS += -Wall -O2 -Wno-unused-function
CFLAGS += -MD
@@ -31,4 +41,7 @@ $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: $(OUTPUT)/%.o $(LIBLI
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBLIVEUPDATE_O) $(LDLIBS) -o $@
EXTRA_CLEAN += $(TEST_O)
+# Clean up the binaries of both modes regardless of NOLIBC.
+EXTRA_CLEAN += $(OUTPUT)/liveupdate $(OUTPUT)/liveupdate.o $(OUTPUT)/liveupdate.d
+EXTRA_CLEAN += $(OUTPUT)/init $(OUTPUT)/init.d
EXTRA_CLEAN += $(TEST_DEP_FILES)
diff --git a/tools/testing/selftests/liveupdate/init.c b/tools/testing/selftests/liveupdate/init.c
index fb08bd58b9b9..824c9da2facf 100644
--- a/tools/testing/selftests/liveupdate/init.c
+++ b/tools/testing/selftests/liveupdate/init.c
@@ -115,7 +115,8 @@ static int run_test(int stage)
_exit(1);
}
- waitpid(pid, &status, 0);
+ if (waitpid(pid, &status, 0) < 0)
+ return -1;
return (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : -1;
}
@@ -144,7 +145,6 @@ static int get_current_stage(void)
int main(int argc, char *argv[])
{
int current_stage;
- int err;
if (mount_filesystems())
goto err_reboot;
--
2.56.1.911.g883d8bcb20-goog