* [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code
@ 2016-12-16 3:54 Xiao Yang
2016-12-16 3:54 ` [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
2017-01-19 14:39 ` [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Cyril Hrubis
0 siblings, 2 replies; 11+ messages in thread
From: Xiao Yang @ 2016-12-16 3:54 UTC (permalink / raw)
To: ltp
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c | 14 ++++++++++++++
testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h | 4 ++++
testcases/kernel/syscalls/ipc/msgget/msgget02.c | 4 +---
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
index 8ea421f..9452309 100644
--- a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
+++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
+#include <sys/msg.h>
#define TST_NO_DEFAULT_MAIN
@@ -79,3 +80,16 @@ int get_used_queues(const char *file, const int lineno)
return used_queues;
}
+
+int create_msg(const char *file, const int lineno, key_t key, int msgflg)
+{
+ int rval;
+
+ rval = msgget(key, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "Can't create message queue at %s:%d",
+ file, lineno);
+ }
+
+ return rval;
+}
diff --git a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
index 39148be..3c313bd 100644
--- a/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
+++ b/testcases/kernel/syscalls/ipc/libnewipc/libnewipc.h
@@ -50,4 +50,8 @@ int get_used_queues(const char *file, const int lineno);
#define GET_USED_QUEUES() \
get_used_queues(__FILE__, __LINE__)
+int create_msg(const char *file, const int lineno, key_t key, int msgflg);
+#define CREATE_MSG(key, msgflg) \
+ create_msg(__FILE__, __LINE__, key, msgflg)
+
#endif /* newlibipc.h */
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
index a3fcb38..1195cc9 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
@@ -96,9 +96,7 @@ static void setup(void)
msgkey = GETIPCKEY();
msgkey1 = GETIPCKEY();
- queue_id = msgget(msgkey, IPC_CREAT | IPC_EXCL);
- if (queue_id == -1)
- tst_brk(TBROK | TERRNO, "can't create message queue");
+ queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL);
pw = SAFE_GETPWNAM("nobody");
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API
2016-12-16 3:54 [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Xiao Yang
@ 2016-12-16 3:54 ` Xiao Yang
2016-12-27 7:44 ` Xiao Yang
2017-01-19 15:21 ` Cyril Hrubis
2017-01-19 14:39 ` [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Cyril Hrubis
1 sibling, 2 replies; 11+ messages in thread
From: Xiao Yang @ 2016-12-16 3:54 UTC (permalink / raw)
To: ltp
1) The msgsnd03 was merged into msgsnd02
2) The msgsnd04 was merged into msgsnd05
3) take use of CREATE_MSG
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
runtest/ltplite | 2 -
runtest/stress.part3 | 2 -
runtest/syscalls | 2 -
runtest/syscalls-ipc | 2 -
testcases/kernel/syscalls/.gitignore | 2 -
testcases/kernel/syscalls/ipc/msgsnd/Makefile | 29 +--
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 198 +++++-----------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c | 245 ++++++++------------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c | 178 ---------------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c | 155 -------------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c | 285 ++++++++----------------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c | 252 +++++----------------
12 files changed, 318 insertions(+), 1034 deletions(-)
delete mode 100644 testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
delete mode 100644 testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
diff --git a/runtest/ltplite b/runtest/ltplite
index 83141d1..d4580ad 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -514,8 +514,6 @@ msgrcv08 msgrcv08
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index fcf27d0..41f8b25 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -429,8 +429,6 @@ msgrcv07 msgrcv07
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/runtest/syscalls b/runtest/syscalls
index 884ab80..dd9f9a9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -693,8 +693,6 @@ msgrcv08 msgrcv08
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 8212222..91060b9 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -27,8 +27,6 @@ msgrcv08 msgrcv08
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 3201fa9..84c7977 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -414,8 +414,6 @@
/ipc/msgrcv/msgrcv08
/ipc/msgsnd/msgsnd01
/ipc/msgsnd/msgsnd02
-/ipc/msgsnd/msgsnd03
-/ipc/msgsnd/msgsnd04
/ipc/msgsnd/msgsnd05
/ipc/msgsnd/msgsnd06
/ipc/semctl/semctl01
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/Makefile b/testcases/kernel/syscalls/ipc/msgsnd/Makefile
index f467389..207fb16 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/Makefile
+++ b/testcases/kernel/syscalls/ipc/msgsnd/Makefile
@@ -1,23 +1,26 @@
#
-# 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 ?= ../../../../..
+ifeq ($(UCLINUX),1)
+FILTER_OUT_MAKE_TARGETS += msgsnd05 msgsnd06
+endif
+
include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+include $(abs_srcdir)/../Makefile2.inc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 0ca2be0..64fff40 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -1,169 +1,81 @@
/*
+ * 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
- * msgsnd01.c
- *
* DESCRIPTION
- * msgsnd01 - test that msgsnd() enqueues a message correctly
- *
- * ALGORITHM
- * create a message queue
- * initialize a message buffer with a known message and type
- * loop if that option was specified
- * enqueue the message
- * check the return code
- * if failure, issue a FAIL message.
- * otherwise,
- * if doing functionality testing
- * stat the message queue
- * check for # of bytes = MSGSIZE and # of messages = 1
- * if correct,
- * issue a PASS message
- * otherwise
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * None
+ * test that msgsnd() enqueues a message correctly
*/
-#include "test.h"
-
-#include "ipcmsg.h"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd01";
-int TST_TOTAL = 1;
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
-int msg_q_1;
-MSGBUF msg_buf, rd_buf;
+#include "tst_test.h"
+#include "libnewipc.h"
-struct msqid_ds qs_buf;
+static key_t msgkey;
+static int queue_id;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} rcv_buf, snd_buf = {MSGTYPE, "hello, world"};
-int main(int ac, char **av)
+static void verify_msgsnd(void)
{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /*
- * Use TEST macro to make the call
- */
-
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
-
- if (TEST_RETURN == -1) {
- tst_resm(TFAIL, "%s call failed - errno = %d : %s",
- TCID, TEST_ERRNO, strerror(TEST_ERRNO));
- continue;
- }
-
- /* get the queue status */
- if (msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1) {
- tst_brkm(TBROK, cleanup, "Could not "
- "get queue status");
- }
+ struct msqid_ds qs_buf;
- if (qs_buf.msg_cbytes != MSGSIZE) {
- tst_resm(TFAIL, "queue bytes != MSGSIZE");
- }
-
- if (qs_buf.msg_qnum != 1) {
- tst_resm(TFAIL, "queue message != 1");
- }
+ TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
+ if (TEST_RETURN == -1) {
+ tst_res(TFAIL | TTERRNO, "msgsnd() failed");
+ return;
+ }
- tst_resm(TPASS, "queue bytes = MSGSIZE and "
- "queue messages = 1");
+ if (msgctl(queue_id, IPC_STAT, &qs_buf) == -1)
+ tst_brk(TBROK | TERRNO, "msgctl() failed to get queue status");
- /*
- * remove the message by reading from the queue
- */
- if (msgrcv(msg_q_1, &rd_buf, MSGSIZE, 1, 0) == -1) {
- tst_brkm(TBROK, cleanup, "Could not read from queue");
- }
- }
+ if (qs_buf.msg_cbytes == MSGSIZE && qs_buf.msg_qnum == 1)
+ tst_res(TPASS, "queue bytes and number of queues matched");
+ else
+ tst_res(TFAIL, "queue bytes or number of queues mismatched");
- cleanup();
- tst_exit();
+ if (msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0) == -1)
+ tst_brk(TBROK | TERRNO, "msgrcv() failed");
}
-/*
- * 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();
-
- msgkey = getipckey();
-
- /* create a message queue with read/write permissions */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
+ queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
}
-/*
- * 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 if it exists */
- 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 = "msgsnd01",
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_msgsnd,
+ .needs_tmpdir = 1
+};
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
index 6547ab2..9367775 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
@@ -1,175 +1,126 @@
/*
+ * 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
- * msgsnd02.c
- *
* DESCRIPTION
- * msgsnd02 - test for EACCES and EFAULT errors
- *
- * ALGORITHM
- * create a message queue without write permission
- * create a trivial message buffer
- * loop if that option was specified
- * call msgsnd() using two different invalid cases
- * check the errno value
- * issue a PASS message if we get EACCES or EFAULT
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd02 [-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
+ * 1) test for EACCES error
+ * 2) test for EFAULT error
+ * 3) test for EINVAL error
*/
-#include <pwd.h>
-#include "test.h"
-
-#include "ipcmsg.h"
-
-void cleanup(void);
-void setup(void);
-char *TCID = "msgsnd02";
-int TST_TOTAL = 2;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-MSGBUF msg_buf; /* a buffer for the message to queue */
-int bad_q = -1; /* a value to use as a bad queue ID */
-
-struct test_case_t {
- int *queue_id;
- MSGBUF *buffer;
- int error;
-} TC[] = {
- /* EACCES - there is no write permission for the queue */
- {
- &msg_q_1, &msg_buf, EACCES},
- /* EFAULT - the message buffer address is invalid */
- {
-&msg_q_1, NULL, EFAULT},};
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <pwd.h>
-int main(int ac, char **av)
+#include "tst_test.h"
+#include "libnewipc.h"
+
+static key_t msgkey;
+static int queue_id = -1;
+static int bad_id = -1;
+static struct passwd *pw;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} snd_buf = {1, "hello, world"};
+
+static struct tcase {
+ int *id;
+ struct buf *buffer;
+ long mtype;
+ int msgsz;
+ int exp_err;
+ /*1: nobody expected 0: root expected */
+ int exp_user;
+} tcases[] = {
+ {&queue_id, &snd_buf, 1, MSGSIZE, EACCES, 1},
+ {&queue_id, NULL, 1, MSGSIZE, EFAULT, 0},
+ {&bad_id, &snd_buf, 1, MSGSIZE, EINVAL, 0},
+ {&queue_id, &snd_buf, 0, MSGSIZE, EINVAL, 0},
+ {&queue_id, &snd_buf, -1, MSGSIZE, EINVAL, 0},
+ {&queue_id, &snd_buf, 1, -1, EINVAL, 0}
+};
+
+static void verify_msgsnd(struct tcase *tc)
{
- 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
- */
+ snd_buf.type = tc->mtype;
- for (i = 0; i < TST_TOTAL; i++) {
- TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer, 1, 0));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- continue;
- }
-
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - "
- "errno = %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- }
- }
+ TEST(msgsnd(*tc->id, tc->buffer, tc->msgsz, 0));
+ if (TEST_RETURN != -1) {
+ tst_res(TFAIL, "smgsnd() succeeded unexpectedly");
+ return;
}
- cleanup();
-
- tst_exit();
+ if (TEST_ERRNO == tc->exp_err) {
+ tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
+ } else {
+ tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
+ " expected %s", tst_strerrno(tc->exp_err));
+ }
}
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void do_test(unsigned int n)
{
- tst_require_root();
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ pid_t pid;
+ struct tcase *tc = &tcases[n];
- 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");
+ if (tc->exp_user == 0) {
+ verify_msgsnd(tc);
+ return;
}
- /*
- * 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 a message queue without write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
+ pid = SAFE_FORK();
+ if (pid) {
+ tst_reap_children();
+ } else {
+ SAFE_SETUID(pw->pw_uid);
+ verify_msgsnd(tc);
+ exit(0);
}
-
- /* initialize the message buffer with something trivial */
- msg_buf.mtype = MSGTYPE;
- msg_buf.mtext[0] = 'a';
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
+static void setup(void)
{
- /* if it exists, remove the message queue that was created */
- rm_queue(msg_q_1);
+ msgkey = GETIPCKEY();
- tst_rmdir();
+ queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+ pw = SAFE_GETPWNAM("nobody");
}
+
+static void cleanup(void)
+{
+ 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 = "msgsnd02",
+ .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/msgsnd/msgsnd03.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
deleted file mode 100644
index ef6e58e..0000000
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
+++ /dev/null
@@ -1,178 +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
- * msgsnd03.c
- *
- * DESCRIPTION
- * msgsnd03 - test for EINVAL error
- *
- * ALGORITHM
- * create a message queue with read/write permissions
- * create a trivial message buffer
- * loop if that option was specified
- * call msgsnd() using four different invalid cases
- * check the errno value
- * issue a PASS message if we get EINVAL
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd03 [-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"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd03";
-int TST_TOTAL = 4;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-MSGBUF msg_buf; /* a buffer for the message to queue */
-int bad_q = -1; /* a value to use as a bad queue ID */
-
-struct test_case_t {
- int *queue_id;
- MSGBUF *buffer;
- long mtype;
- int msg_size;
- int error;
-} TC[] = {
- /* EINVAL - the queue ID is invalid */
- {
- &bad_q, &msg_buf, 1, 1, EINVAL},
- /* EINVAL - the message type is not positive (0) */
- {
- &msg_q_1, &msg_buf, 0, 1, EINVAL},
- /* EINVAL - the message type is not positive (>0) */
- {
- &msg_q_1, &msg_buf, -1, 1, EINVAL},
- /* EINVAL - the message size is less than zero */
- {
- &msg_q_1, &msg_buf, 1, -1, EINVAL}
-};
-
-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++) {
-
- /* set the message type */
- msg_buf.mtype = TC[i].mtype;
-
- /* make the call with the TEST macro */
- TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer,
- TC[i].msg_size, 0));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- continue;
- }
-
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - "
- "errno = %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- }
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See ../lib/libipc.c for more information.
- */
- tst_tmpdir();
-
- msgkey = getipckey();
-
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer with something trivial */
- msg_buf.mtype = MSGTYPE;
- msg_buf.mtext[0] = 'a';
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test@completion
- * or premature exit.
- */
-void cleanup(void)
-{
- /* if it exists, remove the message queue that was created */
- rm_queue(msg_q_1);
-
- tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
deleted file mode 100644
index 4432d67..0000000
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
+++ /dev/null
@@ -1,155 +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
- * msgsnd04.c
- *
- * DESCRIPTION
- * msgsnd04 - test for EAGAIN error
- *
- * ALGORITHM
- * create a message queue with read/write permissions
- * initialize a message buffer with a known message and type
- * enqueue the message in a loop until the queue is full
- * loop if that option was specified
- * attempt to enqueue another message - msgsnd()
- * check the errno value
- * issue a PASS message if we get EAGAIN
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd04 [-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"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd04";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-MSGBUF msg_buf;
-
-int main(int ac, char **av)
-{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /*
- * Attempt to write another message to the full queue.
- */
-
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded when error expected");
- continue;
- }
-
- switch (TEST_ERRNO) {
- case EAGAIN:
- 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_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();
-
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
-
- /* write messages to the queue until it is full */
- while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
- msg_buf.mtype += 1;
- }
-}
-
-/*
- * 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();
-
-}
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
index 16d62f8..0d13065 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
@@ -1,234 +1,125 @@
/*
+ * 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
- * msgsnd05.c
- *
* DESCRIPTION
- * msgsnd05 - test for EINTR error
- *
- * ALGORITHM
- * create a message queue with read/write permissions
- * initialize a message buffer with a known message and type
- * enqueue the message in a loop until the queue is full
- * loop if that option was specified
- * fork a child process
- * child attempts to enqueue a message to the full queue and sleeps
- * parent sends a SIGHUP to the child then waits for the child to complete
- * child get a return from msgsnd()
- * check the errno value
- * issue a PASS message if we get EINTR
- * otherwise, the tests fails
- * issue a FAIL message
- * child exits, parent calls cleanup
- *
- * USAGE: <for command-line>
- * msgsnd05 [-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
- * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
- * - Fix concurrency issue. Due to the use of usleep function to
- * synchronize processes, synchronization issues can occur on a loaded
- * system. Fix this by using pipes to synchronize processes.
- *
- * RESTRICTIONS
- * none
+ * 1) test for EAGAIN error
+ * 2) test for EINTR error
*/
-#include "test.h"
-
-#include "ipcmsg.h"
-
+#include <errno.h>
+#include <stdlib.h>
#include <sys/types.h>
-#include <sys/wait.h>
-
-void do_child(void);
-void cleanup(void);
-void setup(void);
-#ifdef UCLINUX
-#define PIPE_NAME "msgsnd05"
-void do_child_uclinux(void);
-#endif
-
-char *TCID = "msgsnd05";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-
-MSGBUF msg_buf;
-
-int main(int ac, char **av)
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#include "tst_test.h"
+#include "libnewipc.h"
+
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} snd_buf = {1, "hello, world"};
+
+static struct tcase {
+ int flag;
+ int exp_err;
+ /*1: nobody expected 0: root expected */
+ int exp_user;
+} tcases[] = {
+ {IPC_NOWAIT, EAGAIN, 0},
+ {0, EINTR, 1}
+};
+
+static void verify_msgsnd(struct tcase *tc)
{
- int lc;
- pid_t c_pid;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
-#ifdef UCLINUX
- maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
-#endif
-
- 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;
-
- /*
- * fork a child that will attempt to write a message
- * to the queue without IPC_NOWAIT
- */
- if ((c_pid = FORK_OR_VFORK()) == -1) {
- tst_brkm(TBROK, cleanup, "could not fork");
- }
-
- if (c_pid == 0) { /* child */
- /*
- * Attempt to write another message to the full queue.
- * Without the IPC_NOWAIT flag, the child sleeps
- */
-
-#ifdef UCLINUX
- if (self_exec(av[0], "d", msg_q_1) < 0) {
- tst_brkm(TBROK, cleanup, "could not self_exec");
- }
-#else
- do_child();
-#endif
- } else {
- TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
-
- /* send a signal that must be caught to the child */
- if (kill(c_pid, SIGHUP) == -1)
- tst_brkm(TBROK, cleanup, "kill failed");
-
- waitpid(c_pid, NULL, 0);
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-/*
- * do_child()
- */
-void do_child(void)
-{
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
-
+ TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, tc->flag));
if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded when error expected");
- exit(-1);
+ tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
+ return;
}
- switch (TEST_ERRNO) {
- case EINTR:
- 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;
+ if (TEST_ERRNO == tc->exp_err) {
+ tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
+ } else {
+ tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
+ " expected %s", tst_strerrno(tc->exp_err));
}
-
- exit(0);
}
-void sighandler(int sig)
+static void sighandler(int sig)
{
if (sig == SIGHUP)
return;
else
- tst_brkm(TBROK, NULL, "received unexpected signal %d", sig);
+ tst_brk(TBROK, "received unexpected signal %d", sig);
}
-#ifdef UCLINUX
-/*
- * do_child_uclinux() - capture signals, initialize buffer, then run do_child()
- */
-void do_child_uclinux(void)
+static void do_test(unsigned int n)
{
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
-
- tst_sig(FORK, sighandler, cleanup);
+ pid_t pid;
+ struct tcase *tc = &tcases[n];
- do_child();
-}
-#endif
+ if (tc->exp_user == 0) {
+ verify_msgsnd(tc);
+ return;
+ }
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
- /* capture signals in our own handler */
- tst_sig(FORK, sighandler, cleanup);
+ pid = SAFE_FORK();
+ if (!pid) {
+ verify_msgsnd(tc);
+ exit(0);
+ }
- TEST_PAUSE;
+ TST_PROCESS_STATE_WAIT(pid, 'S');
- /*
- * 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_KILL(pid, SIGHUP);
+ tst_reap_children();
+}
- msgkey = getipckey();
+static void setup(void)
+{
+ SAFE_SIGNAL(SIGHUP, sighandler);
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
+ msgkey = GETIPCKEY();
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
+ queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
- /* write messages to the queue until it is full */
- while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
- msg_buf.mtype += 1;
- }
+ while (msgsnd(queue_id, &snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
+ snd_buf.type += 1;
}
-/*
- * 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 = "msgsnd05",
+ .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/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
index 42f6e79..737fc7f 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
@@ -1,222 +1,92 @@
/*
+ * 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
- * msgsnd06.c
- *
* DESCRIPTION
- * msgsnd06 - test for EIDRM error
- *
- * ALGORITHM
- * loop if that option was specified
- * create a message queue with read/write permissions
- * initialize a message buffer with a known message and type
- * enqueue messages in a loop until the queue is full
- * fork a child process
- * child attempts to enqueue a message to the full queue and sleeps
- * parent removes the queue and then exits
- * child get a return from msgsnd()
- * check the errno value
- * issue a PASS message if we get EIDRM
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd06 [-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
- * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
- * - Fix concurrency issue. Due to the use of usleep function to
- * synchronize processes, synchronization issues can occur on a loaded
- * system. Fix this by using pipes to synchronize processes.
- *
- * RESTRICTIONS
- * none
+ * test for EIDRM error
*/
-#include <sys/wait.h>
-#include "test.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
-#include "ipcmsg.h"
+#include "tst_test.h"
+#include "libnewipc.h"
-void cleanup(void);
-void setup(void);
-void do_child(void);
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} snd_buf = {1, "hello, world"};
-char *TCID = "msgsnd06";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-
-MSGBUF msg_buf;
-
-int main(int ac, char **av)
+static void verify_msgsnd(void)
{
- int lc;
- pid_t c_pid;
- int status, e_code;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
-#ifdef UCLINUX
-#define PIPE_NAME "msgsnd06"
- maybe_run_child(&do_child, "d", &msg_q_1);
-#endif
-
- 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;
-
- msgkey = getipckey();
-
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
- == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
-
- /* write messages to the queue until it is full */
- while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
- msg_buf.mtype += 1;
- }
-
- /*
- * fork a child that will attempt to write a message
- * to the queue without IPC_NOWAIT
- */
- if ((c_pid = FORK_OR_VFORK()) == -1) {
- tst_brkm(TBROK, cleanup, "could not fork");
- }
-
- if (c_pid == 0) { /* child */
-
-#ifdef UCLINUX
- if (self_exec(av[0], "d", msg_q_1) < 0) {
- tst_brkm(TBROK, cleanup, "could not self_exec");
- }
-#else
- do_child();
-#endif
- } else {
- TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
-
- /* remove the queue */
- rm_queue(msg_q_1);
-
- /* wait for the child to finish */
- wait(&status);
- /* make sure the child returned a good exit status */
- e_code = status >> 8;
- if (e_code != 0) {
- tst_resm(TFAIL, "Failures reported above");
- }
- }
+ TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
+ if (TEST_RETURN != -1) {
+ tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
+ return;
}
- cleanup();
-
- tst_exit();
+ if (TEST_ERRNO == EIDRM) {
+ tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
+ } else {
+ tst_res(TFAIL | TTERRNO,
+ "msgsnd() failed unexpectedly, expected EIDRM");
+ }
}
-/*
- * do_child()
- */
-void do_child(void)
+static void do_test(void)
{
- int retval = 0;
+ pid_t pid;
-#ifdef UCLINUX
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
+ queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
-#endif
- /*
- * Attempt to write another message to the full queue.
- * Without the IPC_NOWAIT flag, the child sleeps
- */
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
+ while (msgsnd(queue_id, &snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
+ snd_buf.type += 1;
- if (TEST_RETURN != -1) {
- retval = 1;
- tst_resm(TFAIL, "call succeeded when error expected");
- exit(retval);
+ pid = SAFE_FORK();
+ if (!pid) {
+ verify_msgsnd();
+ exit(0);
}
- switch (TEST_ERRNO) {
- case EIDRM:
- tst_resm(TPASS, "expected failure - errno = %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
+ TST_PROCESS_STATE_WAIT(pid, 'S');
- /* mark the queue as invalid as it was removed */
- msg_q_1 = -1;
- break;
- default:
- retval = 1;
- tst_resm(TFAIL,
- "call failed with an unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- break;
+ if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL)) {
+ tst_res(TWARN | TERRNO, "failed to delete message queue %i",
+ queue_id);
}
- exit(retval);
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See ../lib/libipc.c for more information.
- */
- tst_tmpdir();
+ tst_reap_children();
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
+static void setup(void)
{
-
- tst_rmdir();
-
+ msgkey = GETIPCKEY();
}
+
+static struct tst_test test = {
+ .tid = "msgsnd06",
+ .needs_tmpdir = 1,
+ .needs_root = 1,
+ .forks_child = 1,
+ .setup = setup,
+ .test_all = do_test
+};
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API
2016-12-16 3:54 ` [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
@ 2016-12-27 7:44 ` Xiao Yang
2017-01-19 15:21 ` Cyril Hrubis
1 sibling, 0 replies; 11+ messages in thread
From: Xiao Yang @ 2016-12-27 7:44 UTC (permalink / raw)
To: ltp
Ping :-)
On 2016/12/16 11:54, Xiao Yang wrote:
> 1) The msgsnd03 was merged into msgsnd02
> 2) The msgsnd04 was merged into msgsnd05
> 3) take use of CREATE_MSG
>
> Signed-off-by: Xiao Yang<yangx.jy@cn.fujitsu.com>
> ---
> runtest/ltplite | 2 -
> runtest/stress.part3 | 2 -
> runtest/syscalls | 2 -
> runtest/syscalls-ipc | 2 -
> testcases/kernel/syscalls/.gitignore | 2 -
> testcases/kernel/syscalls/ipc/msgsnd/Makefile | 29 +--
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 198 +++++-----------
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c | 245 ++++++++------------
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c | 178 ---------------
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c | 155 -------------
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c | 285 ++++++++----------------
> testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c | 252 +++++----------------
> 12 files changed, 318 insertions(+), 1034 deletions(-)
> delete mode 100644 testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
> delete mode 100644 testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
>
> diff --git a/runtest/ltplite b/runtest/ltplite
> index 83141d1..d4580ad 100644
> --- a/runtest/ltplite
> +++ b/runtest/ltplite
> @@ -514,8 +514,6 @@ msgrcv08 msgrcv08
>
> msgsnd01 msgsnd01
> msgsnd02 msgsnd02
> -msgsnd03 msgsnd03
> -msgsnd04 msgsnd04
> msgsnd05 msgsnd05
> msgsnd06 msgsnd06
>
> diff --git a/runtest/stress.part3 b/runtest/stress.part3
> index fcf27d0..41f8b25 100644
> --- a/runtest/stress.part3
> +++ b/runtest/stress.part3
> @@ -429,8 +429,6 @@ msgrcv07 msgrcv07
>
> msgsnd01 msgsnd01
> msgsnd02 msgsnd02
> -msgsnd03 msgsnd03
> -msgsnd04 msgsnd04
> msgsnd05 msgsnd05
> msgsnd06 msgsnd06
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 884ab80..dd9f9a9 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -693,8 +693,6 @@ msgrcv08 msgrcv08
>
> msgsnd01 msgsnd01
> msgsnd02 msgsnd02
> -msgsnd03 msgsnd03
> -msgsnd04 msgsnd04
> msgsnd05 msgsnd05
> msgsnd06 msgsnd06
>
> diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
> index 8212222..91060b9 100644
> --- a/runtest/syscalls-ipc
> +++ b/runtest/syscalls-ipc
> @@ -27,8 +27,6 @@ msgrcv08 msgrcv08
>
> msgsnd01 msgsnd01
> msgsnd02 msgsnd02
> -msgsnd03 msgsnd03
> -msgsnd04 msgsnd04
> msgsnd05 msgsnd05
> msgsnd06 msgsnd06
>
> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
> index 3201fa9..84c7977 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -414,8 +414,6 @@
> /ipc/msgrcv/msgrcv08
> /ipc/msgsnd/msgsnd01
> /ipc/msgsnd/msgsnd02
> -/ipc/msgsnd/msgsnd03
> -/ipc/msgsnd/msgsnd04
> /ipc/msgsnd/msgsnd05
> /ipc/msgsnd/msgsnd06
> /ipc/semctl/semctl01
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/Makefile b/testcases/kernel/syscalls/ipc/msgsnd/Makefile
> index f467389..207fb16 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/Makefile
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/Makefile
> @@ -1,23 +1,26 @@
> #
> -# 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 ?= ../../../../..
>
> +ifeq ($(UCLINUX),1)
> +FILTER_OUT_MAKE_TARGETS += msgsnd05 msgsnd06
> +endif
> +
> include $(top_srcdir)/include/mk/testcases.mk
> -include $(abs_srcdir)/../Makefile.inc
> +include $(abs_srcdir)/../Makefile2.inc
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
> index 0ca2be0..64fff40 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
> @@ -1,169 +1,81 @@
> /*
> + * 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
> - * msgsnd01.c
> - *
> * DESCRIPTION
> - * msgsnd01 - test that msgsnd() enqueues a message correctly
> - *
> - * ALGORITHM
> - * create a message queue
> - * initialize a message buffer with a known message and type
> - * loop if that option was specified
> - * enqueue the message
> - * check the return code
> - * if failure, issue a FAIL message.
> - * otherwise,
> - * if doing functionality testing
> - * stat the message queue
> - * check for # of bytes = MSGSIZE and # of messages = 1
> - * if correct,
> - * issue a PASS message
> - * otherwise
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE:<for command-line>
> - * msgsnd01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
> - * where, -c n : Run n copies concurrently.
> - * -f : Turn off functionality Testing.
> - * -i n : Execute test n times.
> - * -I x : Execute test for x seconds.
> - * -P x : Pause for x seconds between iterations.
> - * -t : Turn on syscall timing.
> - *
> - * HISTORY
> - * 03/2001 - Written by Wayne Boyer
> - *
> - * RESTRICTIONS
> - * None
> + * test that msgsnd() enqueues a message correctly
> */
>
> -#include "test.h"
> -
> -#include "ipcmsg.h"
> -
> -void cleanup(void);
> -void setup(void);
> -
> -char *TCID = "msgsnd01";
> -int TST_TOTAL = 1;
> +#include<errno.h>
> +#include<sys/types.h>
> +#include<sys/ipc.h>
> +#include<sys/msg.h>
>
> -int msg_q_1;
> -MSGBUF msg_buf, rd_buf;
> +#include "tst_test.h"
> +#include "libnewipc.h"
>
> -struct msqid_ds qs_buf;
> +static key_t msgkey;
> +static int queue_id;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} rcv_buf, snd_buf = {MSGTYPE, "hello, world"};
>
> -int main(int ac, char **av)
> +static void verify_msgsnd(void)
> {
> - int lc;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> - setup(); /* global setup */
> -
> - /* The following loop checks looping state if -i option given */
> -
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - /* reset tst_count in case we are looping */
> - tst_count = 0;
> -
> - /*
> - * Use TEST macro to make the call
> - */
> -
> - TEST(msgsnd(msg_q_1,&msg_buf, MSGSIZE, 0));
> -
> - if (TEST_RETURN == -1) {
> - tst_resm(TFAIL, "%s call failed - errno = %d : %s",
> - TCID, TEST_ERRNO, strerror(TEST_ERRNO));
> - continue;
> - }
> -
> - /* get the queue status */
> - if (msgctl(msg_q_1, IPC_STAT,&qs_buf) == -1) {
> - tst_brkm(TBROK, cleanup, "Could not "
> - "get queue status");
> - }
> + struct msqid_ds qs_buf;
>
> - if (qs_buf.msg_cbytes != MSGSIZE) {
> - tst_resm(TFAIL, "queue bytes != MSGSIZE");
> - }
> -
> - if (qs_buf.msg_qnum != 1) {
> - tst_resm(TFAIL, "queue message != 1");
> - }
> + TEST(msgsnd(queue_id,&snd_buf, MSGSIZE, 0));
> + if (TEST_RETURN == -1) {
> + tst_res(TFAIL | TTERRNO, "msgsnd() failed");
> + return;
> + }
>
> - tst_resm(TPASS, "queue bytes = MSGSIZE and "
> - "queue messages = 1");
> + if (msgctl(queue_id, IPC_STAT,&qs_buf) == -1)
> + tst_brk(TBROK | TERRNO, "msgctl() failed to get queue status");
>
> - /*
> - * remove the message by reading from the queue
> - */
> - if (msgrcv(msg_q_1,&rd_buf, MSGSIZE, 1, 0) == -1) {
> - tst_brkm(TBROK, cleanup, "Could not read from queue");
> - }
> - }
> + if (qs_buf.msg_cbytes == MSGSIZE&& qs_buf.msg_qnum == 1)
> + tst_res(TPASS, "queue bytes and number of queues matched");
> + else
> + tst_res(TFAIL, "queue bytes or number of queues mismatched");
>
> - cleanup();
> - tst_exit();
> + if (msgrcv(queue_id,&rcv_buf, MSGSIZE, 1, 0) == -1)
> + tst_brk(TBROK | TERRNO, "msgrcv() failed");
> }
>
> -/*
> - * 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();
> -
> - msgkey = getipckey();
> -
> - /* create a message queue with read/write permissions */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> - }
> -
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> + queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
> }
>
> -/*
> - * 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 if it exists */
> - 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 = "msgsnd01",
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = verify_msgsnd,
> + .needs_tmpdir = 1
> +};
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
> index 6547ab2..9367775 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
> @@ -1,175 +1,126 @@
> /*
> + * 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
> - * msgsnd02.c
> - *
> * DESCRIPTION
> - * msgsnd02 - test for EACCES and EFAULT errors
> - *
> - * ALGORITHM
> - * create a message queue without write permission
> - * create a trivial message buffer
> - * loop if that option was specified
> - * call msgsnd() using two different invalid cases
> - * check the errno value
> - * issue a PASS message if we get EACCES or EFAULT
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE:<for command-line>
> - * msgsnd02 [-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
> + * 1) test for EACCES error
> + * 2) test for EFAULT error
> + * 3) test for EINVAL error
> */
> -#include<pwd.h>
> -#include "test.h"
> -
> -#include "ipcmsg.h"
> -
> -void cleanup(void);
> -void setup(void);
>
> -char *TCID = "msgsnd02";
> -int TST_TOTAL = 2;
> -
> -char nobody_uid[] = "nobody";
> -struct passwd *ltpuser;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -MSGBUF msg_buf; /* a buffer for the message to queue */
> -int bad_q = -1; /* a value to use as a bad queue ID */
> -
> -struct test_case_t {
> - int *queue_id;
> - MSGBUF *buffer;
> - int error;
> -} TC[] = {
> - /* EACCES - there is no write permission for the queue */
> - {
> - &msg_q_1,&msg_buf, EACCES},
> - /* EFAULT - the message buffer address is invalid */
> - {
> -&msg_q_1, NULL, EFAULT},};
> +#include<errno.h>
> +#include<string.h>
> +#include<stdlib.h>
> +#include<sys/types.h>
> +#include<sys/ipc.h>
> +#include<sys/msg.h>
> +#include<pwd.h>
>
> -int main(int ac, char **av)
> +#include "tst_test.h"
> +#include "libnewipc.h"
> +
> +static key_t msgkey;
> +static int queue_id = -1;
> +static int bad_id = -1;
> +static struct passwd *pw;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} snd_buf = {1, "hello, world"};
> +
> +static struct tcase {
> + int *id;
> + struct buf *buffer;
> + long mtype;
> + int msgsz;
> + int exp_err;
> + /*1: nobody expected 0: root expected */
> + int exp_user;
> +} tcases[] = {
> + {&queue_id,&snd_buf, 1, MSGSIZE, EACCES, 1},
> + {&queue_id, NULL, 1, MSGSIZE, EFAULT, 0},
> + {&bad_id,&snd_buf, 1, MSGSIZE, EINVAL, 0},
> + {&queue_id,&snd_buf, 0, MSGSIZE, EINVAL, 0},
> + {&queue_id,&snd_buf, -1, MSGSIZE, EINVAL, 0},
> + {&queue_id,&snd_buf, 1, -1, EINVAL, 0}
> +};
> +
> +static void verify_msgsnd(struct tcase *tc)
> {
> - 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
> - */
> + snd_buf.type = tc->mtype;
>
> - for (i = 0; i< TST_TOTAL; i++) {
> - TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer, 1, 0));
> -
> - if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded unexpectedly");
> - continue;
> - }
> -
> - if (TEST_ERRNO == TC[i].error) {
> - tst_resm(TPASS, "expected failure - "
> - "errno = %d : %s", TEST_ERRNO,
> - strerror(TEST_ERRNO));
> - } else {
> - tst_resm(TFAIL, "unexpected error - %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> - }
> - }
> + TEST(msgsnd(*tc->id, tc->buffer, tc->msgsz, 0));
> + if (TEST_RETURN != -1) {
> + tst_res(TFAIL, "smgsnd() succeeded unexpectedly");
> + return;
> }
>
> - cleanup();
> -
> - tst_exit();
> + if (TEST_ERRNO == tc->exp_err) {
> + tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
> + } else {
> + tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
> + " expected %s", tst_strerrno(tc->exp_err));
> + }
> }
>
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> +static void do_test(unsigned int n)
> {
> - tst_require_root();
> -
> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
> + pid_t pid;
> + struct tcase *tc =&tcases[n];
>
> - 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");
> + if (tc->exp_user == 0) {
> + verify_msgsnd(tc);
> + return;
> }
>
> - /*
> - * 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 a message queue without write permission */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD)) == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> + pid = SAFE_FORK();
> + if (pid) {
> + tst_reap_children();
> + } else {
> + SAFE_SETUID(pw->pw_uid);
> + verify_msgsnd(tc);
> + exit(0);
> }
> -
> - /* initialize the message buffer with something trivial */
> - msg_buf.mtype = MSGTYPE;
> - msg_buf.mtext[0] = 'a';
> }
>
> -/*
> - * cleanup() - performs all the ONE TIME cleanup for this test at completion
> - * or premature exit.
> - */
> -void cleanup(void)
> +static void setup(void)
> {
> - /* if it exists, remove the message queue that was created */
> - rm_queue(msg_q_1);
> + msgkey = GETIPCKEY();
>
> - tst_rmdir();
> + queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
>
> + pw = SAFE_GETPWNAM("nobody");
> }
> +
> +static void cleanup(void)
> +{
> + 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 = "msgsnd02",
> + .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/msgsnd/msgsnd03.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
> deleted file mode 100644
> index ef6e58e..0000000
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
> +++ /dev/null
> @@ -1,178 +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
> - * msgsnd03.c
> - *
> - * DESCRIPTION
> - * msgsnd03 - test for EINVAL error
> - *
> - * ALGORITHM
> - * create a message queue with read/write permissions
> - * create a trivial message buffer
> - * loop if that option was specified
> - * call msgsnd() using four different invalid cases
> - * check the errno value
> - * issue a PASS message if we get EINVAL
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE:<for command-line>
> - * msgsnd03 [-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"
> -
> -void cleanup(void);
> -void setup(void);
> -
> -char *TCID = "msgsnd03";
> -int TST_TOTAL = 4;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -MSGBUF msg_buf; /* a buffer for the message to queue */
> -int bad_q = -1; /* a value to use as a bad queue ID */
> -
> -struct test_case_t {
> - int *queue_id;
> - MSGBUF *buffer;
> - long mtype;
> - int msg_size;
> - int error;
> -} TC[] = {
> - /* EINVAL - the queue ID is invalid */
> - {
> - &bad_q,&msg_buf, 1, 1, EINVAL},
> - /* EINVAL - the message type is not positive (0) */
> - {
> - &msg_q_1,&msg_buf, 0, 1, EINVAL},
> - /* EINVAL - the message type is not positive (>0) */
> - {
> - &msg_q_1,&msg_buf, -1, 1, EINVAL},
> - /* EINVAL - the message size is less than zero */
> - {
> - &msg_q_1,&msg_buf, 1, -1, EINVAL}
> -};
> -
> -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++) {
> -
> - /* set the message type */
> - msg_buf.mtype = TC[i].mtype;
> -
> - /* make the call with the TEST macro */
> - TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer,
> - TC[i].msg_size, 0));
> -
> - if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded unexpectedly");
> - continue;
> - }
> -
> - if (TEST_ERRNO == TC[i].error) {
> - tst_resm(TPASS, "expected failure - "
> - "errno = %d : %s", TEST_ERRNO,
> - strerror(TEST_ERRNO));
> - } else {
> - tst_resm(TFAIL, "unexpected error - %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> - }
> - }
> - }
> -
> - cleanup();
> -
> - tst_exit();
> -}
> -
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> -{
> -
> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> - TEST_PAUSE;
> -
> - /*
> - * Create a temporary directory and cd into it.
> - * This helps to ensure that a unique msgkey is created.
> - * See ../lib/libipc.c for more information.
> - */
> - tst_tmpdir();
> -
> - msgkey = getipckey();
> -
> - /* create a message queue with read/write permission */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> - }
> -
> - /* initialize the message buffer with something trivial */
> - msg_buf.mtype = MSGTYPE;
> - msg_buf.mtext[0] = 'a';
> -}
> -
> -/*
> - * 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();
> -
> -}
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
> deleted file mode 100644
> index 4432d67..0000000
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
> +++ /dev/null
> @@ -1,155 +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
> - * msgsnd04.c
> - *
> - * DESCRIPTION
> - * msgsnd04 - test for EAGAIN error
> - *
> - * ALGORITHM
> - * create a message queue with read/write permissions
> - * initialize a message buffer with a known message and type
> - * enqueue the message in a loop until the queue is full
> - * loop if that option was specified
> - * attempt to enqueue another message - msgsnd()
> - * check the errno value
> - * issue a PASS message if we get EAGAIN
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE:<for command-line>
> - * msgsnd04 [-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"
> -
> -void cleanup(void);
> -void setup(void);
> -
> -char *TCID = "msgsnd04";
> -int TST_TOTAL = 1;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -MSGBUF msg_buf;
> -
> -int main(int ac, char **av)
> -{
> - int lc;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> - setup(); /* global setup */
> -
> - /* The following loop checks looping state if -i option given */
> -
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - /* reset tst_count in case we are looping */
> - tst_count = 0;
> -
> - /*
> - * Attempt to write another message to the full queue.
> - */
> -
> - TEST(msgsnd(msg_q_1,&msg_buf, MSGSIZE, IPC_NOWAIT));
> -
> - if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded when error expected");
> - continue;
> - }
> -
> - switch (TEST_ERRNO) {
> - case EAGAIN:
> - 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_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();
> -
> - /* create a message queue with read/write permission */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> - }
> -
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> -
> - /* write messages to the queue until it is full */
> - while (msgsnd(msg_q_1,&msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
> - msg_buf.mtype += 1;
> - }
> -}
> -
> -/*
> - * 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();
> -
> -}
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
> index 16d62f8..0d13065 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
> @@ -1,234 +1,125 @@
> /*
> + * 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
> - * msgsnd05.c
> - *
> * DESCRIPTION
> - * msgsnd05 - test for EINTR error
> - *
> - * ALGORITHM
> - * create a message queue with read/write permissions
> - * initialize a message buffer with a known message and type
> - * enqueue the message in a loop until the queue is full
> - * loop if that option was specified
> - * fork a child process
> - * child attempts to enqueue a message to the full queue and sleeps
> - * parent sends a SIGHUP to the child then waits for the child to complete
> - * child get a return from msgsnd()
> - * check the errno value
> - * issue a PASS message if we get EINTR
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * child exits, parent calls cleanup
> - *
> - * USAGE:<for command-line>
> - * msgsnd05 [-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
> - * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
> - * - Fix concurrency issue. Due to the use of usleep function to
> - * synchronize processes, synchronization issues can occur on a loaded
> - * system. Fix this by using pipes to synchronize processes.
> - *
> - * RESTRICTIONS
> - * none
> + * 1) test for EAGAIN error
> + * 2) test for EINTR error
> */
>
> -#include "test.h"
> -
> -#include "ipcmsg.h"
> -
> +#include<errno.h>
> +#include<stdlib.h>
> #include<sys/types.h>
> -#include<sys/wait.h>
> -
> -void do_child(void);
> -void cleanup(void);
> -void setup(void);
> -#ifdef UCLINUX
> -#define PIPE_NAME "msgsnd05"
> -void do_child_uclinux(void);
> -#endif
> -
> -char *TCID = "msgsnd05";
> -int TST_TOTAL = 1;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -
> -MSGBUF msg_buf;
> -
> -int main(int ac, char **av)
> +#include<sys/ipc.h>
> +#include<sys/msg.h>
> +
> +#include "tst_test.h"
> +#include "libnewipc.h"
> +
> +static key_t msgkey;
> +static int queue_id = -1;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} snd_buf = {1, "hello, world"};
> +
> +static struct tcase {
> + int flag;
> + int exp_err;
> + /*1: nobody expected 0: root expected */
> + int exp_user;
> +} tcases[] = {
> + {IPC_NOWAIT, EAGAIN, 0},
> + {0, EINTR, 1}
> +};
> +
> +static void verify_msgsnd(struct tcase *tc)
> {
> - int lc;
> - pid_t c_pid;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> -#ifdef UCLINUX
> - maybe_run_child(&do_child_uclinux, "d",&msg_q_1);
> -#endif
> -
> - 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;
> -
> - /*
> - * fork a child that will attempt to write a message
> - * to the queue without IPC_NOWAIT
> - */
> - if ((c_pid = FORK_OR_VFORK()) == -1) {
> - tst_brkm(TBROK, cleanup, "could not fork");
> - }
> -
> - if (c_pid == 0) { /* child */
> - /*
> - * Attempt to write another message to the full queue.
> - * Without the IPC_NOWAIT flag, the child sleeps
> - */
> -
> -#ifdef UCLINUX
> - if (self_exec(av[0], "d", msg_q_1)< 0) {
> - tst_brkm(TBROK, cleanup, "could not self_exec");
> - }
> -#else
> - do_child();
> -#endif
> - } else {
> - TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
> -
> - /* send a signal that must be caught to the child */
> - if (kill(c_pid, SIGHUP) == -1)
> - tst_brkm(TBROK, cleanup, "kill failed");
> -
> - waitpid(c_pid, NULL, 0);
> - }
> - }
> -
> - cleanup();
> -
> - tst_exit();
> -}
> -
> -/*
> - * do_child()
> - */
> -void do_child(void)
> -{
> - TEST(msgsnd(msg_q_1,&msg_buf, MSGSIZE, 0));
> -
> + TEST(msgsnd(queue_id,&snd_buf, MSGSIZE, tc->flag));
> if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded when error expected");
> - exit(-1);
> + tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
> + return;
> }
>
> - switch (TEST_ERRNO) {
> - case EINTR:
> - 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;
> + if (TEST_ERRNO == tc->exp_err) {
> + tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
> + } else {
> + tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
> + " expected %s", tst_strerrno(tc->exp_err));
> }
> -
> - exit(0);
> }
>
> -void sighandler(int sig)
> +static void sighandler(int sig)
> {
> if (sig == SIGHUP)
> return;
> else
> - tst_brkm(TBROK, NULL, "received unexpected signal %d", sig);
> + tst_brk(TBROK, "received unexpected signal %d", sig);
> }
>
> -#ifdef UCLINUX
> -/*
> - * do_child_uclinux() - capture signals, initialize buffer, then run do_child()
> - */
> -void do_child_uclinux(void)
> +static void do_test(unsigned int n)
> {
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> -
> - tst_sig(FORK, sighandler, cleanup);
> + pid_t pid;
> + struct tcase *tc =&tcases[n];
>
> - do_child();
> -}
> -#endif
> + if (tc->exp_user == 0) {
> + verify_msgsnd(tc);
> + return;
> + }
>
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> -{
> - /* capture signals in our own handler */
> - tst_sig(FORK, sighandler, cleanup);
> + pid = SAFE_FORK();
> + if (!pid) {
> + verify_msgsnd(tc);
> + exit(0);
> + }
>
> - TEST_PAUSE;
> + TST_PROCESS_STATE_WAIT(pid, 'S');
>
> - /*
> - * 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_KILL(pid, SIGHUP);
> + tst_reap_children();
> +}
>
> - msgkey = getipckey();
> +static void setup(void)
> +{
> + SAFE_SIGNAL(SIGHUP, sighandler);
>
> - /* create a message queue with read/write permission */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> - }
> + msgkey = GETIPCKEY();
>
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> + queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
>
> - /* write messages to the queue until it is full */
> - while (msgsnd(msg_q_1,&msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
> - msg_buf.mtype += 1;
> - }
> + while (msgsnd(queue_id,&snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
> + snd_buf.type += 1;
> }
>
> -/*
> - * 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 = "msgsnd05",
> + .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/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
> index 42f6e79..737fc7f 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
> @@ -1,222 +1,92 @@
> /*
> + * 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
> - * msgsnd06.c
> - *
> * DESCRIPTION
> - * msgsnd06 - test for EIDRM error
> - *
> - * ALGORITHM
> - * loop if that option was specified
> - * create a message queue with read/write permissions
> - * initialize a message buffer with a known message and type
> - * enqueue messages in a loop until the queue is full
> - * fork a child process
> - * child attempts to enqueue a message to the full queue and sleeps
> - * parent removes the queue and then exits
> - * child get a return from msgsnd()
> - * check the errno value
> - * issue a PASS message if we get EIDRM
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE:<for command-line>
> - * msgsnd06 [-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
> - * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
> - * - Fix concurrency issue. Due to the use of usleep function to
> - * synchronize processes, synchronization issues can occur on a loaded
> - * system. Fix this by using pipes to synchronize processes.
> - *
> - * RESTRICTIONS
> - * none
> + * test for EIDRM error
> */
>
> -#include<sys/wait.h>
> -#include "test.h"
> +#include<errno.h>
> +#include<stdlib.h>
> +#include<sys/types.h>
> +#include<sys/ipc.h>
> +#include<sys/msg.h>
>
> -#include "ipcmsg.h"
> +#include "tst_test.h"
> +#include "libnewipc.h"
>
> -void cleanup(void);
> -void setup(void);
> -void do_child(void);
> +static key_t msgkey;
> +static int queue_id = -1;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} snd_buf = {1, "hello, world"};
>
> -char *TCID = "msgsnd06";
> -int TST_TOTAL = 1;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -
> -MSGBUF msg_buf;
> -
> -int main(int ac, char **av)
> +static void verify_msgsnd(void)
> {
> - int lc;
> - pid_t c_pid;
> - int status, e_code;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> -#ifdef UCLINUX
> -#define PIPE_NAME "msgsnd06"
> - maybe_run_child(&do_child, "d",&msg_q_1);
> -#endif
> -
> - 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;
> -
> - msgkey = getipckey();
> -
> - /* create a message queue with read/write permission */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
> - == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> - }
> -
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> -
> - /* write messages to the queue until it is full */
> - while (msgsnd(msg_q_1,&msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
> - msg_buf.mtype += 1;
> - }
> -
> - /*
> - * fork a child that will attempt to write a message
> - * to the queue without IPC_NOWAIT
> - */
> - if ((c_pid = FORK_OR_VFORK()) == -1) {
> - tst_brkm(TBROK, cleanup, "could not fork");
> - }
> -
> - if (c_pid == 0) { /* child */
> -
> -#ifdef UCLINUX
> - if (self_exec(av[0], "d", msg_q_1)< 0) {
> - tst_brkm(TBROK, cleanup, "could not self_exec");
> - }
> -#else
> - do_child();
> -#endif
> - } else {
> - TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
> -
> - /* remove the queue */
> - rm_queue(msg_q_1);
> -
> - /* wait for the child to finish */
> - wait(&status);
> - /* make sure the child returned a good exit status */
> - e_code = status>> 8;
> - if (e_code != 0) {
> - tst_resm(TFAIL, "Failures reported above");
> - }
> - }
> + TEST(msgsnd(queue_id,&snd_buf, MSGSIZE, 0));
> + if (TEST_RETURN != -1) {
> + tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
> + return;
> }
>
> - cleanup();
> -
> - tst_exit();
> + if (TEST_ERRNO == EIDRM) {
> + tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
> + } else {
> + tst_res(TFAIL | TTERRNO,
> + "msgsnd() failed unexpectedly, expected EIDRM");
> + }
> }
>
> -/*
> - * do_child()
> - */
> -void do_child(void)
> +static void do_test(void)
> {
> - int retval = 0;
> + pid_t pid;
>
> -#ifdef UCLINUX
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> + queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
>
> -#endif
> - /*
> - * Attempt to write another message to the full queue.
> - * Without the IPC_NOWAIT flag, the child sleeps
> - */
> - TEST(msgsnd(msg_q_1,&msg_buf, MSGSIZE, 0));
> + while (msgsnd(queue_id,&snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
> + snd_buf.type += 1;
>
> - if (TEST_RETURN != -1) {
> - retval = 1;
> - tst_resm(TFAIL, "call succeeded when error expected");
> - exit(retval);
> + pid = SAFE_FORK();
> + if (!pid) {
> + verify_msgsnd();
> + exit(0);
> }
>
> - switch (TEST_ERRNO) {
> - case EIDRM:
> - tst_resm(TPASS, "expected failure - errno = %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> + TST_PROCESS_STATE_WAIT(pid, 'S');
>
> - /* mark the queue as invalid as it was removed */
> - msg_q_1 = -1;
> - break;
> - default:
> - retval = 1;
> - tst_resm(TFAIL,
> - "call failed with an unexpected error - %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> - break;
> + if (queue_id != -1&& msgctl(queue_id, IPC_RMID, NULL)) {
> + tst_res(TWARN | TERRNO, "failed to delete message queue %i",
> + queue_id);
> }
> - exit(retval);
> -}
> -
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> -{
> -
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> - TEST_PAUSE;
>
> - /*
> - * Create a temporary directory and cd into it.
> - * This helps to ensure that a unique msgkey is created.
> - * See ../lib/libipc.c for more information.
> - */
> - tst_tmpdir();
> + tst_reap_children();
> }
>
> -/*
> - * cleanup() - performs all the ONE TIME cleanup for this test at completion
> - * or premature exit.
> - */
> -void cleanup(void)
> +static void setup(void)
> {
> -
> - tst_rmdir();
> -
> + msgkey = GETIPCKEY();
> }
> +
> +static struct tst_test test = {
> + .tid = "msgsnd06",
> + .needs_tmpdir = 1,
> + .needs_root = 1,
> + .forks_child = 1,
> + .setup = setup,
> + .test_all = do_test
> +};
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code
2016-12-16 3:54 [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Xiao Yang
2016-12-16 3:54 ` [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
@ 2017-01-19 14:39 ` Cyril Hrubis
2017-01-23 10:31 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Xiao Yang
1 sibling, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-19 14:39 UTC (permalink / raw)
To: ltp
Hi!
> +int create_msg(const char *file, const int lineno, key_t key, int msgflg);
> +#define CREATE_MSG(key, msgflg) \
> + create_msg(__FILE__, __LINE__, key, msgflg)
Looking at this, we should rather start tst_safe_sysv_ipc.h and
implement it as SAFE_MSGGET() so that possibly reusable outside the ipc
directory as well.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API
2016-12-16 3:54 ` [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
2016-12-27 7:44 ` Xiao Yang
@ 2017-01-19 15:21 ` Cyril Hrubis
1 sibling, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-19 15:21 UTC (permalink / raw)
To: ltp
Hi!
> +static void cleanup(void)
> {
> - /* if it exists, remove the message queue if it exists */
> - rm_queue(msg_q_1);
> -
> - tst_rmdir();
> -
> + if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL)) {
You should initialized the queue_id to -1, since otherwise you may
attempt to remove queue id 0 if cleanup is executed before msgget()
returns and queue_id is initialized.
> + tst_res(TWARN | TERRNO, "failed to delete message queue %i",
> + queue_id);
> + }
> }
> +
> +static struct tst_test test = {
> + .tid = "msgsnd01",
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = verify_msgsnd,
> + .needs_tmpdir = 1
> +}
Otherwise it looks fine.
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
> index 6547ab2..9367775 100644
...
> +static key_t msgkey;
> +static int queue_id = -1;
> +static int bad_id = -1;
> +static struct passwd *pw;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} snd_buf = {1, "hello, world"};
> +
> +static struct tcase {
> + int *id;
> + struct buf *buffer;
> + long mtype;
> + int msgsz;
> + int exp_err;
> + /*1: nobody expected 0: root expected */
> + int exp_user;
> +} tcases[] = {
> + {&queue_id, &snd_buf, 1, MSGSIZE, EACCES, 1},
> + {&queue_id, NULL, 1, MSGSIZE, EFAULT, 0},
> + {&bad_id, &snd_buf, 1, MSGSIZE, EINVAL, 0},
> + {&queue_id, &snd_buf, 0, MSGSIZE, EINVAL, 0},
> + {&queue_id, &snd_buf, -1, MSGSIZE, EINVAL, 0},
> + {&queue_id, &snd_buf, 1, -1, EINVAL, 0}
> +};
> +
> +static void verify_msgsnd(struct tcase *tc)
> {
> - 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
> - */
> + snd_buf.type = tc->mtype;
This is kind of hack. Why can't we create three struct buf variables and
assign them to the tcases structure instead of modyfing it this way?
Otherwise it looks fine.
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
> index 16d62f8..0d13065 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
> @@ -1,234 +1,125 @@
> /*
> + * 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
> - * msgsnd05.c
> - *
> * DESCRIPTION
> - * msgsnd05 - test for EINTR error
> - *
> - * ALGORITHM
> - * create a message queue with read/write permissions
> - * initialize a message buffer with a known message and type
> - * enqueue the message in a loop until the queue is full
> - * loop if that option was specified
> - * fork a child process
> - * child attempts to enqueue a message to the full queue and sleeps
> - * parent sends a SIGHUP to the child then waits for the child to complete
> - * child get a return from msgsnd()
> - * check the errno value
> - * issue a PASS message if we get EINTR
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * child exits, parent calls cleanup
> - *
> - * USAGE: <for command-line>
> - * msgsnd05 [-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
> - * 14/03/2008 Matthieu Fertr?? (Matthieu.Fertre@irisa.fr)
> - * - Fix concurrency issue. Due to the use of usleep function to
> - * synchronize processes, synchronization issues can occur on a loaded
> - * system. Fix this by using pipes to synchronize processes.
> - *
> - * RESTRICTIONS
> - * none
> + * 1) test for EAGAIN error
> + * 2) test for EINTR error
> */
>
> -#include "test.h"
> -
> -#include "ipcmsg.h"
> -
> +#include <errno.h>
> +#include <stdlib.h>
> #include <sys/types.h>
> -#include <sys/wait.h>
> -
> -void do_child(void);
> -void cleanup(void);
> -void setup(void);
> -#ifdef UCLINUX
> -#define PIPE_NAME "msgsnd05"
> -void do_child_uclinux(void);
> -#endif
> -
> -char *TCID = "msgsnd05";
> -int TST_TOTAL = 1;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -
> -MSGBUF msg_buf;
> -
> -int main(int ac, char **av)
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
> +
> +#include "tst_test.h"
> +#include "libnewipc.h"
> +
> +static key_t msgkey;
> +static int queue_id = -1;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} snd_buf = {1, "hello, world"};
> +
> +static struct tcase {
> + int flag;
> + int exp_err;
> + /*1: nobody expected 0: root expected */
> + int exp_user;
> +} tcases[] = {
> + {IPC_NOWAIT, EAGAIN, 0},
> + {0, EINTR, 1}
> +};
> +
> +static void verify_msgsnd(struct tcase *tc)
> {
> - int lc;
> - pid_t c_pid;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> -#ifdef UCLINUX
> - maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
> -#endif
> -
> - 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;
> -
> - /*
> - * fork a child that will attempt to write a message
> - * to the queue without IPC_NOWAIT
> - */
> - if ((c_pid = FORK_OR_VFORK()) == -1) {
> - tst_brkm(TBROK, cleanup, "could not fork");
> - }
> -
> - if (c_pid == 0) { /* child */
> - /*
> - * Attempt to write another message to the full queue.
> - * Without the IPC_NOWAIT flag, the child sleeps
> - */
> -
> -#ifdef UCLINUX
> - if (self_exec(av[0], "d", msg_q_1) < 0) {
> - tst_brkm(TBROK, cleanup, "could not self_exec");
> - }
> -#else
> - do_child();
> -#endif
> - } else {
> - TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
> -
> - /* send a signal that must be caught to the child */
> - if (kill(c_pid, SIGHUP) == -1)
> - tst_brkm(TBROK, cleanup, "kill failed");
> -
> - waitpid(c_pid, NULL, 0);
> - }
> - }
> -
> - cleanup();
> -
> - tst_exit();
> -}
> -
> -/*
> - * do_child()
> - */
> -void do_child(void)
> -{
> - TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
> -
> + TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, tc->flag));
> if (TEST_RETURN != -1) {
> - tst_resm(TFAIL, "call succeeded when error expected");
> - exit(-1);
> + tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
> + return;
> }
>
> - switch (TEST_ERRNO) {
> - case EINTR:
> - 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;
> + if (TEST_ERRNO == tc->exp_err) {
> + tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
> + } else {
> + tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
> + " expected %s", tst_strerrno(tc->exp_err));
> }
> -
> - exit(0);
> }
>
> -void sighandler(int sig)
> +static void sighandler(int sig)
> {
> if (sig == SIGHUP)
> return;
> else
> - tst_brkm(TBROK, NULL, "received unexpected signal %d", sig);
> + tst_brk(TBROK, "received unexpected signal %d", sig);
Using tst_brk() in signal handler is NOT safe.
Looking at the code the best solution would be to just call
_exit(TBROK); here instead, which is one of the things you can do safely
in a signal handler.
Otherwise it looks fine.
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
> index 42f6e79..737fc7f 100644
> --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
> +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
> @@ -1,222 +1,92 @@
> /*
> + * 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
> - * msgsnd06.c
> - *
> * DESCRIPTION
> - * msgsnd06 - test for EIDRM error
> - *
> - * ALGORITHM
> - * loop if that option was specified
> - * create a message queue with read/write permissions
> - * initialize a message buffer with a known message and type
> - * enqueue messages in a loop until the queue is full
> - * fork a child process
> - * child attempts to enqueue a message to the full queue and sleeps
> - * parent removes the queue and then exits
> - * child get a return from msgsnd()
> - * check the errno value
> - * issue a PASS message if we get EIDRM
> - * otherwise, the tests fails
> - * issue a FAIL message
> - * call cleanup
> - *
> - * USAGE: <for command-line>
> - * msgsnd06 [-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
> - * 14/03/2008 Matthieu Fertr?? (Matthieu.Fertre@irisa.fr)
> - * - Fix concurrency issue. Due to the use of usleep function to
> - * synchronize processes, synchronization issues can occur on a loaded
> - * system. Fix this by using pipes to synchronize processes.
> - *
> - * RESTRICTIONS
> - * none
> + * test for EIDRM error
This may be a bit more detailed, i.e. something as:
Tests if EIDRM is returned when message queue was removed while msgsnd()
was trying to send a message.
> -#include <sys/wait.h>
> -#include "test.h"
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/msg.h>
>
> -#include "ipcmsg.h"
> +#include "tst_test.h"
> +#include "libnewipc.h"
>
> -void cleanup(void);
> -void setup(void);
> -void do_child(void);
> +static key_t msgkey;
> +static int queue_id = -1;
> +static struct buf {
> + long type;
> + char text[MSGSIZE];
> +} snd_buf = {1, "hello, world"};
>
> -char *TCID = "msgsnd06";
> -int TST_TOTAL = 1;
> -
> -int msg_q_1 = -1; /* The message queue id created in setup */
> -
> -MSGBUF msg_buf;
> -
> -int main(int ac, char **av)
> +static void verify_msgsnd(void)
> {
> - int lc;
> - pid_t c_pid;
> - int status, e_code;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> -
> -#ifdef UCLINUX
> -#define PIPE_NAME "msgsnd06"
> - maybe_run_child(&do_child, "d", &msg_q_1);
> -#endif
> -
> - 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;
> -
> - msgkey = getipckey();
> -
> - /* create a message queue with read/write permission */
> - if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
> - == -1) {
> - tst_brkm(TBROK, cleanup, "Can't create message queue");
> - }
> -
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> -
> - /* write messages to the queue until it is full */
> - while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
> - msg_buf.mtype += 1;
> - }
> -
> - /*
> - * fork a child that will attempt to write a message
> - * to the queue without IPC_NOWAIT
> - */
> - if ((c_pid = FORK_OR_VFORK()) == -1) {
> - tst_brkm(TBROK, cleanup, "could not fork");
> - }
> -
> - if (c_pid == 0) { /* child */
> -
> -#ifdef UCLINUX
> - if (self_exec(av[0], "d", msg_q_1) < 0) {
> - tst_brkm(TBROK, cleanup, "could not self_exec");
> - }
> -#else
> - do_child();
> -#endif
> - } else {
> - TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
> -
> - /* remove the queue */
> - rm_queue(msg_q_1);
> -
> - /* wait for the child to finish */
> - wait(&status);
> - /* make sure the child returned a good exit status */
> - e_code = status >> 8;
> - if (e_code != 0) {
> - tst_resm(TFAIL, "Failures reported above");
> - }
> - }
> + TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
> + if (TEST_RETURN != -1) {
> + tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
> + return;
> }
>
> - cleanup();
> -
> - tst_exit();
> + if (TEST_ERRNO == EIDRM) {
> + tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
> + } else {
> + tst_res(TFAIL | TTERRNO,
> + "msgsnd() failed unexpectedly, expected EIDRM");
> + }
> }
>
> -/*
> - * do_child()
> - */
> -void do_child(void)
> +static void do_test(void)
> {
> - int retval = 0;
> + pid_t pid;
>
> -#ifdef UCLINUX
> - /* initialize the message buffer */
> - init_buf(&msg_buf, MSGTYPE, MSGSIZE);
> + queue_id = CREATE_MSG(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
>
> -#endif
> - /*
> - * Attempt to write another message to the full queue.
> - * Without the IPC_NOWAIT flag, the child sleeps
> - */
> - TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
> + while (msgsnd(queue_id, &snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
> + snd_buf.type += 1;
>
> - if (TEST_RETURN != -1) {
> - retval = 1;
> - tst_resm(TFAIL, "call succeeded when error expected");
> - exit(retval);
> + pid = SAFE_FORK();
> + if (!pid) {
> + verify_msgsnd();
> + exit(0);
> }
>
> - switch (TEST_ERRNO) {
> - case EIDRM:
> - tst_resm(TPASS, "expected failure - errno = %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> + TST_PROCESS_STATE_WAIT(pid, 'S');
>
> - /* mark the queue as invalid as it was removed */
> - msg_q_1 = -1;
> - break;
> - default:
> - retval = 1;
> - tst_resm(TFAIL,
> - "call failed with an unexpected error - %d : %s",
> - TEST_ERRNO, strerror(TEST_ERRNO));
> - break;
> + if (queue_id != -1 && msgctl(queue_id, IPC_RMID, NULL)) {
> + tst_res(TWARN | TERRNO, "failed to delete message queue %i",
> + queue_id);
Uh, the queue_id canot be -1 here, right?
Also this is tst_brk(TBROK | TERRNO, ...) not TWARN, we are not in
cleanup here.
And the queue_id should be reset to -1 right after it was removed
succesfully and there should be a cleanup that removes the queue if
queue_id is not set to -1, because the test may still call tst_brk()
somewhere between the creation and removal of the queue. We have to be
careful with System V queues since these are global persistent objects
that can outlive the test easily.
> }
> - exit(retval);
> -}
> -
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> -{
> -
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> - TEST_PAUSE;
>
> - /*
> - * Create a temporary directory and cd into it.
> - * This helps to ensure that a unique msgkey is created.
> - * See ../lib/libipc.c for more information.
> - */
> - tst_tmpdir();
> + tst_reap_children();
> }
>
> -/*
> - * cleanup() - performs all the ONE TIME cleanup for this test at completion
> - * or premature exit.
> - */
> -void cleanup(void)
> +static void setup(void)
> {
> -
> - tst_rmdir();
> -
> + msgkey = GETIPCKEY();
> }
> +
> +static struct tst_test test = {
> + .tid = "msgsnd06",
> + .needs_tmpdir = 1,
> + .needs_root = 1,
> + .forks_child = 1,
> + .setup = setup,
> + .test_all = do_test
> +};
> --
> 1.8.3.1
>
>
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c
2017-01-19 14:39 ` [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Cyril Hrubis
@ 2017-01-23 10:31 ` Xiao Yang
2017-01-23 10:31 ` [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros Xiao Yang
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Xiao Yang @ 2017-01-23 10:31 UTC (permalink / raw)
To: ltp
Add SAFE_MSGGET(), SAFE_MSGSND(), SAFE_MSGRCV() and
SAFE_MSGCTL() macros to simplify IPC related cases.
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
include/tst_safe_sysv_ipc.h | 40 +++++++++++++++++++++++
include/tst_test.h | 1 +
lib/tst_safe_sysv_ipc.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+)
create mode 100644 include/tst_safe_sysv_ipc.h
create mode 100644 lib/tst_safe_sysv_ipc.c
diff --git a/include/tst_safe_sysv_ipc.h b/include/tst_safe_sysv_ipc.h
new file mode 100644
index 0000000..29ded4f
--- /dev/null
+++ b/include/tst_safe_sysv_ipc.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017 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_SAFE_SYSV_IPC_H__
+# define TST_SAFE_SYSV_IPC_H__
+
+int safe_msgget(const char *file, const int lineno, key_t key, int msgflg);
+#define SAFE_MSGGET(key, msgflg) \
+ safe_msgget(__FILE__, __LINE__, (key), (msgflg))
+
+int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
+ size_t msgsz, int msgflg);
+#define SAFE_MSGSND(msqid, msgp, msgsz, msgflg) \
+ safe_msgsnd(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgflg))
+
+ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
+ size_t msgsz, long msgtyp, int msgflg);
+#define SAFE_MSGRCV(msqid, msgp, msgsz, msgtyp, msgflg) \
+ safe_msgrcv(__FILE__, __LINE__, (msqid), (msgp), (msgsz), (msgtyp), (msgflg))
+
+int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
+ struct msqid_ds *buf);
+#define SAFE_MSGCTL(msqid, cmd, buf) \
+ safe_msgctl(__FILE__, __LINE__, (msqid), (cmd), (buf))
+
+#endif
diff --git a/include/tst_test.h b/include/tst_test.h
index acb4b93..c68d880 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -34,6 +34,7 @@
#include "tst_kvercmp.h"
#include "tst_clone.h"
#include "tst_kernel.h"
+#include "tst_safe_sysv_ipc.h"
/*
* Reports testcase result.
diff --git a/lib/tst_safe_sysv_ipc.c b/lib/tst_safe_sysv_ipc.c
new file mode 100644
index 0000000..79b12d7
--- /dev/null
+++ b/lib/tst_safe_sysv_ipc.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017 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/>.
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+
+int safe_msgget(const char *file, const int lineno, key_t key, int msgflg)
+{
+ int rval;
+
+ rval = msgget(key, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: msgget() failed",
+ file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
+ size_t msgsz, int msgflg)
+{
+ int rval;
+
+ rval = msgsnd(msqid, msgp, msgsz, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: msgsnd() failed",
+ file, lineno);
+ }
+
+ return rval;
+}
+
+ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
+ size_t msgsz, long msgtyp, int msgflg)
+{
+ ssize_t rval;
+
+ rval = msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: msgrcv() failed",
+ file, lineno);
+ }
+
+ return rval;
+}
+
+int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
+ struct msqid_ds *buf)
+{
+ int rval;
+
+ rval = msgctl(msqid, cmd, buf);
+ if (rval == -1) {
+ tst_brk(TBROK | TERRNO, "%s:%d: msgctl() failed",
+ file, lineno);
+ }
+
+ return rval;
+}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros
2017-01-23 10:31 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Xiao Yang
@ 2017-01-23 10:31 ` Xiao Yang
2017-01-23 13:02 ` Cyril Hrubis
2017-01-23 10:31 ` [LTP] [PATCH v2 3/3] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
2017-01-23 13:02 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Cyril Hrubis
2 siblings, 1 reply; 11+ messages in thread
From: Xiao Yang @ 2017-01-23 10:31 UTC (permalink / raw)
To: ltp
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/msgget/msgget01.c | 6 ++----
testcases/kernel/syscalls/ipc/msgget/msgget02.c | 4 +---
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget01.c b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
index 8d2db4d..e19e0da 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget01.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
@@ -48,11 +48,9 @@ static void verify_msgget(void)
queue_id = TEST_RETURN;
- if (msgsnd(queue_id, &snd_buf, MSGSIZE, 0) == -1)
- tst_brk(TBROK | TERRNO, "msgsnd() failed");
+ SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
- if (msgrcv(queue_id, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT) == -1)
- tst_brk(TBROK | TERRNO, "msgrcv() failed");
+ SAFE_MSGRCV(queue_id, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT);
if (strcmp(snd_buf.text, rcv_buf.text) == 0)
tst_res(TPASS, "message received = message sent");
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
index a3fcb38..d5e2820 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
@@ -96,9 +96,7 @@ static void setup(void)
msgkey = GETIPCKEY();
msgkey1 = GETIPCKEY();
- queue_id = msgget(msgkey, IPC_CREAT | IPC_EXCL);
- if (queue_id == -1)
- tst_brk(TBROK | TERRNO, "can't create message queue");
+ queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL);
pw = SAFE_GETPWNAM("nobody");
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v2 3/3] ipc/msgsnd0*: cleanup && convert to new API
2017-01-23 10:31 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Xiao Yang
2017-01-23 10:31 ` [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros Xiao Yang
@ 2017-01-23 10:31 ` Xiao Yang
2017-01-23 14:23 ` Cyril Hrubis
2017-01-23 13:02 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Cyril Hrubis
2 siblings, 1 reply; 11+ messages in thread
From: Xiao Yang @ 2017-01-23 10:31 UTC (permalink / raw)
To: ltp
1) The msgsnd03 was merged into msgsnd02
2) The msgsnd04 was merged into msgsnd05
3) take use of IPC related macros
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
runtest/ltplite | 2 -
runtest/stress.part3 | 2 -
runtest/syscalls | 2 -
runtest/syscalls-ipc | 2 -
testcases/kernel/syscalls/.gitignore | 2 -
.../kernel/syscalls/ipc/msgsnd/.msgsnd02.c.swo | Bin 0 -> 12288 bytes
testcases/kernel/syscalls/ipc/msgsnd/Makefile | 29 ++-
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c | 196 ++++----------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c | 255 ++++++++----------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c | 178 -------------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c | 155 -----------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c | 287 +++++++--------------
testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c | 252 +++++-------------
13 files changed, 326 insertions(+), 1036 deletions(-)
create mode 100644 testcases/kernel/syscalls/ipc/msgsnd/.msgsnd02.c.swo
delete mode 100644 testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
delete mode 100644 testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
diff --git a/runtest/ltplite b/runtest/ltplite
index 83141d1..d4580ad 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -514,8 +514,6 @@ msgrcv08 msgrcv08
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index fcf27d0..41f8b25 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -429,8 +429,6 @@ msgrcv07 msgrcv07
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/runtest/syscalls b/runtest/syscalls
index 884ab80..dd9f9a9 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -693,8 +693,6 @@ msgrcv08 msgrcv08
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 8212222..91060b9 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -27,8 +27,6 @@ msgrcv08 msgrcv08
msgsnd01 msgsnd01
msgsnd02 msgsnd02
-msgsnd03 msgsnd03
-msgsnd04 msgsnd04
msgsnd05 msgsnd05
msgsnd06 msgsnd06
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 3201fa9..84c7977 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -414,8 +414,6 @@
/ipc/msgrcv/msgrcv08
/ipc/msgsnd/msgsnd01
/ipc/msgsnd/msgsnd02
-/ipc/msgsnd/msgsnd03
-/ipc/msgsnd/msgsnd04
/ipc/msgsnd/msgsnd05
/ipc/msgsnd/msgsnd06
/ipc/semctl/semctl01
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/.msgsnd02.c.swo b/testcases/kernel/syscalls/ipc/msgsnd/.msgsnd02.c.swo
new file mode 100644
index 0000000000000000000000000000000000000000..f916bda9a903750736dfb29f914eb3fd68f7c09b
GIT binary patch
literal 12288
zcmeI2U5F&r702(!sG0Z?**rv0<ZLfHbWeKvV~i`f?n2qyGj?{SXHs3W<2X*5>Z;q*
zm94HS>)x8S9cL2)`SK-Tf_VuT$cuST41|S<;EOLR2)>vI3W7d}$wR;pL;knAs;9d%
zuJ|Zcv%jtCdrzHv&i|ac)yr0=a=Eca_m{rI@VSFA?e(8L@|)jZI&pB0vC#LW8vd-0
z>szMV^Mx$MXSUxr9q*Wnt}2IRR|aLtg|tk;MfnO3J?@spP{4;P%1&UF`(jUcc5<jJ
zm8@fYWkZ<)nF60zf!o-<OVx_H>U8cDee>kz=XH?TX9{ErWC~;oWC~;oWC~;oWC~;o
ze1R2^!3p+5#Q&8fhpWl)#LO}InjJC)G6gaPG6gaPG6gaPG6gaPG6gaPG6gaPG6lYX
z3Ya!yU%i2`J8wkr`2YX(-~XR{gR#GYYe0Z+gZFO77`O(8;4Jv~HpX5CFM&f~f?e<!
z*aqJPC2$h_>sH483H|~84qgE-fak!|AObe9z#2FU?gIpF0w3PO*c;$Q@JH|*_$Bxe
zcpRAE`(PKWfb$>^?gqDmcfXG7!OP%T-~kPs1n<r<_80JH@B(-m{2W{c4}zP)CtqXi
z-{52LCipFQ25f;mI0H_D9Qg0ejQt0E1YQHLf<J-ZfoH+5z%$?~2*D2c9ykk5fqTH+
z;4W|jH~~JmiLv*=AHehA7vN{$r@#e20A=tIYWWU$8~hEt1+IbT!LPxOfe&<`fg-pI
zs2=zh$Ud0@Uv>o!&#}3ZdQFMWlkK<F83rtun_d)PEIBJ;P;eO!#YZ(DEl*vh>AJSv
zZZ#gQ=SMF)71U(c53h)})pJ}MHdQs`ac+yYdO2!(MD_#Q3DYs@s0(tVm!m36xgrzN
zl#WG0hLI&n3K@q<Nz@0}kl7sm%*{O>@rbt_yMUzTlwHV0-q_OgCOt()UDuoIMap$e
z$K^IjpKR`O$*IqUF!wmcm(v*sOU^l6%BSw=)OlL0()>IjC`-EIi6S*NYHfY3aj{6v
z&DGUHfezR~8t=Z3OcMR_>PsPxG#DVgmbP4Puhfl=t){k?&v|~ww}&~z&BjTjR%@*l
z80N9`6+RrTSkvp8ft1wh^+#%}IE7VP--;cKEO9w5gT<x#b{^x?VZ}9^2ujJf&qJp>
zY>$LTDPtAmKwEWVvvDyW3>Gg0gLX6$_>j0OI1)~!HiJ>QL++^sV+jM;Dia*je3sYs
zOKN^pvk*-cda7Q>Ew8E|t;GxciJ%<`jvhHr73Gl4rQM)jucHNN!TtQG{dT-v_``~A
zN%(s<^`y)5ktduz4~^iUi@i~8;x5V&mgAPh)ESX0#tnznco=&AI2wE_!~%`mY*}ll
zLKx#dON1;?(r}TN`gMoJ9MYc^5WTvgwOZG8Vv2Ees$F7{je5&y$K9>;N%c|@#!9KA
zj%1#S7k7i`tCtY-1rm{E;RZ$4lYvezqN5RTGsX8qTvxTUYE9(=MOeJx*bofIPSox4
zaCENbpDdzq2za^;r)xf2QdJYAcrc&dh((&mLT&iosq7YUPZp`(XkOM<;T%~WYq$hM
z+#G6qnzY6(eyn-*I_4eI#^y2;#Ao|fJHuoQ%i89up(6gY7*uXYZnavi-YQZR=7*40
zy-m8ai*7$a@zJ^ItpTCR3)Kf`w3UpTgsAcW#anLLe6&zLx)M#Inh1X4BH=tK0yL(D
zQ4te^1$8UUY{l`-r#4{N9H?^SdfavWT%1~E`s>u}A*F>(Qn7kwh#mb2xsznB?qS#W
z_DBu`KD)4rZrn*p#DOWqz@~*@Ft%2Cjfw`n7OPX^X-`ehV2j1B0WENXE$X!6S#D%=
z%DGO*;{&|4Tk7Q|hSP_U8a*0*Fc{dS-i3()y!Wf#^Zoz9*yF6FN?FX<N*f`}j)jgl
z<1^l+lo?ZXrUkmUFnUnpd7RuV1RFn8b4!zRaa$hERVU}-9z2@6SZ~$z#)i>YZ?f{j
zcquck*T9iIl08RI5c+$e*)OT3w*81i&yVnHpl9xL3c1CdeQY)+S$;4izl&=)tu!}j
zg?l_SUD}8`E*|@<j>SE};Y9hlz7eS``+msrXqR}*i+Js|x?X!&YZ}@^jn#&+O|V&R
z7|lAiT0D$MqYX_r8nw+;O{a}bePg{<FA=r4T9Z1Fq^*YW@cO1fT63H5YeI*w?Q=vb
zQy<fOpL=m&PCsxR<TNnD(DbCrO1Us5#31NmJ7`%4j$!JIuI%{%hYM4ZBjML|sly3R
zyl&(clg#s&9Qsj6ejpv+E0F08$u%XOir7X4hT>$EK+7TL)bhI$f#91Tc{YAQ`QAC=
z2>Iv&T1s_KL@q)b6)}RqH851(utHy?hM!&_!lNlrB@;d5)fpa_c~=D{lE9!K@*&Ig
z&<#hLsKrgZ79UsA#xIg2{~FpPboP3Z@>YQw9>VhCtk5bCMZ)p$D~{Go{NltJQOys7
NQjwM_m8$B|{{f0z*v|j}
literal 0
HcmV?d00001
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/Makefile b/testcases/kernel/syscalls/ipc/msgsnd/Makefile
index f467389..207fb16 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/Makefile
+++ b/testcases/kernel/syscalls/ipc/msgsnd/Makefile
@@ -1,23 +1,26 @@
#
-# 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 ?= ../../../../..
+ifeq ($(UCLINUX),1)
+FILTER_OUT_MAKE_TARGETS += msgsnd05 msgsnd06
+endif
+
include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
+include $(abs_srcdir)/../Makefile2.inc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 0ca2be0..49aaf1f 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -1,169 +1,79 @@
/*
+ * 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
- * msgsnd01.c
- *
* DESCRIPTION
- * msgsnd01 - test that msgsnd() enqueues a message correctly
- *
- * ALGORITHM
- * create a message queue
- * initialize a message buffer with a known message and type
- * loop if that option was specified
- * enqueue the message
- * check the return code
- * if failure, issue a FAIL message.
- * otherwise,
- * if doing functionality testing
- * stat the message queue
- * check for # of bytes = MSGSIZE and # of messages = 1
- * if correct,
- * issue a PASS message
- * otherwise
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- * None
+ * test that msgsnd() enqueues a message correctly.
*/
-#include "test.h"
-
-#include "ipcmsg.h"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd01";
-int TST_TOTAL = 1;
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
-int msg_q_1;
-MSGBUF msg_buf, rd_buf;
+#include "tst_test.h"
+#include "libnewipc.h"
-struct msqid_ds qs_buf;
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} rcv_buf, snd_buf = {MSGTYPE, "hello"};
-int main(int ac, char **av)
+static void verify_msgsnd(void)
{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /*
- * Use TEST macro to make the call
- */
-
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
-
- if (TEST_RETURN == -1) {
- tst_resm(TFAIL, "%s call failed - errno = %d : %s",
- TCID, TEST_ERRNO, strerror(TEST_ERRNO));
- continue;
- }
-
- /* get the queue status */
- if (msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1) {
- tst_brkm(TBROK, cleanup, "Could not "
- "get queue status");
- }
+ struct msqid_ds qs_buf;
- if (qs_buf.msg_cbytes != MSGSIZE) {
- tst_resm(TFAIL, "queue bytes != MSGSIZE");
- }
-
- if (qs_buf.msg_qnum != 1) {
- tst_resm(TFAIL, "queue message != 1");
- }
+ TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
+ if (TEST_RETURN == -1) {
+ tst_res(TFAIL | TTERRNO, "msgsnd() failed");
+ return;
+ }
- tst_resm(TPASS, "queue bytes = MSGSIZE and "
- "queue messages = 1");
+ SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
- /*
- * remove the message by reading from the queue
- */
- if (msgrcv(msg_q_1, &rd_buf, MSGSIZE, 1, 0) == -1) {
- tst_brkm(TBROK, cleanup, "Could not read from queue");
- }
- }
+ if (qs_buf.msg_cbytes == MSGSIZE && qs_buf.msg_qnum == 1)
+ tst_res(TPASS, "queue bytes and number of queues matched");
+ else
+ tst_res(TFAIL, "queue bytes or number of queues mismatched");
- cleanup();
- tst_exit();
+ SAFE_MSGRCV(queue_id, &rcv_buf, MSGSIZE, 1, 0);
}
-/*
- * 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();
-
- msgkey = getipckey();
-
- /* create a message queue with read/write permissions */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
+ queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
}
-/*
- * 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 if it exists */
- 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 = "msgsnd01",
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_msgsnd,
+ .needs_tmpdir = 1
+};
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
index 6547ab2..219d40f 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
@@ -1,175 +1,134 @@
/*
+ * 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
- * msgsnd02.c
- *
* DESCRIPTION
- * msgsnd02 - test for EACCES and EFAULT errors
- *
- * ALGORITHM
- * create a message queue without write permission
- * create a trivial message buffer
- * loop if that option was specified
- * call msgsnd() using two different invalid cases
- * check the errno value
- * issue a PASS message if we get EACCES or EFAULT
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd02 [-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
+ * 1) The calling process does not have write permission on the message
+ * queue, so msgsnd(2) fails and sets errno to EACCES.
+ * 2) msgsnd(2) fails and sets errno to EFAULT if the message buffer address
+ * is invalid.
+ * 3) msgsnd(2) fails and sets errno to EINVAL if the queue ID is invalid.
+ * 4) msgsnd(2) fails and sets errno to EINVAL if the message type is not
+ * positive (0).
+ * 5) msgsnd(2) fails and sets errno to EINVAL if the message type is not
+ * positive (>0).
+ * 6) msgsnd(2) fails and sets errno to EINVAL if the message size is less
+ * than zero.
*/
-#include <pwd.h>
-#include "test.h"
-
-#include "ipcmsg.h"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd02";
-int TST_TOTAL = 2;
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-MSGBUF msg_buf; /* a buffer for the message to queue */
-int bad_q = -1; /* a value to use as a bad queue ID */
-
-struct test_case_t {
- int *queue_id;
- MSGBUF *buffer;
- int error;
-} TC[] = {
- /* EACCES - there is no write permission for the queue */
- {
- &msg_q_1, &msg_buf, EACCES},
- /* EFAULT - the message buffer address is invalid */
- {
-&msg_q_1, NULL, EFAULT},};
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <pwd.h>
-int main(int ac, char **av)
+#include "tst_test.h"
+#include "libnewipc.h"
+
+static key_t msgkey;
+static int queue_id = -1;
+static int bad_id = -1;
+static struct passwd *pw;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} snd_buf[] = {
+ {1, "hello"},
+ {0, "hello"},
+ {-1, "hello"}
+};
+
+static struct tcase {
+ int *id;
+ struct buf *buffer;
+ int msgsz;
+ int exp_err;
+ /*1: nobody expected 0: root expected */
+ int exp_user;
+} tcases[] = {
+ {&queue_id, &snd_buf[0], MSGSIZE, EACCES, 1},
+ {&queue_id, NULL, MSGSIZE, EFAULT, 0},
+ {&bad_id, &snd_buf[0], MSGSIZE, EINVAL, 0},
+ {&queue_id, &snd_buf[1], MSGSIZE, EINVAL, 0},
+ {&queue_id, &snd_buf[2], MSGSIZE, EINVAL, 0},
+ {&queue_id, &snd_buf[0], -1, EINVAL, 0}
+};
+
+static void verify_msgsnd(struct tcase *tc)
{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /*
- * loop through the test cases
- */
-
- for (i = 0; i < TST_TOTAL; i++) {
- TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer, 1, 0));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- continue;
- }
-
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - "
- "errno = %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- }
- }
+ TEST(msgsnd(*tc->id, tc->buffer, tc->msgsz, 0));
+ if (TEST_RETURN != -1) {
+ tst_res(TFAIL, "smgsnd() succeeded unexpectedly");
+ return;
}
- cleanup();
-
- tst_exit();
+ if (TEST_ERRNO == tc->exp_err) {
+ tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
+ } else {
+ tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
+ " expected %s", tst_strerrno(tc->exp_err));
+ }
}
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void do_test(unsigned int n)
{
- tst_require_root();
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ pid_t pid;
+ struct tcase *tc = &tcases[n];
- 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");
+ if (tc->exp_user == 0) {
+ verify_msgsnd(tc);
+ return;
}
- /*
- * 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 a message queue without write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
+ pid = SAFE_FORK();
+ if (pid) {
+ tst_reap_children();
+ } else {
+ SAFE_SETUID(pw->pw_uid);
+ verify_msgsnd(tc);
}
-
- /* initialize the message buffer with something trivial */
- msg_buf.mtype = MSGTYPE;
- msg_buf.mtext[0] = 'a';
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
+static void setup(void)
{
- /* if it exists, remove the message queue that was created */
- rm_queue(msg_q_1);
+ msgkey = GETIPCKEY();
- tst_rmdir();
+ queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+ pw = SAFE_GETPWNAM("nobody");
}
+
+static void cleanup(void)
+{
+ 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 = "msgsnd02",
+ .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/msgsnd/msgsnd03.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
deleted file mode 100644
index ef6e58e..0000000
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd03.c
+++ /dev/null
@@ -1,178 +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
- * msgsnd03.c
- *
- * DESCRIPTION
- * msgsnd03 - test for EINVAL error
- *
- * ALGORITHM
- * create a message queue with read/write permissions
- * create a trivial message buffer
- * loop if that option was specified
- * call msgsnd() using four different invalid cases
- * check the errno value
- * issue a PASS message if we get EINVAL
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd03 [-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"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd03";
-int TST_TOTAL = 4;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-MSGBUF msg_buf; /* a buffer for the message to queue */
-int bad_q = -1; /* a value to use as a bad queue ID */
-
-struct test_case_t {
- int *queue_id;
- MSGBUF *buffer;
- long mtype;
- int msg_size;
- int error;
-} TC[] = {
- /* EINVAL - the queue ID is invalid */
- {
- &bad_q, &msg_buf, 1, 1, EINVAL},
- /* EINVAL - the message type is not positive (0) */
- {
- &msg_q_1, &msg_buf, 0, 1, EINVAL},
- /* EINVAL - the message type is not positive (>0) */
- {
- &msg_q_1, &msg_buf, -1, 1, EINVAL},
- /* EINVAL - the message size is less than zero */
- {
- &msg_q_1, &msg_buf, 1, -1, EINVAL}
-};
-
-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++) {
-
- /* set the message type */
- msg_buf.mtype = TC[i].mtype;
-
- /* make the call with the TEST macro */
- TEST(msgsnd(*(TC[i].queue_id), TC[i].buffer,
- TC[i].msg_size, 0));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- continue;
- }
-
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - "
- "errno = %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- }
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See ../lib/libipc.c for more information.
- */
- tst_tmpdir();
-
- msgkey = getipckey();
-
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer with something trivial */
- msg_buf.mtype = MSGTYPE;
- msg_buf.mtext[0] = 'a';
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test@completion
- * or premature exit.
- */
-void cleanup(void)
-{
- /* if it exists, remove the message queue that was created */
- rm_queue(msg_q_1);
-
- tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
deleted file mode 100644
index 4432d67..0000000
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd04.c
+++ /dev/null
@@ -1,155 +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
- * msgsnd04.c
- *
- * DESCRIPTION
- * msgsnd04 - test for EAGAIN error
- *
- * ALGORITHM
- * create a message queue with read/write permissions
- * initialize a message buffer with a known message and type
- * enqueue the message in a loop until the queue is full
- * loop if that option was specified
- * attempt to enqueue another message - msgsnd()
- * check the errno value
- * issue a PASS message if we get EAGAIN
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd04 [-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"
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "msgsnd04";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-MSGBUF msg_buf;
-
-int main(int ac, char **av)
-{
- int lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
-
- /*
- * Attempt to write another message to the full queue.
- */
-
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded when error expected");
- continue;
- }
-
- switch (TEST_ERRNO) {
- case EAGAIN:
- 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_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();
-
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
-
- /* write messages to the queue until it is full */
- while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
- msg_buf.mtype += 1;
- }
-}
-
-/*
- * 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();
-
-}
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
index 16d62f8..42c89a8 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
@@ -1,234 +1,127 @@
/*
+ * 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
- * msgsnd05.c
- *
* DESCRIPTION
- * msgsnd05 - test for EINTR error
- *
- * ALGORITHM
- * create a message queue with read/write permissions
- * initialize a message buffer with a known message and type
- * enqueue the message in a loop until the queue is full
- * loop if that option was specified
- * fork a child process
- * child attempts to enqueue a message to the full queue and sleeps
- * parent sends a SIGHUP to the child then waits for the child to complete
- * child get a return from msgsnd()
- * check the errno value
- * issue a PASS message if we get EINTR
- * otherwise, the tests fails
- * issue a FAIL message
- * child exits, parent calls cleanup
- *
- * USAGE: <for command-line>
- * msgsnd05 [-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
- * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
- * - Fix concurrency issue. Due to the use of usleep function to
- * synchronize processes, synchronization issues can occur on a loaded
- * system. Fix this by using pipes to synchronize processes.
- *
- * RESTRICTIONS
- * none
+ * 1) msgsnd(2) fails and sets errno to EAGAIN if the message can't be
+ * sent due to the msg_qbytes limit for the queue and IPC_NOWAIT is
+ * specified.
+ * 2) msgsnd(2) fails and sets errno to EINTR if msgsnd(2) sleeps on a
+ * full message queue condition and the process catches a signal.
*/
-#include "test.h"
-
-#include "ipcmsg.h"
-
+#include <errno.h>
+#include <unistd.h>
#include <sys/types.h>
-#include <sys/wait.h>
-
-void do_child(void);
-void cleanup(void);
-void setup(void);
-#ifdef UCLINUX
-#define PIPE_NAME "msgsnd05"
-void do_child_uclinux(void);
-#endif
-
-char *TCID = "msgsnd05";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-
-MSGBUF msg_buf;
-
-int main(int ac, char **av)
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+#include "tst_test.h"
+#include "libnewipc.h"
+
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} snd_buf = {1, "hello"};
+
+static struct tcase {
+ int flag;
+ int exp_err;
+ /*1: nobody expected 0: root expected */
+ int exp_user;
+} tcases[] = {
+ {IPC_NOWAIT, EAGAIN, 0},
+ {0, EINTR, 1}
+};
+
+static void verify_msgsnd(struct tcase *tc)
{
- int lc;
- pid_t c_pid;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
-#ifdef UCLINUX
- maybe_run_child(&do_child_uclinux, "d", &msg_q_1);
-#endif
-
- 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;
-
- /*
- * fork a child that will attempt to write a message
- * to the queue without IPC_NOWAIT
- */
- if ((c_pid = FORK_OR_VFORK()) == -1) {
- tst_brkm(TBROK, cleanup, "could not fork");
- }
-
- if (c_pid == 0) { /* child */
- /*
- * Attempt to write another message to the full queue.
- * Without the IPC_NOWAIT flag, the child sleeps
- */
-
-#ifdef UCLINUX
- if (self_exec(av[0], "d", msg_q_1) < 0) {
- tst_brkm(TBROK, cleanup, "could not self_exec");
- }
-#else
- do_child();
-#endif
- } else {
- TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
-
- /* send a signal that must be caught to the child */
- if (kill(c_pid, SIGHUP) == -1)
- tst_brkm(TBROK, cleanup, "kill failed");
-
- waitpid(c_pid, NULL, 0);
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-/*
- * do_child()
- */
-void do_child(void)
-{
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
-
+ TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, tc->flag));
if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded when error expected");
- exit(-1);
+ tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
+ return;
}
- switch (TEST_ERRNO) {
- case EINTR:
- 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;
+ if (TEST_ERRNO == tc->exp_err) {
+ tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
+ } else {
+ tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
+ " expected %s", tst_strerrno(tc->exp_err));
}
-
- exit(0);
}
-void sighandler(int sig)
+static void sighandler(int sig)
{
if (sig == SIGHUP)
return;
else
- tst_brkm(TBROK, NULL, "received unexpected signal %d", sig);
+ _exit(TBROK);
}
-#ifdef UCLINUX
-/*
- * do_child_uclinux() - capture signals, initialize buffer, then run do_child()
- */
-void do_child_uclinux(void)
+static void do_test(unsigned int n)
{
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
+ pid_t pid;
+ struct tcase *tc = &tcases[n];
- tst_sig(FORK, sighandler, cleanup);
+ if (tc->exp_user == 0) {
+ verify_msgsnd(tc);
+ return;
+ }
- do_child();
+ pid = SAFE_FORK();
+ if (!pid) {
+ verify_msgsnd(tc);
+ _exit(0);
+ }
+
+ TST_PROCESS_STATE_WAIT(pid, 'S');
+ SAFE_KILL(pid, SIGHUP);
+ tst_reap_children();
}
-#endif
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
{
- /* capture signals in our own handler */
- tst_sig(FORK, sighandler, cleanup);
-
- TEST_PAUSE;
+ SAFE_SIGNAL(SIGHUP, sighandler);
- /*
- * 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();
+ queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
-
- /* write messages to the queue until it is full */
- while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
- msg_buf.mtype += 1;
- }
+ while (msgsnd(queue_id, &snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
+ snd_buf.type += 1;
}
-/*
- * 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 = "msgsnd05",
+ .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/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
index 42f6e79..2436481 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
@@ -1,222 +1,90 @@
/*
+ * 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
- * msgsnd06.c
- *
* DESCRIPTION
- * msgsnd06 - test for EIDRM error
- *
- * ALGORITHM
- * loop if that option was specified
- * create a message queue with read/write permissions
- * initialize a message buffer with a known message and type
- * enqueue messages in a loop until the queue is full
- * fork a child process
- * child attempts to enqueue a message to the full queue and sleeps
- * parent removes the queue and then exits
- * child get a return from msgsnd()
- * check the errno value
- * issue a PASS message if we get EIDRM
- * otherwise, the tests fails
- * issue a FAIL message
- * call cleanup
- *
- * USAGE: <for command-line>
- * msgsnd06 [-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
- * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr)
- * - Fix concurrency issue. Due to the use of usleep function to
- * synchronize processes, synchronization issues can occur on a loaded
- * system. Fix this by using pipes to synchronize processes.
- *
- * RESTRICTIONS
- * none
+ * Tests if EIDRM is returned when message queue was removed while
+ * msgsnd() was trying to send a message.
*/
-#include <sys/wait.h>
-#include "test.h"
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
-#include "ipcmsg.h"
+#include "tst_test.h"
+#include "libnewipc.h"
-void cleanup(void);
-void setup(void);
-void do_child(void);
+static key_t msgkey;
+static int queue_id = -1;
+static struct buf {
+ long type;
+ char text[MSGSIZE];
+} snd_buf = {1, "hello"};
-char *TCID = "msgsnd06";
-int TST_TOTAL = 1;
-
-int msg_q_1 = -1; /* The message queue id created in setup */
-
-MSGBUF msg_buf;
-
-int main(int ac, char **av)
+static void verify_msgsnd(void)
{
- int lc;
- pid_t c_pid;
- int status, e_code;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
-#ifdef UCLINUX
-#define PIPE_NAME "msgsnd06"
- maybe_run_child(&do_child, "d", &msg_q_1);
-#endif
-
- 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;
-
- msgkey = getipckey();
-
- /* create a message queue with read/write permission */
- if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW))
- == -1) {
- tst_brkm(TBROK, cleanup, "Can't create message queue");
- }
-
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
-
- /* write messages to the queue until it is full */
- while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) {
- msg_buf.mtype += 1;
- }
-
- /*
- * fork a child that will attempt to write a message
- * to the queue without IPC_NOWAIT
- */
- if ((c_pid = FORK_OR_VFORK()) == -1) {
- tst_brkm(TBROK, cleanup, "could not fork");
- }
-
- if (c_pid == 0) { /* child */
-
-#ifdef UCLINUX
- if (self_exec(av[0], "d", msg_q_1) < 0) {
- tst_brkm(TBROK, cleanup, "could not self_exec");
- }
-#else
- do_child();
-#endif
- } else {
- TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
-
- /* remove the queue */
- rm_queue(msg_q_1);
-
- /* wait for the child to finish */
- wait(&status);
- /* make sure the child returned a good exit status */
- e_code = status >> 8;
- if (e_code != 0) {
- tst_resm(TFAIL, "Failures reported above");
- }
- }
+ TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
+ if (TEST_RETURN != -1) {
+ tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
+ return;
}
- cleanup();
-
- tst_exit();
+ if (TEST_ERRNO == EIDRM) {
+ tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
+ } else {
+ tst_res(TFAIL | TTERRNO,
+ "msgsnd() failed unexpectedly, expected EIDRM");
+ }
}
-/*
- * do_child()
- */
-void do_child(void)
+static void do_test(void)
{
- int retval = 0;
+ pid_t pid;
-#ifdef UCLINUX
- /* initialize the message buffer */
- init_buf(&msg_buf, MSGTYPE, MSGSIZE);
+ queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
-#endif
- /*
- * Attempt to write another message to the full queue.
- * Without the IPC_NOWAIT flag, the child sleeps
- */
- TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));
+ while (msgsnd(queue_id, &snd_buf, MSGSIZE, IPC_NOWAIT) != -1)
+ snd_buf.type += 1;
- if (TEST_RETURN != -1) {
- retval = 1;
- tst_resm(TFAIL, "call succeeded when error expected");
- exit(retval);
+ pid = SAFE_FORK();
+ if (!pid) {
+ verify_msgsnd();
+ _exit(0);
}
- switch (TEST_ERRNO) {
- case EIDRM:
- tst_resm(TPASS, "expected failure - errno = %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
+ TST_PROCESS_STATE_WAIT(pid, 'S');
- /* mark the queue as invalid as it was removed */
- msg_q_1 = -1;
- break;
- default:
- retval = 1;
- tst_resm(TFAIL,
- "call failed with an unexpected error - %d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- break;
- }
- exit(retval);
-}
+ SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- /*
- * Create a temporary directory and cd into it.
- * This helps to ensure that a unique msgkey is created.
- * See ../lib/libipc.c for more information.
- */
- tst_tmpdir();
+ tst_reap_children();
}
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
+static void setup(void)
{
-
- tst_rmdir();
-
+ msgkey = GETIPCKEY();
}
+
+static struct tst_test test = {
+ .tid = "msgsnd06",
+ .needs_tmpdir = 1,
+ .needs_root = 1,
+ .forks_child = 1,
+ .setup = setup,
+ .test_all = do_test
+};
--
1.8.3.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c
2017-01-23 10:31 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Xiao Yang
2017-01-23 10:31 ` [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros Xiao Yang
2017-01-23 10:31 ` [LTP] [PATCH v2 3/3] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
@ 2017-01-23 13:02 ` Cyril Hrubis
2 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-23 13:02 UTC (permalink / raw)
To: ltp
Hi!
> diff --git a/include/tst_test.h b/include/tst_test.h
> index acb4b93..c68d880 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -34,6 +34,7 @@
> #include "tst_kvercmp.h"
> #include "tst_clone.h"
> #include "tst_kernel.h"
> +#include "tst_safe_sysv_ipc.h"
I've removed this include from the tst_test.h since the tst_test.h
header is polluted enough already and these safe macros would be used
only by a very small number of tests anyway.
> +int safe_msgget(const char *file, const int lineno, key_t key, int msgflg)
> +{
> + int rval;
> +
> + rval = msgget(key, msgflg);
> + if (rval == -1) {
> + tst_brk(TBROK | TERRNO, "%s:%d: msgget() failed",
> + file, lineno);
And I've also changed these tst_brk() messages to print the parameters
passed to the msg*() functions as well in order to provide as much
information as possible.
> + }
> +
> + return rval;
> +}
And pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros
2017-01-23 10:31 ` [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros Xiao Yang
@ 2017-01-23 13:02 ` Cyril Hrubis
0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-23 13:02 UTC (permalink / raw)
To: ltp
Hi!
I've changed these two test to include the tst_safe_sysv_ipc.h header
and pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH v2 3/3] ipc/msgsnd0*: cleanup && convert to new API
2017-01-23 10:31 ` [LTP] [PATCH v2 3/3] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
@ 2017-01-23 14:23 ` Cyril Hrubis
0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-23 14:23 UTC (permalink / raw)
To: ltp
Hi!
> diff --git a/testcases/kernel/syscalls/ipc/msgsnd/.msgsnd02.c.swo b/testcases/kernel/syscalls/ipc/msgsnd/.msgsnd02.c.swo
> new file mode 100644
I've removed this file, as it was included in the commit by accident.
And I've also modified the SAFE_MSGCTL() to set the msqid to -1 on cmd
== IPC_RMID (similarily what we do for fd for SAFE_CLOSE()). Since with
that we can safely add a cleanup() to the msgsnd06 that removes the
queue if the test exits with TBROK somewhere between the queue being
created and removed.
Pushed with this diff:
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 49aaf1f..7101bdb 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -26,6 +26,7 @@
#include <sys/msg.h>
#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
#include "libnewipc.h"
static key_t msgkey;
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
index 219d40f..5bdc6c8 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
@@ -39,6 +39,7 @@
#include <pwd.h>
#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
#include "libnewipc.h"
static key_t msgkey;
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
index 42c89a8..3d13f3e 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
@@ -31,6 +31,7 @@
#include <sys/msg.h>
#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
#include "libnewipc.h"
static key_t msgkey;
@@ -86,6 +87,7 @@ static void do_test(unsigned int n)
pid = SAFE_FORK();
if (!pid) {
+ SAFE_SIGNAL(SIGHUP, sighandler);
verify_msgsnd(tc);
_exit(0);
}
@@ -97,8 +99,6 @@ static void do_test(unsigned int n)
static void setup(void)
{
- SAFE_SIGNAL(SIGHUP, sighandler);
-
msgkey = GETIPCKEY();
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
index 2436481..787cf97 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
@@ -28,6 +28,7 @@
#include <sys/msg.h>
#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
#include "libnewipc.h"
static key_t msgkey;
@@ -80,11 +81,20 @@ static void setup(void)
msgkey = GETIPCKEY();
}
+static void cleanup(void)
+{
+ 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 = "msgsnd06",
.needs_tmpdir = 1,
.needs_root = 1,
.forks_child = 1,
.setup = setup,
+ .cleanup = cleanup,
.test_all = do_test
};
Thanks!
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-01-23 14:23 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-16 3:54 [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Xiao Yang
2016-12-16 3:54 ` [LTP] [PATCH 2/2] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
2016-12-27 7:44 ` Xiao Yang
2017-01-19 15:21 ` Cyril Hrubis
2017-01-19 14:39 ` [LTP] [PATCH 1/2] ipc/libnewipc.c: add CREATE_MSG to optimize duplicate code Cyril Hrubis
2017-01-23 10:31 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Xiao Yang
2017-01-23 10:31 ` [LTP] [PATCH v2 2/3] ipc/msgget0*: Make use of IPC related macros Xiao Yang
2017-01-23 13:02 ` Cyril Hrubis
2017-01-23 10:31 ` [LTP] [PATCH v2 3/3] ipc/msgsnd0*: cleanup && convert to new API Xiao Yang
2017-01-23 14:23 ` Cyril Hrubis
2017-01-23 13:02 ` [LTP] [PATCH v2 1/3] lib/tst_safe_sysv_ipc.c : Add tst_safe_sysv_ipc.c Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.