Skip to contentSkip to conversation

selftests/liveupdate: add end to end test infrastructure and scripts

PATCH Superseded Jordan Richards 4 participants 10 messages Feb 5 – Mar 2

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover selftests/liveupdate: add end to end test infrastructure and scripts

This patch series adds end to end testing infrastructure required to verify the liveupdate feature, building and running the existing selftests on supported architectures.

To support executing the selftests as part of an init process, this patch series also adds ftruncate() to nolibc.

Changelog from v1 [1]:
- Moved ftruncate() wrapper to nolibc and fixed issue building selftests without nolibc
- Fixed handling of CROSS_COMPILE env variable
- Remove unecessary complexity in luo_test.sh
- Move results_* directory to selftests/liveupdate/

[1] https://lore.kernel.org/linux-mm/[email protected]/

Jordan Richards (1):
tools/nolibc: add ftruncate()

Pasha Tatashin (1):
selftests/liveupdate: add end to end test infrastructure and scripts

 tools/include/nolibc/unistd.h                 |  11 +
 tools/testing/selftests/liveupdate/.gitignore |   1 +
 tools/testing/selftests/liveupdate/config     |   1 +
 .../selftests/liveupdate/config.aarch64       |   2 +
 .../selftests/liveupdate/config.x86_64        |   2 +
 tools/testing/selftests/liveupdate/init.c     | 179 ++++++++++++
 .../testing/selftests/liveupdate/luo_test.sh  | 276 ++++++++++++++++++
 .../selftests/liveupdate/luo_test_utils.c     |  27 +-
 tools/testing/selftests/liveupdate/run.sh     |  63 ++++
 9 files changed, 549 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/liveupdate/config.aarch64
 create mode 100644 tools/testing/selftests/liveupdate/config.x86_64
 create mode 100644 tools/testing/selftests/liveupdate/init.c
 create mode 100755 tools/testing/selftests/liveupdate/luo_test.sh
 create mode 100755 tools/testing/selftests/liveupdate/run.sh

base-commit: 145197c9801f90fed517447e24a9d20f3927cf27 --
2.53.0.rc2.204.g2597b5adb4-goog

#1 lore raw

PATCH v2 1/2 tools/nolibc: add ftruncate()

---
 tools/include/nolibc/unistd.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/include/nolibc/unistd.h +11 -0
index bb5e80f3f05d..845d10f48fd0 100644
@@ -48,6 +48,17 @@ int access(const char *path, int amode)
 	return faccessat(AT_FDCWD, path, amode, 0);
 }
 
+static __attribute__((unused))
+int sys_ftruncate(int fd, off_t length)
+{
+	return my_syscall2(__NR_ftruncate, fd, length);
+}
+
+static __attribute__((unused))
+int ftruncate(int fd, off_t length)
+{
+	return __sysret(sys_ftruncate(fd, length));
+}
 
 static __attribute__((unused))
 int msleep(unsigned int msecs)
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
#2 lore raw

Re: [PATCH v2 1/2] tools/nolibc: add ftruncate()

Hi Jordan,

(please Cc nolibc maintainers on nolibc changes, I only saw this by chance)

Quoted 9 lines · Jordan Richards
---
 tools/include/nolibc/unistd.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/include/nolibc/unistd.h +0 -0
index bb5e80f3f05d..845d10f48fd0 100644

tools/include/nolibc/unistd.h int access(const char *path, int amode) · line 55

Quoted 8 lines
tools/include/nolibc/unistd.h +5 -0
@@ -48,6 +48,17 @@ int access(const char *path, int amode)
 	return faccessat(AT_FDCWD, path, amode, 0);
 }
 
+static __attribute__((unused))
+int sys_ftruncate(int fd, off_t length)
+{
+	return my_syscall2(__NR_ftruncate, fd, length);
+}

off_t is now always 64bit on nolibc. On 32-bit architectures however __NR_ftruncate only takes a 32bit value, leading to the wrong kind of truncation. Use __NR_ftruncate64 instead where available.

Please also add a simple test to
tools/testing/selftests/nolibc/nolibc-test.c

Quoted 12 lines
tools/include/nolibc/unistd.h +6 -0
+
+static __attribute__((unused))
+int ftruncate(int fd, off_t length)
+{
+	return __sysret(sys_ftruncate(fd, length));
+}
 
 static __attribute__((unused))
 int msleep(unsigned int msecs)
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
#3 lore raw

Re: [PATCH v2 1/2] tools/nolibc: add ftruncate()

Hi Thomas,

Quoted 2 lines

