All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 0/7] Refactor mqns testing suite
@ 2022-07-22 12:04 Andrea Cervesato via ltp
  2022-07-22 12:04 ` [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API Andrea Cervesato via ltp
                   ` (7 more replies)
  0 siblings, 8 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:04 UTC (permalink / raw)
  To: ltp

mqns testing suite has been refactored using new LTP API

Andrea Cervesato (7):
  Add more safe macros for mqueue API
  Refactor mqns_01 using new LTP API
  Refactor mqns_02 using new LTP API
  Refactor mqns_03 using new LTP API
  Refactor mqns_04 using new LTP API
  Delete deprecated mqns header files
  Rename common.h into mqns.h for mqns suite

 include/tst_safe_posix_ipc.h                  |  45 +++
 runtest/containers                            |  12 +-
 testcases/kernel/containers/mqns/Makefile     |  27 +-
 testcases/kernel/containers/mqns/mqns.h       | 108 ++++++-
 testcases/kernel/containers/mqns/mqns_01.c    | 185 ++++--------
 testcases/kernel/containers/mqns/mqns_02.c    | 217 ++++----------
 testcases/kernel/containers/mqns/mqns_03.c    | 269 +++++++-----------
 testcases/kernel/containers/mqns/mqns_04.c    | 263 ++++++++---------
 .../kernel/containers/mqns/mqns_helper.h      |  56 ----
 9 files changed, 485 insertions(+), 697 deletions(-)
 delete mode 100644 testcases/kernel/containers/mqns/mqns_helper.h

-- 
2.35.3


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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
@ 2022-07-22 12:04 ` Andrea Cervesato via ltp
  2022-07-26  6:50   ` Petr Vorel
  2022-11-01 11:36   ` Richard Palethorpe
  2022-07-22 12:04 ` [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API Andrea Cervesato via ltp
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:04 UTC (permalink / raw)
  To: ltp

Added SAFE_MQ_UNLINK and SAFE_MQ_CLOSE in tst_safe_posix_ipc.h

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_safe_posix_ipc.h | 45 ++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/include/tst_safe_posix_ipc.h b/include/tst_safe_posix_ipc.h
index b60c12c9e..5bfef03a9 100644
--- a/include/tst_safe_posix_ipc.h
+++ b/include/tst_safe_posix_ipc.h
@@ -12,6 +12,12 @@
 #define SAFE_MQ_OPEN(pathname, oflags, ...) \
 	safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__)
 
+#define SAFE_MQ_CLOSE(__mqdes) \
+	safe_mq_close(__FILE__, __LINE__, (__mqdes))
+
+#define SAFE_MQ_UNLINK(name) \
+	safe_mq_unlink(__FILE__, __LINE__, (name))
+
 static inline int safe_mq_open(const char *file, const int lineno,
 			       const char *pathname, int oflags, ...)
 {
@@ -41,6 +47,45 @@ static inline int safe_mq_open(const char *file, const int lineno,
 		tst_brk_(file, lineno, TBROK | TERRNO,
 			"mq_open(%s,%d,%04o,%p) failed", pathname, oflags,
 			mode, attr);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid mq_open(%s) return value %d", pathname, rval);
+	}
+
+	return rval;
+}
+
+static inline int safe_mq_close(const char *file, const int lineno,
+				mqd_t __mqdes)
+{
+	int rval;
+
+	rval = mq_close(__mqdes);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"mq_close(%d) failed", __mqdes);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid mq_close(%d) return value %d", __mqdes, rval);
+	}
+
+	return rval;
+}
+
+static inline int safe_mq_unlink(const char *file, const int lineno,
+				const char* name)
+{
+	int rval;
+
+	rval = mq_unlink(name);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"mq_unlink(%s) failed", name);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid mq_unlink(%s) return value %d", name, rval);
 	}
 
 	return rval;
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
  2022-07-22 12:04 ` [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API Andrea Cervesato via ltp
@ 2022-07-22 12:04 ` Andrea Cervesato via ltp
  2022-08-11  9:53   ` Richard Palethorpe
  2022-07-22 12:04 ` [LTP] [PATCH v3 3/7] Refactor mqns_02 " Andrea Cervesato via ltp
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:04 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/containers                         |   3 +-
 testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
 testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
 3 files changed, 166 insertions(+), 131 deletions(-)
 create mode 100644 testcases/kernel/containers/mqns/common.h

diff --git a/runtest/containers b/runtest/containers
index 2637b62fe..863a964ad 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -16,7 +16,8 @@ pidns31 pidns31
 pidns32 pidns32
 
 mqns_01 mqns_01
-mqns_01_clone mqns_01 -clone
+mqns_01_clone mqns_01 -m clone
+mqns_01_unshare mqns_01 -m unshare
 mqns_02 mqns_02
 mqns_02_clone mqns_02 -clone
 mqns_03 mqns_03
diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
new file mode 100644
index 000000000..92a77b566
--- /dev/null
+++ b/testcases/kernel/containers/mqns/common.h
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef MQNS_H
+#define MQNS_H
+
+#include <stdlib.h>
+#include "lapi/namespaces_constants.h"
+#include "tst_test.h"
+#include "tst_safe_posix_ipc.h"
+
+enum {
+	T_CLONE,
+	T_UNSHARE,
+	T_NONE,
+};
+
+static int dummy_child1(void *v)
+{
+	(void)v;
+	return 0;
+}
+
+static inline void check_newipc(void)
+{
+	int pid, status;
+
+	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1, NULL);
+	if (pid < 0)
+		tst_brk(TCONF | TERRNO, "CLONE_NEWIPC not supported");
+
+	SAFE_WAITPID(pid, &status, 0);
+}
+
+static inline int get_clone_unshare_enum(const char* str_op)
+{
+	if (!str_op)
+		return T_NONE;
+	else if (!strcmp(str_op, "clone"))
+		return T_CLONE;
+	else if (!strcmp(str_op, "unshare"))
+		return T_UNSHARE;
+
+	return T_NONE;
+}
+
+static void clone_test(unsigned long clone_flags, int (*fn1)(void *arg), void *arg1)
+{
+	int pid;
+
+	pid = ltp_clone_quick(clone_flags | SIGCHLD, fn1, arg1);
+	if (pid < 0)
+		tst_brk(TBROK | TERRNO, "ltp_clone_quick error");
+}
+
+static void unshare_test(unsigned long clone_flags, int (*fn1)(void *arg), void *arg1)
+{
+	int pid;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		SAFE_UNSHARE(clone_flags);
+
+		fn1(arg1);
+		exit(0);
+	}
+}
+
+static void plain_test(int (*fn1)(void *arg), void *arg1)
+{
+	int pid;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		fn1(arg1);
+		exit(0);
+	}
+}
+
+static void clone_unshare_test(int use_clone, unsigned long clone_flags,
+			       int (*fn1)(void *arg), void *arg1)
+{
+	switch (use_clone) {
+	case T_NONE:
+		plain_test(fn1, arg1);
+	break;
+	case T_CLONE:
+		clone_test(clone_flags, fn1, arg1);
+	break;
+	case T_UNSHARE:
+		unshare_test(clone_flags, fn1, arg1);
+	break;
+	default:
+		tst_brk(TBROK, "%s: bad use_clone option: %d", __FUNCTION__, use_clone);
+	break;
+	}
+}
+
+#endif /* MQNS_H */
diff --git a/testcases/kernel/containers/mqns/mqns_01.c b/testcases/kernel/containers/mqns/mqns_01.c
index 1d109e020..a34dc4f66 100644
--- a/testcases/kernel/containers/mqns/mqns_01.c
+++ b/testcases/kernel/containers/mqns/mqns_01.c
@@ -1,148 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) International Business Machines Corp., 2009
-* Copyright (c) Nadia Derbey, 2009
-* 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: Nadia Derbey <Nadia.Derbey@bull.net>
-*
-* Check mqns isolation: father mqns cannot be accessed from newinstance
-*
-* Mount mqueue fs
-* Create a posix mq -->mq1
-* unshare
-* In unshared process:
-*    Mount newinstance mqueuefs
-*    Check that mq1 is not readable from new ns
-
-***************************************************************************/
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#include <sys/wait.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "mqns.h"
-#include "mqns_helper.h"
-
-char *TCID = "posixmq_namespace_01";
-int TST_TOTAL = 1;
-
-int p1[2];
-int p2[2];
-
-int check_mqueue(void *vtest)
+ * Copyright (c) International Business Machines Corp., 2009
+ * Copyright (c) Nadia Derbey, 2009 <Nadia.Derbey@bull.net>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Create a mqueue inside the parent and check if it can be accessed from
+ * the isolated/forked child namespace.
+ */
+
+#include "common.h"
+
+#define MQNAME "/MQ1"
+
+static mqd_t mqd;
+static char *str_op;
+static int use_clone;
+
+static int check_mqueue(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[30];
-	mqd_t mqd;
+	mqd_t mqd1;
 
-	(void) vtest;
+	mqd1 = mq_open(MQNAME, O_RDONLY);
 
-	close(p1[1]);
-	close(p2[0]);
+	if (use_clone == T_NONE) {
+		if (mqd1 == -1)
+			tst_res(TFAIL, "Queue has been accessed form plain cloned process");
+		else
+			tst_res(TPASS, "Can't access to queue from plain cloned process");
 
-	if (read(p1[0], buf, strlen("go") + 1) < 0) {
-		printf("read(p1[0], ...) failed: %s\n", strerror(errno));
-		exit(1);
-	}
-	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDONLY);
-	if (mqd == -1) {
-		if (write(p2[1], "notfnd", strlen("notfnd") + 1) < 0) {
-			perror("write(p2[1], ...) failed");
-			exit(1);
-		}
-	} else {
-		if (write(p2[1], "exists", strlen("exists") + 1) < 0) {
-			perror("write(p2[1], \"exists\", 7) failed");
-			exit(1);
-		} else if (mq_close(mqd) < 0) {
-			perror("mq_close(mqd) failed");
-			exit(1);
-		}
+		return 0;
 	}
 
-	exit(0);
+	if (mqd1 == -1)
+		tst_res(TPASS, "Can't access to queue from isolated process");
+	else
+		tst_res(TFAIL, "Queue has been accessed from isolated process");
+
+	return 0;
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
-	check_mqns();
+	tst_res(TINFO, "Checking namespaces isolation from parent to child");
+
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int r;
-	mqd_t mqd;
-	char buf[30];
-	int use_clone = T_UNSHARE;
-
-	setup();
-
-	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through clone(2).");
-		use_clone = T_CLONE;
-	} else
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through unshare(2).");
-
-	if (pipe(p1) == -1 || pipe(p2) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
-	}
+	use_clone = get_clone_unshare_enum(str_op);
 
