All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases
@ 2018-06-12 15:46 Cyril Hrubis
  2018-06-12 15:46 ` [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer Cyril Hrubis
                   ` (9 more replies)
  0 siblings, 10 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp



Cyril Hrubis (9):
  tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer
  tst_safe_sysv_ipc: SAFE_{SHMCTL,MSGCTL} return retval
  syscalls/ipc: Rewrite msgctl01 + merge msgctl06
  syscalls/ipc: Rewrite msgctl02 to new library.
  syscalls/ipc: Convert to newlib and merge msgctl{13,03}
  syscalls/ipc: Rewrite + merge msgctl{04, 05}
  syscalls/ipc: Rewrite msgctl12 to new library
  syscalls/ipc: Remove msgctl07
  syscalls/ipc: Fix Makefile

 include/tst_safe_sysv_ipc.h                     |  12 +-
 lib/tst_safe_sysv_ipc.c                         |  33 ++-
 runtest/ltplite                                 |   3 -
 runtest/stress.part3                            |   3 -
 runtest/syscalls                                |   4 -
 runtest/syscalls-ipc                            |   4 -
 testcases/kernel/syscalls/ipc/msgctl/.gitignore |   4 -
 testcases/kernel/syscalls/ipc/msgctl/Makefile   |   8 +-
 testcases/kernel/syscalls/ipc/msgctl/msgctl01.c | 242 ++++++++++----------
 testcases/kernel/syscalls/ipc/msgctl/msgctl02.c | 207 +++++------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl03.c | 159 +++----------
 testcases/kernel/syscalls/ipc/msgctl/msgctl04.c | 249 +++++++-------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl05.c | 186 ---------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl06.c | 142 ------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl07.c | 292 ------------------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl12.c |  84 +++----
 testcases/kernel/syscalls/ipc/msgctl/msgctl13.c |  86 -------
 17 files changed, 360 insertions(+), 1358 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl05.c
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl06.c
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl07.c
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl13.c

-- 
2.13.6


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

* [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 10:32   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 2/9] tst_safe_sysv_ipc: SAFE_{SHMCTL, MSGCTL} return retval Cyril Hrubis
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

We recently had a regression in Sys V IPC when IPC_STAT returned
non-zero integer on success wrongly, which wasn't caught by LTP test but
breaks software in the wild.

This commit changes safe_shmctl() and safe_msgctl() to check the return
value with != 0 for IPC_STAT, IPC_SET and IPC_RMID and with == -1
otherwise.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 lib/tst_safe_sysv_ipc.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/lib/tst_safe_sysv_ipc.c b/lib/tst_safe_sysv_ipc.c
index ff53a2420..86f2d934b 100644
--- a/lib/tst_safe_sysv_ipc.c
+++ b/lib/tst_safe_sysv_ipc.c
@@ -23,6 +23,24 @@
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
 