(please Cc nolibc maintainers on nolibc changes, I only saw this by chance)

Will do, sorry about that.

Quoted 3 lines

off_t is now always 64bit on nolibc. On 32-bit architectures however __NR_ftruncate only takes a 32bit value, leading to the wrong kind of truncation. Use __NR_ftruncate64 instead where available.

Good call. On some archs (arm, mips, ppc) register pairs need to start in an even register. I assume adding a flag like:

  #define ARCH_ALIGN_REGISTER_PAIR 1

in "nolibc/arch-xxx.h" is appropriate?

Quoted 2 lines

Please also add a simple test to
tools/testing/selftests/nolibc/nolibc-test.c

Will include in the next version.

Thanks for the review,
Jordan

#4 lore raw

Re: [PATCH v2 1/2] tools/nolibc: add ftruncate()

On 2026-03-02 22:20:43+0000, Jordan Richards wrote:

(...)

Quoted 10 lines
Quoted 3 lines

off_t is now always 64bit on nolibc. On 32-bit architectures however __NR_ftruncate only takes a 32bit value, leading to the wrong kind of truncation. Use __NR_ftruncate64 instead where available.

Good call. On some archs (arm, mips, ppc) register pairs need to start in an even register. I assume adding a flag like:

  #define ARCH_ALIGN_REGISTER_PAIR 1

in "nolibc/arch-xxx.h" is appropriate?

I would use a custom sys_ftruncate64() wrapper function for those. Similar to sys_mmap() on some architectures or sys_fork() on s390.

(...)

Thomas

#5 lore raw

PATCH v2 2/2 selftests/liveupdate: add end to end test infrastructure and scripts

In reply to Jordan Richards

From: Pasha Tatashin <[email protected]>

Add the end to end testing infrastructure required to verify the liveupdate feature. This includes a custom init process, a test orchestration script, and a batch runner.

The framework consists of:

init.c:
A lightweight init process that manages the kexec lifecycle. It mounts necessary filesystems, determines the current execution stage (1 or 2) via the kernel command line, and handles the kexec_file_load() sequence to transition between kernels.

luo_test.sh:
The primary KTAP-compliant test driver. It handles:
- Kernel configuration merging and building.
- Cross-compilation detection for x86_64 and arm64.
- Generation of the initrd containing the test binary and init.
- QEMU execution with automatic accelerator detection (KVM, HVF, or TCG).

run.sh:
A wrapper script to discover and execute all luo_*.c tests across supported architectures, providing a summary of pass/fail/skip results.

---
 tools/testing/selftests/liveupdate/.gitignore |   1 +
 tools/testing/selftests/liveupdate/config     |   1 +
 .../selftests/liveupdate/config.aarch64       |   2 +
 .../selftests/liveupdate/config.x86_64        |   2 +
 tools/testing/selftests/liveupdate/init.c     | 179 ++++++++++++
 .../testing/selftests/liveupdate/luo_test.sh  | 276 ++++++++++++++++++
 .../selftests/liveupdate/luo_test_utils.c     |  27 +-
 tools/testing/selftests/liveupdate/run.sh     |  63 ++++
 8 files changed, 538 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/liveupdate/config.aarch64
 create mode 100644 tools/testing/selftests/liveupdate/config.x86_64
 create mode 100644 tools/testing/selftests/liveupdate/init.c
 create mode 100755 tools/testing/selftests/liveupdate/luo_test.sh
 create mode 100755 tools/testing/selftests/liveupdate/run.sh
tools/testing/selftests/liveupdate/.gitignore +1 -0
index 661827083ab6..cb08ddb0dfee 100644
@@ -6,4 +6,5 @@
 !*.sh
 !.gitignore
 !config
+!config.*
 !Makefile
tools/testing/selftests/liveupdate/config +1 -0
index 91d03f9a6a39..016d009dba13 100644
@@ -1,4 +1,5 @@
 CONFIG_BLK_DEV_INITRD=y
+CONFIG_DEVTMPFS=y
 CONFIG_KEXEC_FILE=y
 CONFIG_KEXEC_HANDOVER=y
 CONFIG_KEXEC_HANDOVER_ENABLE_DEFAULT=y
tools/testing/selftests/liveupdate/config.aarch64 new file +2 -0
new file mode 100644
index 000000000000..445716403925
@@ -0,0 +1,2 @@
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
tools/testing/selftests/liveupdate/config.x86_64 new file +2 -0
new file mode 100644
index 000000000000..810d9c9d213e
@@ -0,0 +1,2 @@
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
tools/testing/selftests/liveupdate/init.c new file +179 -0

