All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] ipc/lib: add header files for new API
@ 2016-11-23  7:18 Xiao Yang
  2016-11-23  7:18 ` [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Xiao Yang @ 2016-11-23  7:18 UTC (permalink / raw)
  To: ltp

1) add tst_ipcmsg.h for new API
2) add tst_ipcsem.h for new API
3)add tst_ipcshm.h for new API
4) fix libipc.c for new API

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/lib/libipc.c     |  6 +--
 testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h | 61 ++++++++++++++++++++++++++
 testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h | 52 ++++++++++++++++++++++
 testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h | 47 ++++++++++++++++++++
 4 files changed, 163 insertions(+), 3 deletions(-)
 create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h
 create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h
 create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h

diff --git a/testcases/kernel/syscalls/ipc/lib/libipc.c b/testcases/kernel/syscalls/ipc/lib/libipc.c
index 4de7faa..856bfdb 100644
--- a/testcases/kernel/syscalls/ipc/lib/libipc.c
+++ b/testcases/kernel/syscalls/ipc/lib/libipc.c
@@ -58,7 +58,7 @@ key_t getipckey(void)
 	static int count = 0;
 
 	if (NULL == (curdir = getcwd(curdir, size))) {
-		tst_brkm(TBROK, cleanup, "Can't get current directory "
+		tst_brkm(TBROK, NULL, "Can't get current directory "
 			 "in getipckey()");
 	}
 
@@ -72,7 +72,7 @@ key_t getipckey(void)
 	count++;
 
 	if ((ipc_key = ftok(curdir, proj_id)) == -1) {
-		tst_brkm(TBROK, cleanup, "Can't get msgkey from ftok()");
+		tst_brkm(TBROK, NULL, "Can't get msgkey from ftok()");
 	}
 
 	return (ipc_key);
@@ -145,7 +145,7 @@ int getuserid(char *user)
 
 	/* get the uid value for the user */
 	if ((ent = getpwnam(user)) == NULL) {
-		tst_brkm(TBROK, cleanup, "Couldn't get password entry for %s",
+		tst_brkm(TBROK, NULL, "Couldn't get password entry for %s",
 			 user);
 	}
 
diff --git a/testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h b/testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h
new file mode 100644
index 0000000..ec80e31
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * ipcmsg.h - common definitions for the IPC message tests.
+ */
+
+#ifndef __IPCMSG_H
+#define __IPCMSG_H	1
+
+#include <errno.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+
+#define MSG_RD  0400            /* read permission for the queue */
+#define MSG_WR  0200            /* write permission for the queue */
+#define MSG_RW	(MSG_RD | MSG_WR)
+
+#define MSGSIZE	1024		/* a resonable size for a message */
+#define MSGTYPE 1		/* a type ID for a message */
+
+#define NR_MSGQUEUES	16	/* MSGMNI as defined in linux/msg.h */
+
+#define min(a, b)	(((a) < (b)) ? @ : (b))
+
+typedef struct mbuf {		/* a generic message structure */
+	long mtype;
+	char mtext[MSGSIZE + 1];  /* add 1 here so the message can be 1024   */
+} MSGBUF;			  /* characters long with a '\0' termination */
+
+#ifdef LIBIPC
+key_t msgkey;                   /* the ftok() generated message key */
+#else
+extern key_t msgkey;                   /* the ftok() generated message key */
+#endif
+
+void init_buf(MSGBUF *m_buf, int type, int size);
+void rm_queue(int queue_id);
+
+key_t getipckey(void);
+int getuserid(char *user);
+
+int get_max_msgqueues(void);
+int get_used_msgqueues(void);
+
+#endif /* ipcmsg.h */
diff --git a/testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h b/testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h
new file mode 100644
index 0000000..d9be9ab
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * ipcsem.h - common definitions for the IPC semaphore tests
+ */
+
+#ifndef __IPCSEM_H
+#define __IPCSEM_H
+
+#include <errno.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#include "lapi/semun.h"
+
+#define SEM_RD	0400
+#define SEM_ALT	0200
+#define SEM_RA	(SEM_RD | SEM_ALT)
+
+/*
+ * a reasonable value for the number of
+ * "primitive semaphores" per ID
+ */
+#define PSEMS	10
+
+#ifdef LIBIPC
+key_t semkey;			/* an IPC key generated by ftok() */
+#else
+extern key_t semkey;		/* an IPC key generated by ftok() */
+#endif
+
+void rm_sema(int sem_id);
+
+int getipckey(void);
+int getuserid(char *user);
+
+#endif /* ipcsem.h */
diff --git a/testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h b/testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h
new file mode 100644
index 0000000..c5876d4
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * ipcshm.h - common definitions for the IPC shared memory tests
+ */
+
+#ifndef __IPCSHM_H
+#define __IPCSHM_H
+
+#include <errno.h>
+#include <wait.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#define SHM_RD	0400
+#define SHM_WR	0200
+#define SHM_RW	(SHM_RD | SHM_WR)
+
+#define SHM_SIZE	2048	/* a resonable size for a memory segment */
+#define INT_SIZE	4	/* instead of sizeof(int) */
+
+#define MODE_MASK	0x01FF	/* to get the lower nine permission bits */
+				/* from shmid_ds.ipc_perm.mode		 */
+
+key_t shmkey;			/* an IPC key generated by ftok() */
+
+void rm_shm(int shm_id);
+
+int getipckey(void);
+int getuserid(char *user);
+
+#endif /* ipcshm.h */
-- 
1.8.3.1




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

* [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to new API
  2016-11-23  7:18 [LTP] [PATCH 1/4] ipc/lib: add header files for new API Xiao Yang
@ 2016-11-23  7:18 ` Xiao Yang
  2016-11-23 14:05   ` Cyril Hrubis
  2016-11-23  7:18 ` [LTP] [PATCH 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-11-23  7:18 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/msgget01.c | 188 ++++++------------------
 1 file changed, 45 insertions(+), 143 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget01.c b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
index e8208b7..310b254 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget01.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
@@ -1,186 +1,88 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget01.c
+ * NAME: msgget01.c
  *
  * DESCRIPTION
- *	msgget01 - create a message queue, write a message to it and
- *		   read it back.
- *
- * ALGORITHM
- *	loop if that option was specified
- *	create a message queue
- *	check the return code
- *	  if failure, issue a FAIL message.
- *	otherwise,
- *	  if doing functionality testing by writting a message to the queue,
- *	  reading it back and comparing the two.
- *	  	if the messages are the same,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget01 [-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
+ * create a message queue, write a message to it and
+ * read it back.
  *
- * RESTRICTIONS
- *	none
  */
 
-#include "ipcmsg.h"
-
 #include <string.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#include "tst_ipcmsg.h"
+#include "tst_test.h"
 
-char *TCID = "msgget01";
-int TST_TOTAL = 1;
+static int msg_q_1 = -1;
 
-int msg_q_1 = -1;		/* to hold the message queue ID */
+static void check_functionality(void);
 
-int main(int ac, char **av)
+static void verify_msgget(void)
 {
-	int lc;
-	void check_functionality(void);
-
-	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;
-
-		/*
-		 * Use TEST macro to make the call to create the message queue
-		 */
-
-		TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			msg_q_1 = TEST_RETURN;
-			/*
-			 * write a message to the queue.
-			 * read back the message.
-			 * PASS the test if they are the same.
-			 */
-			check_functionality();
-		}
-
-		/*
-		 * remove the message queue that was created and mark the ID
-		 * as invalid.
-		 */
-		if (msg_q_1 != -1) {
-			rm_queue(msg_q_1);
-			msg_q_1 = -1;
-		}
+	msgkey = getipckey();
+
+	TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
+
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "msgget() failed");
+	} else {
+		msg_q_1 = TEST_RETURN;
+
+		check_functionality();
 	}
 
-	cleanup();
-	tst_exit();
+	rm_queue(msg_q_1);
 }
 
-/*
- * check_functionality() - check the functionality of the tested system call.
- */
-void check_functionality(void)
+static void check_functionality(void)
 {
-	int i = 0;
 	MSGBUF snd_buf, rcv_buf;
 
-	/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */
 	char *queue_msg =
 	    "Qston, check_functionality here.  The message has queued!";
 
-	/*
-	 * copy our message into the buffer and then set the type.
-	 */
-	do {
-		snd_buf.mtext[i++] = *queue_msg;
-	} while (*queue_msg++ != '\0');
+	strcpy(snd_buf.mtext, queue_msg);
 
 	snd_buf.mtype = MSGTYPE;
 
-	/* send the message */
 	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not send a message in the "
+		tst_brk(TBROK, "Could not send a message in the "
 			 "check_functionality() routine.");
 	}
 
-	/* receive the message */
 	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not read a messages in the "
+		tst_brk(TBROK, "Could not read a messages in the "
 			 "check_functionality() routine.");
 	}
 
 	if (strcmp(snd_buf.mtext, rcv_buf.mtext) == 0) {
-		tst_resm(TPASS, "message received = message sent");
+		tst_res(TPASS, "message received = message sent");
 	} else {
-		tst_resm(TFAIL, "message received != message sent");
+		tst_res(TFAIL, "message received != message sent");
 	}
 }
 
