[LTP] [PATCH 3/3] tst_checkpoint: Detect and reinit shell or C style checkpoint file

Li Wang liwang@redhat.com
Mon Jun 16 12:26:19 CEST 2025


Add support to distinguish whether the checkpoint file pointed to by
$LTP_IPC_PATH was initialized by a shell-based or C-based test case.
This ensures the correct reinit is used based on the file format.

To avoids errors when crossing between shell and C checkpoints.

  # ./shell_test05
  shell_test05.c:14: TINFO: Waiting for shell to sleep on checkpoint!
  shell_test05.c:18: TINFO: Waking shell child!
  shell_test_checkpoint.sh:7: TINFO: Waiting for a checkpoint 0
  (null)      1  TBROK  :  tst_checkpoint.c:113: Set test.needs_checkpoints = 1
  (null)      2  TBROK  :  tst_checkpoint.c:113: Remaining cases broken
  shell_test_checkpoint.sh:9: TPASS: Continuing after checkpoint
  shell_test05.c:20: TBROK: tst_checkpoint_wake(0, 1, 10000) failed: ETIMEDOUT (110)
  tst_test.c:1864: TINFO: Killed the leftover descendant processes

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/lib/tst_checkpoint.c | 37 +++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/testcases/lib/tst_checkpoint.c b/testcases/lib/tst_checkpoint.c
index 35a0c0dfa..55ded7e7d 100644
--- a/testcases/lib/tst_checkpoint.c
+++ b/testcases/lib/tst_checkpoint.c
@@ -40,6 +40,37 @@ static int get_val(const char *name, const char *arg, unsigned int *val)
 	return 0;
 }
 
+static int is_shell_checkpoint_file(void)
+{
+	int fd;
+	char magic_buf[4];
+	const char *path = getenv("LTP_IPC_PATH");
+
+	if (!path)
+		tst_brk(TBROK, "LTP_IPC_PATH is not set");
+
+	fd = SAFE_OPEN(path, O_RDONLY);
+	SAFE_READ(1, fd, magic_buf, 4);
+	SAFE_CLOSE(fd);
+
+	if (!memcmp(magic_buf, "LTPM", 4)) {
+		tst_res(TINFO, "Detected Shell checkpoint file (magic = LTPM)");
+		return 1;
+	} else {
+		uint32_t magic_val;
+		memcpy(&magic_val, magic_buf, sizeof(uint32_t));
+
+		if (magic_val == 0x4C54504D) {
+			tst_res(TINFO, "Detected C checkpoint file (magic = 0x4C54504D)");
+			return 0;
+		}
+
+		tst_brk(TBROK, "Unrecognized checkpoint file magic: 0x%08X", magic_val);
+	}
+
+	return -1;
+}
+
 int main(int argc, char *argv[])
 {
 	unsigned int id, timeout, nr_wake;
@@ -78,7 +109,11 @@ int main(int argc, char *argv[])
 		goto help;
 	}
 
-	tst_checkpoint_reinit(__FILE__, __LINE__, NULL);
+	/* Re-init checkpoint file based on its format (Shell or C) */
+	if (is_shell_checkpoint_file())
+		tst_checkpoint_reinit(__FILE__, __LINE__, NULL);
+	else
+		tst_reinit();
 
 	if (type == 0)
 		ret = tst_checkpoint_wait(id, timeout);
-- 
2.49.0



More information about the ltp mailing list