-	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
-		0777, NULL);
-	if (mqd == -1) {
-		perror("mq_open");
-		tst_brkm(TFAIL, NULL, "mq_open failed");
-	}
+	if (use_clone != T_NONE)
+		check_newipc();
 
-	tst_resm(TINFO, "Checking namespaces isolation from parent to child");
-	/* fire off the test */
-	r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
-	if (r < 0) {
-		tst_resm(TFAIL, "failed clone/unshare");
-		mq_close(mqd);
-		tst_syscall(__NR_mq_unlink, NOSLASH_MQ1);
-		tst_exit();
-	}
-
-	close(p1[0]);
-	close(p2[1]);
-	if (write(p1[1], "go", strlen("go") + 1) < 0)
-		tst_resm(TBROK | TERRNO, "write(p1[1], \"go\", ...) failed");
-	else if (read(p2[0], buf, 7) < 0)
-		tst_resm(TBROK | TERRNO, "read(p2[0], buf, ...) failed");
-	else {
-		if (!strcmp(buf, "exists")) {
-			tst_resm(TFAIL, "child process found mqueue");
-		} else if (!strcmp(buf, "notfnd")) {
-			tst_resm(TPASS, "child process didn't find mqueue");
-		} else {
-			tst_resm(TFAIL, "UNKNOWN RESULT");
-		}
-	}
+	mqd = SAFE_MQ_OPEN(MQNAME, O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
+}
 
-	/* destroy the mqueue */
-	if (mq_close(mqd) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "mq_close failed");
+static void cleanup(void)
+{
+	if (mqd != -1) {
+		SAFE_MQ_CLOSE(mqd);
+		SAFE_MQ_UNLINK(MQNAME);
 	}
-	tst_syscall(__NR_mq_unlink, NOSLASH_MQ1);
-
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare>" },
+		{},
+	},
+};
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 3/7] Refactor mqns_02 using new LTP API
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
  2022-07-22 12:04 ` [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API Andrea Cervesato via ltp
  2022-07-22 12:04 ` [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API Andrea Cervesato via ltp
@ 2022-07-22 12:04 ` Andrea Cervesato via ltp
  2022-07-22 12:04 ` [LTP] [PATCH v3 4/7] Refactor mqns_03 " Andrea Cervesato via ltp
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:04 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/containers                         |   3 +-
 testcases/kernel/containers/mqns/mqns_02.c | 225 ++++++---------------
 2 files changed, 67 insertions(+), 161 deletions(-)

diff --git a/runtest/containers b/runtest/containers
index 863a964ad..4042ced4c 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -19,7 +19,8 @@ mqns_01 mqns_01
 mqns_01_clone mqns_01 -m clone
 mqns_01_unshare mqns_01 -m unshare
 mqns_02 mqns_02
-mqns_02_clone mqns_02 -clone
+mqns_02_clone mqns_02 -m clone
+mqns_02_unshare mqns_02 -m unshare
 mqns_03 mqns_03
 mqns_03_clone mqns_03 -clone
 mqns_04 mqns_04
diff --git a/testcases/kernel/containers/mqns/mqns_02.c b/testcases/kernel/containers/mqns/mqns_02.c
index d4e785b59..4383fef73 100644
--- a/testcases/kernel/containers/mqns/mqns_02.c
+++ b/testcases/kernel/containers/mqns/mqns_02.c
@@ -1,180 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) International Business Machines Corp., 2009
-* Copyright (c) Nadia Derbey, 2009
-* 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: Nadia Derbey <Nadia.Derbey@bull.net>
-*
-* Check mqns isolation: child mqns cannot be accessed from father
-*
-* Mount mqueue fs
-* unshare
-* In unshared process:
-*    Mount newinstance mqueuefs
-*    Create a posix mq -->mq1
-* Check that mq1 is not readable from father
-*
-* Changelog:
-*	Dec 16: accomodate new mqns semantics (Serge Hallyn)
-
-***************************************************************************/
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#include <sys/wait.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "mqns.h"
-#include "mqns_helper.h"
-
-char *TCID = "posixmq_namespace_02";
-int TST_TOTAL = 1;
-
-int p1[2];
-int p2[2];
-
-int check_mqueue(void *vtest)
+ * Copyright (c) International Business Machines Corp., 2009
+ * Copyright (c) Nadia Derbey, 2009 <Nadia.Derbey@bull.net>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Create a mqueue with the same name in both parent and isolated/forked child,
+ * then check namespace isolation.
+ */
+
+#include "common.h"
+
+#define MQNAME "/MQ1"
+
+static mqd_t mqd;
+static char *str_op;
+static int use_clone;
+
+static int check_mqueue(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[30];
-	mqd_t mqd;
+	mqd_t mqd1;
 
-	(void) vtest;
+	mqd1 = mq_open(MQNAME, O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
 
-	close(p1[1]);
-	close(p2[0]);
+	if (use_clone == T_NONE) {
+		if (mqd1 == -1)
+			tst_res(TPASS, "Can't create queue from plain cloned process");
+		else
+			tst_res(TFAIL, "Queue has been created form plain cloned process");
 
-	if (read(p1[0], buf, 3) < 0) {
-		perror("read(p1[0], ..) failed");
-		exit(1);
-	} else {
+		return 0;
+	}
 
-		mqd =
-		    tst_syscall(__NR_mq_open, NOSLASH_MQ1,
-			    O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
-		if (mqd == -1) {
-			if (write(p2[1], "mqfail", strlen("mqfail") + 1) < 0) {
-				perror("write(p2[1], \"mqfail\", ..) failed");
-				exit(1);
-			}
-		} else {
-
-			if (write(p2[1], "mqopen", strlen("mqopen") + 1) < 0) {
-				perror("write(p2[1], \"mqopen\", ..) failed");
-				exit(1);
-			} else {
-
-				if (read(p1[0], buf, 5) < 0) {
-					perror("read(p1[0], ..) failed");
-					exit(1);
-				} else {
-
-					/* destroy the mqueue */
-					if (mq_close(mqd) < 0) {
-						perror("mq_close(mqd) failed");
-						exit(1);
-					} else if (tst_syscall(__NR_mq_unlink,
-							   NOSLASH_MQ1) < 0) {
-						perror("mq_unlink(" NOSLASH_MQ1
-						       ") failed");
-						exit(1);
-					} else if (write(p2[1], "done",
-							 strlen("done") + 1)
-						   < 0) {
-						perror("write(p2[1], "
-						       "\"done\", ..) failed");
-						exit(1);
-					}
-
-				}
-
-			}
-
-		}
+	if (mqd1 == -1) {
+		tst_res(TFAIL, "Queue hasn't been created from isolated process");
+	} else {
+		tst_res(TPASS, "Created queue from isolated process");
 
+		SAFE_MQ_CLOSE(mqd1);
+		SAFE_MQ_UNLINK(MQNAME);
 	}
-	exit(0);
 
+	return 0;
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
-	check_mqns();
+	tst_res(TINFO, "Checking namespaces isolation from parent to child");
+
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int r;
-	mqd_t mqd;
-	char buf[30];
-	int use_clone = T_UNSHARE;
-
-	setup();
-
-	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through clone(2).");
-		use_clone = T_CLONE;
-	} else
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through unshare(2).");
-
-	if (pipe(p1) == -1 || pipe(p2) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "pipe");
-	}
+	use_clone = get_clone_unshare_enum(str_op);
 
-	/* fire off the test */
-	r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
-	if (r < 0) {
-		tst_brkm(TFAIL, NULL, "failed clone/unshare");
-	}
+	if (use_clone != T_NONE)
+		check_newipc();
 
-	tst_resm(TINFO, "Checking namespaces isolation (child to parent)");
-
-	close(p1[0]);
-	close(p2[1]);
-	if (write(p1[1], "go", strlen("go") + 1) < 0) {
-		tst_brkm(TBROK, NULL, "write(p1[1], \"go\", ..) failed");
-	}
+	mqd = SAFE_MQ_OPEN(MQNAME, O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
+}
 
-	if (read(p2[0], buf, 7) < 0) {
-		tst_resm(TBROK | TERRNO, "read(p2[0], ..) failed");
-	} else if (!strcmp(buf, "mqfail")) {
-		tst_resm(TFAIL, "child process could not create mqueue");
-		umount(DEV_MQUEUE);
-	} else if (strcmp(buf, "mqopen")) {
-		tst_resm(TFAIL, "child process could not create mqueue");
-		umount(DEV_MQUEUE);
-	} else {
-		mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDONLY);
-		if (mqd == -1) {
-			tst_resm(TPASS,
-				 "Parent process can't see the mqueue");
-		} else {
-			tst_resm(TFAIL | TERRNO,
-				 "Parent process found mqueue");
-			mq_close(mqd);
-		}
-		if (write(p1[1], "cont", 5) < 0) {
-			tst_resm(TBROK | TERRNO, "write(p1[1], ..) failed");
-		}
-		read(p2[0], buf, 7);
+static void cleanup(void)
+{
+	if (mqd != -1) {
+		SAFE_MQ_CLOSE(mqd);
+		SAFE_MQ_UNLINK(MQNAME);
 	}
-
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare>" },
+		{},
+	},
+};
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 4/7] Refactor mqns_03 using new LTP API
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
                   ` (2 preceding siblings ...)
  2022-07-22 12:04 ` [LTP] [PATCH v3 3/7] Refactor mqns_02 " Andrea Cervesato via ltp
@ 2022-07-22 12:04 ` Andrea Cervesato via ltp
  2022-07-22 12:04 ` [LTP] [PATCH v3 5/7] Refactor mqns_04 " Andrea Cervesato via ltp
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:04 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/containers                         |   3 +-
 testcases/kernel/containers/mqns/mqns_03.c | 271 ++++++++-------------
 2 files changed, 100 insertions(+), 174 deletions(-)

diff --git a/runtest/containers b/runtest/containers
index 4042ced4c..496b47037 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -22,7 +22,8 @@ mqns_02 mqns_02
 mqns_02_clone mqns_02 -m clone
 mqns_02_unshare mqns_02 -m unshare
 mqns_03 mqns_03
-mqns_03_clone mqns_03 -clone
+mqns_03_clone mqns_03 -m clone
+mqns_03_unshare mqns_03 -m unshare
 mqns_04 mqns_04
 mqns_04_clone mqns_04 -clone
 