-/*
- * 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();
-
-	msgkey = getipckey();
-}
-
-/*
- * 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 that was created */
-	rm_queue(msg_q_1);
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.tid = "msgget01",
+	.test_all = verify_msgget,
+	.needs_tmpdir = 1
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 3/4] ipc/msgget02.c: reconstruct && convert to new API
  2016-11-23  7:18 [LTP] [PATCH 1/4] ipc/lib: add header files for new API Xiao Yang
  2016-11-23  7:18 ` [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
@ 2016-11-23  7:18 ` Xiao Yang
  2016-11-23 14:13   ` Cyril Hrubis
  2016-11-23  7:18 ` [LTP] [PATCH 4/4] ipc/msgget03.c: cleanup " Xiao Yang
  2016-11-23 13:55 ` [LTP] [PATCH 1/4] ipc/lib: add header files for " Cyril Hrubis
  3 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-11-23  7:18 UTC (permalink / raw)
  To: ltp

1) merge msgget04 into msgget02
2) take use of some SAFE Marcos

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                                 |   1 -
 runtest/stress.part3                            |   1 -
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/.gitignore            |   1 -
 testcases/kernel/syscalls/ipc/msgget/msgget02.c | 225 +++++++++---------------
 testcases/kernel/syscalls/ipc/msgget/msgget04.c | 169 ------------------
 7 files changed, 84 insertions(+), 315 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgget/msgget04.c

diff --git a/runtest/ltplite b/runtest/ltplite
index a05d3ed..53e5999 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -503,7 +503,6 @@ msgctl09 msgctl09
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 274c8a4..8ff228d 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -419,7 +419,6 @@ msgctl09 msgctl09
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/syscalls b/runtest/syscalls
index 2f2dde5..8b1abc2 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -674,7 +674,6 @@ msgctl13 msgctl13
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 5592a00..8212222 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -15,7 +15,6 @@ msgctl13 msgctl13
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 348c235..1267656 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -402,7 +402,6 @@
 /ipc/msgget/msgget01
 /ipc/msgget/msgget02
 /ipc/msgget/msgget03
-/ipc/msgget/msgget04
 /ipc/msgrcv/msgrcv01
 /ipc/msgrcv/msgrcv02
 /ipc/msgrcv/msgrcv03
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
index be9bc61..85104e8 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
@@ -1,176 +1,119 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget02.c
+ * NAME: msgget02.c
  *
  * DESCRIPTION
- *	msgget02 - test for EEXIST and ENOENT errors
- *
- * ALGORITHM
- *	create a message queue
- *	loop if that option was specified
- *	try to recreate the same queue - test #1
- *	try to access a queue that doesn't exist - tests #2 & #3
- *	check the errno value
- *	  issue a PASS message if we get EEXIST or ENOENT depening on test
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget02 [-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
+ * 1) msgget(2) fails if a message queue exists for key and msgflg
+ *    specified both IPC_CREAT and IPC_EXCL.
+ * 2) msgget(2) fails if no message queue exists for key and msgflg
+ *    did not specify IPC_CREAT.
+ * 3) msgget(2) fails if a message queue exists for key, but the
+ *    calling process does not have permission to access the queue,
+ *    and does not have the CAP_IPC_OWNER capability.
  *
- *      28/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- *      - Fix concurrency issue. The second key used for this test was
- *        sometime conflicting with the key from another task.
- *        Generate a valid second key through getipckey to avoid conflicts.
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "test.h"
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <pwd.h>
 
-#include "ipcmsg.h"
+#include "tst_ipcmsg.h"
+#include "tst_test.h"
 
-char *TCID = "msgget02";
-int TST_TOTAL = 3;
+static key_t msgkey1;
+static int msg_q_1 = -1;
 
-struct test_case_t {
-	int error;
-	int msgkey;
+static struct tcase {
+	int *key;
 	int flags;
-} TC[] = {
-	{
-	EEXIST, 0, IPC_CREAT | IPC_EXCL}, {
-	ENOENT, 1, IPC_PRIVATE}, {
-	ENOENT, 1, IPC_EXCL}
+	int exp_err;
+} tcases[] = {
+	{&msgkey, IPC_CREAT | IPC_EXCL, EEXIST},
+	{&msgkey1, IPC_PRIVATE, ENOENT},
+	{&msgkey1, IPC_EXCL, ENOENT},
+	{&msgkey, MSG_RD, EACCES},
+	{&msgkey, MSG_WR, EACCES},
+	{&msgkey, MSG_RD | MSG_WR, EACCES}
 };
 
-key_t msgkey1;
-int msg_q_1 = -1;		/* The message queue id created in setup */
-
-int main(int ac, char **av)
+static void verify_msgget(struct tcase *tc)
 {
-	int lc;
-	int i;
-	key_t key;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
+	TEST(msgget(*tc->key, tc->flags));
 
-	/* 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++) {
-
-			if (TC[i].msgkey == 0)
-				key = msgkey;
-			else
-				key = msgkey1;
-
-			TEST(msgget(key, TC[i].flags));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "msgget() succeeded unexpectedly");
+		return;
+	}
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "msgget() call succeeded "
-					 "on expected fail");
-				continue;
-			}
+	if (TEST_ERRNO == tc->exp_err)
+		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
+			" expected %s", tst_strerrno(tc->exp_err));
+}
 
-			switch (TEST_ERRNO) {
-			case ENOENT:
-			 /*FALLTHROUGH*/ case EEXIST:
-				if (TEST_ERRNO == TC[i].error) {
-					tst_resm(TPASS, "expected failure - "
-						 "errno = %d : %s", TEST_ERRNO,
-						 strerror(TEST_ERRNO));
-					break;
-				}
-			/*FALLTHROUGH*/ default:
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			}
+static void verify_access(unsigned int n)
+{
+	pid_t pid;
+	uid_t uid;
+	struct passwd *pw;
+	struct tcase *tc = &tcases[n];
+
+	if (tc->exp_err != EACCES) {
+		verify_msgget(tc);
+	} else {
+		pw = SAFE_GETPWNAM("nobody");
+		uid = pw->pw_uid;
+
+		pid = SAFE_FORK();
+		if (pid) {
+			SAFE_WAITPID(pid, NULL, 0);
+		} else {
+			SAFE_SETUID(uid);
+			verify_msgget(tc);
 		}
 	}
-
-	cleanup();
-
-	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static 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();
-
 	msgkey = getipckey();
 	msgkey1 = getipckey();
 
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		system("ipcs > /tmp/toto");
-		system("ps -aux >> /tmp/toto");
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-	}
+	msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL);
+	if (msg_q_1 == -1)
+		tst_brk(TBROK, "Can't create message queue");
 }
 
-/*
- * 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 that was created. */
 	rm_queue(msg_q_1);
-
-	tst_rmdir();
-
 }
+
+static struct tst_test test = {
+	.tid = "msgget02",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_access,
+	.tcnt = ARRAY_SIZE(tcases)
+};
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget04.c b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
deleted file mode 100644
index 22f8b38..0000000
--- a/testcases/kernel/syscalls/ipc/msgget/msgget04.c
+++ /dev/null
@@ -1,169 +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
- *	msgget04.c
- *
- * DESCRIPTION
- *	msgget04 - test for an EACCES error by creating a message queue
- *		   with no read or write permission and then attempting
- *		   to access it with various permissions.
- *
- * ALGORITHM
- *	Create a message queue with no read or write permission
- *	loop if that option was specified
- *	Try to access the message queue with various permissions
- *	check the errno value
- *	  issue a PASS message if we get EACCES
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget04 [-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
- *	none
- */
-#include <pwd.h>
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget04";
-int TST_TOTAL = 3;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int msg_q_1 = -1;		/* to hold the message queue id */
-
-int test_flags[] = { MSG_RD, MSG_WR, MSG_RD | MSG_WR };
-
-int main(int ac, char **av)
-{
-	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++) {
-			/*
-			 * Try to access the message queue with specified
-			 * permissions.
-			 */
-
-			TEST(msgget(msgkey, test_flags[i]));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded "
-					 "when EACCES error expected");
-				continue;
-			}
-
-			switch (TEST_ERRNO) {
-			case EACCES:
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
-
-	/*
-	 * 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();
-
-	/*
-	 * Create the message queue without specifying permissions.
-	 */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create message queue"
-			 " - errno = %d : %s", errno, strerror(errno));
-	}
-}
-
-/*
- * 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();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH 4/4] ipc/msgget03.c: cleanup && convert to new API
  2016-11-23  7:18 [LTP] [PATCH 1/4] ipc/lib: add header files for new API Xiao Yang
  2016-11-23  7:18 ` [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
  2016-11-23  7:18 ` [LTP] [PATCH 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
@ 2016-11-23  7:18 ` Xiao Yang
  2016-11-23 14:42   ` Cyril Hrubis
  2016-11-23 13:55 ` [LTP] [PATCH 1/4] ipc/lib: add header files for " Cyril Hrubis
  3 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-11-23  7:18 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/msgget03.c | 192 ++++++++----------------
 1 file changed, 60 insertions(+), 132 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index 2eda252..f096475 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -1,168 +1,96 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget03.c
+ * NAME: msgget03.c
  *
  * DESCRIPTION
- *	msgget03 - test for an ENOSPC error by using up all available
- *		   message queues.
- *
- * ALGORITHM
- *	Get all the message queues that can be allocated
- *	loop if that option was specified
- *	Try to get one more message queue
- *	check the errno value
- *	  issue a PASS message if we get ENOSPC
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget03 [-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.
+ * test for an ENOSPC error by using up all available
+ * message queues.
  *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget03";
-int TST_TOTAL = 1;
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <stdlib.h>
 
-int maxmsgs = 0;
+#include "tst_ipcmsg.h"
+#include "tst_test.h"
 
-int *msg_q_arr = NULL;		/* hold the id's that we create */
-int num_queue = 0;		/* count the queues created */
+static int maxmsgs;
+static int *msg_q_arr;
 
-int main(int ac, char **av)
+static void verify_msgget(void)
 {
-	int lc;
-	int msg_q;
-
-	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;
-
-		/*
-		 * Use a while loop to create the maximum number of queues.
-		 * When we get an error, check for ENOSPC.
-		 */
-		while ((msg_q =
-			msgget(msgkey + num_queue,
-			       IPC_CREAT | IPC_EXCL)) != -1) {
-			msg_q_arr[num_queue] = msg_q;
-			if (num_queue == maxmsgs) {
-				tst_resm(TINFO, "The maximum number of message"
-					 " queues (%d) has been reached",
-					 maxmsgs);
-				break;
-			}
-			num_queue++;
-		}
-
-		switch (errno) {
-		case ENOSPC:
-			tst_resm(TPASS, "expected failure - errno = %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
+	if (TEST_RETURN != -1)
+		tst_res(TFAIL, "msgget() succeeded unexpectedly");
+
+	if (TEST_ERRNO == ENOSPC)
+		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
+			" expected %s", tst_strerrno(ENOSPC));
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static 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();
+	int res, num;
 
 	msgkey = getipckey();
 
 	maxmsgs = get_max_msgqueues();
 	if (maxmsgs < 0)
-		tst_brkm(TBROK, cleanup, "get_max_msgqueues failed");
+		tst_brk(TBROK, "get_max_msgqueues failed");
 
 	msg_q_arr = (int *)calloc(maxmsgs, sizeof(int));
-	if (msg_q_arr == NULL) {
-		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
+	if (!msg_q_arr) {
+		tst_brk(TBROK, "Couldn't allocate memory "
 			 "for msg_q_arr: calloc() failed");
 	}
+
+	for (num = 0; num < maxmsgs; num++) {
+		msg_q_arr[num] = -1;
+
+		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
+		if (res != -1)
+			msg_q_arr[num] = res;
+	}
+
+	tst_res(TINFO, "The maximum number of message queues (%d) has been reached", maxmsgs);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test@completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	int i;
+	int num;
 
-	/*
-	 * remove the message queues if they were created
-	 */
+	if (msg_q_arr) {
+		for (num = 0; num < maxmsgs; num++)
+			rm_queue(msg_q_arr[num]);
 
-	if (msg_q_arr != NULL) {
-		for (i = 0; i < num_queue; i++) {
-			rm_queue(msg_q_arr[i]);
-		}
 		(void)free(msg_q_arr);
 	}
-
-	tst_rmdir();
-
 }
+
+static struct tst_test test = {
+	.tid = "msgget03",
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgget
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 1/4] ipc/lib: add header files for new API
  2016-11-23  7:18 [LTP] [PATCH 1/4] ipc/lib: add header files for new API Xiao Yang
                   ` (2 preceding siblings ...)
  2016-11-23  7:18 ` [LTP] [PATCH 4/4] ipc/msgget03.c: cleanup " Xiao Yang
@ 2016-11-23 13:55 ` Cyril Hrubis
  2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
  3 siblings, 1 reply; 28+ messages in thread
From: Cyril Hrubis @ 2016-11-23 13:55 UTC (permalink / raw)
  To: ltp

Hi!
> 1) add tst_ipcmsg.h for new API
> 2) add tst_ipcsem.h for new API
> 3???add tst_ipcshm.h for new API

Hmm, why can't we add just one libipc.h?

Also I do not think that it's a good idea to prefix anything that is not
in the top level library with tst_, that is kind of confusing.

> 4) fix libipc.c for new API
> 
> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/ipc/lib/libipc.c     |  6 +--
>  testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h | 61 ++++++++++++++++++++++++++
>  testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h | 52 ++++++++++++++++++++++
>  testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h | 47 ++++++++++++++++++++
>  4 files changed, 163 insertions(+), 3 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h
>  create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h
>  create mode 100644 testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h
> 
> diff --git a/testcases/kernel/syscalls/ipc/lib/libipc.c b/testcases/kernel/syscalls/ipc/lib/libipc.c
> index 4de7faa..856bfdb 100644
> --- a/testcases/kernel/syscalls/ipc/lib/libipc.c
> +++ b/testcases/kernel/syscalls/ipc/lib/libipc.c
> @@ -58,7 +58,7 @@ key_t getipckey(void)
>  	static int count = 0;
>  
>  	if (NULL == (curdir = getcwd(curdir, size))) {
> -		tst_brkm(TBROK, cleanup, "Can't get current directory "
> +		tst_brkm(TBROK, NULL, "Can't get current directory "
>  			 "in getipckey()");
>  	}
>  
> @@ -72,7 +72,7 @@ key_t getipckey(void)
>  	count++;
>  
>  	if ((ipc_key = ftok(curdir, proj_id)) == -1) {
> -		tst_brkm(TBROK, cleanup, "Can't get msgkey from ftok()");
> +		tst_brkm(TBROK, NULL, "Can't get msgkey from ftok()");
>  	}
>  
>  	return (ipc_key);
> @@ -145,7 +145,7 @@ int getuserid(char *user)
>  
>  	/* get the uid value for the user */
>  	if ((ent = getpwnam(user)) == NULL) {
> -		tst_brkm(TBROK, cleanup, "Couldn't get password entry for %s",
> +		tst_brkm(TBROK, NULL, "Couldn't get password entry for %s",
>  			 user);
>  	}

Hmm, so when we fail here the oldlib testcases that are using this will
fail to cleanup and the test will leave directory and some IPC objects
on the system.

Maybe it would be better to copy the whole lib directory over to libipc,
clean it and link converted testcases against the newly created libipc,
then, once the last ipc testcase is converved finally remove the old
lib.

> diff --git a/testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h b/testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h
> new file mode 100644
> index 0000000..ec80e31
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/lib/tst_ipcmsg.h
> @@ -0,0 +1,61 @@
> +/*
> + * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * 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.
> + */
> +
> +/*
> + * ipcmsg.h - common definitions for the IPC message tests.
> + */
> +
> +#ifndef __IPCMSG_H
> +#define __IPCMSG_H	1
> +
> +#include <errno.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
> +#include <sys/types.h>
> +
> +#define MSG_RD  0400            /* read permission for the queue */
> +#define MSG_WR  0200            /* write permission for the queue */
> +#define MSG_RW	(MSG_RD | MSG_WR)
> +
> +#define MSGSIZE	1024		/* a resonable size for a message */
> +#define MSGTYPE 1		/* a type ID for a message */
> +
> +#define NR_MSGQUEUES	16	/* MSGMNI as defined in linux/msg.h */
> +
> +#define min(a, b)	(((a) < (b)) ? @ : (b))
> +
> +typedef struct mbuf {		/* a generic message structure */
> +	long mtype;
> +	char mtext[MSGSIZE + 1];  /* add 1 here so the message can be 1024   */
> +} MSGBUF;			  /* characters long with a '\0' termination */
> +
> +#ifdef LIBIPC
> +key_t msgkey;                   /* the ftok() generated message key */
> +#else
> +extern key_t msgkey;                   /* the ftok() generated message key */
> +#endif
> +
> +void init_buf(MSGBUF *m_buf, int type, int size);
> +void rm_queue(int queue_id);
> +
> +key_t getipckey(void);
> +int getuserid(char *user);
> +
> +int get_max_msgqueues(void);
> +int get_used_msgqueues(void);
> +
> +#endif /* ipcmsg.h */
> diff --git a/testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h b/testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h
> new file mode 100644
> index 0000000..d9be9ab
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/lib/tst_ipcsem.h
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * 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.
> + */
> +
> +/*
> + * ipcsem.h - common definitions for the IPC semaphore tests
> + */
> +
> +#ifndef __IPCSEM_H
> +#define __IPCSEM_H
> +
> +#include <errno.h>
> +#include <sys/ipc.h>
> +#include <sys/sem.h>
> +
> +#include "lapi/semun.h"
> +
> +#define SEM_RD	0400
> +#define SEM_ALT	0200
> +#define SEM_RA	(SEM_RD | SEM_ALT)
> +
> +/*
> + * a reasonable value for the number of
> + * "primitive semaphores" per ID
> + */
> +#define PSEMS	10
> +
> +#ifdef LIBIPC
> +key_t semkey;			/* an IPC key generated by ftok() */
> +#else
> +extern key_t semkey;		/* an IPC key generated by ftok() */
> +#endif
> +
> +void rm_sema(int sem_id);
> +
> +int getipckey(void);
> +int getuserid(char *user);
> +
> +#endif /* ipcsem.h */
> diff --git a/testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h b/testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h
> new file mode 100644
> index 0000000..c5876d4
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/lib/tst_ipcshm.h
> @@ -0,0 +1,47 @@
> +/*
> + * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * 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.
> + */
> +
> +/*
> + * ipcshm.h - common definitions for the IPC shared memory tests
> + */
> +
> +#ifndef __IPCSHM_H
> +#define __IPCSHM_H
> +
> +#include <errno.h>
> +#include <wait.h>
> +#include <sys/ipc.h>
> +#include <sys/shm.h>
> +
> +#define SHM_RD	0400
> +#define SHM_WR	0200
> +#define SHM_RW	(SHM_RD | SHM_WR)
> +
> +#define SHM_SIZE	2048	/* a resonable size for a memory segment */
> +#define INT_SIZE	4	/* instead of sizeof(int) */
> +
> +#define MODE_MASK	0x01FF	/* to get the lower nine permission bits */
> +				/* from shmid_ds.ipc_perm.mode		 */
> +
> +key_t shmkey;			/* an IPC key generated by ftok() */
> +
> +void rm_shm(int shm_id);
> +
> +int getipckey(void);
> +int getuserid(char *user);
> +
> +#endif /* ipcshm.h */
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to new API
  2016-11-23  7:18 ` [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
@ 2016-11-23 14:05   ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-11-23 14:05 UTC (permalink / raw)
  To: ltp

Hi!
> +	msgkey = getipckey();
> +
> +	TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
> +
> +	if (TEST_RETURN == -1) {
> +		tst_res(TFAIL | TTERRNO, "msgget() failed");

Just do return; here so that we can omit the else branch.

> +	} else {
> +		msg_q_1 = TEST_RETURN;
> +
> +		check_functionality();

There is no reason to keep the check in the separate funciton now, we
can just do it here instead.

>  	}
>  
> -	cleanup();
> -	tst_exit();
> +	rm_queue(msg_q_1);
>  }
>  
> -/*
> - * check_functionality() - check the functionality of the tested system call.
> - */
> -void check_functionality(void)
> +static void check_functionality(void)
>  {
> -	int i = 0;
>  	MSGBUF snd_buf, rcv_buf;
>  
> -	/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */
>  	char *queue_msg =
>  	    "Qston, check_functionality here.  The message has queued!";
>  
> -	/*
> -	 * copy our message into the buffer and then set the type.
> -	 */
> -	do {
> -		snd_buf.mtext[i++] = *queue_msg;
> -	} while (*queue_msg++ != '\0');
> +	strcpy(snd_buf.mtext, queue_msg);
>  
>  	snd_buf.mtype = MSGTYPE;
>  
> -	/* send the message */
>  	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
> -		tst_brkm(TBROK, cleanup, "Could not send a message in the "
> +		tst_brk(TBROK, "Could not send a message in the "
                        ^
			TBROK | TERRNO
>  			 "check_functionality() routine.");
                           ^
			   We shoud print something shorter and more to
			   the point, such as:

			   tst_brk(TBROK|TERRNO, "msgsnd() failed");
>  	}
>  
> -	/* receive the message */
>  	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1) {
> -		tst_brkm(TBROK, cleanup, "Could not read a messages in the "
> +		tst_brk(TBROK, "Could not read a messages in the "
>  			 "check_functionality() routine.");

		here as well

>  	}
>  
>  	if (strcmp(snd_buf.mtext, rcv_buf.mtext) == 0) {
> -		tst_resm(TPASS, "message received = message sent");
> +		tst_res(TPASS, "message received = message sent");
>  	} else {
> -		tst_resm(TFAIL, "message received != message sent");
> +		tst_res(TFAIL, "message received != message sent");
>  	}
>  }
>  
> -/*
> - * 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();
> -
> -	msgkey = getipckey();
> -}
> -
> -/*
> - * 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 that was created */
> -	rm_queue(msg_q_1);
> -
> -	tst_rmdir();
> -
> -}

We should keep the rm_queue() in the cleanup function and add the
cleanup to the test structure as well, so that the queue is removed if
some part of the test called tst_brk().

And we should also set the msg_q_1 to -1 after the rm_qeueue() in the
verify_msgget() since otherwise we may attempt to remove already removed
queue when the test is called with -i and the test function is called
repeatedly.

> +static struct tst_test test = {
> +	.tid = "msgget01",
> +	.test_all = verify_msgget,
> +	.needs_tmpdir = 1
> +};
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 3/4] ipc/msgget02.c: reconstruct && convert to new API
  2016-11-23  7:18 ` [LTP] [PATCH 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
@ 2016-11-23 14:13   ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-11-23 14:13 UTC (permalink / raw)
  To: ltp

Hi!
> diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
> index be9bc61..85104e8 100644
> --- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
> +++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
> @@ -1,176 +1,119 @@
>  /*
> + * Copyright (c) International Business Machines  Corp., 2001
>   *
> - *   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.
>   */
>  
>  /*
> - * NAME
> - *	msgget02.c
> + * NAME: msgget02.c
>   *
>   * DESCRIPTION
> - *	msgget02 - test for EEXIST and ENOENT errors
> - *
> - * ALGORITHM
> - *	create a message queue
> - *	loop if that option was specified
> - *	try to recreate the same queue - test #1
> - *	try to access a queue that doesn't exist - tests #2 & #3
> - *	check the errno value
> - *	  issue a PASS message if we get EEXIST or ENOENT depening on test
> - *	otherwise, the tests fails
> - *	  issue a FAIL message
> - *	  break any remaining tests
> - *	  call cleanup
> - *
> - * USAGE:  <for command-line>
> - *  msgget02 [-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
> + * 1) msgget(2) fails if a message queue exists for key and msgflg
> + *    specified both IPC_CREAT and IPC_EXCL.
> + * 2) msgget(2) fails if no message queue exists for key and msgflg
> + *    did not specify IPC_CREAT.
> + * 3) msgget(2) fails if a message queue exists for key, but the
> + *    calling process does not have permission to access the queue,
> + *    and does not have the CAP_IPC_OWNER capability.
>   *
> - *      28/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
> - *      - Fix concurrency issue. The second key used for this test was
> - *        sometime conflicting with the key from another task.
> - *        Generate a valid second key through getipckey to avoid conflicts.
> - *
> - * RESTRICTIONS
> - *	none
>   */
>  
> -#include "test.h"
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
> +#include <pwd.h>
>  
> -#include "ipcmsg.h"
> +#include "tst_ipcmsg.h"
> +#include "tst_test.h"
>  
> -char *TCID = "msgget02";
> -int TST_TOTAL = 3;
> +static key_t msgkey1;
> +static int msg_q_1 = -1;
>  
> -struct test_case_t {
> -	int error;
> -	int msgkey;
> +static struct tcase {
> +	int *key;
>  	int flags;
> -} TC[] = {
> -	{
> -	EEXIST, 0, IPC_CREAT | IPC_EXCL}, {
> -	ENOENT, 1, IPC_PRIVATE}, {
> -	ENOENT, 1, IPC_EXCL}
> +	int exp_err;
> +} tcases[] = {
> +	{&msgkey, IPC_CREAT | IPC_EXCL, EEXIST},
> +	{&msgkey1, IPC_PRIVATE, ENOENT},
> +	{&msgkey1, IPC_EXCL, ENOENT},
> +	{&msgkey, MSG_RD, EACCES},
> +	{&msgkey, MSG_WR, EACCES},
> +	{&msgkey, MSG_RD | MSG_WR, EACCES}
>  };
>  
> -key_t msgkey1;
> -int msg_q_1 = -1;		/* The message queue id created in setup */
> -
> -int main(int ac, char **av)
> +static void verify_msgget(struct tcase *tc)
>  {
> -	int lc;
> -	int i;
> -	key_t key;
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();		/* global setup */
> +	TEST(msgget(*tc->key, tc->flags));
>  
> -	/* 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++) {
> -
> -			if (TC[i].msgkey == 0)
> -				key = msgkey;
> -			else
> -				key = msgkey1;
> -
> -			TEST(msgget(key, TC[i].flags));
> +	if (TEST_RETURN != -1) {
> +		tst_res(TFAIL, "msgget() succeeded unexpectedly");
> +		return;
> +	}
>  
> -			if (TEST_RETURN != -1) {
> -				tst_resm(TFAIL, "msgget() call succeeded "
> -					 "on expected fail");
> -				continue;
> -			}
> +	if (TEST_ERRNO == tc->exp_err)
> +		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
> +	else
> +		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
> +			" expected %s", tst_strerrno(tc->exp_err));
> +}
>  
> -			switch (TEST_ERRNO) {
> -			case ENOENT:
> -			 /*FALLTHROUGH*/ case EEXIST:
> -				if (TEST_ERRNO == TC[i].error) {
> -					tst_resm(TPASS, "expected failure - "
> -						 "errno = %d : %s", TEST_ERRNO,
> -						 strerror(TEST_ERRNO));
> -					break;
> -				}
> -			/*FALLTHROUGH*/ default:
> -				tst_resm(TFAIL, "call failed with an "
> -					 "unexpected error - %d : %s",
> -					 TEST_ERRNO, strerror(TEST_ERRNO));
> -				break;
> -			}
> +static void verify_access(unsigned int n)
               ^
	       The function name is confusing, we do not test access()
	       call here. I would have just called this do_test() or
	       something.

> +{
> +	pid_t pid;
> +	uid_t uid;
> +	struct passwd *pw;
> +	struct tcase *tc = &tcases[n];
> +
> +	if (tc->exp_err != EACCES) {

Switching on the expected errno is kind of confusing. I would rather see
as_nobody bitflag in the tcases structure that is set to 1 for this
particular case.

> +		verify_msgget(tc);
> +	} else {
> +		pw = SAFE_GETPWNAM("nobody");
> +		uid = pw->pw_uid;

This should be done in the test setup()

> +		pid = SAFE_FORK();
> +		if (pid) {
> +			SAFE_WAITPID(pid, NULL, 0);

If you do not want to check the child return value here you should
rather call tst_reap_children() that will do that for you.

> +		} else {
> +			SAFE_SETUID(uid);
> +			verify_msgget(tc);

Missing exit(0) here?

>  		}
>  	}
> -
> -	cleanup();
> -
> -	tst_exit();
>  }
>  
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> +static 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();
> -
>  	msgkey = getipckey();
>  	msgkey1 = getipckey();
>  
> -	/* now we have a key, so let's create a message queue */
> -	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
> -		system("ipcs > /tmp/toto");
> -		system("ps -aux >> /tmp/toto");
> -		tst_brkm(TBROK, cleanup, "Can't create message queue");
> -	}
> +	msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL);
> +	if (msg_q_1 == -1)
> +		tst_brk(TBROK, "Can't create message queue");
>  }

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 4/4] ipc/msgget03.c: cleanup && convert to new API
  2016-11-23  7:18 ` [LTP] [PATCH 4/4] ipc/msgget03.c: cleanup " Xiao Yang
@ 2016-11-23 14:42   ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-11-23 14:42 UTC (permalink / raw)
  To: ltp

Hi!
> + * NAME: msgget03.c

This is redundand and obvious information, I would have removed this
line as well.

>   * DESCRIPTION
> - *	msgget03 - test for an ENOSPC error by using up all available
> - *		   message queues.
> - *
> - * ALGORITHM
> - *	Get all the message queues that can be allocated
> - *	loop if that option was specified
> - *	Try to get one more message queue
> - *	check the errno value
> - *	  issue a PASS message if we get ENOSPC
> - *	otherwise, the tests fails
> - *	  issue a FAIL message
> - *	  break any remaining tests
> - *	  call cleanup
> - *
> - * USAGE:  <for command-line>
> - *  msgget03 [-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.
> + * test for an ENOSPC error by using up all available
> + * message queues.
>   *
> - * HISTORY
> - *	03/2001 - Written by Wayne Boyer
> - *
> - * RESTRICTIONS
> - *	none
>   */
>  
> -#include "test.h"
> -
> -#include "ipcmsg.h"
> -
> -char *TCID = "msgget03";
> -int TST_TOTAL = 1;
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
> +#include <stdlib.h>
>  
> -int maxmsgs = 0;
> +#include "tst_ipcmsg.h"
> +#include "tst_test.h"
>  
> -int *msg_q_arr = NULL;		/* hold the id's that we create */
> -int num_queue = 0;		/* count the queues created */
> +static int maxmsgs;
> +static int *msg_q_arr;
>  
> -int main(int ac, char **av)
> +static void verify_msgget(void)
>  {
> -	int lc;
> -	int msg_q;
> -
> -	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;
> -
> -		/*
> -		 * Use a while loop to create the maximum number of queues.
> -		 * When we get an error, check for ENOSPC.
> -		 */
> -		while ((msg_q =
> -			msgget(msgkey + num_queue,
> -			       IPC_CREAT | IPC_EXCL)) != -1) {
> -			msg_q_arr[num_queue] = msg_q;
> -			if (num_queue == maxmsgs) {
> -				tst_resm(TINFO, "The maximum number of message"
> -					 " queues (%d) has been reached",
> -					 maxmsgs);
> -				break;
> -			}
> -			num_queue++;
> -		}
> -
> -		switch (errno) {
> -		case ENOSPC:
> -			tst_resm(TPASS, "expected failure - errno = %d : %s",
> -				 TEST_ERRNO, strerror(TEST_ERRNO));
> -			break;
> -		default:
> -			tst_resm(TFAIL, "call failed with an "
> -				 "unexpected error - %d : %s",
> -				 TEST_ERRNO, strerror(TEST_ERRNO));
> -			break;
> -		}
> -	}
> -
> -	cleanup();
> -
> -	tst_exit();
> +	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
> +	if (TEST_RETURN != -1)
> +		tst_res(TFAIL, "msgget() succeeded unexpectedly");
> +
> +	if (TEST_ERRNO == ENOSPC)
> +		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
> +	else
> +		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
> +			" expected %s", tst_strerrno(ENOSPC));
>  }
>  
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> +static 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();
> +	int res, num;
>  
>  	msgkey = getipckey();
>  
>  	maxmsgs = get_max_msgqueues();
>  	if (maxmsgs < 0)
> -		tst_brkm(TBROK, cleanup, "get_max_msgqueues failed");
> +		tst_brk(TBROK, "get_max_msgqueues failed");
>  	msg_q_arr = (int *)calloc(maxmsgs, sizeof(int));

Just drop the cast to (int *) here.

> -	if (msg_q_arr == NULL) {
> -		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
> +	if (!msg_q_arr) {
> +		tst_brk(TBROK, "Couldn't allocate memory "
>  			 "for msg_q_arr: calloc() failed");
>  	}

We do have SAFE_MALLOC(), we should just do:

msg_q_arr = SAFE_MALLOC(maxmsgs * sizeof(int));

> +	for (num = 0; num < maxmsgs; num++) {
> +		msg_q_arr[num] = -1;
> +
> +		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
> +		if (res != -1)
> +			msg_q_arr[num] = res;
> +	}
> +
> +	tst_res(TINFO, "The maximum number of message queues (%d) has been reached", maxmsgs);
>  }
>  
> -/*
> - * cleanup() - performs all the ONE TIME cleanup for this test at completion
> - * 	       or premature exit.
> - */
> -void cleanup(void)
> +static void cleanup(void)
>  {
> -	int i;
> +	int num;
>  
> -	/*
> -	 * remove the message queues if they were created
> -	 */
> +	if (msg_q_arr) {
> +		for (num = 0; num < maxmsgs; num++)
> +			rm_queue(msg_q_arr[num]);
>  
> -	if (msg_q_arr != NULL) {
> -		for (i = 0; i < num_queue; i++) {
> -			rm_queue(msg_q_arr[i]);
> -		}
>  		(void)free(msg_q_arr);

Just drop the cast to (void) here.

>  	}
> -
> -	tst_rmdir();
> -
>  }
> +
> +static struct tst_test test = {
> +	.tid = "msgget03",
> +	.needs_tmpdir = 1,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = verify_msgget
> +};

Otherwise from the things I pointed out, this series looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h
  2016-11-23 13:55 ` [LTP] [PATCH 1/4] ipc/lib: add header files for " Cyril Hrubis
@ 2016-12-07  5:16   ` Xiao Yang
  2016-12-07  5:16     ` [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API Xiao Yang
                       ` (4 more replies)
  0 siblings, 5 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-07  5:16 UTC (permalink / raw)
  To: ltp

Move test result description to tst_res.h so that we
can use them independently for new ipc.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/tst_res.h  | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/tst_test.h | 30 +-----------------------------
 2 files changed, 51 insertions(+), 29 deletions(-)
 create mode 100644 include/tst_res.h

diff --git a/include/tst_res.h b/include/tst_res.h
new file mode 100644
index 0000000..0f55b01
--- /dev/null
+++ b/include/tst_res.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_RES_H__
+#define TST_RES_H__
+
+/*
+ * Reports testcase result.
+ */
+void tst_res_(const char *file, const int lineno, int ttype,
+	      const char *fmt, ...)
+	__attribute__ ((format (printf, 4, 5)));
+
+#define tst_res(ttype, arg_fmt, ...) \
+	tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__)
+
+void tst_resm_hexd_(const char *file, const int lineno, int ttype,
+		    const void *buf, size_t size, const char *arg_fmt, ...)
+	__attribute__ ((format (printf, 6, 7)));
+
+#define tst_res_hexd(ttype, buf, size, arg_fmt, ...) \
+	tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
+		(arg_fmt), ##__VA_ARGS__)
+
+/*
+ * Reports result and exits a test.
+ */
+void tst_brk_(const char *file, const int lineno, int ttype,
+	      const char *fmt, ...)
+	__attribute__ ((format (printf, 4, 5)))
+	__attribute__ ((noreturn));
+
+#define tst_brk(ttype, arg_fmt, ...) \
+	tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__)
+
+#endif	/* TST_RES_H__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index 1492ff5..92f2e2c 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -22,6 +22,7 @@
 
 #include "tst_common.h"
 #include "tst_res_flags.h"
+#include "tst_res.h"
 #include "tst_checkpoint.h"
 #include "tst_device.h"
 #include "tst_mkfs.h"
@@ -34,35 +35,6 @@
 #include "tst_kvercmp.h"
 #include "tst_clone.h"
 
-/*
- * Reports testcase result.
- */
-void tst_res_(const char *file, const int lineno, int ttype,
-              const char *fmt, ...)
-              __attribute__ ((format (printf, 4, 5)));
-
-#define tst_res(ttype, arg_fmt, ...) \
-	tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__)
-
-void tst_resm_hexd_(const char *file, const int lineno, int ttype,
-	const void *buf, size_t size, const char *arg_fmt, ...)
-	__attribute__ ((format (printf, 6, 7)));
-
-#define tst_res_hexd(ttype, buf, size, arg_fmt, ...) \
-	tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
-			(arg_fmt), ##__VA_ARGS__)
-
-/*
- * Reports result and exits a test.
- */
-void tst_brk_(const char *file, const int lineno, int ttype,
-              const char *fmt, ...)
-              __attribute__ ((format (printf, 4, 5)))
-              __attribute__ ((noreturn));
-
-#define tst_brk(ttype, arg_fmt, ...) \
-	tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__)
-
 pid_t safe_fork(const char *filename, unsigned int lineno);
 #define SAFE_FORK() \
 	safe_fork(__FILE__, __LINE__)
