Skip to contentSkip to conversation

Rewrite sysvipc testing suite using new LTP API

PATCH Superseded Andrea Cervesato 2 participants 18 messages Mar 15, 2022 – Mar 24, 2022

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Rewrite sysvipc testing suite using new LTP API

Rewritten all sysvipc tests and removed libclone dependency. Removed TST_CHECKPOINT_INIT from all tests and replaced it with the .checkpoints support.

Andrea Cervesato (10):
Rewrite mesgq_nstest.c using new LTP API Rewrite msg_comm.c using new LTP API Rewrite sem_comm.c using new LTP API Rewrite sem_nstest.c using new LTP API Rewrite semtest_2ns.c using new LTP API Rewrite shmnstest.c using new LTP API Rewrite shmem_2nstest.c using new LTP API Rewrite shm_comm.c using new LTP API Remove libclone dependency from sysvipc test suite Delete ipcns_helper.h in the sysvipc test suite

 runtest/containers                            |  30 +-
 testcases/kernel/containers/sysvipc/Makefile  |  26 +-
 testcases/kernel/containers/sysvipc/common.h  | 108 ++++++
 .../kernel/containers/sysvipc/ipcns_helper.h  |  41 ---
 .../kernel/containers/sysvipc/mesgq_nstest.c  | 243 +++++--------
 .../kernel/containers/sysvipc/msg_comm.c      | 180 +++-------
 .../kernel/containers/sysvipc/sem_comm.c      | 180 +++-------
 .../kernel/containers/sysvipc/sem_nstest.c    | 210 ++++-------
 .../kernel/containers/sysvipc/semtest_2ns.c   | 326 +++++++-----------
 .../kernel/containers/sysvipc/shm_comm.c      | 167 +++------
 .../kernel/containers/sysvipc/shmem_2nstest.c | 239 +++++--------
 .../kernel/containers/sysvipc/shmnstest.c     | 180 ++++------
 12 files changed, 717 insertions(+), 1213 deletions(-)
 create mode 100644 testcases/kernel/containers/sysvipc/common.h
 delete mode 100644 testcases/kernel/containers/sysvipc/ipcns_helper.h
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v3 1/10 Rewrite mesgq_nstest.c using new LTP API

Added common.h that is replacing ipcns_helper.h for refactored tests. Updated containers runtime file to include the new mesgq_nstest.c command line options.

---
 runtest/containers                            |   6 +-
 testcases/kernel/containers/sysvipc/common.h  | 108 ++++++++
 .../kernel/containers/sysvipc/mesgq_nstest.c  | 243 +++++++-----------
 3 files changed, 202 insertions(+), 155 deletions(-)
 create mode 100644 testcases/kernel/containers/sysvipc/common.h
runtest/containers +3 -3
index eea7bfadb..d863c10a4 100644
@@ -50,9 +50,9 @@ shmem_2nstest_none shmem_2nstest none
 shmem_2nstest_clone shmem_2nstest clone
 shmem_2nstest_unshare shmem_2nstest unshare
 shm_comm shm_comm
-mesgq_nstest_none mesgq_nstest none
-mesgq_nstest_clone mesgq_nstest clone
-mesgq_nstest_unshare mesgq_nstest unshare
+mesgq_nstest_none mesgq_nstest -m none
+mesgq_nstest_clone mesgq_nstest -m clone
+mesgq_nstest_unshare mesgq_nstest -m unshare
 msg_comm msg_comm
 sem_nstest_none sem_nstest none
 sem_nstest_clone sem_nstest clone
testcases/kernel/containers/sysvipc/common.h new file +108 -0

108 lines not on this page · raw message

testcases/kernel/containers/sysvipc/mesgq_nstest.c +91 -152

266 lines not on this page · raw message

Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH v3 01/10] Rewrite mesgq_nstest.c using new LTP API

Hi!

Quoted 18 lines
testcases/kernel/containers/sysvipc/mesgq_nstest.c +1 -16
+#include <sys/wait.h>
 #include <sys/msg.h>