diff --git a/testcases/kernel/containers/mqns/mqns_03.c b/testcases/kernel/containers/mqns/mqns_03.c
index a7452b970..5914a2a9b 100644
--- a/testcases/kernel/containers/mqns/mqns_03.c
+++ b/testcases/kernel/containers/mqns/mqns_03.c
@@ -1,207 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) International Business Machines Corp., 2009
-* 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: Serge Hallyn <serue@us.ibm.com>
-*
-* Check ipcns+sb longevity
-*
-* Mount mqueue fs
-* unshare
-* In unshared process:
-*    Create "/mq1" with mq_open()
-*    Mount mqueuefs
-*    Check that /mq1 exists
-*    Create /dev/mqueue/mq2 through vfs (create(2))
-*    Umount /dev/mqueue
-*    Remount /dev/mqueue
-*    Check that both /mq1 and /mq2 exist
-
-***************************************************************************/
-
-#ifndef _GNU_SOURCE
+ * Copyright (c) International Business Machines Corp., 2009
+ * Copyright (c) Serge Hallyn <serue@us.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test mqueuefs from an isolated/forked process namespace.
+ *
+ * [Algorithm]
+ *
+ * - create /MQ1
+ * - mount mqueue inside the temporary folder
+ * - check for /MQ1 existance
+ * - create /MQ2 inside the temporary folder
+ * - umount
+ * - mount mqueue inside the temporary folder
+ * - check /MQ1 existance
+ * - check /MQ2 existance
+ * - umount
+ */
 #define _GNU_SOURCE
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "mqns.h"
-#include "mqns_helper.h"
 
-char *TCID = "posixmq_namespace_03";
-int TST_TOTAL = 1;
+#include <stdio.h>
+#include "common.h"
+#include "tst_safe_stdio.h"
 
-int p1[2];
-int p2[2];
+#define MQNAME1 "/MQ1"
+#define MQNAME2 "/MQ2"
 
-#define FNAM1 DEV_MQUEUE2 SLASH_MQ1
-#define FNAM2 DEV_MQUEUE2 SLASH_MQ2
+static char *str_op;
+static int use_clone;
+static char *devdir;
+static char *mqueue1;
+static char *mqueue2;
+static int *mq_freed;
 
-int check_mqueue(void *vtest)
+static int check_mqueue(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[30];
-	mqd_t mqd;
 	int rc;
+	mqd_t mqd;
 	struct stat statbuf;
 
-	(void) vtest;
+	mqd = SAFE_MQ_OPEN(MQNAME1, O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
 
-	close(p1[1]);
-	close(p2[0]);
+	SAFE_MQ_CLOSE(mqd);
 
-	if (read(p1[0], buf, 3) != 3) {	/* go */
-		perror("read failed");
-		exit(1);
-	}
+	SAFE_MOUNT("mqueue", devdir, "mqueue", 0, NULL);
 
-	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
-		0755, NULL);
-	if (mqd == -1) {
-		write(p2[1], "mqfail", 7);
-		exit(1);
-	}
+	SAFE_STAT(mqueue1, &statbuf);
+	tst_res(TPASS, "%s exists at first mount", mqueue1);
 
-	mq_close(mqd);
+	rc = SAFE_CREAT(mqueue2, 0755);
+	SAFE_CLOSE(rc);
 
-	rc = mount("mqueue", DEV_MQUEUE2, "mqueue", 0, NULL);
-	if (rc == -1) {
-		write(p2[1], "mount1", 7);
-		exit(1);
-	}
+	SAFE_UMOUNT(devdir);
 
-	rc = stat(FNAM1, &statbuf);
-	if (rc == -1) {
-		write(p2[1], "stat1", 6);
-		exit(1);
-	}
+	SAFE_MOUNT("mqueue", devdir, "mqueue", 0, NULL);
 
-	rc = creat(FNAM2, 0755);
-	if (rc == -1) {
-		write(p2[1], "creat", 6);
-		exit(1);
-	}
+	SAFE_STAT(mqueue1, &statbuf);
+	tst_res(TPASS, "%s exists at second mount", mqueue1);
 
-	close(rc);
+	SAFE_STAT(mqueue2, &statbuf);
+	tst_res(TPASS, "%s exists at second mount", mqueue2);
 
-	rc = umount(DEV_MQUEUE2);
-	if (rc == -1) {
-		write(p2[1], "umount", 7);
-		exit(1);
-	}
+	SAFE_UMOUNT(devdir);
 
-	rc = mount("mqueue", DEV_MQUEUE2, "mqueue", 0, NULL);
-	if (rc == -1) {
-		write(p2[1], "mount2", 7);
-		exit(1);
-	}
+	SAFE_MQ_UNLINK(MQNAME1);
+	SAFE_MQ_UNLINK(MQNAME2);
 
-	rc = stat(FNAM1, &statbuf);
-	if (rc == -1) {
-		write(p2[1], "stat2", 7);
-		exit(1);
-	}
+	*mq_freed = 1;
 
-	rc = stat(FNAM2, &statbuf);
-	if (rc == -1) {
-		write(p2[1], "stat3", 7);
-		exit(1);
-	}
+	return 0;
+}
 
-	write(p2[1], "done", 5);
+static void run(void)
+{
+	tst_res(TINFO, "Checking correct umount+remount of mqueuefs");
 
-	exit(0);
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
-	check_mqns();
+	char *tmpdir;
+
+	use_clone = get_clone_unshare_enum(str_op);
+
+	if (use_clone != T_NONE)
+		check_newipc();
+
+	tmpdir = tst_get_tmpdir();
+
+	SAFE_ASPRINTF(&devdir, "%s/mqueue", tmpdir);
+	SAFE_MKDIR(devdir, 0755);
+
+	SAFE_ASPRINTF(&mqueue1, "%s" MQNAME1, devdir);
+	SAFE_ASPRINTF(&mqueue2, "%s" MQNAME2, devdir);
+
+	mq_freed = SAFE_MMAP(NULL,
+		sizeof(int),
+		PROT_READ | PROT_WRITE,
+		MAP_SHARED | MAP_ANONYMOUS,
+		-1, 0);
 }
 
-int main(int argc, char *argv[])
+static void cleanup(void)
 {
-	int r;
-	char buf[30];
-	int use_clone = T_UNSHARE;
-
-	setup();
-
-	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
-		tst_resm(TINFO, "Testing posix mq namespaces through clone(2)");
-		use_clone = T_CLONE;
-	} else
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through unshare(2)");
-
-	if (pipe(p1) == -1 || pipe(p2) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
-
-	/* fire off the test */
-	r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
-	if (r < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "failed clone/unshare");
-	}
+	if (tst_is_mounted(devdir))
+		SAFE_UMOUNT(devdir);
 
-	tst_resm(TINFO, "Checking correct umount+remount of mqueuefs");
-
-	mkdir(DEV_MQUEUE2, 0755);
-
-	close(p1[0]);
-	close(p2[1]);
-	write(p1[1], "go", 3);
-
-	read(p2[0], buf, 7);
-	r = TFAIL;
-	if (!strcmp(buf, "mqfail")) {
-		tst_resm(TFAIL, "child process could not create mqueue");
-		goto fail;
-	} else if (!strcmp(buf, "mount1")) {
-		tst_resm(TFAIL, "child process could not mount mqueue");
-		goto fail;
-	} else if (!strcmp(buf, "stat1x")) {
-		tst_resm(TFAIL, "mq created by child is not in mqueuefs");
-		goto fail;
-	} else if (!strcmp(buf, "creat")) {
-		tst_resm(TFAIL, "child couldn't creat mq through mqueuefs");
-		goto fail;
-	} else if (!strcmp(buf, "umount")) {
-		tst_resm(TFAIL, "child couldn't umount mqueuefs");
-		goto fail;
-	} else if (!strcmp(buf, "mount2")) {
-		tst_resm(TFAIL, "child couldn't remount mqueuefs");
-		goto fail;
-	} else if (!strcmp(buf, "stat2")) {
-		tst_resm(TFAIL,
-			 "mq_open()d file gone after remount of mqueuefs");
-		goto fail;
-	} else if (!strcmp(buf, "stat3")) {
-		tst_resm(TFAIL,
-			 "creat(2)'d file gone after remount of mqueuefs");
-		goto fail;
+	if (!*mq_freed) {
+		SAFE_MQ_UNLINK(MQNAME1);
+		SAFE_MQ_UNLINK(MQNAME2);
 	}
-
-	tst_resm(TPASS, "umount+remount of mqueuefs remounted the right fs");
-
-	r = 0;
-fail:
-	umount(DEV_MQUEUE2);
-	rmdir(DEV_MQUEUE2);
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare>" },
+		{},
+	},
+};
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 5/7] Refactor mqns_04 using new LTP API
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
                   ` (3 preceding siblings ...)
  2022-07-22 12:04 ` [LTP] [PATCH v3 4/7] Refactor mqns_03 " Andrea Cervesato via ltp
@ 2022-07-22 12:04 ` Andrea Cervesato via ltp
  2022-07-22 12:05 ` [LTP] [PATCH v3 6/7] Delete deprecated mqns header files Andrea Cervesato via ltp
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:04 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/containers                         |   3 +-
 testcases/kernel/containers/mqns/mqns_04.c | 265 +++++++++------------
 2 files changed, 114 insertions(+), 154 deletions(-)

diff --git a/runtest/containers b/runtest/containers
index 496b47037..6728cb50c 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -25,7 +25,8 @@ mqns_03 mqns_03
 mqns_03_clone mqns_03 -m clone
 mqns_03_unshare mqns_03 -m unshare
 mqns_04 mqns_04
-mqns_04_clone mqns_04 -clone
+mqns_04_clone mqns_04 -m clone
+mqns_04_unshare mqns_04 -m unshare
 
 netns_netlink netns_netlink
 netns_breakns_ip_ipv4_netlink netns_breakns.sh
diff --git a/testcases/kernel/containers/mqns/mqns_04.c b/testcases/kernel/containers/mqns/mqns_04.c
index d07a85c04..95ff18ef2 100644
--- a/testcases/kernel/containers/mqns/mqns_04.c
+++ b/testcases/kernel/containers/mqns/mqns_04.c
@@ -1,187 +1,146 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) International Business Machines Corp., 2009
-* 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: Serge Hallyn <serue@us.ibm.com>
-*
-* Check mqueuefs lifetime
-* . parent creates /dev/mqueue2
-* . child mounts mqueue there
-* . child does mq_open("/ab")
-* . parent checks for /dev/mqueue2
-* . child exits
-* . parent checks for /dev/mqueue2
-* . parent tries 'touch /dev/mqueue2/dd' -> should fail
-* . parent umounts /dev/mqueue2
-
-***************************************************************************/
-
-#ifndef _GNU_SOURCE
+ * Copyright (c) International Business Machines Corp., 2009
+ * Copyright (c) Serge Hallyn <serue@us.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test mqueuefs manipulation from child/parent namespaces.
+ *
+ * [Algorithm]
+ *
+ * - parent creates mqueue folder in <tmpdir>
+ * - child mounts mqueue there
+ * - child creates /MQ1 mqueue
+ * - parent checks for <tmpdir>/mqueue/MQ1 existence
+ * - child exits
+ * - parent checks for <tmpdir>/mqueue/MQ1 existence
+ * - parent tries 'touch <tmpdir>/mqueue/MQ2' -> should fail
+ * - parent umount mqueuefs
+ */
 #define _GNU_SOURCE
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <assert.h>
+
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "mqns.h"
-#include "mqns_helper.h"
+#include "common.h"
+#include "tst_safe_stdio.h"
 