-- 
1.8.3.1




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

* [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API
  2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
@ 2016-12-07  5:16     ` Xiao Yang
  2016-12-12 14:58       ` Cyril Hrubis
  2016-12-07  5:16     ` [LTP] [PATCH v2 3/5] ipc/msgget01.c: cleanup && convert to " Xiao Yang
                       ` (3 subsequent siblings)
  4 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-12-07  5:16 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/Makefile             |  40 +++---
 testcases/kernel/syscalls/ipc/libnewipc/Makefile   |  24 ++++
 .../kernel/syscalls/ipc/libnewipc/libnewipc.c      | 145 +++++++++++++++++++++
 .../kernel/syscalls/ipc/libnewipc/libnewipc.h      |  52 ++++++++
 4 files changed, 240 insertions(+), 21 deletions(-)
 create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/Makefile
 create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
 create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h

diff --git a/testcases/kernel/syscalls/ipc/Makefile b/testcases/kernel/syscalls/ipc/Makefile
index 42492db..ca49e49 100644
--- a/testcases/kernel/syscalls/ipc/Makefile
+++ b/testcases/kernel/syscalls/ipc/Makefile
@@ -1,19 +1,18 @@
 #
-#  Copyright (c) International Business Machines  Corp., 2001
+# 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+# You should have received a copy of the GNU General Public License
+# along with this program.
 #
 
 top_srcdir		?= ../../../..
@@ -21,20 +20,19 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/env_pre.mk
 
 LIBDIR			:= lib
-FILTER_OUT_DIRS		:= $(LIBDIR)
-LIB			:= $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a
+NEWLIBDIR		:= libnewipc
+LIB			:= $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a $(NEWLIBDIR)/libnewipc.a
 
-$(LIBDIR):
-	mkdir -p "$@"
-
-$(LIB): $(LIBDIR)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
+$(LIB): $(LIBDIR) $(NEWLIBDIR)
+	$(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all
+	$(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" all
 
 MAKE_DEPS		:= $(LIB)
 
 trunk-clean:: | lib-clean
 
-lib-clean:: $(LIBDIR)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean
+lib-clean:: $(LIBDIR) $(NEWLIBDIR)
+	$(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean
+	$(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" clean
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/Makefile b/testcases/kernel/syscalls/ipc/libnewipc/Makefile
new file mode 100644
index 0000000..e5190f9
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/libnewipc/Makefile
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+#
+# 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.
+#
+
+top_srcdir		?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+LIB			:= libnewipc.a
+
+include $(top_srcdir)/include/mk/lib.mk
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
new file mode 100644
index 0000000..5e27662
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * DESCRIPTION
+ * common routines for the IPC system call tests.
+ *
+ * The library contains the following routines:
+ * getipckey()
+ * rm_queue()
+ * rm_sema()
+ * rm_shm()
+ * get_used_msgqueues()
+ * get_max_msgqueues()
+ */
+
+#define NEWLIBIPC
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/shm.h>
+#include <sys/sem.h>
+
+#include "libnewipc.h"
+#include "tst_res_flags.h"
+#include "tst_res.h"
+#include "tst_safe_macros.h"
+#include "lapi/semun.h"
+
+#define BUFSIZE 512
+
+key_t getipckey(void)
+{
+	int ascii_a = (int) 'a';
+	char buf[BUFSIZE];
+	key_t key;
+	int id;
+	static int count;
+
+	SAFE_GETCWD(buf, BUFSIZE);
+
+	id = count % 26 + ascii_a;
+	count++;
+
+	key = ftok(buf, id);
+	if (key == -1)
+		tst_brk(TBROK | TERRNO, "ftok() failed");
+
+	return key;
+}
+
+void rm_queue(int queue_id)
+{
+	if (queue_id == -1)
+		return;
+
+	if (msgctl(queue_id, IPC_RMID, NULL) == -1) {
+		tst_res(TINFO, "WARNING: message queue deletion failed.");
+		tst_res(TINFO, "This could lead to IPC resource problems.");
+		tst_res(TINFO, "id = %d", queue_id);
+	}
+}
+
+void rm_sema(int sem_id)
+{
+	union semun arr;
+
+	if (sem_id == -1)
+		return;
+
+	if (semctl(sem_id, 0, IPC_RMID, arr) == -1) {
+		tst_res(TINFO, "WARNING: semaphore deletion failed.");
+		tst_res(TINFO, "This could lead to IPC resource problems.");
+		tst_res(TINFO, "id = %d", sem_id);
+	}
+}
+
+void rm_shm(int shm_id)
+{
+	if (shm_id == -1)
+		return;
+
+	if (shmctl(shm_id, IPC_RMID, NULL) == -1) {
+		tst_res(TINFO, "WARNING: shared memory deletion failed.");
+		tst_res(TINFO, "This could lead to IPC resource problems.");
+		tst_res(TINFO, "id = %d", shm_id);
+	}
+}
+
+int get_used_msgqueues(void)
+{
+	FILE *f;
+	int used_queues;
+	char buf[BUFSIZE];
+
+	f = popen("ipcs -q", "r");
+	if (!f)
+		tst_brk(TBROK | TERRNO, "pipe failed");
+
+	/* FIXME: Start at -4 because ipcs prints four lines of header */
+	for (used_queues = -4; fgets(buf, BUFSIZE, f); used_queues++);
+
+	pclose(f);
+
+	if (used_queues < 0) {
+		tst_brk(TBROK, "Could not read output of 'ipcs' to "
+			"calculate used message queues");
+	}
+
+	return used_queues;
+}
+
+int get_max_msgqueues(void)
+{
+	int fd;
+	char buf[BUFSIZE];
+
+	fd = SAFE_OPEN("/proc/sys/kernel/msgmni", O_RDONLY);
+
+	SAFE_READ(0, fd, buf, BUFSIZE);
+
+	SAFE_CLOSE(fd);
+
+	return atoi(buf);
+}
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
new file mode 100644
index 0000000..6a3064d
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * common definitions for the IPC system calls.
+ */
+
+#ifndef __NEWIPC_H
+#define __NEWIPC_H	1
+
+#define MSG_RD	0400
+#define MSG_WR	0200
+#define MSG_RW	(MSG_RD | MSG_WR)
+#define MSGSIZE	1024
+#define MSGTYPE	1
+#define NR_MSGQUEUES	16
+#define min(a, b)	(((a) < (b)) ? @ : (b))
+
+#define SEM_RD	0400
+#define SEM_ALT	0200
+#define SEM_RA	(SEM_RD | SEM_ALT)
+#define PSEMS	10
+
+#define SHM_RD	0400
+#define SHM_WR	0200
+#define SHM_RW	(SHM_RD | SHM_WR)
+#define SHM_SIZE	2048
+#define INT_SIZE	4
+#define MODE_MASK	0x01FF
+
+key_t getipckey(void);
+void rm_queue(int queue_id);
+void rm_sem(int sem_id);
+void rm_shm(int shm_id);
+int get_used_msgqueues(void);
+int get_max_msgqueues(void);
+
+#endif /* newlibipc.h */
-- 
1.8.3.1




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

* [LTP] [PATCH v2 3/5] ipc/msgget01.c: cleanup && convert to new API
  2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
  2016-12-07  5:16     ` [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API Xiao Yang
@ 2016-12-07  5:16     ` Xiao Yang
  2016-12-12 15:07       ` Cyril Hrubis
  2016-12-07  5:16     ` [LTP] [PATCH v2 4/5] ipc/msgget02.c: reconstruct " Xiao Yang
                       ` (2 subsequent siblings)
  4 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-12-07  5:16 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/Makefile   |  31 ++--
 testcases/kernel/syscalls/ipc/msgget/msgget01.c | 209 ++++++------------------
 2 files changed, 72 insertions(+), 168 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/Makefile b/testcases/kernel/syscalls/ipc/msgget/Makefile
index f467389..9d86d3b 100644
--- a/testcases/kernel/syscalls/ipc/msgget/Makefile
+++ b/testcases/kernel/syscalls/ipc/msgget/Makefile
@@ -1,23 +1,28 @@
 #
-#  Copyright (c) International Business Machines  Corp., 2001
+# 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+# You should have received a copy of the GNU General Public License
+# along with this program.
 #
 
 top_srcdir              ?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+
+LDLIBS		+= -lnewipc
+NEWDIR		:= ../libnewipc
+
+CPPFLAGS	+= -I$(abs_srcdir)/$(NEWDIR)
+LDFLAGS		+= -L$(abs_builddir)/$(NEWDIR)
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget01.c b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
index e8208b7..bc6c73a 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget01.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
@@ -1,186 +1,85 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget01.c
- *
  * DESCRIPTION
- *	msgget01 - create a message queue, write a message to it and
- *		   read it back.
- *
- * ALGORITHM
- *	loop if that option was specified
- *	create a message queue
- *	check the return code
- *	  if failure, issue a FAIL message.
- *	otherwise,
- *	  if doing functionality testing by writting a message to the queue,
- *	  reading it back and comparing the two.
- *	  	if the messages are the same,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget01 [-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, write a message to it and
+ * read it back.
  */
 
-#include "ipcmsg.h"
-
+#include <errno.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
 
-char *TCID = "msgget01";
-int TST_TOTAL = 1;
+#include "libnewipc.h"
+#include "tst_test.h"
 
-int msg_q_1 = -1;		/* to hold the message queue ID */
+static int msg_q_1 = -1;
+static key_t msgkey;
 
-int main(int ac, char **av)
+static struct buf {
+	long type;
+	char text[MSGSIZE + 1];
+} snd_buf, rcv_buf;
+
+static void verify_msgget(void)
 {
-	int lc;
-	void check_functionality(void);
-
-	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;
-
-		/*
-		 * Use TEST macro to make the call to create the message queue
-		 */
-
-		TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			msg_q_1 = TEST_RETURN;
-			/*
-			 * write a message to the queue.
-			 * read back the message.
-			 * PASS the test if they are the same.
-			 */
-			check_functionality();
-		}
-
-		/*
-		 * remove the message queue that was created and mark the ID
-		 * as invalid.
-		 */
-		if (msg_q_1 != -1) {
-			rm_queue(msg_q_1);
-			msg_q_1 = -1;
-		}
+	TEST(msgget(msgkey, IPC_CREAT | MSG_RW));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "msgget() failed");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
-}
+	msg_q_1 = TEST_RETURN;
 
-/*
- * check_functionality() - check the functionality of the tested system call.
- */
-void check_functionality(void)
-{
-	int i = 0;
-	MSGBUF snd_buf, rcv_buf;
-
-	/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */
-	char *queue_msg =
-	    "Qston, check_functionality here.  The message has queued!";
-
-	/*
-	 * copy our message into the buffer and then set the type.
-	 */
-	do {
-		snd_buf.mtext[i++] = *queue_msg;
-	} while (*queue_msg++ != '\0');
-
-	snd_buf.mtype = MSGTYPE;
-
-	/* send the message */
-	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not send a message in the "
-			 "check_functionality() routine.");
-	}
+	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1)
+		tst_brk(TBROK | TERRNO, "msgsnd() failed");
 
-	/* receive the message */
-	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not read a messages in the "
-			 "check_functionality() routine.");
-	}
+	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1)
+		tst_brk(TBROK | TERRNO, "msgrcv() failed");
 
-	if (strcmp(snd_buf.mtext, rcv_buf.mtext) == 0) {
-		tst_resm(TPASS, "message received = message sent");
-	} else {
-		tst_resm(TFAIL, "message received != message sent");
-	}
+	if (strcmp(snd_buf.text, rcv_buf.text) == 0)
+		tst_res(TPASS, "message received = message sent");
+	else
+		tst_res(TFAIL, "message received != message sent");
 }
 
-/*
- * 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();
+	strcpy(snd_buf.text, "hello world");
 
-	msgkey = getipckey();
+	snd_buf.type = MSGTYPE;
 }
 
-/*
- * 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 that was created */
 	rm_queue(msg_q_1);
 
-	tst_rmdir();
-
+	msg_q_1 = -1;
 }
+
+static struct tst_test test = {
+	.tid = "msgget01",
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgget,
+	.needs_tmpdir = 1
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 4/5] ipc/msgget02.c: reconstruct && convert to new API
  2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
  2016-12-07  5:16     ` [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API Xiao Yang
  2016-12-07  5:16     ` [LTP] [PATCH v2 3/5] ipc/msgget01.c: cleanup && convert to " Xiao Yang
@ 2016-12-07  5:16     ` Xiao Yang
  2016-12-12 16:17       ` Cyril Hrubis
  2016-12-07  5:16     ` [LTP] [PATCH v2 5/5] ipc/msgget03.c: cleanup " Xiao Yang
  2016-12-12 14:28     ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Cyril Hrubis
  4 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-12-07  5:16 UTC (permalink / raw)
  To: ltp

1) merge msgget04 into msgget02
2) take use of some SAFE Marcos

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                                 |   1 -
 runtest/stress.part3                            |   1 -
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/.gitignore            |   1 -
 testcases/kernel/syscalls/ipc/msgget/msgget02.c | 235 +++++++++---------------
 testcases/kernel/syscalls/ipc/msgget/msgget04.c | 169 -----------------
 7 files changed, 90 insertions(+), 319 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgget/msgget04.c

diff --git a/runtest/ltplite b/runtest/ltplite
index a05d3ed..53e5999 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -503,7 +503,6 @@ msgctl09 msgctl09
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 274c8a4..8ff228d 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -419,7 +419,6 @@ msgctl09 msgctl09
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/syscalls b/runtest/syscalls
index e9d7401..feafa3e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -682,7 +682,6 @@ msgctl13 msgctl13
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 5592a00..8212222 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -15,7 +15,6 @@ msgctl13 msgctl13
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 63179fe..a490bf9 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -405,7 +405,6 @@
 /ipc/msgget/msgget01
 /ipc/msgget/msgget02
 /ipc/msgget/msgget03
-/ipc/msgget/msgget04
 /ipc/msgrcv/msgrcv01
 /ipc/msgrcv/msgrcv02
 /ipc/msgrcv/msgrcv03
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
index be9bc61..66484fc 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
@@ -1,176 +1,121 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget02.c
- *
  * DESCRIPTION
- *	msgget02 - test for EEXIST and ENOENT errors
- *
- * ALGORITHM
- *	create a message queue
- *	loop if that option was specified
- *	try to recreate the same queue - test #1
- *	try to access a queue that doesn't exist - tests #2 & #3
- *	check the errno value
- *	  issue a PASS message if we get EEXIST or ENOENT depening on test
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget02 [-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
+ * 1) msgget(2) fails if a message queue exists for key and msgflg
+ *    specified both IPC_CREAT and IPC_EXCL.
+ * 2) msgget(2) fails if no message queue exists for key and msgflg
+ *    did not specify IPC_CREAT.
+ * 3) msgget(2) fails if a message queue exists for key, but the
+ *    calling process does not have permission to access the queue,
+ *    and does not have the CAP_IPC_OWNER capability.
  *
- *      28/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- *      - Fix concurrency issue. The second key used for this test was
- *        sometime conflicting with the key from another task.
- *        Generate a valid second key through getipckey to avoid conflicts.
- *
- * RESTRICTIONS
- *	none
  */
-
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget02";
-int TST_TOTAL = 3;
-
-struct test_case_t {
-	int error;
-	int msgkey;
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <pwd.h>
+
+#include "libnewipc.h"
+#include "tst_test.h"
+
+static key_t msgkey, msgkey1;
+static int msg_q_1 = -1;
+static struct passwd *pw;
+
+static struct tcase {
+	int *key;
 	int flags;
-} TC[] = {
-	{
-	EEXIST, 0, IPC_CREAT | IPC_EXCL}, {
-	ENOENT, 1, IPC_PRIVATE}, {
-	ENOENT, 1, IPC_EXCL}
+	int exp_err;
+	/*1: nobody expected  0: root expected */
+	int exp_user;
+} tcases[] = {
+	{&msgkey, IPC_CREAT | IPC_EXCL, EEXIST, 0},
+	{&msgkey1, IPC_PRIVATE, ENOENT, 0},
+	{&msgkey1, IPC_EXCL, ENOENT, 0},
+	{&msgkey, MSG_RD, EACCES, 1},
+	{&msgkey, MSG_WR, EACCES, 1},
+	{&msgkey, MSG_RD | MSG_WR, EACCES, 1}
 };
 
-key_t msgkey1;
-int msg_q_1 = -1;		/* The message queue id created in setup */
-
-int main(int ac, char **av)
+static void verify_msgget(struct tcase *tc)
 {
-	int lc;
-	int i;
-	key_t key;
-
-	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++) {
-
-			if (TC[i].msgkey == 0)
-				key = msgkey;
-			else
-				key = msgkey1;
+	TEST(msgget(*tc->key, tc->flags));
 
-			TEST(msgget(key, TC[i].flags));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "msgget() succeeded unexpectedly");
+		return;
+	}
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "msgget() call succeeded "
-					 "on expected fail");
-				continue;
-			}
+	if (TEST_ERRNO == tc->exp_err)
+		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
+			" expected %s", tst_strerrno(tc->exp_err));
+}
 