-#include <libclone.h>
-#include "test.h"
-#include "ipcns_helper.h"
-
-#define KEY_VAL		154326L
-#define UNSHARESTR	"unshare"
-#define CLONESTR	"clone"
-#define NONESTR		"none"
-
-char *TCID = "mesgq_nstest";
-int TST_TOTAL = 1;
-int p1[2];
-int p2[2];
-struct msg_buf {
-	long int mtype;		/* type of received/sent message */
-	char mtext[80];		/* text of the message */

testcases/kernel/containers/sysvipc/mesgq_nstest.c line 36

Quoted 10 lines
testcases/kernel/containers/sysvipc/mesgq_nstest.c +10 -0
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
+
+#define KEY_VAL 154326L
+#define MSG_TYPE 5
+#define MSG_TEXT "My message!"
+
+static char *str_op = "clone";

There is a small problem with setting the str_op here. The test library expects that the str_* variables are initialized to NULL and uses that logic to detect redefinitions (i.e. passing a parameter more than once on the commandline). Which means that we get a warning in the case that we pass -m on the commandline and because of that warning the test ends with non-zero exit value.

I guess that the easiests solution would be not to initialize it here and instead default to T_NONE in the get_clone_unshare_enum() when NULL is passed.

Quoted 47 lines
testcases/kernel/containers/sysvipc/mesgq_nstest.c +21 -18
+static int use_clone;
+static int ipc_id = -1;
+
+static struct msg_buf {
+	long mtype;
+	char mtext[80];
 } msg;
 
-void mesgq_read(int id)
+static int check_mesgq(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	int READMAX = 80;
-	int n;
-	/* read msg type 5 on the Q; msgtype, flags are last 2 params.. */
+	int id, n;
 
-	n = msgrcv(id, &msg, READMAX, 5, 0);
-	if (n == -1)
-		perror("msgrcv"), tst_exit();
-
-	tst_resm(TINFO, "Mesg read of %d bytes; Type %ld: Msg: %.*s",
-		 n, msg.mtype, n, msg.mtext);
-}
+	id = msgget(KEY_VAL, 0);
 
-int check_mesgq(void *vtest)
-{
-	char buf[3];
-	int id;
+	if (id < 0) {
+		if (use_clone == T_NONE)
+			tst_res(TFAIL, "Plain cloned process didn't find mesgq");
+		else
+			tst_res(TPASS, "%s: container didn't find mesgq", str_op);
+	} else {
+		if (use_clone == T_NONE)
+			tst_res(TPASS, "Plain cloned process found mesgq inside container");
+		else
+			tst_res(TFAIL, "%s: container init process found mesgq", str_op);
 
-	(void) vtest;
+		n = SAFE_MSGRCV(id, &msg, sizeof(msg.mtext), MSG_TYPE, 0);
 
-	close(p1[1]);
-	close(p2[0]);
+		tst_res(TINFO, "Mesg read of %d bytes, Type %ld, Msg: %s", n, msg.mtype, msg.mtext);
 

testcases/kernel/containers/sysvipc/mesgq_nstest.c line 68

Quoted 10 lines
testcases/kernel/containers/sysvipc/mesgq_nstest.c +2 -7
-	read(p1[0], buf, 3);
-	id = msgget(KEY_VAL, 0);
-	if (id == -1)
-		write(p2[1], "notfnd", 7);
-	else {
-		write(p2[1], "exists", 7);
-		mesgq_read(id);
+		if (strcmp(msg.mtext, MSG_TEXT))
+			tst_res(TFAIL, "Received the wrong text message");
 	}

We can save some indentation by using return instead of else here as:

	if (id < 0) {
		...
		return;
	}

	if (use_clone == T_NONE)
	...

	n = SAFE_MSGRCV(...);

Also it does not make sense to try to receive any messages in the case that use_clone != T_NONE.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v3 2/10 Rewrite msg_comm.c using new LTP API

In reply to Andrea Cervesato
---
 .../kernel/containers/sysvipc/msg_comm.c      | 180 ++++++------------
 1 file changed, 55 insertions(+), 125 deletions(-)
testcases/kernel/containers/sysvipc/msg_comm.c +55 -125
index 0da328997..674922159 100644
@@ -1,20 +1,16 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Test SysV IPC message passing through different processes.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: msg_comm.c
+ * [Algorithm]
  *
- * Description:
  * 1. Clones two child processes with CLONE_NEWIPC flag, each child
  *    gets System V message queue (msg) with the _identical_ key.
  * 2. Child1 appends a message with identifier #1 to the message queue.
@@ -27,152 +23,86 @@
  */
 
 #define _GNU_SOURCE
-#include <sys/ipc.h>
+
+#include <sys/wait.h>
 #include <sys/msg.h>
 #include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include "ipcns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
 #define TESTKEY 124426L
-#define MSGSIZE 50
-char *TCID	= "msg_comm";
-int TST_TOTAL	= 1;
 
 struct sysv_msg {
 	long mtype;
-	char mtext[MSGSIZE];
+	char mtext[1];
 };
 
-static void cleanup(void)
+static int chld1_msg(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-	check_newipc();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
-}
-
-int chld1_msg(void *arg)
-{
-	int id, n, rval = 0;
+	int id;
 	struct sysv_msg m;
 	struct sysv_msg rec;
 
-	id = msgget(TESTKEY, IPC_CREAT | 0600);
-	if (id == -1) {
-		perror("msgget");
-		return 2;
-	}
+	id = SAFE_MSGGET(TESTKEY, IPC_CREAT | 0600);
 
 	m.mtype = 1;
 	m.mtext[0] = 'A';
-	if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
-		perror("msgsnd");
-		msgctl(id, IPC_RMID, NULL);
-		return 2;
-	}
 
-	/* wait for child2 to write into the message queue */
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	SAFE_MSGSND(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0);
+
+	TST_CHECKPOINT_WAIT(0);
+
+	TEST(msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long), 2, IPC_NOWAIT));
+	if (TST_RET < 0 && TST_ERR != ENOMSG)
+		tst_brk(TBROK | TERRNO, "msgrcv error");
 
 	/* if child1 message queue has changed (by child2) report fail */
-	n = msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long),
-		   2, IPC_NOWAIT);
-	if (n == -1 && errno != ENOMSG) {
-		perror("msgrcv");
-		msgctl(id, IPC_RMID, NULL);
-		return 2;
-	}
-	/* if mtype #2 was found in the message queue, it is fail */
-	if (n > 0) {
-		rval = 1;
-	}
-
-	/* tell child2 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-
-	msgctl(id, IPC_RMID, NULL);
-	return rval;
+	if (TST_RET > 0)
+		tst_res(TFAIL, "messages leak between namespacess");
+	else
+		tst_res(TPASS, "messages does not leak between namespaces");
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_MSGCTL(id, IPC_RMID, NULL);
+
+	return 0;
 }
 
-int chld2_msg(void *arg)
+static int chld2_msg(LTP_ATTRIBUTE_UNUSED void *arg)
 {
 	int id;
 	struct sysv_msg m;
 
-	id = msgget(TESTKEY, IPC_CREAT | 0600);
-	if (id == -1) {
-		perror("msgget");
-		return 2;
-	}
+	id = SAFE_MSGGET(TESTKEY, IPC_CREAT | 0600);
 
 	m.mtype = 2;
 	m.mtext[0] = 'B';
-	if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
-		perror("msgsnd");
-		msgctl(id, IPC_RMID, NULL);
-		return 2;
-	}
 
-	/* tell child1 to continue and wait for it */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	SAFE_MSGSND(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_MSGCTL(id, IPC_RMID, NULL);
 
-	msgctl(id, IPC_RMID, NULL);
 	return 0;
 }
 
