[LTP] [PATCH] lib/checkpoint: remove deprecated tst_checkpoint_init() and legacy macro

Li Wang liwang@redhat.com
Sat Jun 28 05:13:02 CEST 2025


The function tst_checkpoint_init() and macro TST_CHECKPOINT_INIT were
used by old library tests for setting up checkpoint futex memory.

These APIs have been fully replaced by tst_reinit() and in the new
checkpoint infrastructure.

So let's get rid of them and rewrite the checkpoint tests in newlib_tests/.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 include/old/old_checkpoint.h                  |   8 --
 include/tst_checkpoint_fn.h                   |   8 --
 lib/newlib_tests/.gitignore                   |   3 +
 lib/newlib_tests/tst_checkpoint.c             | 114 ++++++++++++++++++
 .../tst_checkpoint_wait_timeout.c             |  42 +++++++
 .../tst_checkpoint_wake_timeout.c             |  29 +++++
 lib/tests/.gitignore                          |   3 -
 lib/tests/tst_checkpoint.c                    |  59 ---------
 lib/tests/tst_checkpoint_wait_timeout.c       |  58 ---------
 lib/tests/tst_checkpoint_wake_timeout.c       |  41 -------
 lib/tst_checkpoint.c                          |  51 +-------
 11 files changed, 194 insertions(+), 222 deletions(-)
 create mode 100644 lib/newlib_tests/tst_checkpoint.c
 create mode 100644 lib/newlib_tests/tst_checkpoint_wait_timeout.c
 create mode 100644 lib/newlib_tests/tst_checkpoint_wake_timeout.c
 delete mode 100644 lib/tests/tst_checkpoint.c
 delete mode 100644 lib/tests/tst_checkpoint_wait_timeout.c
 delete mode 100644 lib/tests/tst_checkpoint_wake_timeout.c

diff --git a/include/old/old_checkpoint.h b/include/old/old_checkpoint.h
index c8ffc92da..f91fef9f6 100644
--- a/include/old/old_checkpoint.h
+++ b/include/old/old_checkpoint.h
@@ -32,14 +32,6 @@
 #include "test.h"
 #include "tst_checkpoint_fn.h"
 
-/*
- * Checkpoint initializaton, must be done first.
- *
- * NOTE: tst_tmpdir() must be called beforehand.
- */
-#define TST_CHECKPOINT_INIT(cleanup_fn) \
-	tst_checkpoint_init(__FILE__, __LINE__, cleanup_fn)
-
 #define TST_SAFE_CHECKPOINT_WAIT(cleanup_fn, id) \
         tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0);
 
diff --git a/include/tst_checkpoint_fn.h b/include/tst_checkpoint_fn.h
index 3a010d616..7d40c0849 100644
--- a/include/tst_checkpoint_fn.h
+++ b/include/tst_checkpoint_fn.h
@@ -5,14 +5,6 @@
 #ifndef TST_CHECKPOINT_FN__
 #define TST_CHECKPOINT_FN__
 