-			switch (TEST_ERRNO) {
-			case ENOENT:
-			 /*FALLTHROUGH*/ case EEXIST:
-				if (TEST_ERRNO == TC[i].error) {
-					tst_resm(TPASS, "expected failure - "
-						 "errno = %d : %s", TEST_ERRNO,
-						 strerror(TEST_ERRNO));
-					break;
-				}
-			/*FALLTHROUGH*/ default:
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			}
+static void do_test(unsigned int n)
+{
+	pid_t pid;
+	struct tcase *tc = &tcases[n];
+
+	if (tc->exp_user == 0) {
+		verify_msgget(tc);
+	} else {
+		pid = SAFE_FORK();
+		if (pid) {
+			tst_reap_children();
+		} else {
+			SAFE_SETUID(pw->pw_uid);
+			verify_msgget(tc);
+			exit(0);
 		}
 	}
-
-	cleanup();
-
-	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static 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();
-
 	msgkey = getipckey();
 	msgkey1 = getipckey();
 
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		system("ipcs > /tmp/toto");
-		system("ps -aux >> /tmp/toto");
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-	}
+	msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL);
+	if (msg_q_1 == -1)
+		tst_brk(TBROK | TERRNO, "Can't create message queue");
+
+	pw = SAFE_GETPWNAM("nobody");
 }
 
