[LTP] [PATCH] checkpoint: add test for child reinitializing checkpoint region
Li Wang
liwang@redhat.com
Sun Jun 29 10:39:16 CEST 2025
This adds a pair of tests that verify checkpoint synchronization across
a parent and a re-exec'd child. The child process uses `tst_reinit()` to
reconnect to the shared checkpoint memory region established by the parent.
The parent waits on checkpoint 0, while the child wakes it after verifying
CLI arguments and reinitializing the IPC region.
Follow-up: https://lists.linux.it/pipermail/ltp/2025-June/044063.html
Signed-off-by: Li Wang <liwang@redhat.com>
---
lib/newlib_tests/.gitignore | 2 ++
lib/newlib_tests/runtest.sh | 4 +++
lib/newlib_tests/tst_checkpoint_child.c | 27 +++++++++++++++++
lib/newlib_tests/tst_checkpoint_parent.c | 38 ++++++++++++++++++++++++
4 files changed, 71 insertions(+)
create mode 100644 lib/newlib_tests/tst_checkpoint_child.c
create mode 100644 lib/newlib_tests/tst_checkpoint_parent.c
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index 3545f5ac5..a4984d2ec 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -16,6 +16,8 @@ tst_capability02
tst_cgroup01
tst_cgroup02
tst_checkpoint
+tst_checkpoint_parent
+tst_checkpoint_child
tst_checkpoint_wait_timeout
tst_checkpoint_wake_timeout
tst_device
diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
index f2133d365..d87751c2f 100755
--- a/lib/newlib_tests/runtest.sh
+++ b/lib/newlib_tests/runtest.sh
@@ -18,6 +18,10 @@ test1[59]
test2[04]
tst_bool_expr
tst_capability02
+tst_checkpoint
+tst_checkpoint_parent
+tst_checkpoint_wait_timeout
+tst_checkpoint_wake_timeout
tst_device
tst_expiration_timer
tst_fuzzy_sync0[1-3]
diff --git a/lib/newlib_tests/tst_checkpoint_child.c b/lib/newlib_tests/tst_checkpoint_child.c
new file mode 100644
index 000000000..c4eaccacc
--- /dev/null
+++ b/lib/newlib_tests/tst_checkpoint_child.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Child process: this binary is expected to be exec'd by the parent.
+ *
+ * It reinitializes the shared memory region using tst_reinit(),
+ * verifies the command-line argument, and signals checkpoint 0.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_checkpoint.h"
+
+int main(int argc, char *argv[])
+{
+ tst_reinit();
+
+ if (argc != 2)
+ tst_brk(TFAIL, "argc is %d, expected 2", argc);
+
+ if (strcmp(argv[1], "canary"))
+ tst_brk(TFAIL, "argv[1] is %s, expected 'canary'", argv[1]);
+
+ tst_res(TINFO, "Child: signaling checkpoint");
+ TST_CHECKPOINT_WAKE(0);
+
+ return 0;
+}
diff --git a/lib/newlib_tests/tst_checkpoint_parent.c b/lib/newlib_tests/tst_checkpoint_parent.c
new file mode 100644
index 000000000..9d7f1783b
--- /dev/null
+++ b/lib/newlib_tests/tst_checkpoint_parent.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Parent process: spawns a child which reinitializes checkpoint region
+ * using tst_reinit(). Waits for a checkpoint signal from the child.
+ */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "tst_checkpoint.h"
+
+static void run(void)
+{
+ pid_t pid = SAFE_FORK();
+
+ if (pid == 0) {
+ TEST(execlp("tst_checkpoint_child", "tst_checkpoint_child", "canary", NULL));
+ tst_brk(TFAIL | TTERRNO, "Failed to execute tst_checkpoint_child");
+ }
+
+ TST_CHECKPOINT_WAIT(0);
+ tst_res(TPASS, "Parent: checkpoint reached");
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ return;
+}
+
+static struct tst_test test = {
+ .forks_child = 1,
+ .needs_checkpoints = 1,
+ .child_needs_reinit = 1,
+ .test_all = run,
+};
--
2.50.0
More information about the ltp
mailing list