-/*
- * Checkpoint initializaton, must be done first.
- *
- * NOTE: tst_tmpdir() must be called beforehand.
- */
-void tst_checkpoint_init(const char *file, const int lineno,
-			 void (*cleanup_fn)(void));
-
 /*
  * Waits for wakeup.
  *
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index 8acaec0b6..3545f5ac5 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -15,6 +15,9 @@ tst_capability01
 tst_capability02
 tst_cgroup01
 tst_cgroup02
+tst_checkpoint
+tst_checkpoint_wait_timeout
+tst_checkpoint_wake_timeout
 tst_device
 tst_safe_fileops
 tst_res_hexd
diff --git a/lib/newlib_tests/tst_checkpoint.c b/lib/newlib_tests/tst_checkpoint.c
new file mode 100644
index 000000000..a283f03ef
--- /dev/null
+++ b/lib/newlib_tests/tst_checkpoint.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Modernized checkpoint usage.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "tst_checkpoint.h"
+
+/* Test 1: Basic checkpoint signal from child to parent */
+static void checkpoint_test1(void)
+{
+	pid_t pid = SAFE_FORK();
+
+	if (pid == 0) {
+		tst_res(TINFO, "Child: signaling checkpoint");
+		TST_CHECKPOINT_WAKE(0);
+		_exit(0);
+	}
+
+	TST_CHECKPOINT_WAIT(0);
+	tst_res(TPASS, "Parent: checkpoint reached");
+
+	SAFE_WAITPID(pid, NULL, 0);
+
+	return;
+}
+
+/* Test 2: Checkpoint wait with timeout, wake from child */
+static void checkpoint_test2(void)
+{
+	pid_t pid = SAFE_FORK();
+
+	if (pid == 0) {
+		tst_res(TINFO, "Child: signaling checkpoint");
+		TST_CHECKPOINT_WAKE2(0, 1);
+		_exit(0);
+	}
+
+	TST_CHECKPOINT_WAIT2(0, 1000);
+	tst_res(TPASS, "Parent: checkpoint reached");
+
+	SAFE_WAITPID(pid, NULL, 0);
+
+	return;
+}
+
+/* Test 3: Wake two child waiters on the same checkpoint */
+static void checkpoint_test3(void)
+{
+	pid_t pid1, pid2;
+
+	pid1 = SAFE_FORK();
+	if (pid1 == 0) {
+		tst_res(TINFO, "Child 1: waiting on checkpoint 0 (no timeout)");
+		TST_CHECKPOINT_WAIT(0);
+		_exit(0);
+	}
+
+	pid2 = SAFE_FORK();
+	if (pid2 == 0) {
+		tst_res(TINFO, "Child 2: waiting on checkpoint 0 (1000ms timeout)");
+		TST_CHECKPOINT_WAIT2(0, 1000);
+		_exit(0);
+	}
+
+	TST_CHECKPOINT_WAKE2(0, 2);
+	tst_res(TPASS, "Parent: checkpoint wake issued");
+
+	tst_reap_children();
+
+	return;
+}
+
+/* Test 4: Two-way checkpoint handshake (child->parent->child) */
+static void checkpoint_test4(void)
+{
+	pid_t pid = SAFE_FORK();
+
+	if (pid == 0) {
+		tst_res(TINFO, "Child: waking and then waiting on checkpoint 0");
+		TST_CHECKPOINT_WAKE_AND_WAIT(0);
+		_exit(0);
+	}
+
+	TST_CHECKPOINT_WAIT(0);
+	TST_CHECKPOINT_WAKE(0);
+
+	tst_res(TPASS, "Parent: checkpoint handshake completed");
+
+	SAFE_WAITPID(pid, NULL, 0);
+
+	return;
+}
+
+static void run(void)
+{
+	checkpoint_test1();
+	checkpoint_test2();
+	checkpoint_test3();
+	checkpoint_test4();
+
+	return;
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/lib/newlib_tests/tst_checkpoint_wait_timeout.c b/lib/newlib_tests/tst_checkpoint_wait_timeout.c
new file mode 100644
index 000000000..2fa6f8cf9
--- /dev/null
+++ b/lib/newlib_tests/tst_checkpoint_wait_timeout.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Test: checkpoint wait with timeout.
+ * Expected: child blocks on checkpoint wait, parent exits without signaling.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "tst_checkpoint.h"
+
+static void run(void)
+{
+	pid_t pid;
+
+	pid = SAFE_FORK();
+
+	if (pid == 0) {
+		int ret = tst_checkpoint_wait(0, 1000);
+
+		if (ret == -1 && errno == ETIMEDOUT)
+			tst_res(TPASS, "Child: checkpoint wait timed out as expected");
+		else
+			tst_brk(TBROK | TERRNO, "checkpoint wait failed");
+
+		_exit(0);
+	}
+
+	tst_res(TINFO, "Parent: exiting without signaling checkpoint");
+	SAFE_WAITPID(pid, NULL, 0);
+
+	return;
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/lib/newlib_tests/tst_checkpoint_wake_timeout.c b/lib/newlib_tests/tst_checkpoint_wake_timeout.c
new file mode 100644
index 000000000..c37fd6945
--- /dev/null
+++ b/lib/newlib_tests/tst_checkpoint_wake_timeout.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Test: checkpoint wake without matching wait.
+ * Expected: wake completes with ETIMEDOUT errno as expected.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+#include "tst_checkpoint.h"
+
+static void run(void)
+{
+	int ret = tst_checkpoint_wake(0, 1, 1000);
+
+	if (ret == -1 && errno == ETIMEDOUT)
+		tst_res(TPASS, "checkpoint wake timed out as expected");
+	else
+		tst_brk(TBROK | TERRNO, "checkpoint wake failed");
+
+	return;
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_checkpoints = 1,
+};
diff --git a/lib/tests/.gitignore b/lib/tests/.gitignore
index 1d880c1b7..00237f532 100644
--- a/lib/tests/.gitignore
+++ b/lib/tests/.gitignore
@@ -1,7 +1,4 @@
 /tst_tmpdir_test
-/tst_checkpoint
-/tst_checkpoint_wait_timeout
-/tst_checkpoint_wake_timeout
 /tst_process_state
 /tst_cleanup_once
 /tst_safe_macros
diff --git a/lib/tests/tst_checkpoint.c b/lib/tests/tst_checkpoint.c
deleted file mode 100644
index 2cb17a5f7..000000000
--- a/lib/tests/tst_checkpoint.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2012-2015 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <sys/wait.h>
-
-#include "test.h"
-
-char *TCID = "tst_checkpoint";
-int TST_TOTAL = 1;
-
-int main(void)
-{
-	int pid;
-
-	tst_tmpdir();
-
-	TST_CHECKPOINT_INIT(tst_rmdir);
-
-	pid = fork();
-
-	switch (pid) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, NULL, "Fork failed");
-	break;
-	case 0:
-		fprintf(stderr, "Child: checkpoint signaling\n");
-		TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-		exit(0);
-	break;
-	default:
-		TST_SAFE_CHECKPOINT_WAIT(tst_rmdir, 0);
-		fprintf(stderr, "Parent: checkpoint reached\n");
-	break;
-	}
-
-	wait(NULL);
-	tst_rmdir();
-	return 0;
-}
diff --git a/lib/tests/tst_checkpoint_wait_timeout.c b/lib/tests/tst_checkpoint_wait_timeout.c
deleted file mode 100644
index c5fae670e..000000000
--- a/lib/tests/tst_checkpoint_wait_timeout.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012-2015 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <sys/wait.h>
-
-#include "test.h"
-
-char *TCID = "tst_checkpoint_wait_timeout";
-int TST_TOTAL = 1;
-
-int main(void)
-{
-	int pid;
-
-	tst_tmpdir();
-
-	TST_CHECKPOINT_INIT(tst_rmdir);
-
-	pid = fork();
-
-	switch (pid) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, NULL, "Fork failed");
-	break;
-	case 0:
-		TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-		fprintf(stderr, "Child: checkpoint reached\n");
-		exit(0);
-	break;
-	default:
-		fprintf(stderr, "Parent: exiting without signaling\n");
-		tst_rmdir();
-		exit(0);
-	break;
-	}
-
-	return 0;
-}
diff --git a/lib/tests/tst_checkpoint_wake_timeout.c b/lib/tests/tst_checkpoint_wake_timeout.c
deleted file mode 100644
index 8af1feb18..000000000
--- a/lib/tests/tst_checkpoint_wake_timeout.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2013 Linux Test Project
- * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <sys/wait.h>
-
-#include "test.h"
-
-char *TCID = "tst_checkpoint_wake_timeout";
-int TST_TOTAL = 1;
-
-int main(void)
-{
-	tst_tmpdir();
-
-	TST_CHECKPOINT_INIT(tst_rmdir);
-	TST_SAFE_CHECKPOINT_WAKE(tst_rmdir, 0);
-	fprintf(stderr, "Parent: checkpoint reached\n");
-
-	return 0;
-}
diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c
index 6a294b28b..d36103fbb 100644
--- a/lib/tst_checkpoint.c
+++ b/lib/tst_checkpoint.c
@@ -32,54 +32,15 @@
 
 #define DEFAULT_MSEC_TIMEOUT 10000
 