-/*
- * 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 that was created. */
 	rm_queue(msg_q_1);
 
-	tst_rmdir();
-
+	msg_q_1 = -1;
 }
+
+static struct tst_test test = {
+	.tid = "msgget02",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = do_test
+};
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget04.c b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
deleted file mode 100644
index 22f8b38..0000000
--- a/testcases/kernel/syscalls/ipc/msgget/msgget04.c
+++ /dev/null
@@ -1,169 +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
- *	msgget04.c
- *
- * DESCRIPTION
- *	msgget04 - test for an EACCES error by creating a message queue
- *		   with no read or write permission and then attempting
- *		   to access it with various permissions.
- *
- * ALGORITHM
- *	Create a message queue with no read or write permission
- *	loop if that option was specified
- *	Try to access the message queue with various permissions
- *	check the errno value
- *	  issue a PASS message if we get EACCES
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget04 [-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
- *	none
- */
-#include <pwd.h>
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget04";
-int TST_TOTAL = 3;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int msg_q_1 = -1;		/* to hold the message queue id */
-
-int test_flags[] = { MSG_RD, MSG_WR, MSG_RD | MSG_WR };
-
-int main(int ac, char **av)
-{
-	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++) {
-			/*
-			 * Try to access the message queue with specified
-			 * permissions.
-			 */
-
-			TEST(msgget(msgkey, test_flags[i]));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded "
-					 "when EACCES error expected");
-				continue;
-			}
-
-			switch (TEST_ERRNO) {
-			case EACCES:
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
-
-	/*
-	 * 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();
-
-	/*
-	 * Create the message queue without specifying permissions.
-	 */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create message queue"
-			 " - errno = %d : %s", errno, strerror(errno));
-	}
-}
-
-/*
- * 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();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v2 5/5] ipc/msgget03.c: cleanup && convert to new API
  2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
                       ` (2 preceding siblings ...)
  2016-12-07  5:16     ` [LTP] [PATCH v2 4/5] ipc/msgget02.c: reconstruct " Xiao Yang
@ 2016-12-07  5:16     ` Xiao Yang
  2016-12-12 16:24       ` Cyril Hrubis
  2016-12-12 14:28     ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Cyril Hrubis
  4 siblings, 1 reply; 28+ messages in thread
From: Xiao Yang @ 2016-12-07  5:16 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/msgget03.c | 199 ++++++++----------------
 1 file changed, 63 insertions(+), 136 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index 2eda252..f6d66ce 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -1,168 +1,95 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget03.c
- *
  * DESCRIPTION
- *	msgget03 - test for an ENOSPC error by using up all available
- *		   message queues.
- *
- * ALGORITHM
- *	Get all the message queues that can be allocated
- *	loop if that option was specified
- *	Try to get one more message queue
- *	check the errno value
- *	  issue a PASS message if we get ENOSPC
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget03 [-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.
+ * test for an ENOSPC error by using up all available
+ * message queues.
  *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget03";
-int TST_TOTAL = 1;
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <stdlib.h>
 
-int maxmsgs = 0;
+#include "libnewipc.h"
+#include "tst_test.h"
 
-int *msg_q_arr = NULL;		/* hold the id's that we create */
-int num_queue = 0;		/* count the queues created */
+static int maxmsgs;
+static int *msg_q_arr;
+static key_t msgkey;
 