179 lines not on this page · raw message

tools/testing/selftests/liveupdate/luo_test.sh new file +276 -0

276 lines not on this page · raw message

tools/testing/selftests/liveupdate/luo_test_utils.c +14 -13
index 3c8721c505df..100dc0f69f37 100644
@@ -20,9 +20,14 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <linux/unistd.h>
 
 #include "luo_test_utils.h"
 
+#ifdef NOLIBC
+#include <sys.h>
+#endif
+
 int luo_open_device(void)
 {
 	return open(LUO_DEVICE, O_RDWR);
@@ -32,8 +37,8 @@ int luo_create_session(int luo_fd, const char *name)
 {
 	struct liveupdate_ioctl_create_session arg = { .size = sizeof(arg) };
 
-	snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s",
-		 LIVEUPDATE_SESSION_NAME_LENGTH - 1, name);
+	strncpy((char *)arg.name, name, LIVEUPDATE_SESSION_NAME_LENGTH);
+	arg.name[LIVEUPDATE_SESSION_NAME_LENGTH - 1] = '\0';
 
 	if (ioctl(luo_fd, LIVEUPDATE_IOCTL_CREATE_SESSION, &arg) < 0)
 		return -errno;
@@ -45,8 +50,8 @@ int luo_retrieve_session(int luo_fd, const char *name)
 {
 	struct liveupdate_ioctl_retrieve_session arg = { .size = sizeof(arg) };
 
-	snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s",
-		 LIVEUPDATE_SESSION_NAME_LENGTH - 1, name);
+	strncpy((char *)arg.name, name, LIVEUPDATE_SESSION_NAME_LENGTH);
+	arg.name[LIVEUPDATE_SESSION_NAME_LENGTH - 1] = '\0';
 
 	if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg) < 0)
 		return -errno;
