selftests/liveupdate: Move luo_test_utils.* into a reusable library

Move luo_test_utils.[ch] into a lib/ directory and make libliveupdate
library. Pull the rules to build them out into a separate
libliveupdate.mk script. This will enable these utilities to be
also built by and used within other selftests (such as VFIO).

Update path in vmtest.sh as that one uses hardcoded path for util.

No functional change intended.

Co-developed-by: David Matlack <dmatlack@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
Acked-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Vipin Sharma <vipinsh@google.com>
Link: https://patch.msgid.link/20260720203202.1964557-3-vipinsh@google.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
This commit is contained in:
Vipin Sharma 2026-07-20 13:32:02 -07:00 committed by Mike Rapoport (Microsoft)
parent 2f3f53a373
commit df1a0d068d
11 changed files with 39 additions and 22 deletions

View File

@ -3,6 +3,7 @@
!/**/
!*.c
!*.h
!*.mk
!*.sh
!.gitignore
!config

View File

@ -1,7 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
LIB_C += luo_test_utils.c
TEST_GEN_PROGS += liveupdate
TEST_GEN_PROGS_EXTENDED += luo_kexec_simple
@ -12,25 +10,21 @@ TEST_GEN_PROGS_EXTENDED += luo_stress_files
TEST_FILES += do_kexec.sh
include ../lib.mk
include lib/libliveupdate.mk
CFLAGS += $(KHDR_INCLUDES)
CFLAGS += -Wall -O2 -Wno-unused-function
CFLAGS += -MD
LIB_O := $(patsubst %.c, $(OUTPUT)/%.o, $(LIB_C))
TEST_O := $(patsubst %, %.o, $(TEST_GEN_PROGS))
TEST_O += $(patsubst %, %.o, $(TEST_GEN_PROGS_EXTENDED))
TEST_DEP_FILES := $(patsubst %.o, %.d, $(LIB_O))
TEST_DEP_FILES := $(patsubst %.o, %.d, $(LIBLIVEUPDATE_O))
TEST_DEP_FILES += $(patsubst %.o, %.d, $(TEST_O))
-include $(TEST_DEP_FILES)
$(LIB_O): $(OUTPUT)/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIBLIVEUPDATE_O)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIBLIVEUPDATE_O) $(LDLIBS) -o $@
$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/%: %.o $(LIB_O)
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) $< $(LIB_O) $(LDLIBS) -o $@
EXTRA_CLEAN += $(LIB_O)
EXTRA_CLEAN += $(TEST_O)
EXTRA_CLEAN += $(TEST_DEP_FILES)

View File

@ -7,13 +7,13 @@
* Utility functions for LUO kselftests.
*/
#ifndef LUO_TEST_UTILS_H
#define LUO_TEST_UTILS_H
#ifndef SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
#define SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H
#include <errno.h>
#include <string.h>
#include <linux/liveupdate.h>
#include "../kselftest.h"
#include "../../../kselftest.h"
#define LUO_DEVICE "/dev/liveupdate"
@ -46,4 +46,4 @@ typedef void (*luo_test_stage2_fn)(int luo_fd, int state_session_fd);
int luo_test(int argc, char *argv[], const char *state_session_name,
luo_test_stage1_fn stage1, luo_test_stage2_fn stage2);
#endif /* LUO_TEST_UTILS_H */
#endif /* SELFTESTS_LIVEUPDATE_LIB_LIVEUPDATE_H */

View File

@ -0,0 +1,20 @@
include $(top_srcdir)/scripts/subarch.include
ARCH ?= $(SUBARCH)
LIBLIVEUPDATE_SRCDIR := $(selfdir)/liveupdate/lib
LIBLIVEUPDATE_C := lu_utils.c
LIBLIVEUPDATE_OUTPUT := $(OUTPUT)/libliveupdate
LIBLIVEUPDATE_O := $(patsubst %.c, $(LIBLIVEUPDATE_OUTPUT)/%.o, $(LIBLIVEUPDATE_C))
CFLAGS += -I$(LIBLIVEUPDATE_SRCDIR)/include
$(LIBLIVEUPDATE_OUTPUT):
$(Q)mkdir -p $@
$(LIBLIVEUPDATE_O): $(LIBLIVEUPDATE_OUTPUT)/%.o : $(LIBLIVEUPDATE_SRCDIR)/%.c | $(LIBLIVEUPDATE_OUTPUT)
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
EXTRA_CLEAN += $(LIBLIVEUPDATE_OUTPUT)

View File

@ -23,7 +23,7 @@
#include <stdarg.h>
#include <linux/unistd.h>
#include "luo_test_utils.h"
#include <libliveupdate.h>
int luo_open_device(void)
{

View File

@ -24,9 +24,9 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <libliveupdate.h>
#include <linux/liveupdate.h>
#include "luo_test_utils.h"
#include "../kselftest.h"
#include "../kselftest_harness.h"

View File

@ -8,7 +8,7 @@
* across a single kexec reboot.
*/
#include "luo_test_utils.h"
#include <libliveupdate.h>
#define TEST_SESSION_NAME "test-session"
#define TEST_MEMFD_TOKEN 0x1A

View File

@ -9,7 +9,7 @@
* files.
*/
#include "luo_test_utils.h"
#include <libliveupdate.h>
#define SESSION_EMPTY_1 "multi-test-empty-1"
#define SESSION_EMPTY_2 "multi-test-empty-2"

View File

@ -10,7 +10,8 @@
#include <stdio.h>
#include <unistd.h>
#include "luo_test_utils.h"
#include <libliveupdate.h>
#define NUM_FILES 500
#define STATE_SESSION_NAME "kexec_many_files_state"

View File

@ -10,7 +10,8 @@
#include <stdio.h>
#include <unistd.h>
#include "luo_test_utils.h"
#include <libliveupdate.h>
#define NUM_SESSIONS 2000
#define STATE_SESSION_NAME "kexec_many_state"

View File

@ -131,9 +131,9 @@ function mkinitrd() {
"$CROSS_COMPILE"gcc -static -O2 -nostdinc -nostdlib \
-I "$headers_dir/include" \
-I "$kernel_dir/tools/include/nolibc" \
-I "$test_dir" \
-I "$test_dir/lib/include" \
-o "$workspace_dir/test_binary" \
"$test_dir/$test_name.c" "$test_dir/luo_test_utils.c"
"$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 \