-int main(int ac, char **av)
+static void verify_msgget(void)
 {
-	int lc;
-	int msg_q;
-
-	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;
-
-		/*
-		 * Use a while loop to create the maximum number of queues.
-		 * When we get an error, check for ENOSPC.
-		 */
-		while ((msg_q =
-			msgget(msgkey + num_queue,
-			       IPC_CREAT | IPC_EXCL)) != -1) {
-			msg_q_arr[num_queue] = msg_q;
-			if (num_queue == maxmsgs) {
-				tst_resm(TINFO, "The maximum number of message"
-					 " queues (%d) has been reached",
-					 maxmsgs);
-				break;
-			}
-			num_queue++;
-		}
-
-		switch (errno) {
-		case ENOSPC:
-			tst_resm(TPASS, "expected failure - errno = %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
+	if (TEST_RETURN != -1)
+		tst_res(TFAIL, "msgget() succeeded unexpectedly");
+
+	if (TEST_ERRNO == ENOSPC)
+		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
+			" expected %s", tst_strerrno(ENOSPC));
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static 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();
+	int res, num;
 
 	msgkey = getipckey();
 
 	maxmsgs = get_max_msgqueues();
 	if (maxmsgs < 0)
-		tst_brkm(TBROK, cleanup, "get_max_msgqueues failed");
+		tst_brk(TBROK, "get_max_msgqueues failed");
 
-	msg_q_arr = (int *)calloc(maxmsgs, sizeof(int));
-	if (msg_q_arr == NULL) {
-		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
-			 "for msg_q_arr: calloc() failed");
+	msg_q_arr = SAFE_MALLOC(maxmsgs * sizeof(int));
+
+	for (num = 0; num < maxmsgs; num++) {
+		msg_q_arr[num] = -1;
+
+		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
+		if (res != -1)
+			msg_q_arr[num] = res;
 	}
+
+	tst_res(TINFO, "The maximum number of message queues (%d) reached",
+		maxmsgs);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test@completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	int i;
+	int num;
 
-	/*
-	 * remove the message queues if they were created
-	 */
-
-	if (msg_q_arr != NULL) {
-		for (i = 0; i < num_queue; i++) {
-			rm_queue(msg_q_arr[i]);
+	if (msg_q_arr) {
+		for (num = 0; num < maxmsgs; num++) {
+			rm_queue(msg_q_arr[num]);
+			msg_q_arr[num] = -1;
 		}
-		(void)free(msg_q_arr);
-	}
-
-	tst_rmdir();
 
+		free(msg_q_arr);
+	}
 }
+
+static struct tst_test test = {
+	.tid = "msgget03",
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgget
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h
  2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
                       ` (3 preceding siblings ...)
  2016-12-07  5:16     ` [LTP] [PATCH v2 5/5] ipc/msgget03.c: cleanup " Xiao Yang
@ 2016-12-12 14:28     ` Cyril Hrubis
  2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
  2016-12-13  7:46       ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
  4 siblings, 2 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-12 14:28 UTC (permalink / raw)
  To: ltp

Hi!
> Move test result description to tst_res.h so that we
> can use them independently for new ipc.

Isn't definining TST_NO_DEFAULT_MAIN before you include tst_test.h
enough? Is there any other problem?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API
  2016-12-07  5:16     ` [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API Xiao Yang
@ 2016-12-12 14:58       ` Cyril Hrubis
  2016-12-12 15:10         ` Cyril Hrubis
  0 siblings, 1 reply; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-12 14:58 UTC (permalink / raw)
  To: ltp

Hi!
>  include $(top_srcdir)/include/mk/generic_trunk_target.mk
> diff --git a/testcases/kernel/syscalls/ipc/libnewipc/Makefile b/testcases/kernel/syscalls/ipc/libnewipc/Makefile
> new file mode 100644
> index 0000000..e5190f9
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/libnewipc/Makefile
> @@ -0,0 +1,24 @@
> +#
> +# Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
> +#
> +# 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.
> +#
> +
> +top_srcdir		?= ../../../../..
> +
> +include $(top_srcdir)/include/mk/env_pre.mk
> +
> +LIB			:= libnewipc.a

Should be INTERNAL_LIB so that it's skipped at installation phase.

> +include $(top_srcdir)/include/mk/lib.mk
> diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
> new file mode 100644
> index 0000000..5e27662
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
> @@ -0,0 +1,145 @@
> +/*
> + * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * 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.
> + */
> +
> +/*
> + * DESCRIPTION
> + * common routines for the IPC system call tests.
> + *
> + * The library contains the following routines:
> + * getipckey()
> + * rm_queue()
> + * rm_sema()
> + * rm_shm()
> + * get_used_msgqueues()
> + * get_max_msgqueues()

This is kind of redundant information, pretty much anybody can see what
functions are implemented here.

> + */
> +
> +#define NEWLIBIPC

This macro seems to be unused.

> +#include <unistd.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <stdlib.h>
> +#include <pwd.h>
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
> +#include <sys/shm.h>
> +#include <sys/sem.h>
> +
> +#include "libnewipc.h"
> +#include "tst_res_flags.h"
> +#include "tst_res.h"
> +#include "tst_safe_macros.h"
> +#include "lapi/semun.h"
> +
> +#define BUFSIZE 512
> +
> +key_t getipckey(void)
> +{
> +	int ascii_a = (int) 'a';

Eh, why do you store the value into an variable when you can just use
the (int) 'a' in the computation directly...

> +	char buf[BUFSIZE];
> +	key_t key;
> +	int id;
> +	static int count;
> +
> +	SAFE_GETCWD(buf, BUFSIZE);
> +
> +	id = count % 26 + ascii_a;
> +	count++;

This could be written just as:

	id = (count++) % 26 + (int)'a';

> +	key = ftok(buf, id);
> +	if (key == -1)
> +		tst_brk(TBROK | TERRNO, "ftok() failed");
> +
> +	return key;
> +}
> +
> +void rm_queue(int queue_id)
> +{
> +	if (queue_id == -1)
> +		return;
> +
> +	if (msgctl(queue_id, IPC_RMID, NULL) == -1) {
> +		tst_res(TINFO, "WARNING: message queue deletion failed.");
                         ^
			 This really should be TWARN, even the message
			 includes 'WARNING' in the string. And we should
			 include errno with TERRNO as well.

			 Or even better we should exit the test with
			 TBROK here.

> +		tst_res(TINFO, "This could lead to IPC resource problems.");
> +		tst_res(TINFO, "id = %d", queue_id);
> +	}
> +}
> +
> +void rm_sema(int sem_id)
> +{
> +	union semun arr;
> +
> +	if (sem_id == -1)
> +		return;
> +
> +	if (semctl(sem_id, 0, IPC_RMID, arr) == -1) {
> +		tst_res(TINFO, "WARNING: semaphore deletion failed.");
                        ^
			Here as well.

> +		tst_res(TINFO, "This could lead to IPC resource problems.");
> +		tst_res(TINFO, "id = %d", sem_id);
> +	}
> +}
> +
> +void rm_shm(int shm_id)
> +{
> +	if (shm_id == -1)
> +		return;
> +
> +	if (shmctl(shm_id, IPC_RMID, NULL) == -1) {
> +		tst_res(TINFO, "WARNING: shared memory deletion failed.");
                              ^
			      And here as well.

> +		tst_res(TINFO, "This could lead to IPC resource problems.");
> +		tst_res(TINFO, "id = %d", shm_id);
> +	}
> +}

Moreover these there calls should really be implemented in a similar
style as SAFE_MACROS. I.e. macro RM_SHM() would pass filename and lineno
to the actuall function so that it can be printed in the resulting error
message.

> +int get_used_msgqueues(void)
> +{
> +	FILE *f;
> +	int used_queues;
> +	char buf[BUFSIZE];
> +
> +	f = popen("ipcs -q", "r");
> +	if (!f)
> +		tst_brk(TBROK | TERRNO, "pipe failed");
> +
> +	/* FIXME: Start at -4 because ipcs prints four lines of header */
> +	for (used_queues = -4; fgets(buf, BUFSIZE, f); used_queues++);
> +
> +	pclose(f);

Parsing output of a ipcs looks quite fragile to me. Why can't we use
/proc/sysvipc/msg directly instead?

> +	if (used_queues < 0) {
> +		tst_brk(TBROK, "Could not read output of 'ipcs' to "
> +			"calculate used message queues");
> +	}
> +
> +	return used_queues;
> +}
> +
> +int get_max_msgqueues(void)
> +{
> +	int fd;
> +	char buf[BUFSIZE];
> +
> +	fd = SAFE_OPEN("/proc/sys/kernel/msgmni", O_RDONLY);
> +
> +	SAFE_READ(0, fd, buf, BUFSIZE);
> +
> +	SAFE_CLOSE(fd);
> +
> +	return atoi(buf);

We have SAFE_FILE_SCANF() exactly for this purpose.

> +}
> diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
> new file mode 100644
> index 0000000..6a3064d
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * 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.
> + */
> +
> +/*
> + * common definitions for the IPC system calls.
> + */
> +
> +#ifndef __NEWIPC_H
> +#define __NEWIPC_H	1

Identifiers starting with underscore are reserved for system libraries
such as libc. Use something as LIBNEWIPC_H__ here.

> +#define MSG_RD	0400
> +#define MSG_WR	0200
> +#define MSG_RW	(MSG_RD | MSG_WR)
> +#define MSGSIZE	1024
> +#define MSGTYPE	1
> +#define NR_MSGQUEUES	16
> +#define min(a, b)	(((a) < (b)) ? @ : (b))
> +
> +#define SEM_RD	0400
> +#define SEM_ALT	0200
> +#define SEM_RA	(SEM_RD | SEM_ALT)
> +#define PSEMS	10
> +
> +#define SHM_RD	0400
> +#define SHM_WR	0200
> +#define SHM_RW	(SHM_RD | SHM_WR)
> +#define SHM_SIZE	2048
> +#define INT_SIZE	4
> +#define MODE_MASK	0x01FF
> +
> +key_t getipckey(void);
> +void rm_queue(int queue_id);
> +void rm_sem(int sem_id);
> +void rm_shm(int shm_id);
> +int get_used_msgqueues(void);
> +int get_max_msgqueues(void);
> +
> +#endif /* newlibipc.h */
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 3/5] ipc/msgget01.c: cleanup && convert to new API
  2016-12-07  5:16     ` [LTP] [PATCH v2 3/5] ipc/msgget01.c: cleanup && convert to " Xiao Yang
@ 2016-12-12 15:07       ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-12 15:07 UTC (permalink / raw)
  To: ltp

>  top_srcdir              ?= ../../../../..
>  
>  include $(top_srcdir)/include/mk/testcases.mk
> -include $(abs_srcdir)/../Makefile.inc
> +
> +LDLIBS		+= -lnewipc
> +NEWDIR		:= ../libnewipc
> +
> +CPPFLAGS	+= -I$(abs_srcdir)/$(NEWDIR)
> +LDFLAGS		+= -L$(abs_builddir)/$(NEWDIR)

I guess that we can simply write:

CPPFLAGS += -I$(abs_srcdir)/../libnewipc
LDFLAGS  += -L$(abs_builddir)/../libnewipc

It's not longer than defining the dir variable anyway.

>  include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget01.c b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
> index e8208b7..bc6c73a 100644
> --- a/testcases/kernel/syscalls/ipc/msgget/msgget01.c
> +++ b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
> @@ -1,186 +1,85 @@
>  /*
> + * Copyright (c) International Business Machines  Corp., 2001
>   *
> - *   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.
>   */
>  
>  /*
> - * NAME
> - *	msgget01.c
> - *
>   * DESCRIPTION
> - *	msgget01 - create a message queue, write a message to it and
> - *		   read it back.
> - *
> - * ALGORITHM
> - *	loop if that option was specified
> - *	create a message queue
> - *	check the return code
> - *	  if failure, issue a FAIL message.
> - *	otherwise,
> - *	  if doing functionality testing by writting a message to the queue,
> - *	  reading it back and comparing the two.
> - *	  	if the messages are the same,
> - *			issue a PASS message
> - *		otherwise
> - *			issue a FAIL message
> - *	call cleanup
> - *
> - * USAGE:  <for command-line>
> - *  msgget01 [-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, write a message to it and
> + * read it back.
>   */
>  
> -#include "ipcmsg.h"
> -
> +#include <errno.h>
>  #include <string.h>
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
>  
> -char *TCID = "msgget01";
> -int TST_TOTAL = 1;
> +#include "libnewipc.h"
> +#include "tst_test.h"
>  
> -int msg_q_1 = -1;		/* to hold the message queue ID */
> +static int msg_q_1 = -1;
> +static key_t msgkey;
>  
> -int main(int ac, char **av)
> +static struct buf {
> +	long type;
> +	char text[MSGSIZE + 1];
> +} snd_buf, rcv_buf;
> +
> +static void verify_msgget(void)
>  {
> -	int lc;
> -	void check_functionality(void);
> -
> -	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;
> -
> -		/*
> -		 * Use TEST macro to make the call to create the message queue
> -		 */
> -
> -		TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
> -
> -		if (TEST_RETURN == -1) {
> -			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
> -				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
> -		} else {
> -			msg_q_1 = TEST_RETURN;
> -			/*
> -			 * write a message to the queue.
> -			 * read back the message.
> -			 * PASS the test if they are the same.
> -			 */
> -			check_functionality();
> -		}
> -
> -		/*
> -		 * remove the message queue that was created and mark the ID
> -		 * as invalid.
> -		 */
> -		if (msg_q_1 != -1) {
> -			rm_queue(msg_q_1);
> -			msg_q_1 = -1;
> -		}
> +	TEST(msgget(msgkey, IPC_CREAT | MSG_RW));
> +	if (TEST_RETURN == -1) {
> +		tst_res(TFAIL | TTERRNO, "msgget() failed");
> +		return;
>  	}
>  
> -	cleanup();
> -	tst_exit();
> -}
> +	msg_q_1 = TEST_RETURN;
>  
> -/*
> - * check_functionality() - check the functionality of the tested system call.
> - */
> -void check_functionality(void)
> -{
> -	int i = 0;
> -	MSGBUF snd_buf, rcv_buf;
> -
> -	/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */
> -	char *queue_msg =
> -	    "Qston, check_functionality here.  The message has queued!";
> -
> -	/*
> -	 * copy our message into the buffer and then set the type.
> -	 */
> -	do {
> -		snd_buf.mtext[i++] = *queue_msg;
> -	} while (*queue_msg++ != '\0');
> -
> -	snd_buf.mtype = MSGTYPE;
> -
> -	/* send the message */
> -	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
> -		tst_brkm(TBROK, cleanup, "Could not send a message in the "
> -			 "check_functionality() routine.");
> -	}
> +	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1)
> +		tst_brk(TBROK | TERRNO, "msgsnd() failed");
>  
> -	/* receive the message */
> -	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1) {
> -		tst_brkm(TBROK, cleanup, "Could not read a messages in the "
> -			 "check_functionality() routine.");
> -	}
> +	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1)
> +		tst_brk(TBROK | TERRNO, "msgrcv() failed");
>  
> -	if (strcmp(snd_buf.mtext, rcv_buf.mtext) == 0) {
> -		tst_resm(TPASS, "message received = message sent");
> -	} else {
> -		tst_resm(TFAIL, "message received != message sent");
> -	}
> +	if (strcmp(snd_buf.text, rcv_buf.text) == 0)
> +		tst_res(TPASS, "message received = message sent");
> +	else
> +		tst_res(TFAIL, "message received != message sent");
>  }
>  
> -/*
> - * 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();
> +	strcpy(snd_buf.text, "hello world");
>  
> -	msgkey = getipckey();
> +	snd_buf.type = MSGTYPE;

You can initialize the snd_buf statically.

>  }
>  
> -/*
> - * 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 that was created */
>  	rm_queue(msg_q_1);
>  
> -	tst_rmdir();
> -
> +	msg_q_1 = -1;

There is no reason to reset msg_q_1 here, since we will never get back
to the test code once we call cleanup in the test library.

>  }
> +
> +static struct tst_test test = {
> +	.tid = "msgget01",
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = verify_msgget,
> +	.needs_tmpdir = 1
> +};
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API
  2016-12-12 14:58       ` Cyril Hrubis
@ 2016-12-12 15:10         ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-12 15:10 UTC (permalink / raw)
  To: ltp

Hi!
> > +void rm_queue(int queue_id)
> > +{
> > +	if (queue_id == -1)
> > +		return;
> > +
> > +	if (msgctl(queue_id, IPC_RMID, NULL) == -1) {
> > +		tst_res(TINFO, "WARNING: message queue deletion failed.");
>                          ^
> 			 This really should be TWARN, even the message
> 			 includes 'WARNING' in the string. And we should
> 			 include errno with TERRNO as well.
> 
> 			 Or even better we should exit the test with
> 			 TBROK here.

I see that these functions are used in the cleanup, hence TWARN is the
one that should be used here.

But even so, why can't we just do:

if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL))
	tst_res(TWARN | TERRNO, "Failed to delete message queue %i", queue_id);

In the test cleanup?

Is this really worth of creating a library function?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 4/5] ipc/msgget02.c: reconstruct && convert to new API
  2016-12-07  5:16     ` [LTP] [PATCH v2 4/5] ipc/msgget02.c: reconstruct " Xiao Yang
@ 2016-12-12 16:17       ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-12 16:17 UTC (permalink / raw)
  To: ltp

Hi!
> +static void cleanup(void)
>  {
> -	/* if it exists, remove the message queue that was created. */
>  	rm_queue(msg_q_1);
>  
> -	tst_rmdir();
> -
> +	msg_q_1 = -1;

Here again, no need to reset the msg_q_1 to -1, otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 5/5] ipc/msgget03.c: cleanup && convert to new API
  2016-12-07  5:16     ` [LTP] [PATCH v2 5/5] ipc/msgget03.c: cleanup " Xiao Yang
@ 2016-12-12 16:24       ` Cyril Hrubis
  0 siblings, 0 replies; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-12 16:24 UTC (permalink / raw)
  To: ltp

Hi!
> +	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
> +	if (TEST_RETURN != -1)
> +		tst_res(TFAIL, "msgget() succeeded unexpectedly");
> +
> +	if (TEST_ERRNO == ENOSPC)
> +		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
> +	else
> +		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
> +			" expected %s", tst_strerrno(ENOSPC));
                                        ^
					This just generates "ENOSPC" we
					can as well just write it
					directly to the message string.

And as the tst_res() spans across two lines it would be better to use
curly braces around the if blocks.

>  }
>  
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> +static 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();
> +	int res, num;
>  
>  	msgkey = getipckey();
>  
>  	maxmsgs = get_max_msgqueues();
>  	if (maxmsgs < 0)
> -		tst_brkm(TBROK, cleanup, "get_max_msgqueues failed");
> +		tst_brk(TBROK, "get_max_msgqueues failed");
>  
> -	msg_q_arr = (int *)calloc(maxmsgs, sizeof(int));
> -	if (msg_q_arr == NULL) {
> -		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
> -			 "for msg_q_arr: calloc() failed");
> +	msg_q_arr = SAFE_MALLOC(maxmsgs * sizeof(int));
> +
> +	for (num = 0; num < maxmsgs; num++) {
> +		msg_q_arr[num] = -1;
> +
> +		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
> +		if (res != -1)
> +			msg_q_arr[num] = res;
>  	}
> +
> +	tst_res(TINFO, "The maximum number of message queues (%d) reached",
> +		maxmsgs);
>  }
>  
> -/*
> - * cleanup() - performs all the ONE TIME cleanup for this test at completion
> - * 	       or premature exit.
> - */
> -void cleanup(void)
> +static void cleanup(void)
>  {
> -	int i;
> +	int num;
>  
> -	/*
> -	 * remove the message queues if they were created
> -	 */
> -
> -	if (msg_q_arr != NULL) {
> -		for (i = 0; i < num_queue; i++) {
> -			rm_queue(msg_q_arr[i]);
> +	if (msg_q_arr) {
> +		for (num = 0; num < maxmsgs; num++) {
> +			rm_queue(msg_q_arr[num]);
> +			msg_q_arr[num] = -1;

Again, no need to reset the message queue identifier here.

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API
  2016-12-12 14:28     ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Cyril Hrubis
@ 2016-12-13  7:39       ` Xiao Yang
  2016-12-13  7:39         ` [LTP] [PATCH v3 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
                           ` (3 more replies)
  2016-12-13  7:46       ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
  1 sibling, 4 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-13  7:39 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/Makefile             | 40 +++++------
 testcases/kernel/syscalls/ipc/libnewipc/Makefile   | 24 +++++++
 .../kernel/syscalls/ipc/libnewipc/libnewipc.c      | 81 ++++++++++++++++++++++
 .../kernel/syscalls/ipc/libnewipc/libnewipc.h      | 53 ++++++++++++++
 4 files changed, 177 insertions(+), 21 deletions(-)
 create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/Makefile
 create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
 create mode 100644 testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h

diff --git a/testcases/kernel/syscalls/ipc/Makefile b/testcases/kernel/syscalls/ipc/Makefile
index 42492db..ca49e49 100644
--- a/testcases/kernel/syscalls/ipc/Makefile
+++ b/testcases/kernel/syscalls/ipc/Makefile
@@ -1,19 +1,18 @@
 #
-#  Copyright (c) International Business Machines  Corp., 2001
+# 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+# You should have received a copy of the GNU General Public License
+# along with this program.
 #
 
 top_srcdir		?= ../../../..
@@ -21,20 +20,19 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/env_pre.mk
 
 LIBDIR			:= lib
-FILTER_OUT_DIRS		:= $(LIBDIR)
-LIB			:= $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a
+NEWLIBDIR		:= libnewipc
+LIB			:= $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a $(NEWLIBDIR)/libnewipc.a
 
-$(LIBDIR):
-	mkdir -p "$@"
-
-$(LIB): $(LIBDIR)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
+$(LIB): $(LIBDIR) $(NEWLIBDIR)
+	$(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all
+	$(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" all
 
 MAKE_DEPS		:= $(LIB)
 
 trunk-clean:: | lib-clean
 
-lib-clean:: $(LIBDIR)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean
+lib-clean:: $(LIBDIR) $(NEWLIBDIR)
+	$(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean
+	$(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" clean
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/Makefile b/testcases/kernel/syscalls/ipc/libnewipc/Makefile
new file mode 100644
index 0000000..efd8da7
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/libnewipc/Makefile
@@ -0,0 +1,24 @@
+#
+# Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+#
+# 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.
+#
+
+top_srcdir		?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INTERNAL_LIB		:= libnewipc.a
+
+include $(top_srcdir)/include/mk/lib.mk
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
new file mode 100644
index 0000000..8ea421f
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * DESCRIPTION
+ * common routines for the IPC system call tests.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+
+#define	TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "libnewipc.h"
+
+#define BUFSIZE 1024
+
+key_t getipckey(const char *file, const int lineno)
+{
+	char buf[BUFSIZE];
+	key_t key;
+	int id;
+	static int count;
+
+	SAFE_GETCWD(buf, BUFSIZE);
+
+	id = count % 26 + (int) 'a';
+	count++;
+
+	key = ftok(buf, id);
+	if (key == -1) {
+		tst_brk(TBROK | TERRNO,
+			"ftok() failed at %s:%d", file, lineno);
+	}
+
+	return key;
+}
+
+int get_used_queues(const char *file, const int lineno)
+{
+	FILE *fp;
+	int used_queues = -1;
+	char buf[BUFSIZE];
+
+	fp = fopen("/proc/sysvipc/msg", "r");
+	if (fp == NULL) {
+		tst_brk(TBROK | TERRNO,
+			"fopen() failed at %s:%d", file, lineno);
+	}
+
+	while (fgets(buf, BUFSIZE, fp) != NULL)
+		used_queues++;
+
+	fclose(fp);
+
+	if (used_queues < 0) {
+		tst_brk(TBROK, "can't read /proc/sysvipc/msg to get "
+			"used message queues@%s:%d", file, lineno);
+	}
+
+	return used_queues;
+}
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
new file mode 100644
index 0000000..39148be
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+/*
+ * common definitions for the IPC system calls.
+ */
+
+#ifndef __LIBNEWIPC_H
+#define __LIBNEWIPC_H	1
+
+#define MSG_RD	0400
+#define MSG_WR	0200
+#define MSG_RW	(MSG_RD | MSG_WR)
+#define MSGSIZE	1024
+#define MSGTYPE	1
+#define NR_MSGQUEUES	16
+#define min(a, b)	(((a) < (b)) ? @ : (b))
+
+#define SEM_RD	0400
+#define SEM_ALT	0200
+#define SEM_RA	(SEM_RD | SEM_ALT)
+#define PSEMS	10
+
+#define SHM_RD	0400
+#define SHM_WR	0200
+#define SHM_RW	(SHM_RD | SHM_WR)
+#define SHM_SIZE	2048
+#define INT_SIZE	4
+#define MODE_MASK	0x01FF
+
+key_t getipckey(const char *file, const int lineno);
+#define GETIPCKEY() \
+	getipckey(__FILE__, __LINE__)
+
+int get_used_queues(const char *file, const int lineno);
+#define GET_USED_QUEUES() \
+	get_used_queues(__FILE__, __LINE__)
+
+#endif /* newlibipc.h */
-- 
1.8.3.1




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

* [LTP] [PATCH v3 2/4] ipc/msgget01.c: cleanup && convert to new API
  2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
@ 2016-12-13  7:39         ` Xiao Yang
  2016-12-13  7:39         ` [LTP] [PATCH v3 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
                           ` (2 subsequent siblings)
  3 siblings, 0 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-13  7:39 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/Makefile   |  30 ++--
 testcases/kernel/syscalls/ipc/msgget/msgget01.c | 214 ++++++------------------
 2 files changed, 72 insertions(+), 172 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/Makefile b/testcases/kernel/syscalls/ipc/msgget/Makefile
index f467389..0e11bba 100644
--- a/testcases/kernel/syscalls/ipc/msgget/Makefile
+++ b/testcases/kernel/syscalls/ipc/msgget/Makefile
@@ -1,23 +1,27 @@
 #
-#  Copyright (c) International Business Machines  Corp., 2001
+# 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+# You should have received a copy of the GNU General Public License
+# along with this program.
 #
 
 top_srcdir              ?= ../../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+
+LDLIBS		+= -lnewipc
+
+CPPFLAGS	+= -I$(abs_srcdir)/../libnewipc
+LDFLAGS		+= -L$(abs_builddir)/../libnewipc
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget01.c b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
index e8208b7..8d2db4d 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget01.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
@@ -1,186 +1,82 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget01.c
- *
  * DESCRIPTION
- *	msgget01 - create a message queue, write a message to it and
- *		   read it back.
- *
- * ALGORITHM
- *	loop if that option was specified
- *	create a message queue
- *	check the return code
- *	  if failure, issue a FAIL message.
- *	otherwise,
- *	  if doing functionality testing by writting a message to the queue,
- *	  reading it back and comparing the two.
- *	  	if the messages are the same,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget01 [-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, write a message to it and
+ * read it back.
  */
 
-#include "ipcmsg.h"
-
+#include <errno.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
 
-char *TCID = "msgget01";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1;		/* to hold the message queue ID */
-
-int main(int ac, char **av)
-{
-	int lc;
-	void check_functionality(void);
-
-	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;
-
-		/*
-		 * Use TEST macro to make the call to create the message queue
-		 */
+#include "tst_test.h"
+#include "libnewipc.h"
 
-		TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR));
+static int queue_id = -1;
+static key_t msgkey;
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			msg_q_1 = TEST_RETURN;
-			/*
-			 * write a message to the queue.
-			 * read back the message.
-			 * PASS the test if they are the same.
-			 */
-			check_functionality();
-		}
+static struct buf {
+	long type;
+	char text[MSGSIZE];
+} rcv_buf, snd_buf = {MSGTYPE, "hello, world"};
 
-		/*
-		 * remove the message queue that was created and mark the ID
-		 * as invalid.
-		 */
-		if (msg_q_1 != -1) {
-			rm_queue(msg_q_1);
-			msg_q_1 = -1;
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * check_functionality() - check the functionality of the tested system call.
- */
-void check_functionality(void)
+static void verify_msgget(void)
 {
-	int i = 0;
-	MSGBUF snd_buf, rcv_buf;
-
-	/* EAGLE: Houston, Tranquility Base here. The Eagle has landed! */
-	char *queue_msg =
-	    "Qston, check_functionality here.  The message has queued!";
-
-	/*
-	 * copy our message into the buffer and then set the type.
-	 */
-	do {
-		snd_buf.mtext[i++] = *queue_msg;
-	} while (*queue_msg++ != '\0');
+	TEST(msgget(msgkey, IPC_CREAT | MSG_RW));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "msgget() failed");
+		return;
+	}
 
-	snd_buf.mtype = MSGTYPE;
+	queue_id = TEST_RETURN;
 
-	/* send the message */
-	if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not send a message in the "
-			 "check_functionality() routine.");
-	}
+	if (msgsnd(queue_id, &snd_buf, MSGSIZE, 0) == -1)
+		tst_brk(TBROK | TERRNO, "msgsnd() failed");
 
-	/* receive the message */
-	if (msgrcv(msg_q_1, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not read a messages in the "
-			 "check_functionality() routine.");
-	}
+	if (msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1)
+		tst_brk(TBROK | TERRNO, "msgrcv() failed");
 
-	if (strcmp(snd_buf.mtext, rcv_buf.mtext) == 0) {
-		tst_resm(TPASS, "message received = message sent");
-	} else {
-		tst_resm(TFAIL, "message received != message sent");
-	}
+	if (strcmp(snd_buf.text, rcv_buf.text) == 0)
+		tst_res(TPASS, "message received = message sent");
+	else
+		tst_res(TFAIL, "message received != message sent");
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static 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();
-
-	msgkey = getipckey();
+	msgkey = GETIPCKEY();
 }
 
-/*
- * 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 that was created */
-	rm_queue(msg_q_1);
-
-	tst_rmdir();
-
+	if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL)) {
+		tst_res(TWARN | TERRNO, "failed to delete message queue %i",
+			queue_id);
+	}
 }
+
+static struct tst_test test = {
+	.tid = "msgget01",
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgget,
+	.needs_tmpdir = 1
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v3 3/4] ipc/msgget02.c: reconstruct && convert to new API
  2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
  2016-12-13  7:39         ` [LTP] [PATCH v3 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
@ 2016-12-13  7:39         ` Xiao Yang
  2016-12-13  7:39         ` [LTP] [PATCH v3 4/4] ipc/msgget03.c: cleanup " Xiao Yang
  2016-12-13 13:52         ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for " Cyril Hrubis
  3 siblings, 0 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-13  7:39 UTC (permalink / raw)
  To: ltp

1) merge msgget04 into msgget02
2) take use of some SAFE Marcos

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                                 |   1 -
 runtest/stress.part3                            |   1 -
 runtest/syscalls                                |   1 -
 runtest/syscalls-ipc                            |   1 -
 testcases/kernel/syscalls/.gitignore            |   1 -
 testcases/kernel/syscalls/ipc/msgget/msgget02.c | 242 +++++++++---------------
 testcases/kernel/syscalls/ipc/msgget/msgget04.c | 169 -----------------
 7 files changed, 94 insertions(+), 322 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgget/msgget04.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 1c5ffd0..83141d1 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -502,7 +502,6 @@ msgctl09 msgctl09
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 7e43124..fcf27d0 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -418,7 +418,6 @@ msgctl09 msgctl09
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/syscalls b/runtest/syscalls
index 9446f7d..884ab80 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -681,7 +681,6 @@ msgctl13 msgctl13
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 5592a00..8212222 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -15,7 +15,6 @@ msgctl13 msgctl13
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
-msgget04 msgget04
 
 msgrcv01 msgrcv01
 msgrcv02 msgrcv02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 533edd2..3201fa9 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -404,7 +404,6 @@
 /ipc/msgget/msgget01
 /ipc/msgget/msgget02
 /ipc/msgget/msgget03
-/ipc/msgget/msgget04
 /ipc/msgrcv/msgrcv01
 /ipc/msgrcv/msgrcv02
 /ipc/msgrcv/msgrcv03
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
index be9bc61..42ce92a 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
@@ -1,176 +1,122 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget02.c
- *
  * DESCRIPTION
- *	msgget02 - test for EEXIST and ENOENT errors
- *
- * ALGORITHM
- *	create a message queue
- *	loop if that option was specified
- *	try to recreate the same queue - test #1
- *	try to access a queue that doesn't exist - tests #2 & #3
- *	check the errno value
- *	  issue a PASS message if we get EEXIST or ENOENT depening on test
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget02 [-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
+ * 1) msgget(2) fails if a message queue exists for key and msgflg
+ *    specified both IPC_CREAT and IPC_EXCL.
+ * 2) msgget(2) fails if no message queue exists for key and msgflg
+ *    did not specify IPC_CREAT.
+ * 3) msgget(2) fails if a message queue exists for key, but the
+ *    calling process does not have permission to access the queue,
+ *    and does not have the CAP_IPC_OWNER capability.
  *
- *      28/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- *      - Fix concurrency issue. The second key used for this test was
- *        sometime conflicting with the key from another task.
- *        Generate a valid second key through getipckey to avoid conflicts.
- *
- * RESTRICTIONS
- *	none
  */
-
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget02";
-int TST_TOTAL = 3;
-
-struct test_case_t {
-	int error;
-	int msgkey;
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <pwd.h>
+
+#include "tst_test.h"
+#include "libnewipc.h"
+
+static key_t msgkey, msgkey1;
+static int queue_id = -1;
+static struct passwd *pw;
+
+static struct tcase {
+	int *key;
 	int flags;
-} TC[] = {
-	{
-	EEXIST, 0, IPC_CREAT | IPC_EXCL}, {
-	ENOENT, 1, IPC_PRIVATE}, {
-	ENOENT, 1, IPC_EXCL}
+	int exp_err;
+	/*1: nobody expected  0: root expected */
+	int exp_user;
+} tcases[] = {
+	{&msgkey, IPC_CREAT | IPC_EXCL, EEXIST, 0},
+	{&msgkey1, IPC_PRIVATE, ENOENT, 0},
+	{&msgkey1, IPC_EXCL, ENOENT, 0},
+	{&msgkey, MSG_RD, EACCES, 1},
+	{&msgkey, MSG_WR, EACCES, 1},
+	{&msgkey, MSG_RW, EACCES, 1}
 };
 
-key_t msgkey1;
-int msg_q_1 = -1;		/* The message queue id created in setup */
-
-int main(int ac, char **av)
+static void verify_msgget(struct tcase *tc)
 {
-	int lc;
-	int i;
-	key_t key;
-
-	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++) {
-
-			if (TC[i].msgkey == 0)
-				key = msgkey;
-			else
-				key = msgkey1;
+	TEST(msgget(*tc->key, tc->flags));
 
-			TEST(msgget(key, TC[i].flags));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "msgget() succeeded unexpectedly");
+		return;
+	}
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "msgget() call succeeded "
-					 "on expected fail");
-				continue;
-			}
+	if (TEST_ERRNO == tc->exp_err)
+		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
+			" expected %s", tst_strerrno(tc->exp_err));
+}
 
