[LTP] [PATCH 1/9] mem: shmt02: Make sure memory is no longer accessible after child exits

Ricardo B. Marlière rbm@suse.com
Fri Jun 27 18:47:56 CEST 2025


From: Ricardo B. Marlière <rbm@suse.com>

The test description states: "Verify that the shared memory segment is
accessible as long as the process is still alive". Make sure to verify that
the segment is not accessible after the child process exits.

Fixes: 1e8516790063 ("mem: Convert shmt02 to new API")
Suggested-by: Andrea Cervesato <andrea.cervesato@suse.de>
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/mem/shmt/shmt02.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/mem/shmt/shmt02.c b/testcases/kernel/mem/shmt/shmt02.c
index 16d99ac7a781c42cc282dd81af8895097b404435..37e07a3d6dce4b2816093d3a633ac9bda279fc50 100644
--- a/testcases/kernel/mem/shmt/shmt02.c
+++ b/testcases/kernel/mem/shmt/shmt02.c
@@ -27,21 +27,25 @@ static void run(void)
 
 	key = GETIPCKEY();
 
-	shmid = SAFE_SHMGET(key, SHMSIZE, IPC_CREAT | 0666);
-
-	cp = SAFE_SHMAT(shmid, NULL, 0);
-	memcpy(cp, tst_rand_data, SHMSIZE);
-
-	SAFE_SHMCTL(shmid, IPC_RMID, NULL);
-
-	if (memcmp(cp, tst_rand_data, SHMSIZE) != 0) {
-		tst_res(TFAIL, "Copied data changed after IPC_RMID");
+	if (!SAFE_FORK()) {
+		shmid = SAFE_SHMGET(key, SHMSIZE, IPC_CREAT | 0666);
+		cp = SAFE_SHMAT(shmid, NULL, 0);
+		memcpy(cp, tst_rand_data, SHMSIZE);
+		SAFE_SHMCTL(shmid, IPC_RMID, NULL);
+		TST_EXP_EQ_LI(memcmp(cp, tst_rand_data, SHMSIZE), 0);
+		TST_CHECKPOINT_WAKE(0);
 		return;
 	}
 
-	tst_res(TPASS, "Copied data has been read back");
+	TST_CHECKPOINT_WAIT(0);
+	shmid = SAFE_SHMGET(key, SHMSIZE, IPC_CREAT | 0666);
+	cp = SAFE_SHMAT(shmid, NULL, 0);
+	TST_EXP_EXPR(memcmp(cp, tst_rand_data, SHMSIZE) < 0);
+	SAFE_SHMCTL(shmid, IPC_RMID, NULL);
 }
 
 static struct tst_test test = {
 	.test_all = run,
+	.needs_checkpoints = 1,
+	.forks_child = 1,
 };

-- 
2.50.0



More information about the ltp mailing list