-static void test(void)
+static void run(void)
 {
-	int status, ret = 0;
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-
-	while (wait(&status) > 0) {
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
-			ret = 1;
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
-			tst_brkm(TBROK | TERRNO, cleanup, "error in child");
-		if (WIFSIGNALED(status)) {
-			tst_resm(TFAIL, "child was killed with signal %s",
-					tst_strsig(WTERMSIG(status)));
-			return;
-		}
-	}
-
-	if (ret)
-		tst_resm(TFAIL, "SysV msg: communication with identical keys"
-				" between namespaces");
-	else
-		tst_resm(TPASS, "SysV msg: communication with identical keys"
-				" between namespaces");
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL);
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	check_newipc();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v3 02/10] Rewrite msg_comm.c using new LTP API

Hi!

Review

Quoted 1 line
(quoted diff) +0 -1
-	if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {

^
I think that sizeof(m.mtext) would be cleaner

As due to a padding the actuall size of a structure may be bigger than the sum of it's members...

Other than that the rest of the code looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v3 3/10 Rewrite sem_comm.c using new LTP API

In reply to Andrea Cervesato
---
 .../kernel/containers/sysvipc/sem_comm.c      | 180 ++++++------------
 1 file changed, 56 insertions(+), 124 deletions(-)
testcases/kernel/containers/sysvipc/sem_comm.c +56 -124
index a2c354a08..854452528 100644
@@ -1,20 +1,16 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Test SysV IPC semaphore usage between cloned processes.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: sem_comm.c
+ * [Algorithm]
  *
- * Description:
  * 1. Clones two child processes with CLONE_NEWIPC flag, each child
  *    creates System V semaphore (sem) with the _identical_ key.
  * 2. Child1 locks the semaphore.
@@ -26,166 +22,102 @@
  */
 
 #define _GNU_SOURCE
-#include <sys/ipc.h>
-#include <sys/types.h>
+
 #include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include "ipcns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include <sys/msg.h>
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
 #include "lapi/sem.h"
+#include "common.h"
 
 #define TESTKEY 124426L
-char *TCID	= "sem_comm";
-int TST_TOTAL	= 1;
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-	check_newipc();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
-}
 