-char *TCID = "posixmq_namespace_04";
-int TST_TOTAL = 1;
+#define CHECK_MQ_OPEN_RET(x) ((x) >= 0 || ((x) == -1 && errno != EMFILE))
 
-int p1[2];
-int p2[2];
+#define MQNAME1 "/MQ1"
+#define MQNAME2 "/MQ2"
 
-#define FNAM1 DEV_MQUEUE2 SLASH_MQ1
-#define FNAM2 DEV_MQUEUE2 SLASH_MQ2
+static char *str_op;
+static int use_clone;
+static char *devdir;
+static char *mqueue1;
+static char *mqueue2;
+static int *mq_freed;
 
-int check_mqueue(void *vtest)
+static int check_mqueue(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[30];
 	mqd_t mqd;
-	int rc;
-
-	(void) vtest;
 
-	close(p1[1]);
-	close(p2[0]);
+	mqd = TST_RETRY_FUNC(
+		mq_open(MQNAME1, O_RDWR | O_CREAT | O_EXCL, 0755, NULL),
+		CHECK_MQ_OPEN_RET);
+	if (mqd == -1)
+		tst_brk(TBROK | TERRNO, "mq_open failed");
 
-	read(p1[0], buf, 3);	/* go */
-
-	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
-		0755, NULL);
-	if (mqd == -1) {
-		write(p2[1], "mqfail", 7);
-		tst_exit();
-	}
+	SAFE_MQ_CLOSE(mqd);
 
-	mq_close(mqd);
+	SAFE_MOUNT("mqueue", devdir, "mqueue", 0, NULL);
 
-	rc = mount("mqueue", DEV_MQUEUE2, "mqueue", 0, NULL);
-	if (rc == -1) {
-		perror("mount");
-		write(p2[1], "mount", 6);
-		tst_exit();
-	}
-
-	write(p2[1], "go", 3);
-	read(p1[0], buf, 3);
-
-	tst_exit();
-}
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-static void setup(void)
-{
-	tst_require_root();
-	check_mqns();
+	return 0;
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
 	int rc;
 	int status;
-	char buf[30];
 	struct stat statbuf;
-	int use_clone = T_UNSHARE;
 
-	setup();
+	tst_res(TINFO, "Checking mqueue filesystem lifetime");
 
-	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through clone(2).");
-		use_clone = T_CLONE;
-	} else
-		tst_resm(TINFO,
-			 "Testing posix mq namespaces through unshare(2).");
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
 
-	if (pipe(p1) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-	if (pipe(p2) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
+	TST_CHECKPOINT_WAIT(0);
 
-	mkdir(DEV_MQUEUE2, 0755);
+	SAFE_STAT(mqueue1, &statbuf);
+	tst_res(TPASS, "%s child's mqueue can be accessed from parent", mqueue1);
 
-	tst_resm(TINFO, "Checking mqueue filesystem lifetime");
+	TST_CHECKPOINT_WAKE(0);
 
-	/* fire off the test */
-	rc = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL);
-	if (rc < 0) {
-		tst_resm(TFAIL, "failed clone/unshare");
-		goto fail;
-	}
+	tst_res(TINFO, "Waiting child to exit");
 
-	close(p1[0]);
-	close(p2[1]);
-	write(p1[1], "go", 3);
-
-	read(p2[0], buf, 7);
-	if (!strcmp(buf, "mqfail")) {
-		tst_resm(TFAIL, "child process could not create mqueue");
-		goto fail;
-	} else if (!strcmp(buf, "mount")) {
-		tst_resm(TFAIL, "child process could not mount mqueue");
-		goto fail;
-	}
+	SAFE_WAIT(&status);
 
-	rc = stat(FNAM1, &statbuf);
-	if (rc == -1) {
-		perror("stat");
-		write(p1[1], "go", 3);
-		tst_resm(TFAIL, "parent could not see child's created mq");
-		goto fail;
-	}
-	write(p1[1], "go", 3);
+	if (!WIFEXITED(status))
+		tst_brk(TBROK, "Child did not exit normally: %s", tst_strstatus(status));
 
-	rc = wait(&status);
-	if (rc == -1) {
-		perror("wait");
-		tst_resm(TFAIL, "error while parent waited on child to exit");
-		goto fail;
-	}
-	if (!WIFEXITED(status)) {
-		tst_resm(TFAIL, "Child did not exit normally (status %d)",
-			 status);
-		goto fail;
-	}
-	rc = stat(FNAM1, &statbuf);
-	if (rc == -1) {
-		tst_resm(TFAIL,
-			 "parent's view of child's mq died with child");
-		goto fail;
-	}
+	SAFE_STAT(mqueue1, &statbuf);
+	tst_res(TPASS, "%s child's mqueue can be accessed from parent after child's dead", mqueue1);
 
-	rc = creat(FNAM2, 0755);
-	if (rc != -1) {
-		tst_resm(TFAIL,
-			 "parent was able to create a file in dead child's mqfs");
-		goto fail;
-	}
+	rc = creat(mqueue2, 0755);
+	if (rc != -1)
+		tst_res(TFAIL, "Parent was able to create a file in dead child's mqueuefs");
+	else
+		tst_res(TPASS, "Parent is not able to create a file in dead child's mqueuefs");
+
+	SAFE_UMOUNT(devdir);
+
+	*mq_freed = 1;
+}
+
+static void setup(void)
+{
+	char *tmpdir;
+
+	use_clone = get_clone_unshare_enum(str_op);
 
-	tst_resm(TPASS, "Child mqueue fs still visible for parent");
+	if (use_clone == T_NONE)
+		tst_brk(TBROK, "Plain process is not supported by this test");
 
-fail:
-	umount(DEV_MQUEUE2);
-	rmdir(DEV_MQUEUE2);
+	tmpdir = tst_get_tmpdir();
 
-	tst_exit();
+	SAFE_ASPRINTF(&devdir, "%s/mqueue", tmpdir);
+	SAFE_MKDIR(devdir, 0755);
+
+	SAFE_ASPRINTF(&mqueue1, "%s" MQNAME1, devdir);
+	SAFE_ASPRINTF(&mqueue2, "%s" MQNAME2, devdir);
+
+	mq_freed = SAFE_MMAP(NULL,
+		sizeof(int),
+		PROT_READ | PROT_WRITE,
+		MAP_SHARED | MAP_ANONYMOUS,
+		-1, 0);
+}
+
+static void cleanup(void)
+{
+	if (tst_is_mounted(devdir))
+		SAFE_UMOUNT(devdir);
+
+	if (!*mq_freed) {
+		SAFE_MQ_UNLINK(MQNAME1);
+		SAFE_MQ_UNLINK(MQNAME2);
+	}
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.needs_checkpoints = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare>" },
+		{},
+	},
+};
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 6/7] Delete deprecated mqns header files
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
                   ` (4 preceding siblings ...)
  2022-07-22 12:04 ` [LTP] [PATCH v3 5/7] Refactor mqns_04 " Andrea Cervesato via ltp
@ 2022-07-22 12:05 ` Andrea Cervesato via ltp
  2022-07-22 12:05 ` [LTP] [PATCH v3 7/7] Rename common.h into mqns.h for mqns suite Andrea Cervesato via ltp
  2022-10-11 10:15 ` [LTP] [PATCH v3 0/7] Refactor mqns testing suite Richard Palethorpe
  7 siblings, 0 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:05 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/containers/mqns/Makefile     | 27 ++-------
 testcases/kernel/containers/mqns/mqns.h       | 11 ----
 .../kernel/containers/mqns/mqns_helper.h      | 56 -------------------
 3 files changed, 5 insertions(+), 89 deletions(-)
 delete mode 100644 testcases/kernel/containers/mqns/mqns.h
 delete mode 100644 testcases/kernel/containers/mqns/mqns_helper.h

diff --git a/testcases/kernel/containers/mqns/Makefile b/testcases/kernel/containers/mqns/Makefile
index 64c3763ee..eb0f97c2b 100644
--- a/testcases/kernel/containers/mqns/Makefile
+++ b/testcases/kernel/containers/mqns/Makefile
@@ -1,29 +1,12 @@
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2009                 ##
-## Copyright (c) Nadia Derbey, 2009                                           ##
-##                                                                            ##
-## 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., 2009
+# Copyright (c) Nadia Derbey, 2009 
+# Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
 
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
 
-LDLIBS			:= -lpthread -lrt -lclone $(LDLIBS)
+LDLIBS			:= -lpthread -lrt $(LDLIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/containers/mqns/mqns.h b/testcases/kernel/containers/mqns/mqns.h
deleted file mode 100644
index 5a9056838..000000000
--- a/testcases/kernel/containers/mqns/mqns.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __MQNS_H
-#define __MQNS_H
-
-#define DEV_MQUEUE "/dev/mqueue"
-#define DEV_MQUEUE2 "/dev/mqueue2"
-#define SLASH_MQ1 "/MQ1"
-#define NOSLASH_MQ1 "MQ1"
-#define SLASH_MQ2 "/MQ2"
-#define NOSLASH_MQ2 "MQ2"
-
-#endif /* __MQNS_H */
diff --git a/testcases/kernel/containers/mqns/mqns_helper.h b/testcases/kernel/containers/mqns/mqns_helper.h
deleted file mode 100644
index 605378d48..000000000
--- a/testcases/kernel/containers/mqns/mqns_helper.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2009
- * Copyright (c) Nadia Derbey, 2009
- * 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: Serge Hallyn <serue@us.ibm.com>
- ***************************************************************************/
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <mqueue.h>
-#include "../libclone/libclone.h"
-#include "lapi/syscalls.h"
-#include "safe_macros.h"
-#include "test.h"
-
-static int dummy_child(void *v)
-{
-	(void) v;
-	return 0;
-}
-
-static void check_mqns(void)
-{
-	int pid, status;
-	mqd_t mqd;
-
-	if (tst_kvercmp(2, 6, 30) < 0)
-		tst_brkm(TCONF, NULL, "Kernel version is lower than expected");
-
-	mq_unlink("/checkmqnsenabled");
-	mqd =
-	    mq_open("/checkmqnsenabled", O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
-	if (mqd == -1)
-		tst_brkm(TCONF, NULL, "mq_open check failed");
-
-	mq_close(mqd);
-	mq_unlink("/checkmqnsenabled");
-
-	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);
-}
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [LTP] [PATCH v3 7/7] Rename common.h into mqns.h for mqns suite
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
                   ` (5 preceding siblings ...)
  2022-07-22 12:05 ` [LTP] [PATCH v3 6/7] Delete deprecated mqns header files Andrea Cervesato via ltp
@ 2022-07-22 12:05 ` Andrea Cervesato via ltp
  2022-07-26  7:00   ` Petr Vorel
  2022-10-11 10:15 ` [LTP] [PATCH v3 0/7] Refactor mqns testing suite Richard Palethorpe
  7 siblings, 1 reply; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-07-22 12:05 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/containers/mqns/{common.h => mqns.h} | 0
 testcases/kernel/containers/mqns/mqns_01.c            | 2 +-
 testcases/kernel/containers/mqns/mqns_02.c            | 2 +-
 testcases/kernel/containers/mqns/mqns_03.c            | 2 +-
 testcases/kernel/containers/mqns/mqns_04.c            | 2 +-
 5 files changed, 4 insertions(+), 4 deletions(-)
 rename testcases/kernel/containers/mqns/{common.h => mqns.h} (100%)

diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/mqns.h
similarity index 100%
rename from testcases/kernel/containers/mqns/common.h
rename to testcases/kernel/containers/mqns/mqns.h
diff --git a/testcases/kernel/containers/mqns/mqns_01.c b/testcases/kernel/containers/mqns/mqns_01.c
index a34dc4f66..7e62ab3d6 100644
--- a/testcases/kernel/containers/mqns/mqns_01.c
+++ b/testcases/kernel/containers/mqns/mqns_01.c
@@ -12,7 +12,7 @@
  * the isolated/forked child namespace.
  */
 
-#include "common.h"
+#include "mqns.h"
 
 #define MQNAME "/MQ1"
 
diff --git a/testcases/kernel/containers/mqns/mqns_02.c b/testcases/kernel/containers/mqns/mqns_02.c
index 4383fef73..59d483be7 100644
--- a/testcases/kernel/containers/mqns/mqns_02.c
+++ b/testcases/kernel/containers/mqns/mqns_02.c
@@ -12,7 +12,7 @@
  * then check namespace isolation.
  */
 
-#include "common.h"
+#include "mqns.h"
 
 #define MQNAME "/MQ1"
 
diff --git a/testcases/kernel/containers/mqns/mqns_03.c b/testcases/kernel/containers/mqns/mqns_03.c
index 5914a2a9b..54ba54304 100644
--- a/testcases/kernel/containers/mqns/mqns_03.c
+++ b/testcases/kernel/containers/mqns/mqns_03.c
@@ -25,7 +25,7 @@
 #define _GNU_SOURCE
 
 #include <stdio.h>
-#include "common.h"
+#include "mqns.h"
 #include "tst_safe_stdio.h"
 
 #define MQNAME1 "/MQ1"
diff --git a/testcases/kernel/containers/mqns/mqns_04.c b/testcases/kernel/containers/mqns/mqns_04.c
index 95ff18ef2..b3f538592 100644
--- a/testcases/kernel/containers/mqns/mqns_04.c
+++ b/testcases/kernel/containers/mqns/mqns_04.c
@@ -24,7 +24,7 @@
 #define _GNU_SOURCE
 
 #include <stdio.h>
-#include "common.h"
+#include "mqns.h"
 #include "tst_safe_stdio.h"
 
 #define CHECK_MQ_OPEN_RET(x) ((x) >= 0 || ((x) == -1 && errno != EMFILE))
-- 
2.35.3


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API
  2022-07-22 12:04 ` [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API Andrea Cervesato via ltp
@ 2022-07-26  6:50   ` Petr Vorel
  2022-11-01 11:36   ` Richard Palethorpe
  1 sibling, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-07-26  6:50 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi Andrea,

> Added SAFE_MQ_UNLINK and SAFE_MQ_CLOSE in tst_safe_posix_ipc.h

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 7/7] Rename common.h into mqns.h for mqns suite
  2022-07-22 12:05 ` [LTP] [PATCH v3 7/7] Rename common.h into mqns.h for mqns suite Andrea Cervesato via ltp
@ 2022-07-26  7:00   ` Petr Vorel
  2022-07-26 11:52     ` [LTP] [PATCH] tools: Check headers with checkpatch.pl Richard Palethorpe via ltp
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2022-07-26  7:00 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Richard Palethorpe, ltp

Hi Andrea,

> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  testcases/kernel/containers/mqns/{common.h => mqns.h} | 0

could you please also fix this checkpatch error (preferably as a separate patch):

mqns.h:37: ERROR: "foo* bar" should be "foo *bar"
mqns.h:96: WARNING: __func__ should be used instead of gcc specific __FUNCTION__

Checkpatch also reports wrong comment style, but I'd ignore it (complains for
*.h, it's ok for *.c):
mqns.h:1: WARNING: Improper SPDX comment style for 'mqns.h', please use '/*' instead

@Richie: not sure I might have asked before: it'd be great to have make target
also for header files, so that they are checked with make check. Now we have to
run checkpatch manually to check them.

Kind regards,
Petr

>  testcases/kernel/containers/mqns/mqns_01.c            | 2 +-
>  testcases/kernel/containers/mqns/mqns_02.c            | 2 +-
>  testcases/kernel/containers/mqns/mqns_03.c            | 2 +-
>  testcases/kernel/containers/mqns/mqns_04.c            | 2 +-
>  5 files changed, 4 insertions(+), 4 deletions(-)
>  rename testcases/kernel/containers/mqns/{common.h => mqns.h} (100%)
...

Patch itself it's obviously correct.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [LTP] [PATCH] tools: Check headers with checkpatch.pl
  2022-07-26  7:00   ` Petr Vorel
@ 2022-07-26 11:52     ` Richard Palethorpe via ltp
  2022-07-26 12:03       ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Palethorpe via ltp @ 2022-07-26 11:52 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

checkpatch.pl doesn't load included headers so they must be passed to
it specifically. This change automatically includes headers from the
current directory. Manual intervention is still required if a test
author changes a header located elsewhere. However you can now write
'make check-header.h', once in the correct directory.

Note that our Sparse based tool (amongst others) loads headers and
checks at least some of the content.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Suggested-by: Petr Vorel <pvorel@suse.cz>
---
 include/mk/env_post.mk             | 1 +
 include/mk/generic_leaf_target.inc | 2 +-
 include/mk/rules.mk                | 9 +++++++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