@@ -57,7 +62,7 @@ int luo_retrieve_session(int luo_fd, const char *name)
 int create_and_preserve_memfd(int session_fd, int token, const char *data)
 {
 	struct liveupdate_session_preserve_fd arg = { .size = sizeof(arg) };
-	long page_size = sysconf(_SC_PAGE_SIZE);
+	long page_size = getpagesize();
 	void *map = MAP_FAILED;
 	int mfd = -1, ret = -1;
 
@@ -93,7 +98,7 @@ int restore_and_verify_memfd(int session_fd, int token,
 			     const char *expected_data)
 {
 	struct liveupdate_session_retrieve_fd arg = { .size = sizeof(arg) };
-	long page_size = sysconf(_SC_PAGE_SIZE);
+	long page_size = getpagesize();
 	void *map = MAP_FAILED;
 	int mfd = -1, ret = -1;
 
@@ -204,16 +209,11 @@ void daemonize_and_wait(void)
 
 static int parse_stage_args(int argc, char *argv[])
 {
-	static struct option long_options[] = {
-		{"stage", required_argument, 0, 's'},
-		{0, 0, 0, 0}
-	};
-	int option_index = 0;
 	int stage = 1;
 	int opt;
 
 	optind = 1;
-	while ((opt = getopt_long(argc, argv, "s:", long_options, &option_index)) != -1) {
+	while ((opt = getopt(argc, argv, "s:")) != -1) {
 		switch (opt) {
 		case 's':
 			stage = atoi(optarg);
@@ -224,6 +224,7 @@ static int parse_stage_args(int argc, char *argv[])
 			fail_exit("Unknown argument");
 		}
 	}
+
 	return stage;
 }
 
@@ -251,7 +252,7 @@ int luo_test(int argc, char *argv[],
 		fail_exit("Failed to check for state session");
 
 	if (target_stage != detected_stage) {
-		ksft_exit_fail_msg("Stage mismatch Requested --stage %d, but system is in stage %d.\n"
+		ksft_exit_fail_msg("Stage mismatch Requested stage %d, but system is in stage %d.\n"
 				   "(State session %s: %s)\n",
 				   target_stage, detected_stage, state_session_name,
 				   (detected_stage == 2) ? "EXISTS" : "MISSING");
tools/testing/selftests/liveupdate/run.sh new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
#6 lore raw
Quoted 1 line · Jordan Richards

From: Pasha Tatashin <[email protected]>

(...)

Quoted 5 lines
tools/testing/selftests/liveupdate/luo_test_utils.c +0 -0
index 3c8721c505df..100dc0f69f37 100644

tools/testing/selftests/liveupdate/luo_test_utils.c line 29

Quoted 10 lines
tools/testing/selftests/liveupdate/luo_test_utils.c +4 -0
@@ -20,9 +20,14 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <linux/unistd.h>
 
 #include "luo_test_utils.h"
 
+#ifdef NOLIBC
+#include <sys.h>
+#endif

This should not be necessary.
I am actively trying to get rid of the checks for the NOLIBC macro.

Quoted 4 lines
tools/testing/selftests/liveupdate/luo_test_utils.c +1 -0
+
 int luo_open_device(void)
 {
 	return open(LUO_DEVICE, O_RDWR);

(...)

tools/testing/selftests/liveupdate/luo_test_utils.c int luo_retrieve_session(int luo_fd, const char *name) · line 54

Quoted 8 lines
tools/testing/selftests/liveupdate/luo_test_utils.c +2 -2
@@ -45,8 +50,8 @@ int luo_retrieve_session(int luo_fd, const char *name)
 {
 	struct liveupdate_ioctl_retrieve_session arg = { .size = sizeof(arg) };
 
-	snprintf((char *)arg.name, LIVEUPDATE_SESSION_NAME_LENGTH, "%.*s",
-		 LIVEUPDATE_SESSION_NAME_LENGTH - 1, name);
+	strncpy((char *)arg.name, name, LIVEUPDATE_SESSION_NAME_LENGTH);
+	arg.name[LIVEUPDATE_SESSION_NAME_LENGTH - 1] = '\0';

FWIW we are currently working on "%.*s" support.

Quoted 3 lines
tools/testing/selftests/liveupdate/luo_test_utils.c +0 -0
 	if (ioctl(luo_fd, LIVEUPDATE_IOCTL_RETRIEVE_SESSION, &arg) < 0)
 		return -errno;

(...)

#7 lore raw
Quoted 6 lines

tools/testing/selftests/liveupdate/luo_test_utils.c line 29

Quoted 3 lines
tools/testing/selftests/liveupdate/luo_test_utils.c +3 -0
+#ifdef NOLIBC
+#include <sys.h>
+#endif

This should not be necessary.
I am actively trying to get rid of the checks for the NOLIBC macro.

Oops, that's no longer used directly. Will remove in v3.

maintainer Reviewed-by on v2 2/2
#8 lore raw
In reply to Jordan Richards

Hi Jordan,

Quoted 22 lines · Jordan Richards

From: Pasha Tatashin <[email protected]>

Add the end to end testing infrastructure required to verify the liveupdate feature. This includes a custom init process, a test orchestration script, and a batch runner.

The framework consists of:

init.c:
A lightweight init process that manages the kexec lifecycle. It mounts necessary filesystems, determines the current execution stage (1 or 2) via the kernel command line, and handles the kexec_file_load() sequence to transition between kernels.

luo_test.sh:
The primary KTAP-compliant test driver. It handles:
- Kernel configuration merging and building.
- Cross-compilation detection for x86_64 and arm64.
- Generation of the initrd containing the test binary and init.
- QEMU execution with automatic accelerator detection (KVM, HVF, or TCG).

Quoted 6 lines

run.sh:
A wrapper script to discover and execute all luo_*.c tests across supported architectures, providing a summary of pass/fail/skip results.

I think you also need

Quoted 1 line

With nolibc fixes Thomas requested:

Signature · 2 lines
Sincerely yours,
Mike.
maintainer Acked-by
#9 lore raw
Quoted 32 lines · Mike Rapoport

Hi Jordan,

Quoted 22 lines · Jordan Richards

From: Pasha Tatashin <[email protected]>

Add the end to end testing infrastructure required to verify the liveupdate feature. This includes a custom init process, a test orchestration script, and a batch runner.

The framework consists of:

init.c:
A lightweight init process that manages the kexec lifecycle. It mounts necessary filesystems, determines the current execution stage (1 or 2) via the kernel command line, and handles the kexec_file_load() sequence to transition between kernels.

luo_test.sh:
The primary KTAP-compliant test driver. It handles:
- Kernel configuration merging and building.
- Cross-compilation detection for x86_64 and arm64.
- Generation of the initrd containing the test binary and init.
- QEMU execution with automatic accelerator detection (KVM, HVF, or TCG).

Quoted 6 lines

run.sh:
A wrapper script to discover and execute all luo_*.c tests across supported architectures, providing a summary of pass/fail/skip results.

Quoted 8 lines

I think you also need

Quoted 1 line

With nolibc fixes Thomas requested:

I didn't look too closely, but at a quick skim, LGTM.

Signature · 2 lines
Regards,
Pratyush Yadav