-int chld1_sem(void *arg)
+static int chld1_sem(LTP_ATTRIBUTE_UNUSED void *arg)
 {
 	int id;
 	union semun su;
 	struct sembuf sm;
 
-	id = semget(TESTKEY, 1, IPC_CREAT);
-	if (id == -1) {
-		perror("semget");
-		return 2;
-	}
+	id = SAFE_SEMGET(TESTKEY, 1, IPC_CREAT);
 
 	su.val = 1;
-	if (semctl(id, 0, SETVAL, su) == -1) {
-		perror("semctl");
-		semctl(id, 0, IPC_RMID);
-		return 2;
-	}
+	SAFE_SEMCTL(id, 0, SETVAL, su);
 
 	/* tell child2 to continue and wait for it to create the semaphore */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	sm.sem_num = 0;
 	sm.sem_op = -1;
 	sm.sem_flg = IPC_NOWAIT;
-	if (semop(id, &sm, 1) == -1) {
-		perror("semop");
-		semctl(id, 0, IPC_RMID);
-		return 2;
-	}
+	SAFE_SEMOP(id, &sm, 1);
 
 	/* tell child2 to continue and wait for it to lock the semaphore */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	sm.sem_op = 1;
-	semop(id, &sm, 1);
+	SAFE_SEMOP(id, &sm, 1);
+
+	SAFE_SEMCTL(id, 0, IPC_RMID);
 
-	semctl(id, 0, IPC_RMID);
 	return 0;
 }
 
