blob: 13b14cff518c4646f1aedbf8eda2fce74e725112 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * msgctl03.c
23 *
24 * DESCRIPTION
25 * msgctl03 - create a message queue, then issue the IPC_RMID command
26 *
27 * ALGORITHM
28 * create a message queue
29 * loop if that option was specified
30 * call msgctl() with the IPC_RMID command
31 * check the return code
32 * if failure, issue a FAIL message and break remaining tests
33 * otherwise,
34 * if doing functionality testing
35 * issue an IPC_STAT on the queue that was just removed
36 * if the call fails
37 * issue a PASS message
38 * otherwise
39 * issue a FAIL message
40 * else issue a PASS message
41 * call cleanup
42 *
43 * USAGE: <for command-line>
44 * msgctl03 [-c n] [-f] [-I x] [-P x] [-t]
45 * where, -c n : Run n copies concurrently.
46 * -f : Turn off functionality Testing.
47 * -I x : Execute test for x seconds.
48 * -P x : Pause for x seconds between iterations.
49 * -t : Turn on syscall timing.
50 *
51 * HISTORY
52 * 03/2001 - Written by Wayne Boyer
53 *
54 * RESTRICTIONS
55 * This test does not support looping.
56 */
57
58#include "test.h"
plars865695b2001-08-27 22:15:12 +000059
robbiew23499f02002-11-18 19:54:58 +000060#include "ipcmsg.h"
plars865695b2001-08-27 22:15:12 +000061
62char *TCID = "msgctl03";
63int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000064
subrata_modak56207ce2009-03-23 13:35:39 +000065int msg_q_1 = -1; /* to hold the message queue id */
plars865695b2001-08-27 22:15:12 +000066
67struct msqid_ds qs_buf;
68
robbiew23499f02002-11-18 19:54:58 +000069int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000070{
Cyril Hrubis74225622014-06-02 17:54:38 +020071 const char *msg;
plars865695b2001-08-27 22:15:12 +000072
Cyril Hrubis74225622014-06-02 17:54:38 +020073 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080074 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000075
subrata_modak56207ce2009-03-23 13:35:39 +000076 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000077
78 /*
79 * Remove the queue that was created in setup()
80 */
81
82 TEST(msgctl(msg_q_1, IPC_RMID, NULL));
subrata_modakbdbaec52009-02-26 12:14:51 +000083
plars865695b2001-08-27 22:15:12 +000084 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080085 tst_brkm(TFAIL | TTERRNO, cleanup, "msgctl() call failed");
plars865695b2001-08-27 22:15:12 +000086 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020087 /*
88 * if the queue is gone, then an IPC_STAT msgctl()
89 * call should generate an EINVAL error.
90 */
91 if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)) {
92 if (errno == EINVAL) {
93 tst_resm(TPASS, "The queue is gone");
94 } else {
95 tst_resm(TFAIL, "IPC_RMID succeeded ,"
96 " but functional test did not"
97 " get expected EINVAL error");
plars865695b2001-08-27 22:15:12 +000098 }
plars865695b2001-08-27 22:15:12 +000099 }
100 }
101
102 msg_q_1 = -1;
103
104 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800105 tst_exit();
plars865695b2001-08-27 22:15:12 +0000106}
107
108/*
109 * setup() - performs all the ONE TIME setup for this test.
110 */
subrata_modak56207ce2009-03-23 13:35:39 +0000111void setup(void)
plars865695b2001-08-27 22:15:12 +0000112{
Garrett Cooper2c282152010-12-16 00:55:50 -0800113
plars865695b2001-08-27 22:15:12 +0000114 tst_sig(NOFORK, DEF_HANDLER, cleanup);
115
plars865695b2001-08-27 22:15:12 +0000116 TEST_PAUSE;
117
118 /*
119 * Create a temporary directory and cd into it.
120 * This helps to ensure that a unique msgkey is created.
121 * See ../lib/libipc.c for more information.
122 */
123 tst_tmpdir();
124
125 /* get a message key */
126 msgkey = getipckey();
127
128 /* now we have a key, so let's create a message queue */
129 if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
130 tst_brkm(TBROK, cleanup, "Can't create message queue");
131 }
132}
133
134/*
135 * cleanup() - performs all the ONE TIME cleanup for this test at completion
136 * or premature exit.
137 */
subrata_modak56207ce2009-03-23 13:35:39 +0000138void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000139{
140 /* if it exists, remove the message queue */
141 rm_queue(msg_q_1);
142
plars865695b2001-08-27 22:15:12 +0000143 tst_rmdir();
144
Chris Dearmanec6edca2012-10-17 19:54:01 -0700145}