Introduce two new, non-kexec selftests to validate the state transition
logic for individual LUO sessions, with a focus on the PREPARE, FREEZE,
and CANCEL events. While other tests cover the full kexec lifecycle, it
is critical to also test the internal per-session state machine's logic
and rollback capabilities in isolation. These tests provide this focused
coverage, ensuring the core session management ioctls behave as
expected.
The new test cases are:
1. session_prepare_cancel_cycle:
- Verifies the fundamental NORMAL -> PREPARED -> NORMAL state
transition path.
- It creates a session, preserves a file, sends a per-session PREPARE
event, asserts the state is PREPARED, then sends a CANCEL event and
asserts the state has correctly returned to NORMAL.
2. session_freeze_cancel_cycle:
- Extends the first test by validating the more critical ... ->
FROZEN -> NORMAL rollback path.
- It follows the same steps but adds a FREEZE event after PREPARE,
asserting the session enters the FROZEN state.
- It then sends a CANCEL event, verifying that a session can be rolled
back even from this final pre-kexec state. This is essential for
robustly handling aborts.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
tools/testing/selftests/liveupdate/Makefile | 9 ++-
.../testing/selftests/liveupdate/liveupdate.c | 56 +++++++++++++++++++
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/liveupdate/Makefile b/tools/testing/selftests/liveupdate/Makefile
index ffce73233149..25a6dec790bb 100644
--- a/tools/testing/selftests/liveupdate/Makefile
+++ b/tools/testing/selftests/liveupdate/Makefile
@@ -16,11 +16,18 @@ LUO_MANUAL_TESTS += luo_unreclaimed
TEST_FILES += do_kexec.sh
-TEST_GEN_PROGS += liveupdate
+LUO_MAIN_TESTS += liveupdate
# --- Automatic Rule Generation (Do not edit below) ---
TEST_GEN_PROGS_EXTENDED += $(LUO_MANUAL_TESTS)
+TEST_GEN_PROGS := $(LUO_MAIN_TESTS)
+
+liveupdate_SOURCES := liveupdate.c $(LUO_SHARED_SRCS)
+
+$(OUTPUT)/liveupdate: $(liveupdate_SOURCES) $(LUO_SHARED_HDRS)
+ $(call msg,LINK,,$@)
+ $(Q)$(LINK.c) $^ $(LDLIBS) -o $@
# Define the full list of sources for each manual test.
$(foreach test,$(LUO_MANUAL_TESTS), \
diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
index 7c0ceaac0283..804aa25ce5ae 100644
--- a/tools/testing/selftests/liveupdate/liveupdate.c
+++ b/tools/testing/selftests/liveupdate/liveupdate.c
@@ -17,6 +17,7 @@
#include <sys/mman.h>
#include <linux/liveupdate.h>
+#include "luo_test_utils.h"
#include "../kselftest.h"
#include "../kselftest_harness.h"
@@ -52,6 +53,16 @@ const char *const luo_state_str[] = {
[LIVEUPDATE_STATE_UPDATED] = "updated",
};
+static int get_session_state(int session_fd)
+{
+ struct liveupdate_session_get_state arg = { .size = sizeof(arg) };
+
+ if (ioctl(session_fd, LIVEUPDATE_SESSION_GET_STATE, &arg) < 0)
+ return -errno;
+
+ return arg.state;
+}
+
static int run_luo_selftest_cmd(int fd_dbg, __u64 cmd_code,
struct luo_arg_subsystem *subsys_arg)
{
@@ -345,4 +356,49 @@ TEST_F(subsystem, prepare_fail)
ASSERT_EQ(0, unregister_subsystem(self->fd_dbg, &self->si[i]));
}
+TEST_F(state, session_freeze_cancel_cycle)
+{
+ int session_fd;
+ const char *session_name = "freeze_cancel_session";
+ const int memfd_token = 5678;
+
+ session_fd = luo_create_session(self->fd, session_name);
+ ASSERT_GE(session_fd, 0);
+
+ ASSERT_EQ(0, create_and_preserve_memfd(session_fd, memfd_token,
+ "freeze test data"));
+
+ ASSERT_EQ(0, luo_set_session_event(session_fd, LIVEUPDATE_PREPARE));
+ ASSERT_EQ(get_session_state(session_fd), LIVEUPDATE_STATE_PREPARED);
+
+ ASSERT_EQ(0, luo_set_session_event(session_fd, LIVEUPDATE_FREEZE));
+ ASSERT_EQ(get_session_state(session_fd), LIVEUPDATE_STATE_FROZEN);
+
+ ASSERT_EQ(0, luo_set_session_event(session_fd, LIVEUPDATE_CANCEL));
+ ASSERT_EQ(get_session_state(session_fd), LIVEUPDATE_STATE_NORMAL);
+
+ close(session_fd);
+}
+
+TEST_F(state, session_prepare_cancel_cycle)
+{
+ const char *session_name = "prepare_cancel_session";
+ const int memfd_token = 1234;
+ int session_fd;
+
+ session_fd = luo_create_session(self->fd, session_name);
+ ASSERT_GE(session_fd, 0);
+
+ ASSERT_EQ(0, create_and_preserve_memfd(session_fd, memfd_token,
+ "prepare test data"));
+
+ ASSERT_EQ(0, luo_set_session_event(session_fd, LIVEUPDATE_PREPARE));
+ ASSERT_EQ(get_session_state(session_fd), LIVEUPDATE_STATE_PREPARED);
+
+ ASSERT_EQ(0, luo_set_session_event(session_fd, LIVEUPDATE_CANCEL));
+ ASSERT_EQ(get_session_state(session_fd), LIVEUPDATE_STATE_NORMAL);
+
+ close(session_fd);
+}
+
TEST_HARNESS_MAIN
--
2.51.0.536.g15c5d4f767-goog