-int chld2_sem(void *arg)
+static int chld2_sem(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int id, rval = 0;
+	int id;
 	struct sembuf sm;
 	union semun su;
 
 	/* wait for child1 to create the semaphore */
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 
-	id = semget(TESTKEY, 1, IPC_CREAT);
-	if (id == -1) {
-		perror("semget");
-		return 2;
-	}
+	id = SAFE_SEMGET(TESTKEY, 1, IPC_CREAT);
 
 	su.val = 1;
-	if (semctl(id, 0, SETVAL, su) == -1) {
-		perror("semctl");
-		semctl(id, 0, IPC_RMID);
-		return 2;
-	}
+	SAFE_SEMCTL(id, 0, SETVAL, su);
 
 	/* tell child1 to continue and wait for it to lock the semaphore */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	sm.sem_num = 0;
 	sm.sem_op = -1;
 	sm.sem_flg = IPC_NOWAIT;
-	if (semop(id, &sm, 1) == -1) {
-		if (errno == EAGAIN) {
-			rval = 1;
-		} else {
-			perror("semop");
-			semctl(id, 0, IPC_RMID);
-			return 2;
-		}
+	TEST(semop(id, &sm, 1));
+	if (TST_RET < 0) {
+		if (TST_ERR != EAGAIN)
+			tst_brk(TBROK | TERRNO, "semop error");
+
+		tst_res(TFAIL, "can't lock semaphore between namespaces");
+	} else {
+		tst_res(TPASS, "locked semaphore between namespaces");
 	}
 
 	/* tell child1 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
+	TST_CHECKPOINT_WAKE(0);
 
 	sm.sem_op = 1;
-	semop(id, &sm, 1);
+	SAFE_SEMOP(id, &sm, 1);
+
+	SAFE_SEMCTL(id, 0, IPC_RMID);
 
-	semctl(id, 0, IPC_RMID);
-	return rval;
+	return 0;
 }
 
-static void test(void)
+static void run(void)
 {
-	int status, ret = 0;
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-
-	while (wait(&status) > 0) {
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
-			ret = 1;
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
-			tst_brkm(TBROK | TERRNO, cleanup, "error in child");
-		if (WIFSIGNALED(status)) {
-			tst_resm(TFAIL, "child was killed with signal %s",
-					tst_strsig(WTERMSIG(status)));
-			return;
-		}
-	}
-
-	if (ret)
-		tst_resm(TFAIL, "SysV sem: communication with identical keys"
-				" between namespaces");
-	else
-		tst_resm(TPASS, "SysV sem: communication with identical keys"
-				" between namespaces");
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL);
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	check_newipc();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v3 03/10] Rewrite sem_comm.c using new LTP API

Hi!

testcases/kernel/containers/sysvipc/sem_comm.c line 91

Quoted 6 lines
testcases/kernel/containers/sysvipc/sem_comm.c +6 -0
+	TEST(semop(id, &sm, 1));
+	if (TST_RET < 0) {
+		if (TST_ERR != EAGAIN)
+			tst_brk(TBROK | TERRNO, "semop error");
+
+		tst_res(TFAIL, "can't lock semaphore between namespaces");

The message is very confusing here. If we get here the semaphone was locked by the other child in a different namespace. We should print something as "semaphore decremented from different namespace"

testcases/kernel/containers/sysvipc/sem_comm.c line 93

Quoted 2 lines
testcases/kernel/containers/sysvipc/sem_comm.c +2 -0
+	} else {
+		tst_res(TPASS, "locked semaphore between namespaces");

Here as well, confusing message.

testcases/kernel/containers/sysvipc/sem_comm.c line 100

Quoted 9 lines
testcases/kernel/containers/sysvipc/sem_comm.c +2 -2
 	}
 
 	/* tell child1 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
+	TST_CHECKPOINT_WAKE(0);
 
 	sm.sem_op = 1;
-	semop(id, &sm, 1);
+	SAFE_SEMOP(id, &sm, 1);

I wonder if it's necessary to modify the semaphore value before the RMDID here. Can't we just remove it instead?

Quoted 1 line
(quoted diff) +1 -0
+	SAFE_SEMCTL(id, 0, IPC_RMID);
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 4/10 Rewrite sem_nstest.c using new LTP API

In reply to Andrea Cervesato

Updated containers runtest file to include new sem_nstest.c options.

---
 runtest/containers                            |   6 +-
 .../kernel/containers/sysvipc/sem_nstest.c    | 210 ++++++------------
 2 files changed, 76 insertions(+), 140 deletions(-)
runtest/containers +3 -3
index d863c10a4..4f56b1b4d 100644
@@ -54,9 +54,9 @@ mesgq_nstest_none mesgq_nstest -m none
 mesgq_nstest_clone mesgq_nstest -m clone
 mesgq_nstest_unshare mesgq_nstest -m unshare
 msg_comm msg_comm
-sem_nstest_none sem_nstest none
-sem_nstest_clone sem_nstest clone
-sem_nstest_unshare sem_nstest unshare
+sem_nstest_none sem_nstest -m none
+sem_nstest_clone sem_nstest -m clone
+sem_nstest_unshare sem_nstest -m unshare
 semtest_2ns_none semtest_2ns none
 semtest_2ns_clone semtest_2ns clone
 semtest_2ns_unshare semtest_2ns unshare
testcases/kernel/containers/sysvipc/sem_nstest.c +73 -137

231 lines not on this page · raw message

Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v3 04/10] Rewrite sem_nstest.c using new LTP API

Hi!
Same problem here as in the msgq_nstest.c the global str_op must not be initialized otherwise the test throws a warning.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

PATCH v3 5/10 Rewrite semtest_2ns.c using new LTP API

In reply to Andrea Cervesato

Updated containers runtest file to include new semtest_2ns.c options.

---
 runtest/containers                            |   6 +-
 .../kernel/containers/sysvipc/semtest_2ns.c   | 326 +++++++-----------
 2 files changed, 127 insertions(+), 205 deletions(-)
runtest/containers +3 -3
index 4f56b1b4d..3130ccfbd 100644
@@ -57,9 +57,9 @@ msg_comm msg_comm
 sem_nstest_none sem_nstest -m none
 sem_nstest_clone sem_nstest -m clone
 sem_nstest_unshare sem_nstest -m unshare
-semtest_2ns_none semtest_2ns none
-semtest_2ns_clone semtest_2ns clone
-semtest_2ns_unshare semtest_2ns unshare
+semtest_2ns_none semtest_2ns -m none
+semtest_2ns_clone semtest_2ns -m clone
+semtest_2ns_unshare semtest_2ns -m unshare
 sem_comm sem_comm
 
 utstest_unshare_1 utstest unshare 1
testcases/kernel/containers/sysvipc/semtest_2ns.c +124 -202

354 lines not on this page · raw message

Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v3 05/10] Rewrite semtest_2ns.c using new LTP API

Hi!

testcases/kernel/containers/sysvipc/semtest_2ns.c line 40

Quoted 12 lines
testcases/kernel/containers/sysvipc/semtest_2ns.c +10 -1
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+#include <sys/sem.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
-int check_sem2(void *vtest)
+#define MY_KEY 124326L
+
+static char *str_op = "clone";

Same problem here.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

PATCH v3 6/10 Rewrite shmnstest.c using new LTP API

In reply to Andrea Cervesato

Updated containers runtest file to include new shmnstest.c options.

---
 runtest/containers                            |   6 +-
 .../kernel/containers/sysvipc/shmnstest.c     | 180 ++++++------------
 2 files changed, 62 insertions(+), 124 deletions(-)
runtest/containers +3 -3
index 3130ccfbd..b1b9b522a 100644
@@ -43,9 +43,9 @@ netns_comm_ip_ipv4_ioctl netns_comm.sh ip ipv4 ioctl
 netns_comm_ip_ipv6_ioctl netns_comm.sh ip ipv6 ioctl
 netns_sysfs netns_sysfs.sh
 
-shmnstest_none shmnstest none
-shmnstest_clone shmnstest clone
-shmnstest_unshare shmnstest unshare
+shmnstest_none shmnstest -m none
+shmnstest_clone shmnstest -m clone
+shmnstest_unshare shmnstest -m unshare
 shmem_2nstest_none shmem_2nstest none
 shmem_2nstest_clone shmem_2nstest clone
 shmem_2nstest_unshare shmem_2nstest unshare
testcases/kernel/containers/sysvipc/shmnstest.c +59 -121

203 lines not on this page · raw message

Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] [PATCH v3 06/10] Rewrite shmnstest.c using new LTP API

Hi!

Quoted 1 line

+static char *str_op = "clone";

And same here.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v3 7/10 Rewrite shmem_2nstest.c using new LTP API

In reply to Andrea Cervesato

Updated containers runtime file to include new shmem_2nstest.c options.

---
 runtest/containers                            |   6 +-
 .../kernel/containers/sysvipc/shmem_2nstest.c | 239 ++++++------------
 2 files changed, 86 insertions(+), 159 deletions(-)
runtest/containers +3 -3
index b1b9b522a..591d56b18 100644
@@ -46,9 +46,9 @@ netns_sysfs netns_sysfs.sh
 shmnstest_none shmnstest -m none
 shmnstest_clone shmnstest -m clone
 shmnstest_unshare shmnstest -m unshare
-shmem_2nstest_none shmem_2nstest none
-shmem_2nstest_clone shmem_2nstest clone
-shmem_2nstest_unshare shmem_2nstest unshare
+shmem_2nstest_none shmem_2nstest -m none
+shmem_2nstest_clone shmem_2nstest -m clone
+shmem_2nstest_unshare shmem_2nstest -m unshare
 shm_comm shm_comm
 mesgq_nstest_none mesgq_nstest -m none
 mesgq_nstest_clone mesgq_nstest -m clone
testcases/kernel/containers/sysvipc/shmem_2nstest.c +83 -156

270 lines not on this page · raw message

Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

Re: [LTP] [PATCH v3 07/10] Rewrite shmem_2nstest.c using new LTP API

Hi!

Quoted 1 line

+static char *str_op = "clone";

And here as well.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

PATCH v3 8/10 Rewrite shm_comm.c using new LTP API

In reply to Andrea Cervesato
---
 .../kernel/containers/sysvipc/shm_comm.c      | 167 ++++++------------
 1 file changed, 50 insertions(+), 117 deletions(-)
testcases/kernel/containers/sysvipc/shm_comm.c +50 -117
index 4b3bbfaa8..12ad49110 100644
@@ -1,20 +1,17 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Test if SysV IPC shared memory is properly working between two different
+ * namespaces.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: shm_comm.c
+ * [Algorithm]
  *
- * Description:
  * 1. Clones two child processes with CLONE_NEWIPC flag, each child
  *    allocates System V shared memory segment (shm) with the _identical_
  *    key and attaches that segment into its address space.
@@ -27,141 +24,77 @@
  */
 
 #define _GNU_SOURCE
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include "ipcns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
 
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
 #define TESTKEY 124426L
 #define SHMSIZE 50
-char *TCID	= "shm_comm";
-int TST_TOTAL	= 1;
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-	check_newipc();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
-}
 
-int chld1_shm(void *arg)
+static int chld1_shm(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int id, rval = 0;
+	int id;
 	char *shmem;
 
-	id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
-	if (id == -1) {
-		perror("shmget");
-		return 2;
-	}
-
-	if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
-		perror("shmat");
-		shmctl(id, IPC_RMID, NULL);
-		return 2;
-	}
+	id = SAFE_SHMGET(TESTKEY, SHMSIZE, IPC_CREAT);
 
+	shmem = SAFE_SHMAT(id, NULL, 0);
 	*shmem = 'A';
 
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	/* if child1 shared segment has changed (by child2) report fail */
 	if (*shmem != 'A')
-		rval = 1;
+		tst_res(TFAIL, "shared memory leak between namespaces");
+	else
+		tst_res(TPASS, "shared memory didn't leak between namespaces");
+
+	TST_CHECKPOINT_WAKE(0);
 
-	/* tell child2 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
+	SAFE_SHMDT(shmem);
+	SAFE_SHMCTL(id, IPC_RMID, NULL);
 
-	shmdt(shmem);
-	shmctl(id, IPC_RMID, NULL);
-	return rval;
+	return 0;
 }
 
-int chld2_shm(void *arg)
+static int chld2_shm(LTP_ATTRIBUTE_UNUSED void *arg)
 {
 	int id;
 	char *shmem;
 
-	id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
-	if (id == -1) {
-		perror("shmget");
-		return 2;
-	}
+	id = SAFE_SHMGET(TESTKEY, SHMSIZE, IPC_CREAT);
 
-	if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
-		perror("shmat");
-		shmctl(id, IPC_RMID, NULL);
-		return 2;
-	}
+	shmem = SAFE_SHMAT(id, NULL, 0);
 
-	/* wait for child1 to write to his segment */
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 
 	*shmem = 'B';
 
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_SHMDT(shmem);
+	SAFE_SHMCTL(id, IPC_RMID, NULL);
 
-	shmdt(shmem);
-	shmctl(id, IPC_RMID, NULL);
 	return 0;
 }
 