+/*
+ * The IPC_STAT, IPC_SET and IPC_RMID can return either 0 or -1.
+ *
+ * Linux specific cmds either returns -1 on failure or positive integer
+ * either index into an kernel array or shared primitive indentifier.
+ */
+static int ret_check(int cmd, int ret)
+{
+	switch (cmd) {
+	case IPC_STAT:
+	case IPC_SET:
+	case IPC_RMID:
+		return ret != 0;
+	default:
+		return ret == -1;
+	}
+}
+
 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg)
 {
 	int rval;
@@ -72,11 +90,13 @@ int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
 	int rval;
 
 	rval = msgctl(msqid, cmd, buf);
-	if (rval == -1) {
-		tst_brk(TBROK | TERRNO, "%s:%d: msgctl(%i, %i, %p) failed",
-			file, lineno, msqid, cmd, buf);
+	if (ret_check(cmd, rval)) {
+		tst_brk(TBROK | TERRNO,
+			"%s:%d: msgctl(%i, %i, %p) = %i failed",
+			file, lineno, msqid, cmd, buf, rval);
 	}
 
+
 	return rval;
 }
 
@@ -127,9 +147,10 @@ int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
 	int rval;
 
 	rval = shmctl(shmid, cmd, buf);
-	if (rval == -1) {
-		tst_brk(TBROK | TERRNO, "%s:%d: shmctl(%i, %i, %p) failed",
-			file, lineno, shmid, cmd, buf);
+	if (ret_check(cmd, rval)) {
+		tst_brk(TBROK | TERRNO,
+			"%s:%d: shmctl(%i, %i, %p) = %i failed",
+			file, lineno, shmid, cmd, buf, rval);
 	}
 
 	return rval;
-- 
2.13.6


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

* [LTP] [RFC PATCH 2/9] tst_safe_sysv_ipc: SAFE_{SHMCTL, MSGCTL} return retval
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
  2018-06-12 15:46 ` [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 10:49   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06 Cyril Hrubis
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

These calls do return index into kernel internal array or IPC id for
Linux specific cmds, hence we need to propagate the return value.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_safe_sysv_ipc.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/tst_safe_sysv_ipc.h b/include/tst_safe_sysv_ipc.h
index e01957f75..4c7500531 100644
--- a/include/tst_safe_sysv_ipc.h
+++ b/include/tst_safe_sysv_ipc.h
@@ -39,10 +39,10 @@ ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
 
 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
 		struct msqid_ds *buf);
-#define SAFE_MSGCTL(msqid, cmd, buf) do { \
-	safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf)); \
+#define SAFE_MSGCTL(msqid, cmd, buf) ({ \
+	int tst_ret_ = safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf)); \
 	(msqid) = ((cmd) == IPC_RMID ? -1 : (msqid)); \
-	} while (0)
+	tst_ret_;})
 
 int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
 		int shmflg);
@@ -59,9 +59,9 @@ int safe_shmdt(const char *file, const int lineno, const void *shmaddr);
 
 int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
 		struct shmid_ds *buf);
-#define SAFE_SHMCTL(shmid, cmd, buf) do { \
-	safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \
+#define SAFE_SHMCTL(shmid, cmd, buf) ({ \
+	int tst_ret_ = safe_shmctl(__FILE__, __LINE__, (shmid), (cmd), (buf)); \
 	(shmid) = ((cmd) == IPC_RMID ? -1 : (shmid)); \
-	} while (0)
+	tst_ret_;})
 
 #endif /* TST_SAFE_SYSV_IPC_H__ */
-- 
2.13.6


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

* [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
  2018-06-12 15:46 ` [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer Cyril Hrubis
  2018-06-12 15:46 ` [LTP] [RFC PATCH 2/9] tst_safe_sysv_ipc: SAFE_{SHMCTL, MSGCTL} return retval Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13  8:56   ` Li Wang
  2018-06-13 11:24   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 4/9] syscalls/ipc: Rewrite msgctl02 to new library Cyril Hrubis
                   ` (6 subsequent siblings)
  9 siblings, 2 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

Rewrite msgctl01 to be much more strict, now we assert all fields of the
buffer we get from IPC_STAT.

This also removes msgctl06 that was testing the very same IPC_STAT
command but checked different subset of the msqid_ds buffer.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/ltplite                                 |   1 -
 runtest/stress.part3                            |   1 -
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/ipc/msgctl/.gitignore |   1 -
 testcases/kernel/syscalls/ipc/msgctl/msgctl01.c | 242 ++++++++++++------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl06.c | 142 --------------
 7 files changed, 122 insertions(+), 267 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 249262674..cb9517883 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -484,7 +484,6 @@ msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
 msgctl05 msgctl05
-msgctl06 msgctl06
 msgctl07 msgctl07
 
 msgget01 msgget01
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index d9287197b..e97b08456 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -400,7 +400,6 @@ msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
 msgctl05 msgctl05
-msgctl06 msgctl06
 msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
diff --git a/runtest/syscalls b/runtest/syscalls
index 65c96edab..7befd5c66 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -690,7 +690,6 @@ msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
 msgctl05 msgctl05
-msgctl06 msgctl06
 msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index c734e239d..9ae91bb4c 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -3,7 +3,6 @@ msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
 msgctl05 msgctl05
-msgctl06 msgctl06
 msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
diff --git a/testcases/kernel/syscalls/ipc/msgctl/.gitignore b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
index 2edde5de4..257a2231b 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/.gitignore
+++ b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
@@ -3,7 +3,6 @@
 /msgctl03
 /msgctl04
 /msgctl05
-/msgctl06
 /msgctl07
 /msgctl12
 /msgctl13
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl01.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl01.c
index 18389627d..aa8d075e9 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl01.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl01.c
@@ -1,153 +1,155 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *	03/2001 - Written by Wayne Boyer
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   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 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.
+ * 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
+ * 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
  */
 
 /*
- * NAME
- *	msgctl01.c
- *
- * DESCRIPTION
- *	msgctl01 - create a message queue, then issue the IPC_STAT command
- *		   and RMID commands to test the functionality
- *
- * ALGORITHM
- *	create a message queue
- *	loop if that option was specified
- *	call msgctl() with the IPC_STAT command
- *	check the return code
- *	  if failure, issue a FAIL message and break remaining tests
- *	otherwise,
- *	  if doing functionality testing
- *	  	if the max number of bytes on the queue is > 0,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	  else issue a PASS message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgctl01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * Test that IPC_STAT command succeeds and the the buffer is filled with
+ * correct data.
  */
+#include <errno.h>
 
-#include "test.h"
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
-#include "ipcmsg.h"
+static int msg_id = -1;
+static time_t creat_time;
+static key_t msgkey;
+static uid_t uid;
+static gid_t gid;
+unsigned short mode = 0660;
 
-char *TCID = "msgctl01";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1;		/* to hold the message queue id */
+static void verify_msgctl(void)
+{
+	struct msqid_ds buf;
 
-struct msqid_ds qs_buf;
+	memset(&buf, 'a', sizeof(buf));
+	TEST(msgctl(msg_id, IPC_STAT, &buf));
 
-int main(int ac, char **av)
-{
-	int lc;
+	if (TEST_RETURN != 0) {
+		tst_res(TFAIL | TTERRNO, "msgctl() returned %li", TEST_RETURN);
+		return;
+	}
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	tst_res(TPASS, "msgctl(IPC_STAT)");
 
-	setup();		/* global setup */
+	if (buf.msg_stime == 0)
+		tst_res(TPASS, "msg_stime = 0");
+	else
+		tst_res(TFAIL, "msg_stime = %lu", (unsigned long)buf.msg_stime);
 
-	/* The following loop checks looping state if -i option given */
+	if (buf.msg_rtime == 0)
+		tst_res(TPASS, "msg_rtime = 0");
+	else
+		tst_res(TFAIL, "msg_rtime = %lu", (unsigned long)buf.msg_rtime);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
+	if (buf.msg_ctime == creat_time || buf.msg_ctime == creat_time + 1) {
+		tst_res(TPASS, "msg_ctime = %lu, expected %lu",
+			(unsigned long)buf.msg_ctime, (unsigned long)creat_time);
+	} else {
+		tst_res(TPASS, "msg_ctime = %lu, expected %lu",
+			(unsigned long)buf.msg_ctime, (unsigned long)creat_time);
+	}
 
-		/*
-		 * Get the msqid_ds structure values for the queue
-		 */
+	if (buf.msg_qnum == 0)
+		tst_res(TPASS, "msg_qnum = 0");
+	else
+		tst_res(TFAIL, "msg_qnum = %li", (long)buf.msg_qnum);
+
+	if (buf.msg_qbytes > 0)
+		tst_res(TPASS, "msg_qbytes = %li", (long)buf.msg_qbytes);
+	else
+		tst_res(TFAIL, "msg_qbytes = %li", (long)buf.msg_qbytes);
+
+	if (buf.msg_lspid == 0)
+		tst_res(TPASS, "msg_lspid = 0");
+	else
+		tst_res(TFAIL, "msg_lspid = %u", (unsigned)buf.msg_lspid);
+
+	if (buf.msg_lrpid == 0)
+		tst_res(TPASS, "msg_lrpid = 0");
+	else
+		tst_res(TFAIL, "msg_lrpid = %u", (unsigned)buf.msg_lrpid);
+
+	if (buf.msg_perm.__key == msgkey) {
+		tst_res(TPASS, "msg_perm.__key == %u", (unsigned)msgkey);
+	} else {
+		tst_res(TFAIL, "msg_perm.__key == %u, expected %u",
+			(unsigned)buf.msg_perm.__key, (unsigned)msgkey);
+	}
 
-		TEST(msgctl(msg_q_1, IPC_STAT, &qs_buf));
+	if (buf.msg_perm.uid == uid) {
+		tst_res(TPASS, "msg_perm.uid = %u", (unsigned)uid);
+	} else {
+		tst_res(TFAIL, "msg_perm.uid = %u, expected %u",
+			(unsigned)buf.msg_perm.uid, (unsigned)uid);
+	}
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "msgctl() call failed");
-		} else {
-			if (qs_buf.msg_qbytes > 0) {
-				tst_resm(TPASS, "qs_buf.msg_qbytes is"
-					 " a positive value");
-			} else {
-				tst_resm(TFAIL, "qs_buf.msg_qbytes did"
-					 " not change");
-			}
-		}
+	if (buf.msg_perm.gid == gid) {
+		tst_res(TPASS, "msg_perm.gid = %u", (unsigned)gid);
+	} else {
+		tst_res(TFAIL, "msg_perm.gid = %u, expected %u",
+			(unsigned)buf.msg_perm.gid, (unsigned)gid);
+	}
 
-		/*
-		 * clean up things in case we are looping
-		 */
-		qs_buf.msg_qbytes = 0x0000;
+	if (buf.msg_perm.cuid == uid) {
+		tst_res(TPASS, "msg_perm.cuid = %u", (unsigned)uid);
+	} else {
+		tst_res(TFAIL, "msg_perm.cuid = %u, expected %u",
+			(unsigned)buf.msg_perm.cuid, (unsigned)uid);
 	}
 
-	cleanup();
+	if (buf.msg_perm.cgid == gid) {
+		tst_res(TPASS, "msg_perm.cgid = %u", (unsigned)gid);
+	} else {
+		tst_res(TFAIL, "msg_perm.cgid = %u, expected %u",
+			(unsigned)buf.msg_perm.cgid, (unsigned)gid);
+	}
 
-	tst_exit();
+	if ((buf.msg_perm.mode & MODE_MASK) == (mode & MODE_MASK)) {
+		tst_res(TPASS, "msg_perm.mode = 0%ho", mode & MODE_MASK);
+	} else {
+		tst_res(TFAIL, "msg_perm.mode = 0%ho, expected %hx",
+			buf.msg_perm.mode, (mode & MODE_MASK));
+	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	msgkey = GETIPCKEY();
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get a message key */
-	msgkey = getipckey();
+	msg_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW | mode);
+	time(&creat_time);
 
-	/* make sure the initial # of bytes is 0 in our buffer */
-	qs_buf.msg_qbytes = 0x0000;
-
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-	}
+	uid = geteuid();
+	gid = getegid();
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/* if it exists, remove the message queue */
-	rm_queue(msg_q_1);
-
-	tst_rmdir();
-
+	if (msg_id > 0)
+		SAFE_MSGCTL(msg_id, IPC_RMID, NULL);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgctl,
+	.needs_tmpdir = 1
+};
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl06.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl06.c
deleted file mode 100644
index 297b5939f..000000000
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl06.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   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
- */
-
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-/* 11/06/2002	Port to LTP	dbarrera@us.ibm.com */
-/* 12/03/2008   Fix concurrency issue     mfertre@irisa.fr */
-
-/*
- * NAME
- *	msgctl06
- *
- * CALLS
- *	msgget(2) msgctl(2)
- *
- * ALGORITHM
- *	Get and manipulate a message queue.
- *
- * RESTRICTIONS
- *
- */
-
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <stdio.h>
-#include "test.h"
-#include "ipcmsg.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "msgctl06";
-int TST_TOTAL = 1;
-
-/*
- * msgctl3_t -- union of msgctl(2)'s possible argument # 3 types.
- */
-typedef union msgctl3_u {
-	struct msqid_ds *msq_ds;	/* pointer to msqid_ds struct */
-	struct ipc_acl *msq_acl;	/* pointer ACL buff and size */
-} msgctl3_t;
-
-extern int local_flag;
-
-int msqid, status;
-struct msqid_ds buf;
-
-int main(int argc, char *argv[])
-{
-	key_t key;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	key = getipckey();
-	TEST(msgget(key, IPC_CREAT | IPC_EXCL));
-	msqid = TEST_RETURN;
-	if (TEST_RETURN == -1) {
-		tst_brkm(TFAIL | TTERRNO, NULL, "msgget() failed");
-	}
-
-	TEST(msgctl(msqid, IPC_STAT, &buf));
-	status = TEST_RETURN;
-	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO,
-			 "msgctl(msqid, IPC_STAT, &buf) failed");
-		(void)msgctl(msqid, IPC_RMID, NULL);
-		tst_exit();
-	}
-
-	/*
-	 * Check contents of msqid_ds structure.
-	 */
-
-	if (buf.msg_qnum != 0) {
-		tst_brkm(TFAIL, NULL, "error: unexpected nbr of messages %ld",
-			 buf.msg_qnum);
-	}
-	if (buf.msg_perm.uid != getuid()) {
-		tst_brkm(TFAIL, NULL, "error: unexpected uid %d",
-			 buf.msg_perm.uid);
-	}
-	if (buf.msg_perm.gid != getgid()) {
-		tst_brkm(TFAIL, NULL, "error: unexpected gid %d",
-			 buf.msg_perm.gid);
-	}
-	if (buf.msg_perm.cuid != getuid()) {
-		tst_brkm(TFAIL, NULL, "error: unexpected cuid %d",
-			 buf.msg_perm.cuid);
-	}
-	if (buf.msg_perm.cgid != getgid()) {
-		tst_brkm(TFAIL, NULL, "error: unexpected cgid %d",
-			 buf.msg_perm.cgid);
-	}
-
-	tst_resm(TPASS, "msgctl06 ran successfully!");
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-}
-
-void cleanup(void)
-{
-	int status;
-
-	(void)msgctl(msqid, IPC_RMID, NULL);
-	if ((status = msgctl(msqid, IPC_STAT, &buf)) != -1) {
-		(void)msgctl(msqid, IPC_RMID, NULL);
-		tst_resm(TFAIL, "msgctl(msqid, IPC_RMID) failed");
-
-	}
-
-	tst_rmdir();
-}
-- 
2.13.6


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

* [LTP] [RFC PATCH 4/9] syscalls/ipc: Rewrite msgctl02 to new library.
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (2 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06 Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 11:47   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 5/9] syscalls/ipc: Convert to newlib and merge msgctl{13, 03} Cyril Hrubis
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/ipc/msgctl/msgctl02.c | 207 +++++++-----------------
 1 file changed, 58 insertions(+), 149 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl02.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl02.c
index 1b3909197..008fd4f71 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl02.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl02.c
@@ -1,175 +1,84 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *    03/2001 - Written by Wayne Boyer
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * 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 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.
  *
- *   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
+ * 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
  */
-
 /*
- * NAME
- *	msgctl02.c
- *
- * DESCRIPTION
- *	msgctl02 - create a message queue, then issue the IPC_SET command
- *		   to lower the msg_qbytes value.
- *
- * ALGORITHM
- *	create a message queue
- *	loop if that option was specified
- *	call msgctl() with the IPC_SET command with a new msg_qbytes value
- *	check the return code
- *	  if failure, issue a FAIL message and break remaining tests
- *	otherwise,
- *	  if doing functionality testing
- *	  	if the msg_qbytes value is the new value
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	  else issue a PASS message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgctl02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * Create a message queue, then issue the IPC_SET command to lower the
+ * msg_qbytes value.
  */
 
-#include "test.h"
+#include <errno.h>
 
-#include "ipcmsg.h"
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
-char *TCID = "msgctl02";
-int TST_TOTAL = 1;
+static int msg_id = -1;
+struct msqid_ds orig_buf;
 
-int msg_q_1 = -1;		/* to hold the message queue id */
-
-struct msqid_ds qs_buf;
-
-unsigned long int new_bytes;
-
-int main(int ac, char **av)
+static void verify_msgctl(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * Set the msqid_ds structure values for the queue
-		 */
-
-		TEST(msgctl(msg_q_1, IPC_SET, &qs_buf));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "msgctl() call failed");
-		} else {
-			/* do a stat to get current queue values */
-			if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)) {
-				tst_resm(TBROK, "stat on queue failed");
-				continue;
-			}
-
-			if (qs_buf.msg_qbytes == new_bytes) {
-				tst_resm(TPASS, "qs_buf.msg_qbytes is"
-					 " the new value - %ld",
-					 qs_buf.msg_qbytes);
-			} else {
-				tst_resm(TFAIL, "qs_buf.msg_qbytes "
-					 "value is not expected");
-				tst_resm(TINFO, "expected - %ld, "
-					 "received - %ld", new_bytes,
-					 qs_buf.msg_qbytes);
-			}
-		}
-
-		/*
-		 * decrement by one the msq_qbytes value
-		 */
-		qs_buf.msg_qbytes -= 1;
-		new_bytes = qs_buf.msg_qbytes;
-	}
+	struct msqid_ds buf = orig_buf;
 
-	cleanup();
+	buf.msg_qbytes -= 1;
 
-	tst_exit();
-}
+	TEST(msgctl(msg_id, IPC_SET, &buf));
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get a message key */
-	msgkey = getipckey();
+	if (TEST_RETURN != 0) {
+		tst_res(TFAIL | TTERRNO, "msgctl(IPC_SET) failed");
+		return;
+	}
 
-	/* make sure the initial # of bytes is 0 in our buffer */
-	qs_buf.msg_qbytes = 0x3000;
+	tst_res(TPASS, "msgctl(IPC_SET) msg_qbytes - 1");
 
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-	}
+	memset(&buf, 0, sizeof(buf));
+	SAFE_MSGCTL(msg_id, IPC_STAT, &buf);
 
-	/* now stat the queue to get the default msg_qbytes value */
-	if ((msgctl(msg_q_1, IPC_STAT, &qs_buf)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't stat the message queue");
+	if (buf.msg_qbytes == orig_buf.msg_qbytes - 1) {
+		tst_res(TPASS, "msg_qbytes = %lu",
+			(unsigned long)buf.msg_qbytes);
+	} else {
+		tst_res(TFAIL, "msg_qbytes = %lu, expected %lu",
+			(unsigned long)buf.msg_qbytes,
+			(unsigned long)orig_buf.msg_qbytes - 1);
 	}
 
-	/* decrement msg_qbytes and copy its value */
-	qs_buf.msg_qbytes -= 1;
-	new_bytes = qs_buf.msg_qbytes;
+	SAFE_MSGCTL(msg_id, IPC_SET, &orig_buf);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void setup(void)
 {
-	/* if it exists, remove the message queue */
-	rm_queue(msg_q_1);
+	key_t msgkey = GETIPCKEY();
+
+	msg_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW | 0660);
 
-	tst_rmdir();
+	SAFE_MSGCTL(msg_id, IPC_STAT, &orig_buf);
+}
 
+static void cleanup(void)
+{
+	if (msg_id > 0)
+		SAFE_MSGCTL(msg_id, IPC_RMID, NULL);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgctl,
+	.needs_tmpdir = 1
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 5/9] syscalls/ipc: Convert to newlib and merge msgctl{13, 03}
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (3 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 4/9] syscalls/ipc: Rewrite msgctl02 to new library Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 11:55   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 6/9] syscalls/ipc: Rewrite + merge msgctl{04, 05} Cyril Hrubis
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

These two tests were both testing IPC_RMID, so I've merged then into
msgctl03 and rewritten the test to new test library.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/ipc/msgctl/.gitignore |   1 -
 testcases/kernel/syscalls/ipc/msgctl/msgctl03.c | 159 ++++++------------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl13.c |  86 -------------
 5 files changed, 35 insertions(+), 213 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl13.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 7befd5c66..6b3133776 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -696,7 +696,6 @@ msgstress02 msgstress02
 msgstress03 msgstress03
 msgstress04 msgstress04
 msgctl12 msgctl12
-msgctl13 msgctl13
 
 msgget01 msgget01
 msgget02 msgget02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 9ae91bb4c..6cf5853dd 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -9,7 +9,6 @@ msgstress02 msgstress02
 msgstress03 msgstress03
 msgstress04 msgstress04
 msgctl12 msgctl12
-msgctl13 msgctl13
 
 msgget01 msgget01
 msgget02 msgget02
diff --git a/testcases/kernel/syscalls/ipc/msgctl/.gitignore b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
index 257a2231b..b321f0c35 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/.gitignore
+++ b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
@@ -5,4 +5,3 @@
 /msgctl05
 /msgctl07
 /msgctl12
-/msgctl13
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl03.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl03.c
index 4693b89b6..836d6e76d 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl03.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl03.c
@@ -1,143 +1,54 @@
 /*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
  *
- *   This program is 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 would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  *
- *   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
+ * You should have received a copy of the GNU General Public License along
+ * with this program.
  */
-
 /*
- * NAME
- *	msgctl03.c
- *
  * DESCRIPTION
- *	msgctl03 - create a message queue, then issue the IPC_RMID command
- *
- * ALGORITHM
- *	create a message queue
- *	loop if that option was specified
- *	call msgctl() with the IPC_RMID command
- *	check the return code
- *	  if failure, issue a FAIL message and break remaining tests
- *	otherwise,
- *	  if doing functionality testing
- *		issue an IPC_STAT on the queue that was just removed
- *	  	if the call fails
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	  else issue a PASS message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgctl03 [-c n] [-f] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	This test does not support looping.
+ *	msgctl13 - test for IPC_RMID
  */
+#include <errno.h>
 
-#include "test.h"
-
-#include "ipcmsg.h"
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
-char *TCID = "msgctl03";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1;		/* to hold the message queue id */
-
-struct msqid_ds qs_buf;
-
-int main(int ac, char **av)
+static void verify_msgctl(void)
 {
+	struct msqid_ds buf;
+	int msg_q;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
+	msg_q = SAFE_MSGGET(IPC_PRIVATE, MSG_RW);
 
-	/*
-	 * Remove the queue that was created in setup()
-	 */
-
-	TEST(msgctl(msg_q_1, IPC_RMID, NULL));
-
-	if (TEST_RETURN == -1) {
-		tst_brkm(TFAIL | TTERRNO, cleanup, "msgctl() call failed");
-	} else {
-		/*
-		 * if the queue is gone, then an IPC_STAT msgctl()
-		 * call should generate an EINVAL error.
-		 */
-		if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)) {
-			if (errno == EINVAL) {
-				tst_resm(TPASS, "The queue is gone");
-			} else {
-				tst_resm(TFAIL, "IPC_RMID succeeded ,"
-					 " but functional test did not"
-					 " get expected EINVAL error");
-			}
-		}
+	TEST(msgctl(msg_q, IPC_RMID, NULL));
+	if (TEST_RETURN != 0) {
+		tst_res(TFAIL | TTERRNO, "msgctl(IPC_RMID) failed");
+		return;
 	}
 
-	msg_q_1 = -1;
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
-	tst_tmpdir();
+	tst_res(TPASS, "msgctl(IPC_RMID)");
 
-	/* get a message key */
-	msgkey = getipckey();
-
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
+	TEST(msgctl(msg_q, IPC_STAT, &buf));
+	if (TEST_ERRNO == EINVAL) {
+		tst_res(TPASS | TTERRNO, "msgctl(IPC_STAT)");
+	} else {
+		tst_res(TFAIL | TTERRNO,
+			"msgctl(IPC_STAT) returned %li", TEST_RETURN);
 	}
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-	/* if it exists, remove the message queue */
-	rm_queue(msg_q_1);
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.test_all = verify_msgctl,
+	.needs_tmpdir = 1
+};
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl13.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl13.c
deleted file mode 100644
index 50d48d4dd..000000000
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl13.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2014 Fujitsu Ltd.
- * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program.
- */
-/*
- * DESCRIPTION
- *	msgctl13 - test for IPC_RMID
- */
-
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <errno.h>
-
-#include "test.h"
-#include "ipcmsg.h"
-
-char *TCID = "msgctl13";
-int TST_TOTAL = 1;
-static struct msqid_ds buf;
-
-static void msgctl_verify(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		msgctl_verify();
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void msgctl_verify(void)
-{
-	int msg_q;
-
-	msg_q = msgget(IPC_PRIVATE, MSG_RW);
-	if (msg_q == -1)
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-
-	TEST(msgctl(msg_q, IPC_RMID, NULL));
-
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL, "msgctl() test IPC_RMID failed with errno: %d",
-			 TEST_ERRNO);
-		return;
-	}
-
-	TEST(msgctl(msg_q, IPC_STAT, &buf));
-	if (TEST_ERRNO == EINVAL)
-		tst_resm(TPASS, "msgctl() test IPC_RMID succeeded");
-	else
-		tst_resm(TFAIL, "msgctl() test IPC_RMID failed unexpectedly");
-}
-
-void cleanup(void)
-{
-}
-- 
2.13.6


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

* [LTP] [RFC PATCH 6/9] syscalls/ipc: Rewrite + merge msgctl{04, 05}
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (4 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 5/9] syscalls/ipc: Convert to newlib and merge msgctl{13, 03} Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 12:00   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library Cyril Hrubis
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/ltplite                                 |   1 -
 runtest/stress.part3                            |   1 -
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/ipc/msgctl/.gitignore |   1 -
 testcases/kernel/syscalls/ipc/msgctl/msgctl04.c | 249 ++++++++----------------
 testcases/kernel/syscalls/ipc/msgctl/msgctl05.c | 186 ------------------
 7 files changed, 82 insertions(+), 358 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl05.c

diff --git a/runtest/ltplite b/runtest/ltplite
index cb9517883..d6d1385b4 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -483,7 +483,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl05 msgctl05
 msgctl07 msgctl07
 
 msgget01 msgget01
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index e97b08456..e3c308fba 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -399,7 +399,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl05 msgctl05
 msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
diff --git a/runtest/syscalls b/runtest/syscalls
index 6b3133776..5692d3e22 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -689,7 +689,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl05 msgctl05
 msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 6cf5853dd..da0d5feea 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -2,7 +2,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl05 msgctl05
 msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
diff --git a/testcases/kernel/syscalls/ipc/msgctl/.gitignore b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
index b321f0c35..4289d42dc 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/.gitignore
+++ b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
@@ -2,6 +2,5 @@
 /msgctl02
 /msgctl03
 /msgctl04
-/msgctl05
 /msgctl07
 /msgctl12
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c
index 0e8fe9f79..a97a9359a 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c
@@ -1,203 +1,118 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *    03/2001 - Written by Wayne Boyer
+ *    12/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * 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 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.
  *
- *   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
+ * 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
  */
-
 /*
- * NAME
- *	msgctl04.c
- *
- * DESCRIPTION
- *	msgctl04 - test for EACCES, EFAULT and EINVAL errors using
- *		   a variety of incorrect calls.
- *
- * ALGORITHM
- *	create two message queues
- *	loop if that option was specified
- *	try to access a queue with some invalid argument
- *	check the errno value
- *	  issue a PASS message if we get EACCES, EFAULT or EINVAL
- *	  depending on the test case
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgctl04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *      12/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
- *      - Fix concurrency issue. The second key used for this test could
- *        conflict with the key from another task.
- *
- * RESTRICTIONS
- *	none
+ * Test for EACCES, EFAULT and EINVAL errors using a variety of incorrect
+ * calls.
  */
+#include <errno.h>
 #include <pwd.h>
 
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgctl04";
-int TST_TOTAL = 6;
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int msg_q_1 = -1;		/* The message queue id created in setup */
-int msg_q_2 = -1;		/* Another queue id created in setup */
-int bad_q = -1;			/* a value to use as a bad queue id */
+static int msg_id1 = -1;
+static int msg_id2 = -1;
+static int msg_id3 = -1;
+static int bad_q = -1;
 
 struct msqid_ds q_buf;
 
-struct test_case_t {		/* This allows testing of many negative */
-	int *queue_id;		/* test cases that can all use the same */
-	int ipc_cmd;		/* basic test setup.                    */
+struct tcase {
+	int *msg_id;
+	int cmd;
 	struct msqid_ds *buf;
 	int error;
-} TC[] = {
+} tc[] = {
 	/* EACCES - there is no read permission for the queue */
-	{
-	&msg_q_1, IPC_STAT, &q_buf, EACCES},
-	    /* EFAULT - the structure address is invalid - IPC_STAT */
-	{
-	&msg_q_2, IPC_STAT, (struct msqid_ds *)-1, EFAULT},
-	    /* EFAULT - the structure address is invalid - IPC_SET */
-	{
-	&msg_q_2, IPC_SET, (struct msqid_ds *)-1, EFAULT},
-	    /* EINVAL - the command (-1) is invalid */
-	{
-	&msg_q_2, -1, &q_buf, EINVAL},
-	    /* EINVAL - the queue id is invalid - IPC_STAT */
-	{
-	&bad_q, IPC_STAT, &q_buf, EINVAL},
-	    /* EINVAL - the queue id is invalid - IPC_SET */
-	{
-	&bad_q, IPC_SET, &q_buf, EINVAL}
+	{&msg_id1, IPC_STAT, &q_buf, EACCES},
+	/* EFAULT - the structure address is invalid - IPC_STAT */
+	{&msg_id2, IPC_STAT, (struct msqid_ds *)-1, EFAULT},
+	/* EFAULT - the structure address is invalid - IPC_SET */
+	{&msg_id2, IPC_SET, (struct msqid_ds *)-1, EFAULT},
+	/* EINVAL - the command (-1) is invalid */
+	{&msg_id2, -1, &q_buf, EINVAL},
+	/* EINVAL - the queue id is invalid - IPC_STAT */
+	{&bad_q, IPC_STAT, &q_buf, EINVAL},
+	/* EINVAL - the queue id is invalid - IPC_SET */
+	{&bad_q, IPC_SET, &q_buf, EINVAL},
+	/* EPERM - cannot delete root owned queue */
+	{&msg_id3, IPC_RMID, NULL, EPERM},
 };
 
-int main(int ac, char **av)
+static void verify_msgctl(unsigned int i)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* loop through the test cases */
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(msgctl(*(TC[i].queue_id), TC[i].ipc_cmd,
-				    TC[i].buf));
+	TEST(msgctl(*(tc[i].msg_id), tc[i].cmd, tc[i].buf));
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "msgctl() call succeeded "
-					 "on expected fail");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS | TTERRNO, "expected failure");
-			} else {
-				tst_resm(TFAIL | TTERRNO, "unexpected error");
-				tst_resm(TINFO, "expected error is - %d : %s",
-					 TC[i].error, strerror(TC[i].error));
-			}
-		}
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "msgctl() returned %li", TEST_RETURN);
+		return;
 	}
 
-	cleanup();
+	if (TEST_ERRNO == tc[i].error) {
+		tst_res(TPASS | TTERRNO, "msgctl(%i, %i, %p)",
+			*tc[i].msg_id, tc[i].cmd, tc[i].buf);
+		return;
+	}
 
-	tst_exit();
+	tst_res(TFAIL | TTERRNO, "msgctl(%i, %i, %p) expected %s",
+		*tc[i].msg_id, tc[i].cmd, tc[i].buf, tst_strerrno(tc[i].error));
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-	key_t msgkey2;
-
-	tst_require_root();
+	key_t msgkey1, msgkey2;
+	struct passwd *ltpuser;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	msg_id3 = SAFE_MSGGET(IPC_PRIVATE, IPC_CREAT | MSG_RW);
 
-	TEST_PAUSE;
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
 
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_resm(TINFO, "setuid(%d) failed", ltpuser->pw_uid);
+	msgkey1 = GETIPCKEY();
+	msgkey2 = GETIPCKEY();
 
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	msgkey = getipckey();
-
-	/* Get an new IPC resource key. */
-	msgkey2 = getipckey();
-
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "Can't create message queue #1");
-	}
-
-	/* now let's create another message queue with read & write access */
-	if ((msg_q_2 =
-	     msgget(msgkey2, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR)) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "Can't create message queue #2");
-	}
+	msg_id1 = SAFE_MSGGET(msgkey1, IPC_CREAT | IPC_EXCL);
+	msg_id2 = SAFE_MSGGET(msgkey2, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * remove the message queues that were created.
-	 */
-	rm_queue(msg_q_1);
+	if (msg_id1 > 0)
+		SAFE_MSGCTL(msg_id1, IPC_RMID, NULL);
 
-	rm_queue(msg_q_2);
-
-	tst_rmdir();
+	if (msg_id2 > 0)
+		SAFE_MSGCTL(msg_id2, IPC_RMID, NULL);
 
+	if (msg_id3 > 0) {
+		SAFE_SETEUID(0);
+		SAFE_MSGCTL(msg_id3, IPC_RMID, NULL);
+	}
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_msgctl,
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl05.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl05.c
deleted file mode 100644
index 632ff8c1f..000000000
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl05.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   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
- */
-
-/*
- * NAME
- *	msgctl05.c
- *
- * DESCRIPTION
- *	msgctl05 - test for EPERM error
- *
- * ALGORITHM
- *	create a message queue as root
- *	fork a child process and change its ID to nobody
- *	loop if that option was specified
- *	try to remove the queue in the child process with msgctl()
- *	check the errno value
- *	  issue a PASS message if we get EPERM
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgctl05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	The test must be run as root.
- *	There must be a nobody ID installed on the system.
- */
-
-#include <string.h>
-#include <pwd.h>
-#include <sys/wait.h>
-
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgctl05";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1;		/* The message queue id created in setup */
-uid_t ltp_uid;			/* The user ID for a non root user */
-char *ltp_user = "nobody";	/* A non root user */
-
-struct msqid_ds q_buf;
-
-int main(int ac, char **av)
-{
-	pid_t pid;
-	void do_child(void);
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	if ((pid = FORK_OR_VFORK()) == -1) {
-		tst_brkm(TBROK, cleanup, "could not fork");
-	}
-
-	if (pid == 0) {		/* child */
-		/* set the user ID of the child to nobody */
-		if (setuid(ltp_uid) == -1) {
-			tst_resm(TBROK, "setuid() failed");
-			exit(1);
-		}
-
-		do_child();
-	} else {		/* parent */
-		if (waitpid(pid, NULL, 0) == -1) {
-			tst_resm(TBROK | TERRNO, "waitpid() failed");
-		}
-
-		/* if it exists, remove the message queue */
-		rm_queue(msg_q_1);
-
-		tst_rmdir();
-	}
-
-	cleanup();
-	/**NOT REACHED**/
-	tst_exit();
-}
-
-/*
- * do_child - make the TEST call as the child process
- */
-void do_child(void)
-{
-	int lc;
-	int i;
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* loop through the test cases */
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(msgctl(msg_q_1, IPC_RMID, NULL));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "msgget() call succeeded "
-					 "on expected fail");
-				continue;
-			}
-
-			switch (TEST_ERRNO) {
-			case EPERM:
-				tst_resm(TPASS, "expected error = %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "call failed with unexpected "
-					 "error - %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			}
-		}
-	}
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See ../lib/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	msgkey = getipckey();
-
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't create message queue #1");
-	}
-
-	/* get the user ID for a non root user */
-	ltp_uid = getuserid(ltp_user);
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test@completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
-- 
2.13.6


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

* [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (5 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 6/9] syscalls/ipc: Rewrite + merge msgctl{04, 05} Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 12:12   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 8/9] syscalls/ipc: Remove msgctl07 Cyril Hrubis
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/ipc/msgctl/msgctl12.c | 84 +++++++++----------------
 1 file changed, 29 insertions(+), 55 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c
index 2621f8040..46e9fdb44 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2014 Fujitsu Ltd.
  * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -14,87 +15,60 @@
  * with this program.
  */
 /*
- * DESCRIPTION
- *	msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT.
+ * msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT.
  */
 
 #define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
 #include <errno.h>
 
-#include "test.h"
-#include "ipcmsg.h"
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
 static int msg_q;
 static int index_q;
 static struct msginfo msginfo_buf;
 static struct msqid_ds msgqid_buf;
 
-static struct test_case_t {
-	int *queue_id;
-	int ipc_cmd;
+static struct tcase {
+	int *msg_id;
+	int cmd;
 	char *name;
 	void *buf;
-} test_cases[] = {
+} tc[] = {
 	{&msg_q, IPC_INFO, "IPC_INFO", &msginfo_buf},
 	{&msg_q, MSG_INFO, "MSG_INFO", &msginfo_buf},
 	{&index_q, MSG_STAT, "MSG_STAT", &msgqid_buf},
 };
 
-char *TCID = "msgctl12";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int argc, char *argv[])
+static void verify_msgctl(unsigned int i)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
+	TEST(msgctl(*tc[i].msg_id,  tc[i].cmd, tc[i].buf));
 
-			TEST(msgctl(*test_cases[i].queue_id,
-				    test_cases[i].ipc_cmd, test_cases[i].buf));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "msgctl() test %s failed with errno: "
-					 "%d", test_cases[i].name, TEST_ERRNO);
-			} else {
-				tst_resm(TPASS, "msgctl() test %s succeeded",
-					 test_cases[i].name);
-			}
-		}
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL,
+			 "msgctl() test %s failed with errno: "
+			 "%d", tc[i].name, TEST_ERRNO);
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "msgctl() test %s succeeded", tc[i].name);
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	msg_q = msgget(IPC_PRIVATE, MSG_RW);
-	if (msg_q < 0)
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-
-	index_q = msgctl(msg_q, IPC_INFO, (struct msqid_ds *)&msginfo_buf);
-	if (index_q < 0)
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
+	msg_q = SAFE_MSGGET(IPC_PRIVATE, MSG_RW);
+	index_q = SAFE_MSGCTL(msg_q, IPC_INFO, (struct msqid_ds*)&msginfo_buf);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	rm_queue(msg_q);
+	if (msg_q > 0)
+		SAFE_MSGCTL(msg_q, IPC_RMID, NULL);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_msgctl,
+	.tcnt = ARRAY_SIZE(tc),
+};
-- 
2.13.6


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

* [LTP] [RFC PATCH 8/9] syscalls/ipc: Remove msgctl07
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (6 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 12:28   ` Petr Vorel
  2018-06-12 15:46 ` [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile Cyril Hrubis
  2018-06-25 12:02 ` [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

The test is very similar to msgrcv01, does not test msgctl() and the
code is messed up, hence it makes sense to remove it rather than moving
it to msgrcv directory.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/ltplite                                 |   1 -
 runtest/stress.part3                            |   1 -
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/ipc/msgctl/.gitignore |   1 -
 testcases/kernel/syscalls/ipc/msgctl/msgctl07.c | 292 ------------------------
 6 files changed, 297 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgctl/msgctl07.c

diff --git a/runtest/ltplite b/runtest/ltplite
index d6d1385b4..f06e8888a 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -483,7 +483,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl07 msgctl07
 
 msgget01 msgget01
 msgget02 msgget02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index e3c308fba..1fb2c12cc 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -399,7 +399,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 5692d3e22..4f58ec2e9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -689,7 +689,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
 msgstress03 msgstress03
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index da0d5feea..00d7eed3a 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -2,7 +2,6 @@ msgctl01 msgctl01
 msgctl02 msgctl02
 msgctl03 msgctl03
 msgctl04 msgctl04
-msgctl07 msgctl07
 msgstress01 msgstress01
 msgstress02 msgstress02
 msgstress03 msgstress03
diff --git a/testcases/kernel/syscalls/ipc/msgctl/.gitignore b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
index 4289d42dc..f179f2606 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/.gitignore
+++ b/testcases/kernel/syscalls/ipc/msgctl/.gitignore
@@ -2,5 +2,4 @@
 /msgctl02
 /msgctl03
 /msgctl04
-/msgctl07
 /msgctl12
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl07.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl07.c
deleted file mode 100644
index b978692ce..000000000
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl07.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   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
- */
-
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-/* 11/06/2002   Port to LTP     dbarrera@us.ibm.com */
-/* 12/03/2008   Fix concurrency issue     mfertre@irisa.fr */
-
-/*
- * NAME
- *	msgctl07
- *
- * CALLS
- *	msgget(2) msgctl(2) msgop(2)
- *
- * ALGORITHM
- *	Get and manipulate a message queue.
- *
- * RESTRICTIONS
- *
- */
-
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/msg.h>
-#include <signal.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include "test.h"
-#include "ipcmsg.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-typedef void (*sighandler_t) (int);
-volatile int ready;
-
-#define BYTES 100
-#define SECS 10
-
-void setup();
-void cleanup();
-void do_child_1();
-void do_child_2();
-
-char *TCID = "msgctl07";
-int TST_TOTAL = 1;
-
-/* Used by main() and do_child_1(): */
-static int msqid;
-struct my_msgbuf {
-	long type;
-	char text[BYTES];
-} p1_msgp, p2_msgp, p3_msgp, c1_msgp, c2_msgp, c3_msgp;
-
-int main(int argc, char *argv[])
-{
-	key_t key;
-	int pid, status;
-	int i, j, k;
-	sighandler_t alrm();
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	key = getipckey();
-	if ((msqid = msgget(key, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "msgget() failed");
-
-	}
-
-	pid = FORK_OR_VFORK();
-	if (pid < 0) {
-		(void)msgctl(msqid, IPC_RMID, NULL);
-		tst_brkm(TFAIL, NULL,
-			 "\tFork failed (may be OK if under stress)");
-	} else if (pid == 0) {
-		do_child_1();
-	} else {
-		struct sigaction act;
-
-		memset(&act, 0, sizeof(act));
-		act.sa_handler = (sighandler_t) alrm;
-		sigemptyset(&act.sa_mask);
-		sigaddset(&act.sa_mask, SIGALRM);
-		if ((sigaction(SIGALRM, &act, NULL)) < 0) {
-			tst_resm(TFAIL | TERRNO, "signal failed");
-			kill(pid, SIGKILL);
-			(void)msgctl(msqid, IPC_RMID, NULL);
-			tst_exit();
-		}
-		ready = 0;
-		alarm(SECS);
-		while (!ready)	/* make the child wait */
-			usleep(50000);
-		for (i = 0; i < BYTES; i++)
-			p1_msgp.text[i] = 'i';
-		p1_msgp.type = 1;
-		if (msgsnd(msqid, &p1_msgp, BYTES, 0) == -1) {
-			tst_resm(TFAIL | TERRNO, "msgsnd() failed");
-			kill(pid, SIGKILL);
-			(void)msgctl(msqid, IPC_RMID, NULL);
-			tst_exit();
-		}
-		wait(&status);
-	}
-	if ((status >> 8) == 1) {
-		tst_brkm(TFAIL, NULL, "test failed. status = %d",
-			 (status >> 8));
-	}
-
-	pid = FORK_OR_VFORK();
-	if (pid < 0) {
-		(void)msgctl(msqid, IPC_RMID, NULL);
-		tst_brkm(TFAIL, NULL,
-			 "\tFork failed (may be OK if under stress)");
-	} else if (pid == 0) {
-		do_child_2();
-	} else {
-		struct sigaction act;
-
-		memset(&act, 0, sizeof(act));
-		act.sa_handler = (sighandler_t) alrm;
-		sigemptyset(&act.sa_mask);
-		sigaddset(&act.sa_mask, SIGALRM);
-		if ((sigaction(SIGALRM, &act, NULL)) < 0) {
-			tst_resm(TFAIL | TERRNO, "signal failed");
-			kill(pid, SIGKILL);
-			(void)msgctl(msqid, IPC_RMID, NULL);
-			tst_exit();
-		}
-		ready = 0;
-		alarm(SECS);
-		while (!ready)	/* make the child wait */
-			usleep(50000);
-		for (i = 0; i < BYTES; i++)
-			p1_msgp.text[i] = 'i';
-		p1_msgp.type = 1;
-		if (msgsnd(msqid, &p1_msgp, BYTES, 0) == -1) {
-			tst_resm(TFAIL | TERRNO, "msgsnd() failed");
-			kill(pid, SIGKILL);
-			(void)msgctl(msqid, IPC_RMID, NULL);
-			tst_exit();
-		}
-		for (j = 0; j < BYTES; j++)
-			p2_msgp.text[j] = 'j';
-		p2_msgp.type = 2;
-		if (msgsnd(msqid, &p2_msgp, BYTES, 0) == -1) {
-			tst_resm(TFAIL | TERRNO, "msgsnd() failed");
-			kill(pid, SIGKILL);
-			(void)msgctl(msqid, IPC_RMID, NULL);
-			tst_exit();
-		}
-		for (k = 0; k < BYTES; k++)
-			p3_msgp.text[k] = 'k';
-		p3_msgp.type = 3;
-		if (msgsnd(msqid, &p3_msgp, BYTES, 0) == -1) {
-			tst_resm(TFAIL | TERRNO, "msgsnd() failed");
-			kill(pid, SIGKILL);
-			(void)msgctl(msqid, IPC_RMID, NULL);
-			tst_exit();
-		}
-		wait(&status);
-	}
-	if ((status >> 8) == 1) {
-		tst_brkm(TFAIL, NULL, "test failed. status = %d",
-			 (status >> 8));
-	}
-	/*
-	 * Remove the message queue from the system
-	 */
-#ifdef DEBUG
-	tst_resm(TINFO, "Removing the message queue");
-#endif
-	fflush(stdout);
-	(void)msgctl(msqid, IPC_RMID, NULL);
-	if ((status = msgctl(msqid, IPC_STAT, NULL)) != -1) {
-		(void)msgctl(msqid, IPC_RMID, NULL);
-		tst_brkm(TFAIL, NULL, "msgctl(msqid, IPC_RMID) failed");
-
-	}
-
-	fflush(stdout);
-	tst_resm(TPASS, "msgctl07 ran successfully!");
-
-	cleanup();
-
-	tst_exit();
-}
-
-sighandler_t alrm(int sig LTP_ATTRIBUTE_UNUSED)
-{
-	ready++;
-	return 0;
-}
-
-void do_child_1(void)
-{
-	int i;
-	int size;
-
-	if ((size = msgrcv(msqid, &c1_msgp, BYTES, 0, 0)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed");
-	}
-	if (size != BYTES) {
-		tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d",
-			 size,
-			 BYTES);
-	}
-	for (i = 0; i < BYTES; i++)
-		if (c1_msgp.text[i] != 'i') {
-			tst_brkm(TFAIL, NULL, "error: corrup message");
-		}
-	exit(0);
-}
-
-void do_child_2(void)
-{
-	int i, j, k;
-	int size;
-
-	if ((size = msgrcv(msqid, &c3_msgp, BYTES, 3, 0)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed");
-	}
-	if (size != BYTES) {
-		tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d",
-			 size,
-			 BYTES);
-	}
-	for (k = 0; k < BYTES; k++)
-		if (c3_msgp.text[k] != 'k') {
-			tst_brkm(TFAIL, NULL, "error: corrupt message");
-		}
-	if ((size = msgrcv(msqid, &c2_msgp, BYTES, 2, 0)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed");
-	}
-	if (size != BYTES) {
-		tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d",
-			 size,
-			 BYTES);
-	}
-	for (j = 0; j < BYTES; j++)
-		if (c2_msgp.text[j] != 'j') {
-			tst_brkm(TFAIL, NULL, "error: corrupt message");
-		}
-	if ((size = msgrcv(msqid, &c1_msgp, BYTES, 1, 0)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed");
-	}
-	if (size != BYTES) {
-		tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d",
-			 size,
-			 BYTES);
-	}
-	for (i = 0; i < BYTES; i++)
-		if (c1_msgp.text[i] != 'i') {
-			tst_brkm(TFAIL, NULL, "error: corrupt message");
-		}
-
-	exit(0);
-}
-
-void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-}
-
-void cleanup(void)
-{
-	tst_rmdir();
-}
-- 
2.13.6


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

* [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (7 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 8/9] syscalls/ipc: Remove msgctl07 Cyril Hrubis
@ 2018-06-12 15:46 ` Cyril Hrubis
  2018-06-13 12:35   ` Petr Vorel
  2018-06-25 12:02 ` [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
  9 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-12 15:46 UTC (permalink / raw)
  To: ltp

Switch to new ipc library now that all testcases are rewritten.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/ipc/msgctl/Makefile | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgctl/Makefile b/testcases/kernel/syscalls/ipc/msgctl/Makefile
index 4472eeb1c..f9ee8d2c2 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/msgctl/Makefile
@@ -19,11 +19,5 @@
 top_srcdir              ?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
-LIBMSGCTL               := $(LIBDIR)/libmsgctl.a
-LDLIBS                  += -lmsgctl
-
-MAKE_DEPS               := $(LIBMSGCTL)
-
-include $(abs_srcdir)/../Makefile.inc
+include $(abs_srcdir)/../Makefile2.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
-- 
2.13.6


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

* [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06
  2018-06-12 15:46 ` [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06 Cyril Hrubis
@ 2018-06-13  8:56   ` Li Wang
  2018-06-20 10:57     ` Cyril Hrubis
  2018-06-13 11:24   ` Petr Vorel
  1 sibling, 1 reply; 25+ messages in thread
From: Li Wang @ 2018-06-13  8:56 UTC (permalink / raw)
  To: ltp

Cyril Hrubis <chrubis@suse.cz> wrote:

> ​[...]
>
>
> -int main(int ac, char **av)
> -{
> -       int lc;
> +       if (TEST_RETURN != 0) {
> +               tst_res(TFAIL | TTERRNO, "msgctl() returned %li",
> TEST_RETURN);
> +               return;
> +       }
>
> -       tst_parse_opts(ac, av, NULL, NULL);
> +       tst_res(TPASS, "msgctl(IPC_STAT)");
>
> -       setup();                /* global setup */
> +       if (buf.msg_stime == 0)
> +               tst_res(TPASS, "msg_stime = 0");
> +       else
> +               tst_res(TFAIL, "msg_stime = %lu", (unsigned
> long)buf.msg_stime);
>
> -       /* The following loop checks looping state if -i option given */
> +       if (buf.msg_rtime == 0)
> +               tst_res(TPASS, "msg_rtime = 0");
> +       else
> +               tst_res(TFAIL, "msg_rtime = %lu", (unsigned
> long)buf.msg_rtime);
>
> -       for (lc = 0; TEST_LOOPING(lc); lc++) {
> -               /* reset tst_count in case we are looping */
> -               tst_count = 0;
> +       if (buf.msg_ctime == creat_time || buf.msg_ctime == creat_time +
> 1) {

​
​I'm thinking that whether 1 second is enough for system shaking. ​If this
program is running on an overload system, this maybe delay more than 1
second and test fails, is that a test defect?​

Maybe gives more flexible as:
    if (buf.msg_ctime <= creat_time && buf.msg_ctime >= creat_time - 3)


> +               tst_res(TPASS, "msg_ctime = %lu, expected %lu",
> +                       (unsigned long)buf.msg_ctime, (unsigned
> long)creat_time);
> +       } else {
> +               tst_res(TPASS, "msg_ctime = %lu, expected %lu",
>

​seems typo here?  TFAIL



> +                       (unsigned long)buf.msg_ctime, (unsigned
> long)creat_time);
> +       }


>
​Beside that, I got this follow errors occasionally:

​# ./msgctl01
tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s
tst_safe_sysv_ipc.c:51: BROK: msgctl01.c:137: msgget(1627794347, 7b0)
failed: EEXIST​

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180613/0f181e3f/attachment.html>

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

* [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer
  2018-06-12 15:46 ` [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer Cyril Hrubis
@ 2018-06-13 10:32   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 10:32 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> We recently had a regression in Sys V IPC when IPC_STAT returned
> non-zero integer on success wrongly, which wasn't caught by LTP test but
> breaks software in the wild.

> This commit changes safe_shmctl() and safe_msgctl() to check the return
> value with != 0 for IPC_STAT, IPC_SET and IPC_RMID and with == -1
> otherwise.
LGTM. I'm surprised this is the first time, I'd expect it for more syscalls.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---


Kind regards,
Petr

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

* [LTP] [RFC PATCH 2/9] tst_safe_sysv_ipc: SAFE_{SHMCTL, MSGCTL} return retval
  2018-06-12 15:46 ` [LTP] [RFC PATCH 2/9] tst_safe_sysv_ipc: SAFE_{SHMCTL, MSGCTL} return retval Cyril Hrubis
@ 2018-06-13 10:49   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 10:49 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> These calls do return index into kernel internal array or IPC id for
> Linux specific cmds, hence we need to propagate the return value.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---


Kind regards,
Petr

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

* [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06
  2018-06-12 15:46 ` [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06 Cyril Hrubis
  2018-06-13  8:56   ` Li Wang
@ 2018-06-13 11:24   ` Petr Vorel
  1 sibling, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 11:24 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Rewrite msgctl01 to be much more strict, now we assert all fields of the
> buffer we get from IPC_STAT.

> This also removes msgctl06 that was testing the very same IPC_STAT
> command but checked different subset of the msqid_ds buffer.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---

Nice improvement :).
I guess it doesn't make sense to check msqid_ds.__msg_cbytes (and it's also nonstandard).

> +	if (buf.msg_lspid == 0)
> +		tst_res(TPASS, "msg_lspid = 0");
> +	else
> +		tst_res(TFAIL, "msg_lspid = %u", (unsigned)buf.msg_lspid);
checkpatch.pl complains about unsigned instead of unsigned int, but that's nothing we should worry about.


Kind regards,
Petr

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

* [LTP] [RFC PATCH 4/9] syscalls/ipc: Rewrite msgctl02 to new library.
  2018-06-12 15:46 ` [LTP] [RFC PATCH 4/9] syscalls/ipc: Rewrite msgctl02 to new library Cyril Hrubis
@ 2018-06-13 11:47   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 11:47 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/kernel/syscalls/ipc/msgctl/msgctl02.c | 207 +++++++-----------------
>  1 file changed, 58 insertions(+), 149 deletions(-)

LGTM.

Kind regards,
Petr

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

* [LTP] [RFC PATCH 5/9] syscalls/ipc: Convert to newlib and merge msgctl{13, 03}
  2018-06-12 15:46 ` [LTP] [RFC PATCH 5/9] syscalls/ipc: Convert to newlib and merge msgctl{13, 03} Cyril Hrubis
@ 2018-06-13 11:55   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 11:55 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> These two tests were both testing IPC_RMID, so I've merged then into
> msgctl03 and rewritten the test to new test library.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---


Kind regards,
Petr

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

* [LTP] [RFC PATCH 6/9] syscalls/ipc: Rewrite + merge msgctl{04, 05}
  2018-06-12 15:46 ` [LTP] [RFC PATCH 6/9] syscalls/ipc: Rewrite + merge msgctl{04, 05} Cyril Hrubis
@ 2018-06-13 12:00   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 12:00 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---

Nice cleanup :).

Kind regards,
Petr

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

* [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library
  2018-06-12 15:46 ` [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library Cyril Hrubis
@ 2018-06-13 12:12   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 12:12 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/kernel/syscalls/ipc/msgctl/msgctl12.c | 84 +++++++++----------------


> -static struct test_case_t {
> -	int *queue_id;
> -	int ipc_cmd;

LGTM, I'd use macro for string, but that's only nitpicking.

#define CMD_NAME(x) .cmd = x, .name = #x


> +static struct tcase {
> +	int *msg_id;
> +	int cmd;
>  	char *name;
>  	void *buf;
> -} test_cases[] = {
> +} tc[] = {
>  	{&msg_q, IPC_INFO, "IPC_INFO", &msginfo_buf},
>  	{&msg_q, MSG_INFO, "MSG_INFO", &msginfo_buf},
>  	{&index_q, MSG_STAT, "MSG_STAT", &msgqid_buf},
+ this:
    {&msg_q, CMD_NAME(IPC_INFO), &msginfo_buf},
    {&msg_q, CMD_NAME(MSG_INFO), &msginfo_buf},
    {&index_q, CMD_NAME(MSG_STAT), &msgqid_buf},


Kind regards,
Petr

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

* [LTP] [RFC PATCH 8/9] syscalls/ipc: Remove msgctl07
  2018-06-12 15:46 ` [LTP] [RFC PATCH 8/9] syscalls/ipc: Remove msgctl07 Cyril Hrubis
@ 2018-06-13 12:28   ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 12:28 UTC (permalink / raw)
  To: ltp

> The test is very similar to msgrcv01, does not test msgctl() and the
> code is messed up, hence it makes sense to remove it rather than moving
> it to msgrcv directory.
Make sense.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

* [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile
  2018-06-12 15:46 ` [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile Cyril Hrubis
@ 2018-06-13 12:35   ` Petr Vorel
  2018-06-20 10:48     ` Cyril Hrubis
  0 siblings, 1 reply; 25+ messages in thread
From: Petr Vorel @ 2018-06-13 12:35 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Switch to new ipc library now that all testcases are rewritten.

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---

I've noticed, that some commits from this patchset aren't bisectable, due
dependency on new library (libnewipc.h).
IMHO it's worth of fixing it.


Kind regards,
Petr

>  testcases/kernel/syscalls/ipc/msgctl/Makefile | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)

> diff --git a/testcases/kernel/syscalls/ipc/msgctl/Makefile b/testcases/kernel/syscalls/ipc/msgctl/Makefile
> index 4472eeb1c..f9ee8d2c2 100644
> --- a/testcases/kernel/syscalls/ipc/msgctl/Makefile
> +++ b/testcases/kernel/syscalls/ipc/msgctl/Makefile
> @@ -19,11 +19,5 @@
>  top_srcdir              ?= ../../../../..

>  include $(top_srcdir)/include/mk/testcases.mk
> -
> -LIBMSGCTL               := $(LIBDIR)/libmsgctl.a
> -LDLIBS                  += -lmsgctl
> -
> -MAKE_DEPS               := $(LIBMSGCTL)
> -
> -include $(abs_srcdir)/../Makefile.inc
> +include $(abs_srcdir)/../Makefile2.inc
>  include $(top_srcdir)/include/mk/generic_leaf_target.mk

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

* [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile
  2018-06-13 12:35   ` Petr Vorel
@ 2018-06-20 10:48     ` Cyril Hrubis
  2018-06-20 15:26       ` Petr Vorel
  0 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-20 10:48 UTC (permalink / raw)
  To: ltp

Hi!
> I've noticed, that some commits from this patchset aren't bisectable, due
> dependency on new library (libnewipc.h).
> IMHO it's worth of fixing it.

I guess that the best I can do is to disable the directory from build
before the patchset and enable it with a new Makefile at the end as it's
nearly impossible to mix the new and old IPC library in one Makefile.

And yes I wanted to send this early, so I kind of ignored the build
problems.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06
  2018-06-13  8:56   ` Li Wang
@ 2018-06-20 10:57     ` Cyril Hrubis
  2018-06-21  8:56       ` Li Wang
  0 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-20 10:57 UTC (permalink / raw)
  To: ltp

Hi!
> ???
> ???I'm thinking that whether 1 second is enough for system shaking. ???If this
> program is running on an overload system, this maybe delay more than 1
> second and test fails, is that a test defect????

Since we are calling just two subsequent syscalls here it's very
unlikely that the difference in times will be greater than 1s even on
loaded system, but for sure we can increase that to two or three that
wouldn't do any harm.

> Maybe gives more flexible as:
>     if (buf.msg_ctime <= creat_time && buf.msg_ctime >= creat_time - 3)
> 
> 
> > +               tst_res(TPASS, "msg_ctime = %lu, expected %lu",
> > +                       (unsigned long)buf.msg_ctime, (unsigned
> > long)creat_time);
> > +       } else {
> > +               tst_res(TPASS, "msg_ctime = %lu, expected %lu",
> >
> 
> ???seems typo here?  TFAIL

Right, thanks for pointing it out!

> > +                       (unsigned long)buf.msg_ctime, (unsigned
> > long)creat_time);
> > +       }
> 
> 
> >
> ???Beside that, I got this follow errors occasionally:
> 
> ???# ./msgctl01
> tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s
> tst_safe_sysv_ipc.c:51: BROK: msgctl01.c:137: msgget(1627794347, 7b0)
> failed: EEXIST???

That means that there is some leftover message queue on the system,
there may be a problem in how the IDs are allocated in the IPC test
library.

Do you have any steps to reproduce the issue?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile
  2018-06-20 10:48     ` Cyril Hrubis
@ 2018-06-20 15:26       ` Petr Vorel
  0 siblings, 0 replies; 25+ messages in thread
From: Petr Vorel @ 2018-06-20 15:26 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Hi!
> > I've noticed, that some commits from this patchset aren't bisectable, due
> > dependency on new library (libnewipc.h).
> > IMHO it's worth of fixing it.

> I guess that the best I can do is to disable the directory from build
> before the patchset and enable it with a new Makefile at the end as it's
> nearly impossible to mix the new and old IPC library in one Makefile.
Seems reasonable for me.
Thanks for handling it.

> And yes I wanted to send this early, so I kind of ignored the build
> problems.
No big deal :).


Kind regards,
Petr

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

* [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06
  2018-06-20 10:57     ` Cyril Hrubis
@ 2018-06-21  8:56       ` Li Wang
  0 siblings, 0 replies; 25+ messages in thread
From: Li Wang @ 2018-06-21  8:56 UTC (permalink / raw)
  To: ltp

Hi Cyril,

On Wed, Jun 20, 2018 at 6:57 PM, Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
>> ???
>> ???I'm thinking that whether 1 second is enough for system shaking. ???If this
>> program is running on an overload system, this maybe delay more than 1
>> second and test fails, is that a test defect????
>
> Since we are calling just two subsequent syscalls here it's very
> unlikely that the difference in times will be greater than 1s even on
> loaded system, but for sure we can increase that to two or three that
> wouldn't do any harm.

Ok, fine.

>
>> Maybe gives more flexible as:
>>     if (buf.msg_ctime <= creat_time && buf.msg_ctime >= creat_time - 3)
>>
>>
>> > +               tst_res(TPASS, "msg_ctime = %lu, expected %lu",
>> > +                       (unsigned long)buf.msg_ctime, (unsigned
>> > long)creat_time);
>> > +       } else {
>> > +               tst_res(TPASS, "msg_ctime = %lu, expected %lu",
>> >
>>
>> ???seems typo here?  TFAIL
>
> Right, thanks for pointing it out!
>
>> > +                       (unsigned long)buf.msg_ctime, (unsigned
>> > long)creat_time);
>> > +       }
>>
>>
>> >
>> ???Beside that, I got this follow errors occasionally:
>>
>> ???# ./msgctl01
>> tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s
>> tst_safe_sysv_ipc.c:51: BROK: msgctl01.c:137: msgget(1627794347, 7b0)
>> failed: EEXIST???
>
> That means that there is some leftover message queue on the system,
> there may be a problem in how the IDs are allocated in the IPC test
> library.
>
> Do you have any steps to reproduce the issue?

No, but I will look it closely then.

BTW, this failure is not caused by your patch. I'm sure that I can
reproduce it without your patch apply at that moment.

And, for the patch set, LGTM.


-- 
Regards,
Li Wang

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

* [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases
  2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
                   ` (8 preceding siblings ...)
  2018-06-12 15:46 ` [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile Cyril Hrubis
@ 2018-06-25 12:02 ` Cyril Hrubis
  9 siblings, 0 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-06-25 12:02 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with the changes requested by Peter and Li, thanks a lot for the
review.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2018-06-25 12:02 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 15:46 [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis
2018-06-12 15:46 ` [LTP] [RFC PATCH 1/9] tst_safe_sysv_ipc: Make safe_shmctl() and safe_msgctl() safer Cyril Hrubis
2018-06-13 10:32   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 2/9] tst_safe_sysv_ipc: SAFE_{SHMCTL, MSGCTL} return retval Cyril Hrubis
2018-06-13 10:49   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 3/9] syscalls/ipc: Rewrite msgctl01 + merge msgctl06 Cyril Hrubis
2018-06-13  8:56   ` Li Wang
2018-06-20 10:57     ` Cyril Hrubis
2018-06-21  8:56       ` Li Wang
2018-06-13 11:24   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 4/9] syscalls/ipc: Rewrite msgctl02 to new library Cyril Hrubis
2018-06-13 11:47   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 5/9] syscalls/ipc: Convert to newlib and merge msgctl{13, 03} Cyril Hrubis
2018-06-13 11:55   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 6/9] syscalls/ipc: Rewrite + merge msgctl{04, 05} Cyril Hrubis
2018-06-13 12:00   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library Cyril Hrubis
2018-06-13 12:12   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 8/9] syscalls/ipc: Remove msgctl07 Cyril Hrubis
2018-06-13 12:28   ` Petr Vorel
2018-06-12 15:46 ` [LTP] [RFC PATCH 9/9] syscalls/ipc: Fix Makefile Cyril Hrubis
2018-06-13 12:35   ` Petr Vorel
2018-06-20 10:48     ` Cyril Hrubis
2018-06-20 15:26       ` Petr Vorel
2018-06-25 12:02 ` [LTP] [RFC PATCH 0/9] Rewrite msgctl testcases Cyril Hrubis

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.