-			switch (TEST_ERRNO) {
-			case ENOENT:
-			 /*FALLTHROUGH*/ case EEXIST:
-				if (TEST_ERRNO == TC[i].error) {
-					tst_resm(TPASS, "expected failure - "
-						 "errno = %d : %s", TEST_ERRNO,
-						 strerror(TEST_ERRNO));
-					break;
-				}
-			/*FALLTHROUGH*/ default:
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			}
+static void do_test(unsigned int n)
+{
+	pid_t pid;
+	struct tcase *tc = &tcases[n];
+
+	if (tc->exp_user == 0) {
+		verify_msgget(tc);
+	} else {
+		pid = SAFE_FORK();
+		if (pid) {
+			tst_reap_children();
+		} else {
+			SAFE_SETUID(pw->pw_uid);
+			verify_msgget(tc);
+			exit(0);
 		}
 	}
-
-	cleanup();
-
-	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	msgkey = GETIPCKEY();
+	msgkey1 = 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();
+	queue_id = msgget(msgkey, IPC_CREAT | IPC_EXCL);
+	if (queue_id == -1)
+		tst_brk(TBROK | TERRNO, "can't create message queue");
 
-	msgkey = getipckey();
-	msgkey1 = getipckey();
-
-	/* now we have a key, so let's create a message queue */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		system("ipcs > /tmp/toto");
-		system("ps -aux >> /tmp/toto");
-		tst_brkm(TBROK, cleanup, "Can't create message queue");
-	}
+	pw = SAFE_GETPWNAM("nobody");
 }
 
-/*
- * 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 that was created. */
-	rm_queue(msg_q_1);
-
-	tst_rmdir();
-
+	if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL)) {
+		tst_res(TWARN | TERRNO, "failed to delete message queue %i",
+			queue_id);
+	}
 }