index dc4df41d3..a00f31b08 100644
--- a/include/mk/env_post.mk
+++ b/include/mk/env_post.mk
@@ -92,6 +92,7 @@ endif
 
 CHECK_TARGETS			?= $(addprefix check-,$(notdir $(patsubst %.c,%,$(sort $(wildcard $(abs_srcdir)/*.c)))))
 CHECK_TARGETS			:= $(filter-out $(addprefix check-, $(FILTER_OUT_MAKE_TARGETS)), $(CHECK_TARGETS))
+CHECK_HEADER_TARGETS		?= $(addprefix check-,$(notdir $(sort $(wildcard $(abs_srcdir)/*.h))))
 CHECK				?= $(abs_top_srcdir)/tools/sparse/sparse-ltp
 CHECK_NOFLAGS			?= $(abs_top_srcdir)/scripts/checkpatch.pl -f --no-tree --terse --no-summary --ignore CONST_STRUCT,VOLATILE,SPLIT_STRING
 SHELL_CHECK			?= $(abs_top_srcdir)/scripts/checkbashisms.pl --force --extra
diff --git a/include/mk/generic_leaf_target.inc b/include/mk/generic_leaf_target.inc
index 33e9c9ea0..565a282bb 100644
--- a/include/mk/generic_leaf_target.inc
+++ b/include/mk/generic_leaf_target.inc
@@ -110,6 +110,6 @@ $(INSTALL_FILES): | $(INSTALL_DEPS)
 install: $(INSTALL_FILES)
 
 $(CHECK_TARGETS): | $(CHECK_DEPS)
-check: $(CHECK_TARGETS) $(SHELL_CHECK_TARGETS)
+check: $(CHECK_HEADER_TARGETS) $(CHECK_TARGETS) $(SHELL_CHECK_TARGETS)
 
 # vim: syntax=make
diff --git a/include/mk/rules.mk b/include/mk/rules.mk
index 32d8d05a7..517863c04 100644
--- a/include/mk/rules.mk
+++ b/include/mk/rules.mk
@@ -57,6 +57,15 @@ else
 	@-$(CHECK) $(CHECK_FLAGS) $(CPPFLAGS) $(CFLAGS) $<
 endif
 
+.PHONY: $(CHECK_HEADER_TARGETS)
+$(CHECK_HEADER_TARGETS): check-%.h: %.h
+ifdef VERBOSE
+	-$(CHECK_NOFLAGS) $<
+else
+	@echo CHECK $(target_rel_dir)$<
+	@-$(CHECK_NOFLAGS) $<
+endif
+
 .PHONY: $(SHELL_CHECK_TARGETS)
 $(SHELL_CHECK_TARGETS): check-%.sh: %.sh
 ifdef VERBOSE
-- 
2.36.1


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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH] tools: Check headers with checkpatch.pl
  2022-07-26 11:52     ` [LTP] [PATCH] tools: Check headers with checkpatch.pl Richard Palethorpe via ltp
@ 2022-07-26 12:03       ` Petr Vorel
  2022-07-26 12:53         ` Richard Palethorpe
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2022-07-26 12:03 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi Richie,

> checkpatch.pl doesn't load included headers so they must be passed to
> it specifically. This change automatically includes headers from the
> current directory. Manual intervention is still required if a test
> author changes a header located elsewhere. However you can now write
> 'make check-header.h', once in the correct directory.

> Note that our Sparse based tool (amongst others) loads headers and
> checks at least some of the content.

Thanks a lot for implementing this.

LGTM, just a small nit: target for headers contain .h extension.
Shouldn't we add .c for C sources for consistency?

It'đ strange, that make check in testcases/misc/math/float/ does not include
tfloat.h, but make check-tfloat.h prints errors. But make check in lib/ works as
expected (adds also *.h).

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH] tools: Check headers with checkpatch.pl
  2022-07-26 12:03       ` Petr Vorel
@ 2022-07-26 12:53         ` Richard Palethorpe
  2022-07-26 14:05           ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Palethorpe @ 2022-07-26 12:53 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hello,

Petr Vorel <pvorel@suse.cz> writes:

> Hi Richie,
>
>> checkpatch.pl doesn't load included headers so they must be passed to
>> it specifically. This change automatically includes headers from the
>> current directory. Manual intervention is still required if a test
>> author changes a header located elsewhere. However you can now write
>> 'make check-header.h', once in the correct directory.
>
>> Note that our Sparse based tool (amongst others) loads headers and
>> checks at least some of the content.
>
> Thanks a lot for implementing this.
>
> LGTM, just a small nit: target for headers contain .h extension.
> Shouldn't we add .c for C sources for consistency?
>
> It'đ strange, that make check in testcases/misc/math/float/ does not include
> tfloat.h, but make check-tfloat.h prints errors. But make check in lib/ works as
> expected (adds also *.h).

The Sparse based tool does include headers though. So really we are
checking the target which includes more than just a single c file.

>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> Kind regards,
> Petr


-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH] tools: Check headers with checkpatch.pl
  2022-07-26 12:53         ` Richard Palethorpe
@ 2022-07-26 14:05           ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-07-26 14:05 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

...
> > LGTM, just a small nit: target for headers contain .h extension.
> > Shouldn't we add .c for C sources for consistency?

> > It'd strange, that make check in testcases/misc/math/float/ does not include
> > tfloat.h, but make check-tfloat.h prints errors. But make check in lib/ works as
> > expected (adds also *.h).

> The Sparse based tool does include headers though. So really we are
> checking the target which includes more than just a single c file.

Ah, that makes sense then. Thanks!

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-07-22 12:04 ` [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API Andrea Cervesato via ltp
@ 2022-08-11  9:53   ` Richard Palethorpe
  2022-08-11 11:13     ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Palethorpe @ 2022-08-11  9:53 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hello,

Andrea Cervesato via ltp <ltp@lists.linux.it> writes:

> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  runtest/containers                         |   3 +-
>  testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>  testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>  3 files changed, 166 insertions(+), 131 deletions(-)
>  create mode 100644 testcases/kernel/containers/mqns/common.h
>
> diff --git a/runtest/containers b/runtest/containers
> index 2637b62fe..863a964ad 100644
> --- a/runtest/containers
> +++ b/runtest/containers
> @@ -16,7 +16,8 @@ pidns31 pidns31
>  pidns32 pidns32
>  
>  mqns_01 mqns_01
> -mqns_01_clone mqns_01 -clone
> +mqns_01_clone mqns_01 -m clone
> +mqns_01_unshare mqns_01 -m unshare
>  mqns_02 mqns_02
>  mqns_02_clone mqns_02 -clone
>  mqns_03 mqns_03
> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
> new file mode 100644
> index 000000000..92a77b566
> --- /dev/null
> +++ b/testcases/kernel/containers/mqns/common.h
> @@ -0,0 +1,101 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#ifndef MQNS_H
> +#define MQNS_H
> +
> +#include <stdlib.h>
> +#include "lapi/namespaces_constants.h"
> +#include "tst_test.h"
> +#include "tst_safe_posix_ipc.h"
> +
> +enum {
> +	T_CLONE,
> +	T_UNSHARE,
> +	T_NONE,
> +};
> +
> +static int dummy_child1(void *v)
> +{
> +	(void)v;
> +	return 0;
> +}
> +
> +static inline void check_newipc(void)
> +{
> +	int pid, status;
> +
> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>  NULL);

ltp_clone_quick is still part of the old API and only uses clone2. I
think it should be replaced with tst_clone. This may require extending
tst_clone. In fact we probably need a test variant to switch between the
clone2 and clone3 syscalls when using tst_clone.

I'll leave it to you whether you want to try that and rebase this patch
set on it.

-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-08-11  9:53   ` Richard Palethorpe
@ 2022-08-11 11:13     ` Andrea Cervesato via ltp
  2022-09-02  9:05       ` Richard Palethorpe
  0 siblings, 1 reply; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-08-11 11:13 UTC (permalink / raw)
  To: rpalethorpe; +Cc: ltp

Hi!

On 8/11/22 11:53, Richard Palethorpe wrote:
> Hello,
>
> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>
>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>> ---
>>   runtest/containers                         |   3 +-
>>   testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>>   testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>>   3 files changed, 166 insertions(+), 131 deletions(-)
>>   create mode 100644 testcases/kernel/containers/mqns/common.h
>>
>> diff --git a/runtest/containers b/runtest/containers
>> index 2637b62fe..863a964ad 100644
>> --- a/runtest/containers
>> +++ b/runtest/containers
>> @@ -16,7 +16,8 @@ pidns31 pidns31
>>   pidns32 pidns32
>>   
>>   mqns_01 mqns_01
>> -mqns_01_clone mqns_01 -clone
>> +mqns_01_clone mqns_01 -m clone
>> +mqns_01_unshare mqns_01 -m unshare
>>   mqns_02 mqns_02
>>   mqns_02_clone mqns_02 -clone
>>   mqns_03 mqns_03
>> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
>> new file mode 100644
>> index 000000000..92a77b566
>> --- /dev/null
>> +++ b/testcases/kernel/containers/mqns/common.h
>> @@ -0,0 +1,101 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>> + */
>> +
>> +#ifndef MQNS_H
>> +#define MQNS_H
>> +
>> +#include <stdlib.h>
>> +#include "lapi/namespaces_constants.h"
>> +#include "tst_test.h"
>> +#include "tst_safe_posix_ipc.h"
>> +
>> +enum {
>> +	T_CLONE,
>> +	T_UNSHARE,
>> +	T_NONE,
>> +};
>> +
>> +static int dummy_child1(void *v)
>> +{
>> +	(void)v;
>> +	return 0;
>> +}
>> +
>> +static inline void check_newipc(void)
>> +{
>> +	int pid, status;
>> +
>> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>>   NULL);
> ltp_clone_quick is still part of the old API and only uses clone2. I
> think it should be replaced with tst_clone. This may require extending
> tst_clone. In fact we probably need a test variant to switch between the
> clone2 and clone3 syscalls when using tst_clone.
>
> I'll leave it to you whether you want to try that and rebase this patch
> set on it.
>
I see ltp_clone_quick as wrapper of ltp_clone, since it's using
ltp_alloc_stack without calling it explicitly all the times before 
ltp_clone.


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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-08-11 11:13     ` Andrea Cervesato via ltp
@ 2022-09-02  9:05       ` Richard Palethorpe
  2022-10-11  9:17         ` Richard Palethorpe
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Palethorpe @ 2022-09-02  9:05 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hello,

Andrea Cervesato <andrea.cervesato@suse.com> writes:

> Hi!
>
> On 8/11/22 11:53, Richard Palethorpe wrote:
>> Hello,
>>
>> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>>
>>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>>> ---
>>>   runtest/containers                         |   3 +-
>>>   testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>>>   testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>>>   3 files changed, 166 insertions(+), 131 deletions(-)
>>>   create mode 100644 testcases/kernel/containers/mqns/common.h
>>>
>>> diff --git a/runtest/containers b/runtest/containers
>>> index 2637b62fe..863a964ad 100644
>>> --- a/runtest/containers
>>> +++ b/runtest/containers
>>> @@ -16,7 +16,8 @@ pidns31 pidns31
>>>   pidns32 pidns32
>>>     mqns_01 mqns_01
>>> -mqns_01_clone mqns_01 -clone
>>> +mqns_01_clone mqns_01 -m clone
>>> +mqns_01_unshare mqns_01 -m unshare
>>>   mqns_02 mqns_02
>>>   mqns_02_clone mqns_02 -clone
>>>   mqns_03 mqns_03
>>> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
>>> new file mode 100644
>>> index 000000000..92a77b566
>>> --- /dev/null
>>> +++ b/testcases/kernel/containers/mqns/common.h
>>> @@ -0,0 +1,101 @@
>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>> +/*
>>> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>>> + */
>>> +
>>> +#ifndef MQNS_H
>>> +#define MQNS_H
>>> +
>>> +#include <stdlib.h>
>>> +#include "lapi/namespaces_constants.h"
>>> +#include "tst_test.h"
>>> +#include "tst_safe_posix_ipc.h"
>>> +
>>> +enum {
>>> +	T_CLONE,
>>> +	T_UNSHARE,
>>> +	T_NONE,
>>> +};
>>> +
>>> +static int dummy_child1(void *v)
>>> +{
>>> +	(void)v;
>>> +	return 0;
>>> +}
>>> +
>>> +static inline void check_newipc(void)
>>> +{
>>> +	int pid, status;
>>> +
>>> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>>>   NULL);
>> ltp_clone_quick is still part of the old API and only uses clone2. I
>> think it should be replaced with tst_clone. This may require extending
>> tst_clone. In fact we probably need a test variant to switch between the
>> clone2 and clone3 syscalls when using tst_clone.
>>
>> I'll leave it to you whether you want to try that and rebase this patch
>> set on it.
>>
> I see ltp_clone_quick as wrapper of ltp_clone, since it's using
> ltp_alloc_stack without calling it explicitly all the times before
> ltp_clone.

ltp_clone is also part of the old API. At some point we should remove that.

-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-09-02  9:05       ` Richard Palethorpe
@ 2022-10-11  9:17         ` Richard Palethorpe
  2022-10-11  9:42           ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Palethorpe @ 2022-10-11  9:17 UTC (permalink / raw)
  To: rpalethorpe; +Cc: ltp

Hello,

Richard Palethorpe <rpalethorpe@suse.de> writes:

> Hello,
>
> Andrea Cervesato <andrea.cervesato@suse.com> writes:
>
>> Hi!
>>
>> On 8/11/22 11:53, Richard Palethorpe wrote:
>>> Hello,
>>>
>>> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>>>
>>>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>>>> ---
>>>>   runtest/containers                         |   3 +-
>>>>   testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>>>>   testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>>>>   3 files changed, 166 insertions(+), 131 deletions(-)
>>>>   create mode 100644 testcases/kernel/containers/mqns/common.h
>>>>
>>>> diff --git a/runtest/containers b/runtest/containers
>>>> index 2637b62fe..863a964ad 100644
>>>> --- a/runtest/containers
>>>> +++ b/runtest/containers
>>>> @@ -16,7 +16,8 @@ pidns31 pidns31
>>>>   pidns32 pidns32
>>>>     mqns_01 mqns_01
>>>> -mqns_01_clone mqns_01 -clone
>>>> +mqns_01_clone mqns_01 -m clone
>>>> +mqns_01_unshare mqns_01 -m unshare
>>>>   mqns_02 mqns_02
>>>>   mqns_02_clone mqns_02 -clone
>>>>   mqns_03 mqns_03
>>>> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
>>>> new file mode 100644
>>>> index 000000000..92a77b566
>>>> --- /dev/null
>>>> +++ b/testcases/kernel/containers/mqns/common.h
>>>> @@ -0,0 +1,101 @@
>>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>>> +/*
>>>> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>>>> + */
>>>> +
>>>> +#ifndef MQNS_H
>>>> +#define MQNS_H
>>>> +
>>>> +#include <stdlib.h>
>>>> +#include "lapi/namespaces_constants.h"
>>>> +#include "tst_test.h"
>>>> +#include "tst_safe_posix_ipc.h"
>>>> +
>>>> +enum {
>>>> +	T_CLONE,
>>>> +	T_UNSHARE,
>>>> +	T_NONE,
>>>> +};
>>>> +
>>>> +static int dummy_child1(void *v)
>>>> +{
>>>> +	(void)v;
>>>> +	return 0;
>>>> +}
>>>> +
>>>> +static inline void check_newipc(void)
>>>> +{
>>>> +	int pid, status;
>>>> +
>>>> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>>>>   NULL);
>>> ltp_clone_quick is still part of the old API and only uses clone2. I
>>> think it should be replaced with tst_clone. This may require extending
>>> tst_clone. In fact we probably need a test variant to switch between the
>>> clone2 and clone3 syscalls when using tst_clone.
>>>
>>> I'll leave it to you whether you want to try that and rebase this patch
>>> set on it.
>>>
>> I see ltp_clone_quick as wrapper of ltp_clone, since it's using
>> ltp_alloc_stack without calling it explicitly all the times before
>> ltp_clone.
>
> ltp_clone is also part of the old API. At some point we should remove
> that.

I'm marking this as changes requested. tst_clone should be made to
support this scenario.

-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-10-11  9:17         ` Richard Palethorpe
@ 2022-10-11  9:42           ` Andrea Cervesato via ltp
  2022-10-11 10:49             ` Richard Palethorpe
  0 siblings, 1 reply; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-10-11  9:42 UTC (permalink / raw)
  To: rpalethorpe; +Cc: ltp

Hi

Are we sure that we don't need this modification before adding 
tst_clone? We can add the patch and then starting to think how to 
replace tst_clone_quick with tst_clone in all tests.

Andrea

On 10/11/22 11:17, Richard Palethorpe wrote:
> Hello,
>
> Richard Palethorpe <rpalethorpe@suse.de> writes:
>
>> Hello,
>>
>> Andrea Cervesato <andrea.cervesato@suse.com> writes:
>>
>>> Hi!
>>>
>>> On 8/11/22 11:53, Richard Palethorpe wrote:
>>>> Hello,
>>>>
>>>> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>>>>
>>>>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>>>>> ---
>>>>>    runtest/containers                         |   3 +-
>>>>>    testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>>>>>    testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>>>>>    3 files changed, 166 insertions(+), 131 deletions(-)
>>>>>    create mode 100644 testcases/kernel/containers/mqns/common.h
>>>>>
>>>>> diff --git a/runtest/containers b/runtest/containers
>>>>> index 2637b62fe..863a964ad 100644
>>>>> --- a/runtest/containers
>>>>> +++ b/runtest/containers
>>>>> @@ -16,7 +16,8 @@ pidns31 pidns31
>>>>>    pidns32 pidns32
>>>>>      mqns_01 mqns_01
>>>>> -mqns_01_clone mqns_01 -clone
>>>>> +mqns_01_clone mqns_01 -m clone
>>>>> +mqns_01_unshare mqns_01 -m unshare
>>>>>    mqns_02 mqns_02
>>>>>    mqns_02_clone mqns_02 -clone
>>>>>    mqns_03 mqns_03
>>>>> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
>>>>> new file mode 100644
>>>>> index 000000000..92a77b566
>>>>> --- /dev/null
>>>>> +++ b/testcases/kernel/containers/mqns/common.h
>>>>> @@ -0,0 +1,101 @@
>>>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>>>> +/*
>>>>> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>>>>> + */
>>>>> +
>>>>> +#ifndef MQNS_H
>>>>> +#define MQNS_H
>>>>> +
>>>>> +#include <stdlib.h>
>>>>> +#include "lapi/namespaces_constants.h"
>>>>> +#include "tst_test.h"
>>>>> +#include "tst_safe_posix_ipc.h"
>>>>> +
>>>>> +enum {
>>>>> +	T_CLONE,
>>>>> +	T_UNSHARE,
>>>>> +	T_NONE,
>>>>> +};
>>>>> +
>>>>> +static int dummy_child1(void *v)
>>>>> +{
>>>>> +	(void)v;
>>>>> +	return 0;
>>>>> +}
>>>>> +
>>>>> +static inline void check_newipc(void)
>>>>> +{
>>>>> +	int pid, status;
>>>>> +
>>>>> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>>>>>    NULL);
>>>> ltp_clone_quick is still part of the old API and only uses clone2. I
>>>> think it should be replaced with tst_clone. This may require extending
>>>> tst_clone. In fact we probably need a test variant to switch between the
>>>> clone2 and clone3 syscalls when using tst_clone.
>>>>
>>>> I'll leave it to you whether you want to try that and rebase this patch
>>>> set on it.
>>>>
>>> I see ltp_clone_quick as wrapper of ltp_clone, since it's using
>>> ltp_alloc_stack without calling it explicitly all the times before
>>> ltp_clone.
>> ltp_clone is also part of the old API. At some point we should remove
>> that.
> I'm marking this as changes requested. tst_clone should be made to
> support this scenario.
>


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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 0/7] Refactor mqns testing suite
  2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
                   ` (6 preceding siblings ...)
  2022-07-22 12:05 ` [LTP] [PATCH v3 7/7] Rename common.h into mqns.h for mqns suite Andrea Cervesato via ltp
@ 2022-10-11 10:15 ` Richard Palethorpe
  7 siblings, 0 replies; 23+ messages in thread
From: Richard Palethorpe @ 2022-10-11 10:15 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hello,

Andrea Cervesato via ltp <ltp@lists.linux.it> writes:

> mqns testing suite has been refactored using new LTP API

It would be easier to just submit one test for review and iterate on
it. This follows the principal of breaking work down into the smallest
chunk practically possible.

Sometimes submitting a large patchset is unavoidable, but this is not
the case here.

I'm setting all of these to "changes requested".

>
> Andrea Cervesato (7):
>   Add more safe macros for mqueue API
>   Refactor mqns_01 using new LTP API
>   Refactor mqns_02 using new LTP API
>   Refactor mqns_03 using new LTP API
>   Refactor mqns_04 using new LTP API
>   Delete deprecated mqns header files
>   Rename common.h into mqns.h for mqns suite
>
>  include/tst_safe_posix_ipc.h                  |  45 +++
>  runtest/containers                            |  12 +-
>  testcases/kernel/containers/mqns/Makefile     |  27 +-
>  testcases/kernel/containers/mqns/mqns.h       | 108 ++++++-
>  testcases/kernel/containers/mqns/mqns_01.c    | 185 ++++--------
>  testcases/kernel/containers/mqns/mqns_02.c    | 217 ++++----------
>  testcases/kernel/containers/mqns/mqns_03.c    | 269 +++++++-----------
>  testcases/kernel/containers/mqns/mqns_04.c    | 263 ++++++++---------
>  .../kernel/containers/mqns/mqns_helper.h      |  56 ----
>  9 files changed, 485 insertions(+), 697 deletions(-)
>  delete mode 100644 testcases/kernel/containers/mqns/mqns_helper.h
>
> -- 
> 2.35.3


-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-10-11  9:42           ` Andrea Cervesato via ltp
@ 2022-10-11 10:49             ` Richard Palethorpe
  2022-10-11 11:19               ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 23+ messages in thread
From: Richard Palethorpe @ 2022-10-11 10:49 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hello,

Andrea Cervesato <andrea.cervesato@suse.com> writes:

> Hi
>
> Are we sure that we don't need this modification before adding
> tst_clone? We can add the patch and then starting to think how to
> replace tst_clone_quick with tst_clone in all tests.

You're not the first person to use this argument. So it's actually
important for precisely the reason you don't want to do it. The next
person wont' want to do it either and we'll sleep walk into never
replacing it.

Meanwhile there are solid reasons why clone3 exists and why we should
test it. That's possibly more important than the API conversion.

BTW I could take over one of these patches and do the work on
tst_clone? I'm pretty familiar with it.

>
> Andrea
>
> On 10/11/22 11:17, Richard Palethorpe wrote:
>> Hello,
>>
>> Richard Palethorpe <rpalethorpe@suse.de> writes:
>>
>>> Hello,
>>>
>>> Andrea Cervesato <andrea.cervesato@suse.com> writes:
>>>
>>>> Hi!
>>>>
>>>> On 8/11/22 11:53, Richard Palethorpe wrote:
>>>>> Hello,
>>>>>
>>>>> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>>>>>
>>>>>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>>>>>> ---
>>>>>>    runtest/containers                         |   3 +-
>>>>>>    testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>>>>>>    testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>>>>>>    3 files changed, 166 insertions(+), 131 deletions(-)
>>>>>>    create mode 100644 testcases/kernel/containers/mqns/common.h
>>>>>>
>>>>>> diff --git a/runtest/containers b/runtest/containers
>>>>>> index 2637b62fe..863a964ad 100644
>>>>>> --- a/runtest/containers
>>>>>> +++ b/runtest/containers
>>>>>> @@ -16,7 +16,8 @@ pidns31 pidns31
>>>>>>    pidns32 pidns32
>>>>>>      mqns_01 mqns_01
>>>>>> -mqns_01_clone mqns_01 -clone
>>>>>> +mqns_01_clone mqns_01 -m clone
>>>>>> +mqns_01_unshare mqns_01 -m unshare
>>>>>>    mqns_02 mqns_02
>>>>>>    mqns_02_clone mqns_02 -clone
>>>>>>    mqns_03 mqns_03
>>>>>> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
>>>>>> new file mode 100644
>>>>>> index 000000000..92a77b566
>>>>>> --- /dev/null
>>>>>> +++ b/testcases/kernel/containers/mqns/common.h
>>>>>> @@ -0,0 +1,101 @@
>>>>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>>>>> +/*
>>>>>> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>>>>>> + */
>>>>>> +
>>>>>> +#ifndef MQNS_H
>>>>>> +#define MQNS_H
>>>>>> +
>>>>>> +#include <stdlib.h>
>>>>>> +#include "lapi/namespaces_constants.h"
>>>>>> +#include "tst_test.h"
>>>>>> +#include "tst_safe_posix_ipc.h"
>>>>>> +
>>>>>> +enum {
>>>>>> +	T_CLONE,
>>>>>> +	T_UNSHARE,
>>>>>> +	T_NONE,
>>>>>> +};
>>>>>> +
>>>>>> +static int dummy_child1(void *v)
>>>>>> +{
>>>>>> +	(void)v;
>>>>>> +	return 0;
>>>>>> +}
>>>>>> +
>>>>>> +static inline void check_newipc(void)
>>>>>> +{
>>>>>> +	int pid, status;
>>>>>> +
>>>>>> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>>>>>>    NULL);
>>>>> ltp_clone_quick is still part of the old API and only uses clone2. I
>>>>> think it should be replaced with tst_clone. This may require extending
>>>>> tst_clone. In fact we probably need a test variant to switch between the
>>>>> clone2 and clone3 syscalls when using tst_clone.
>>>>>
>>>>> I'll leave it to you whether you want to try that and rebase this patch
>>>>> set on it.
>>>>>
>>>> I see ltp_clone_quick as wrapper of ltp_clone, since it's using
>>>> ltp_alloc_stack without calling it explicitly all the times before
>>>> ltp_clone.
>>> ltp_clone is also part of the old API. At some point we should remove
>>> that.
>> I'm marking this as changes requested. tst_clone should be made to
>> support this scenario.
>>


-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API
  2022-10-11 10:49             ` Richard Palethorpe
@ 2022-10-11 11:19               ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 23+ messages in thread
From: Andrea Cervesato via ltp @ 2022-10-11 11:19 UTC (permalink / raw)
  To: rpalethorpe; +Cc: ltp

Hi

On 10/11/22 12:49, Richard Palethorpe wrote:
> Hello,
>
> Andrea Cervesato <andrea.cervesato@suse.com> writes:
>
>> Hi
>>
>> Are we sure that we don't need this modification before adding
>> tst_clone? We can add the patch and then starting to think how to
>> replace tst_clone_quick with tst_clone in all tests.
> You're not the first person to use this argument. So it's actually
> important for precisely the reason you don't want to do it. The next
> person wont' want to do it either and we'll sleep walk into never
> replacing it.
>
> Meanwhile there are solid reasons why clone3 exists and why we should
> test it. That's possibly more important than the API conversion.
>
> BTW I could take over one of these patches and do the work on
> tst_clone? I'm pretty familiar with it.

I can take care to change all tst_quick_clone after pushing these 
patches, no problem.
If you have an example how to use tst_clone, please do so. I will repeat 
the same patter to all remaining tests. Thanks!

Andrea

>> Andrea
>>
>> On 10/11/22 11:17, Richard Palethorpe wrote:
>>> Hello,
>>>
>>> Richard Palethorpe <rpalethorpe@suse.de> writes:
>>>
>>>> Hello,
>>>>
>>>> Andrea Cervesato <andrea.cervesato@suse.com> writes:
>>>>
>>>>> Hi!
>>>>>
>>>>> On 8/11/22 11:53, Richard Palethorpe wrote:
>>>>>> Hello,
>>>>>>
>>>>>> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>>>>>>
>>>>>>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>>>>>>> ---
>>>>>>>     runtest/containers                         |   3 +-
>>>>>>>     testcases/kernel/containers/mqns/common.h  | 101 +++++++++++
>>>>>>>     testcases/kernel/containers/mqns/mqns_01.c | 193 +++++++--------------
>>>>>>>     3 files changed, 166 insertions(+), 131 deletions(-)
>>>>>>>     create mode 100644 testcases/kernel/containers/mqns/common.h
>>>>>>>
>>>>>>> diff --git a/runtest/containers b/runtest/containers
>>>>>>> index 2637b62fe..863a964ad 100644
>>>>>>> --- a/runtest/containers
>>>>>>> +++ b/runtest/containers
>>>>>>> @@ -16,7 +16,8 @@ pidns31 pidns31
>>>>>>>     pidns32 pidns32
>>>>>>>       mqns_01 mqns_01
>>>>>>> -mqns_01_clone mqns_01 -clone
>>>>>>> +mqns_01_clone mqns_01 -m clone
>>>>>>> +mqns_01_unshare mqns_01 -m unshare
>>>>>>>     mqns_02 mqns_02
>>>>>>>     mqns_02_clone mqns_02 -clone
>>>>>>>     mqns_03 mqns_03
>>>>>>> diff --git a/testcases/kernel/containers/mqns/common.h b/testcases/kernel/containers/mqns/common.h
>>>>>>> new file mode 100644
>>>>>>> index 000000000..92a77b566
>>>>>>> --- /dev/null
>>>>>>> +++ b/testcases/kernel/containers/mqns/common.h
>>>>>>> @@ -0,0 +1,101 @@
>>>>>>> +// SPDX-License-Identifier: GPL-2.0-or-later
>>>>>>> +/*
>>>>>>> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>>>>>>> + */
>>>>>>> +
>>>>>>> +#ifndef MQNS_H
>>>>>>> +#define MQNS_H
>>>>>>> +
>>>>>>> +#include <stdlib.h>
>>>>>>> +#include "lapi/namespaces_constants.h"
>>>>>>> +#include "tst_test.h"
>>>>>>> +#include "tst_safe_posix_ipc.h"
>>>>>>> +
>>>>>>> +enum {
>>>>>>> +	T_CLONE,
>>>>>>> +	T_UNSHARE,
>>>>>>> +	T_NONE,
>>>>>>> +};
>>>>>>> +
>>>>>>> +static int dummy_child1(void *v)
>>>>>>> +{
>>>>>>> +	(void)v;
>>>>>>> +	return 0;
>>>>>>> +}
>>>>>>> +
>>>>>>> +static inline void check_newipc(void)
>>>>>>> +{
>>>>>>> +	int pid, status;
>>>>>>> +
>>>>>>> +	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child1,
>>>>>>>     NULL);
>>>>>> ltp_clone_quick is still part of the old API and only uses clone2. I
>>>>>> think it should be replaced with tst_clone. This may require extending
>>>>>> tst_clone. In fact we probably need a test variant to switch between the
>>>>>> clone2 and clone3 syscalls when using tst_clone.
>>>>>>
>>>>>> I'll leave it to you whether you want to try that and rebase this patch
>>>>>> set on it.
>>>>>>
>>>>> I see ltp_clone_quick as wrapper of ltp_clone, since it's using
>>>>> ltp_alloc_stack without calling it explicitly all the times before
>>>>> ltp_clone.
>>>> ltp_clone is also part of the old API. At some point we should remove
>>>> that.
>>> I'm marking this as changes requested. tst_clone should be made to
>>> support this scenario.
>>>
>


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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API
  2022-07-22 12:04 ` [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API Andrea Cervesato via ltp
  2022-07-26  6:50   ` Petr Vorel
@ 2022-11-01 11:36   ` Richard Palethorpe
  1 sibling, 0 replies; 23+ messages in thread
From: Richard Palethorpe @ 2022-11-01 11:36 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hello,

Merged, thanks!

Andrea Cervesato via ltp <ltp@lists.linux.it> writes:

> Added SAFE_MQ_UNLINK and SAFE_MQ_CLOSE in tst_safe_posix_ipc.h
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  include/tst_safe_posix_ipc.h | 45 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>
> diff --git a/include/tst_safe_posix_ipc.h b/include/tst_safe_posix_ipc.h
> index b60c12c9e..5bfef03a9 100644
> --- a/include/tst_safe_posix_ipc.h
> +++ b/include/tst_safe_posix_ipc.h
> @@ -12,6 +12,12 @@
>  #define SAFE_MQ_OPEN(pathname, oflags, ...) \
>  	safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__)
>  
> +#define SAFE_MQ_CLOSE(__mqdes) \
> +	safe_mq_close(__FILE__, __LINE__, (__mqdes))
> +
> +#define SAFE_MQ_UNLINK(name) \
> +	safe_mq_unlink(__FILE__, __LINE__, (name))
> +
>  static inline int safe_mq_open(const char *file, const int lineno,
>  			       const char *pathname, int oflags, ...)
>  {
> @@ -41,6 +47,45 @@ static inline int safe_mq_open(const char *file, const int lineno,
>  		tst_brk_(file, lineno, TBROK | TERRNO,
>  			"mq_open(%s,%d,%04o,%p) failed", pathname, oflags,
>  			mode, attr);
> +	} else if (rval < 0) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"Invalid mq_open(%s) return value %d", pathname, rval);
> +	}
> +
> +	return rval;
> +}
> +
> +static inline int safe_mq_close(const char *file, const int lineno,
> +				mqd_t __mqdes)
> +{
> +	int rval;
> +
> +	rval = mq_close(__mqdes);
> +
> +	if (rval == -1) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"mq_close(%d) failed", __mqdes);
> +	} else if (rval < 0) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"Invalid mq_close(%d) return value %d", __mqdes, rval);
> +	}
> +
> +	return rval;
> +}
> +
> +static inline int safe_mq_unlink(const char *file, const int lineno,
> +				const char* name)
> +{
> +	int rval;
> +
> +	rval = mq_unlink(name);
> +
> +	if (rval == -1) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"mq_unlink(%s) failed", name);
> +	} else if (rval < 0) {
> +		tst_brk_(file, lineno, TBROK | TERRNO,
> +			"Invalid mq_unlink(%s) return value %d", name, rval);
>  	}
>  
>  	return rval;
> -- 
> 2.35.3


-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2022-11-01 11:37 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 12:04 [LTP] [PATCH v3 0/7] Refactor mqns testing suite Andrea Cervesato via ltp
2022-07-22 12:04 ` [LTP] [PATCH v3 1/7] Add more safe macros for mqueue API Andrea Cervesato via ltp
2022-07-26  6:50   ` Petr Vorel
2022-11-01 11:36   ` Richard Palethorpe
2022-07-22 12:04 ` [LTP] [PATCH v3 2/7] Refactor mqns_01 using new LTP API Andrea Cervesato via ltp
2022-08-11  9:53   ` Richard Palethorpe
2022-08-11 11:13     ` Andrea Cervesato via ltp
2022-09-02  9:05       ` Richard Palethorpe
2022-10-11  9:17         ` Richard Palethorpe
2022-10-11  9:42           ` Andrea Cervesato via ltp
2022-10-11 10:49             ` Richard Palethorpe
2022-10-11 11:19               ` Andrea Cervesato via ltp
2022-07-22 12:04 ` [LTP] [PATCH v3 3/7] Refactor mqns_02 " Andrea Cervesato via ltp
2022-07-22 12:04 ` [LTP] [PATCH v3 4/7] Refactor mqns_03 " Andrea Cervesato via ltp
2022-07-22 12:04 ` [LTP] [PATCH v3 5/7] Refactor mqns_04 " Andrea Cervesato via ltp
2022-07-22 12:05 ` [LTP] [PATCH v3 6/7] Delete deprecated mqns header files Andrea Cervesato via ltp
2022-07-22 12:05 ` [LTP] [PATCH v3 7/7] Rename common.h into mqns.h for mqns suite Andrea Cervesato via ltp
2022-07-26  7:00   ` Petr Vorel
2022-07-26 11:52     ` [LTP] [PATCH] tools: Check headers with checkpatch.pl Richard Palethorpe via ltp
2022-07-26 12:03       ` Petr Vorel
2022-07-26 12:53         ` Richard Palethorpe
2022-07-26 14:05           ` Petr Vorel
2022-10-11 10:15 ` [LTP] [PATCH v3 0/7] Refactor mqns testing suite Richard Palethorpe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.