+/*
+ * Global futex array and size for checkpoint synchronization.
+ *
+ * NOTE: These are initialized by setup_ipc()/tst_reinit() in tst_test.c
+ * when .needs_checkpoints is set in the tst_test struct.
+ */
 futex_t *tst_futexes;
 unsigned int tst_max_futexes;
 
-void tst_checkpoint_init(const char *file, const int lineno,
-                         void (*cleanup_fn)(void))
-{
-	int fd;
-	unsigned int page_size;
-
-	if (tst_futexes) {
-		tst_brkm_(file, lineno, TBROK, cleanup_fn,
-			"checkpoints already initialized");
-		return;
-	}
-
-	/*
-	 * The parent test process is responsible for creating the temporary
-	 * directory and therefore must pass non-zero cleanup (to remove the
-	 * directory if something went wrong).
-	 *
-	 * We cannot do this check unconditionally because if we need to init
-	 * the checkpoint from a binary that was started by exec() the
-	 * tst_tmpdir_created() will return false because the tmpdir was
-	 * created by parent. In this case we expect the subprogram can call
-	 * the init as a first function with NULL as cleanup function.
-	 */
-	if (cleanup_fn && !tst_tmpdir_created()) {
-		tst_brkm_(file, lineno, TBROK, cleanup_fn,
-			"You have to create test temporary directory "
-			"first (call tst_tmpdir())");
-		return;
-	}
-
-	page_size = getpagesize();
-
-	fd = SAFE_OPEN(cleanup_fn, "checkpoint_futex_base_file",
-	               O_RDWR | O_CREAT, 0666);
-
-	SAFE_FTRUNCATE(cleanup_fn, fd, page_size);
-
-	tst_futexes = SAFE_MMAP(cleanup_fn, NULL, page_size,
-	                    PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-
-	tst_max_futexes = page_size / sizeof(uint32_t);
-
-	SAFE_CLOSE(cleanup_fn, fd);
-}
-
 int tst_checkpoint_wait(unsigned int id, unsigned int msec_timeout)
 {
 	struct timespec timeout;
-- 
2.50.0



More information about the ltp mailing list