+
+static struct tst_test test = {
+	.tid = "msgget02",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = do_test
+};
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget04.c b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
deleted file mode 100644
index 22f8b38..0000000
--- a/testcases/kernel/syscalls/ipc/msgget/msgget04.c
+++ /dev/null
@@ -1,169 +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
- *	msgget04.c
- *
- * DESCRIPTION
- *	msgget04 - test for an EACCES error by creating a message queue
- *		   with no read or write permission and then attempting
- *		   to access it with various permissions.
- *
- * ALGORITHM
- *	Create a message queue with no read or write permission
- *	loop if that option was specified
- *	Try to access the message queue with various permissions
- *	check the errno value
- *	  issue a PASS message if we get EACCES
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  msgget04 [-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
- *	none
- */
-#include <pwd.h>
-#include "test.h"
-
-#include "ipcmsg.h"
-
-char *TCID = "msgget04";
-int TST_TOTAL = 3;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int msg_q_1 = -1;		/* to hold the message queue id */
-
-int test_flags[] = { MSG_RD, MSG_WR, MSG_RD | MSG_WR };
-
-int main(int ac, char **av)
-{
-	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++) {
-			/*
-			 * Try to access the message queue with specified
-			 * permissions.
-			 */
-
-			TEST(msgget(msgkey, test_flags[i]));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded "
-					 "when EACCES error expected");
-				continue;
-			}
-
-			switch (TEST_ERRNO) {
-			case EACCES:
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-				break;
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
-
-	/*
-	 * 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();
-
-	/*
-	 * Create the message queue without specifying permissions.
-	 */
-	if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create message queue"
-			 " - errno = %d : %s", errno, strerror(errno));
-	}
-}
-
-/*
- * 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();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v3 4/4] ipc/msgget03.c: cleanup && convert to new API
  2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
  2016-12-13  7:39         ` [LTP] [PATCH v3 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
  2016-12-13  7:39         ` [LTP] [PATCH v3 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
@ 2016-12-13  7:39         ` Xiao Yang
  2016-12-13 13:52         ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for " Cyril Hrubis
  3 siblings, 0 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-13  7:39 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/msgget03.c | 202 ++++++++----------------
 1 file changed, 65 insertions(+), 137 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index 2eda252..ca767ab 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -1,168 +1,96 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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.
  */
 
 /*
- * NAME
- *	msgget03.c
- *
  * DESCRIPTION
- *	msgget03 - test for an ENOSPC error by using up all available
- *		   message queues.
- *
- * ALGORITHM
- *	Get all the message queues that can be allocated
- *	loop if that option was specified
- *	Try to get one more message queue
- *	check the errno value
- *	  issue a PASS message if we get ENOSPC
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
+ * test for an ENOSPC error by using up all available
+ * message queues.
  *
- * USAGE:  <for command-line>
- *  msgget03 [-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
- *	none
  */
 
-#include "test.h"
-
-#include "ipcmsg.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <stdlib.h>
 
-char *TCID = "msgget03";
-int TST_TOTAL = 1;
+#include "tst_test.h"
+#include "libnewipc.h"
 
-int maxmsgs = 0;
+static int maxmsgs;
+static int *msg_q_arr;
+static key_t msgkey;
 
-int *msg_q_arr = NULL;		/* hold the id's that we create */
-int num_queue = 0;		/* count the queues created */
-
-int main(int ac, char **av)
+static void verify_msgget(void)
 {
-	int lc;
-	int msg_q;
-
-	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;
-
-		/*
-		 * Use a while loop to create the maximum number of queues.
-		 * When we get an error, check for ENOSPC.
-		 */
-		while ((msg_q =
-			msgget(msgkey + num_queue,
-			       IPC_CREAT | IPC_EXCL)) != -1) {
-			msg_q_arr[num_queue] = msg_q;
-			if (num_queue == maxmsgs) {
-				tst_resm(TINFO, "The maximum number of message"
-					 " queues (%d) has been reached",
-					 maxmsgs);
-				break;
-			}
-			num_queue++;
-		}
-
-		switch (errno) {
-		case ENOSPC:
-			tst_resm(TPASS, "expected failure - errno = %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
+	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
+	if (TEST_RETURN != -1)
+		tst_res(TFAIL, "msgget() succeeded unexpectedly");
+
+	if (TEST_ERRNO == ENOSPC) {
+		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
+	} else {
+		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
+			" expected ENOSPC");
 	}
-
-	cleanup();
-
-	tst_exit();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	int res, num;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	msgkey = 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();
+	SAFE_FILE_SCANF("/proc/sys/kernel/msgmni", "%i", &maxmsgs);
 
-	msgkey = getipckey();
+	msg_q_arr = SAFE_MALLOC(maxmsgs * sizeof(int));
 
-	maxmsgs = get_max_msgqueues();
-	if (maxmsgs < 0)
-		tst_brkm(TBROK, cleanup, "get_max_msgqueues failed");
+	for (num = 0; num < maxmsgs; num++) {
+		msg_q_arr[num] = -1;
 
-	msg_q_arr = (int *)calloc(maxmsgs, sizeof(int));
-	if (msg_q_arr == NULL) {
-		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
-			 "for msg_q_arr: calloc() failed");
+		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
+		if (res != -1)
+			msg_q_arr[num] = res;
 	}
+
+	tst_res(TINFO, "The maximum number of message queues (%d) reached",
+		maxmsgs);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test@completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	int i;
-
-	/*
-	 * remove the message queues if they were created
-	 */
-
-	if (msg_q_arr != NULL) {
-		for (i = 0; i < num_queue; i++) {
-			rm_queue(msg_q_arr[i]);
+	int num;
+
+	if (msg_q_arr) {
+		for (num = 0; num < maxmsgs; num++) {
+			if (msg_q_arr[num] != -1 &&
+			    msgctl(msg_q_arr[num], IPC_RMID, NULL))
+				tst_res(TWARN | TERRNO,
+					"failed to delete message queue %i",
+					msg_q_arr[num]);
 		}
-		(void)free(msg_q_arr);
+		free(msg_q_arr);
 	}
-
-	tst_rmdir();
-
 }
+
+static struct tst_test test = {
+	.tid = "msgget03",
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_msgget
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h
  2016-12-12 14:28     ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Cyril Hrubis
  2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
@ 2016-12-13  7:46       ` Xiao Yang
  1 sibling, 0 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-13  7:46 UTC (permalink / raw)
  To: ltp

On 2016/12/12 22:28, Cyril Hrubis wrote:
> Hi!
>> Move test result description to tst_res.h so that we
>> can use them independently for new ipc.
> Isn't definining TST_NO_DEFAULT_MAIN before you include tst_test.h
> enough? Is there any other problem?
>
Hi Cyril

Thanks for your review.
I don't know that  defining TST_NO_DEFAULT_MAIN can skip main function,
so I remove this patch.  I have rewritten other patches as your suggestions.

Thanks,
Xiao Yang



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

* [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API
  2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
                           ` (2 preceding siblings ...)
  2016-12-13  7:39         ` [LTP] [PATCH v3 4/4] ipc/msgget03.c: cleanup " Xiao Yang
@ 2016-12-13 13:52         ` Cyril Hrubis
  2016-12-14  8:23           ` Cyril Hrubis
  3 siblings, 1 reply; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-13 13:52 UTC (permalink / raw)
  To: ltp

Hi!
> --- a/testcases/kernel/syscalls/ipc/Makefile
> +++ b/testcases/kernel/syscalls/ipc/Makefile
> @@ -1,19 +1,18 @@
>  #
> -#  Copyright (c) International Business Machines  Corp., 2001
> +# 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 St, Fifth Floor, Boston, MA  02110-1301  USA
> +# You should have received a copy of the GNU General Public License
> +# along with this program.
>  #
>  
>  top_srcdir		?= ../../../..
> @@ -21,20 +20,19 @@ top_srcdir		?= ../../../..
>  include $(top_srcdir)/include/mk/env_pre.mk
>  
>  LIBDIR			:= lib
> -FILTER_OUT_DIRS		:= $(LIBDIR)
> -LIB			:= $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a
> +NEWLIBDIR		:= libnewipc
> +LIB			:= $(LIBDIR)/libipc.a $(LIBDIR)/libmsgctl.a $(NEWLIBDIR)/libnewipc.a
>  
> -$(LIBDIR):
> -	mkdir -p "$@"
> -
> -$(LIB): $(LIBDIR)
> -	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
> +$(LIB): $(LIBDIR) $(NEWLIBDIR)
> +	$(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" all
> +	$(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" all
>  
>  MAKE_DEPS		:= $(LIB)
>  
>  trunk-clean:: | lib-clean
>  
> -lib-clean:: $(LIBDIR)
> -	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean
> +lib-clean:: $(LIBDIR) $(NEWLIBDIR)
> +	$(MAKE) -C $(LIBDIR) -f "$(abs_srcdir)/$(LIBDIR)/Makefile" clean
> +	$(MAKE) -C $(NEWLIBDIR) -f "$(abs_srcdir)/$(NEWLIBDIR)/Makefile" clean

I've just found that this whole Makefile has been broken for ages and
that the old library was build only by the inclusion of the Makefile.inc
in the test directories, I wonder why this wasn't breaking parallel
build at all. The whole reason is that MAKE_DEPS is ignored when
MAKE_TARGETS is empty so the $(LIB) targets are not rebuild and removing
the $(LIBDIR) from FILTER_OUT_DIRS is not solution either since that
will break parallel build for sure.

I will do something about this. One solution may be to set the
MAKE_TARGETS to some phony target if it's empty. Let's see if I can
figure out something better.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API
  2016-12-13 13:52         ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for " Cyril Hrubis
@ 2016-12-14  8:23           ` Cyril Hrubis
  2016-12-14  9:19             ` Cyril Hrubis
  0 siblings, 1 reply; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-14  8:23 UTC (permalink / raw)
  To: ltp

Hi!
> I've just found that this whole Makefile has been broken for ages and
> that the old library was build only by the inclusion of the Makefile.inc
> in the test directories, I wonder why this wasn't breaking parallel
> build at all. The whole reason is that MAKE_DEPS is ignored when
> MAKE_TARGETS is empty so the $(LIB) targets are not rebuild and removing
> the $(LIBDIR) from FILTER_OUT_DIRS is not solution either since that
> will break parallel build for sure.
> 
> I will do something about this. One solution may be to set the
> MAKE_TARGETS to some phony target if it's empty. Let's see if I can
> figure out something better.

And, after a bit of research, I've realized, that without introducing
larger changes in the build system the only reasonable way how to build
a library is by using the Makefile.inc in all test subdirectories that
use it. That works since the make in subdirectories is executed in a
shell loop, which means that we will never end up building the same
library at the same time from several subdirectories.

So the correct way how to fix this issue is to add the libnewipc to the
FILTER_OUT_DIRS and create Makefile2.inc similar to Makefile.inc. I will
change the first patch to do exactly that and push the patchset.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API
  2016-12-14  8:23           ` Cyril Hrubis
@ 2016-12-14  9:19             ` Cyril Hrubis
  2016-12-14  9:42               ` Xiao Yang
  0 siblings, 1 reply; 28+ messages in thread
From: Cyril Hrubis @ 2016-12-14  9:19 UTC (permalink / raw)
  To: ltp

Hi!
> So the correct way how to fix this issue is to add the libnewipc to the
> FILTER_OUT_DIRS and create Makefile2.inc similar to Makefile.inc. I will
> change the first patch to do exactly that and push the patchset.

And I've pushed the patches, thanks.

I've added Makefile2.inc and also added clean target to the top level
Makefile so that the libnewipc is cleaned up on make clean.

And also merged the three msgget patches into one, since once the
Makefile.inc is changed for Makefile2.inc in the Makefile the rest of
the msgget testcases fails to build, which breaks bisecting. Ideally
each commit should leave the tree in a state that at least compiles
cleanly...

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API
  2016-12-14  9:19             ` Cyril Hrubis
@ 2016-12-14  9:42               ` Xiao Yang
  0 siblings, 0 replies; 28+ messages in thread
From: Xiao Yang @ 2016-12-14  9:42 UTC (permalink / raw)
  To: ltp

Hi Cyril
on 2016/12/14 17:19, Cyril Hrubis wrote:
> Hi!
>> So the correct way how to fix this issue is to add the libnewipc to the
>> FILTER_OUT_DIRS and create Makefile2.inc similar to Makefile.inc. I will
>> change the first patch to do exactly that and push the patchset.
> And I've pushed the patches, thanks.
>
> I've added Makefile2.inc and also added clean target to the top level
> Makefile so that the libnewipc is cleaned up on make clean.
>
> And also merged the three msgget patches into one, since once the
> Makefile.inc is changed for Makefile2.inc in the Makefile the rest of
> the msgget testcases fails to build, which breaks bisecting. Ideally
> each commit should leave the tree in a state that at least compiles
> cleanly...
>
Thanks for your explanation and fix, so i got it. :-)

Best Regards,
Xiao Yang




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

end of thread, other threads:[~2016-12-14  9:42 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23  7:18 [LTP] [PATCH 1/4] ipc/lib: add header files for new API Xiao Yang
2016-11-23  7:18 ` [LTP] [PATCH 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
2016-11-23 14:05   ` Cyril Hrubis
2016-11-23  7:18 ` [LTP] [PATCH 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
2016-11-23 14:13   ` Cyril Hrubis
2016-11-23  7:18 ` [LTP] [PATCH 4/4] ipc/msgget03.c: cleanup " Xiao Yang
2016-11-23 14:42   ` Cyril Hrubis
2016-11-23 13:55 ` [LTP] [PATCH 1/4] ipc/lib: add header files for " Cyril Hrubis
2016-12-07  5:16   ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang
2016-12-07  5:16     ` [LTP] [PATCH v2 2/5] syscalls/ipc: add newipc library for new API Xiao Yang
2016-12-12 14:58       ` Cyril Hrubis
2016-12-12 15:10         ` Cyril Hrubis
2016-12-07  5:16     ` [LTP] [PATCH v2 3/5] ipc/msgget01.c: cleanup && convert to " Xiao Yang
2016-12-12 15:07       ` Cyril Hrubis
2016-12-07  5:16     ` [LTP] [PATCH v2 4/5] ipc/msgget02.c: reconstruct " Xiao Yang
2016-12-12 16:17       ` Cyril Hrubis
2016-12-07  5:16     ` [LTP] [PATCH v2 5/5] ipc/msgget03.c: cleanup " Xiao Yang
2016-12-12 16:24       ` Cyril Hrubis
2016-12-12 14:28     ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Cyril Hrubis
2016-12-13  7:39       ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API Xiao Yang
2016-12-13  7:39         ` [LTP] [PATCH v3 2/4] ipc/msgget01.c: cleanup && convert to " Xiao Yang
2016-12-13  7:39         ` [LTP] [PATCH v3 3/4] ipc/msgget02.c: reconstruct " Xiao Yang
2016-12-13  7:39         ` [LTP] [PATCH v3 4/4] ipc/msgget03.c: cleanup " Xiao Yang
2016-12-13 13:52         ` [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for " Cyril Hrubis
2016-12-14  8:23           ` Cyril Hrubis
2016-12-14  9:19             ` Cyril Hrubis
2016-12-14  9:42               ` Xiao Yang
2016-12-13  7:46       ` [LTP] [PATCH v2 1/5] tst_test.h: move test result description to tst_res.h Xiao Yang

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.