-static void test(void)
+static void run(void)
 {
-	int status, ret = 0;
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-
-	while (wait(&status) > 0) {
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
-			ret = 1;
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
-			tst_brkm(TBROK | TERRNO, cleanup, "error in child");
-		if (WIFSIGNALED(status)) {
-			tst_resm(TFAIL, "child was killed with signal %s",
-					tst_strsig(WTERMSIG(status)));
-			return;
-		}
-	}
-
-	if (ret)
-		tst_resm(TFAIL, "SysV shm: communication with identical keys"
-				" between namespaces");
-	else
-		tst_resm(TPASS, "SysV shm: communication with identical keys"
-				" between namespaces");
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	check_newipc();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

PATCH v3 9/10 Remove libclone dependency from sysvipc test suite

In reply to Andrea Cervesato
---
 testcases/kernel/containers/sysvipc/Makefile | 26 +++-----------------
 1 file changed, 3 insertions(+), 23 deletions(-)
testcases/kernel/containers/sysvipc/Makefile +3 -23
index 00b537f6a..426fe5292 100644
@@ -1,28 +1,8 @@
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2007                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2007
+# Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
 
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
-
-LDLIBS			:= -lclone $(LDLIBS)
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

PATCH v3 10/10 Delete ipcns_helper.h in the sysvipc test suite

In reply to Andrea Cervesato
---
 .../kernel/containers/sysvipc/ipcns_helper.h  | 41 -------------------
 1 file changed, 41 deletions(-)
 delete mode 100644 testcases/kernel/containers/sysvipc/ipcns_helper.h
testcases/kernel/containers/sysvipc/ipcns_helper.h deleted +0 -41
deleted file mode 100644
index 01ad0fff6..000000000
@@ -1,41 +0,0 @@
-/*
-* Copyright (c) International Business Machines Corp., 2007
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Rishikesh K Rajak <[email protected]>
-***************************************************************************/
-#include <sched.h>
-#include "../libclone/libclone.h"
-#include "test.h"
-#include "safe_macros.h"
-
-static int dummy_child(void *v)
-{
-	(void) v;
-	return 0;
-}
-
-static void check_newipc(void)
-{
-	int pid, status;
-
-	if (tst_kvercmp(2, 6, 19) < 0)
-		tst_brkm(TCONF, NULL, "CLONE_NEWIPC not supported");
-
-	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, dummy_child, NULL);
-	if (pid == -1)
-		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWIPC not supported");
-
-	SAFE_WAIT(NULL, &status);
-}
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp