blob: 68b0ee2daa89d0c7c5ba8ad21bd685d30a043c78 [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 * msgctl02.c
23 *
24 * DESCRIPTION
25 * msgctl02 - create a message queue, then issue the IPC_SET command
26 * to lower the msg_qbytes value.
27 *
28 * ALGORITHM
29 * create a message queue
30 * loop if that option was specified
31 * call msgctl() with the IPC_SET command with a new msg_qbytes value
32 * check the return code
33 * if failure, issue a FAIL message and break remaining tests
34 * otherwise,
35 * if doing functionality testing
36 * if the msg_qbytes value is the new value
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 * msgctl02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
45 * where, -c n : Run n copies concurrently.
46 * -f : Turn off functionality Testing.
47 * -i n : Execute test n times.
48 * -I x : Execute test for x seconds.
49 * -P x : Pause for x seconds between iterations.
50 * -t : Turn on syscall timing.
51 *
52 * HISTORY
53 * 03/2001 - Written by Wayne Boyer
54 *
55 * RESTRICTIONS
56 * none
57 */
58
59#include "test.h"
plars865695b2001-08-27 22:15:12 +000060
robbiew23499f02002-11-18 19:54:58 +000061#include "ipcmsg.h"
plars865695b2001-08-27 22:15:12 +000062
63char *TCID = "msgctl02";
64int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000065
subrata_modak56207ce2009-03-23 13:35:39 +000066int msg_q_1 = -1; /* to hold the message queue id */
plars865695b2001-08-27 22:15:12 +000067
68struct msqid_ds qs_buf;
69
subrata_modak856b1b22008-12-12 07:07:07 +000070unsigned long int new_bytes;
plars865695b2001-08-27 22:15:12 +000071
robbiew23499f02002-11-18 19:54:58 +000072int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000073{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020074 int lc;
Cyril Hrubis74225622014-06-02 17:54:38 +020075 const char *msg;
plars865695b2001-08-27 22:15:12 +000076
Cyril Hrubis74225622014-06-02 17:54:38 +020077 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080078 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000081
82 /* The following loop checks looping state if -i option given */
83
84 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080085 /* reset tst_count in case we are looping */
86 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000087
88 /*
89 * Set the msqid_ds structure values for the queue
90 */
subrata_modakbdbaec52009-02-26 12:14:51 +000091
plars865695b2001-08-27 22:15:12 +000092 TEST(msgctl(msg_q_1, IPC_SET, &qs_buf));
subrata_modakbdbaec52009-02-26 12:14:51 +000093
plars865695b2001-08-27 22:15:12 +000094 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080095 tst_resm(TFAIL | TTERRNO, "msgctl() call failed");
plars865695b2001-08-27 22:15:12 +000096 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020097 /* do a stat to get current queue values */
98 if ((msgctl(msg_q_1, IPC_STAT, &qs_buf) == -1)) {
99 tst_resm(TBROK, "stat on queue failed");
100 continue;
101 }
plars865695b2001-08-27 22:15:12 +0000102
Cyril Hrubise38b9612014-06-02 17:20:57 +0200103 if (qs_buf.msg_qbytes == new_bytes) {
104 tst_resm(TPASS, "qs_buf.msg_qbytes is"
105 " the new value - %ld",
106 qs_buf.msg_qbytes);
plars865695b2001-08-27 22:15:12 +0000107 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200108 tst_resm(TFAIL, "qs_buf.msg_qbytes "
109 "value is not expected");
110 tst_resm(TINFO, "expected - %ld, "
111 "received - %ld", new_bytes,
112 qs_buf.msg_qbytes);
plars865695b2001-08-27 22:15:12 +0000113 }
114 }
115
116 /*
117 * decrement by one the msq_qbytes value
118 */
119 qs_buf.msg_qbytes -= 1;
120 new_bytes = qs_buf.msg_qbytes;
121 }
122
123 cleanup();
124
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800125 tst_exit();
plars865695b2001-08-27 22:15:12 +0000126}
127
128/*
129 * setup() - performs all the ONE TIME setup for this test.
130 */
subrata_modak56207ce2009-03-23 13:35:39 +0000131void setup(void)
plars865695b2001-08-27 22:15:12 +0000132{
Garrett Cooper2c282152010-12-16 00:55:50 -0800133
plars865695b2001-08-27 22:15:12 +0000134 tst_sig(NOFORK, DEF_HANDLER, cleanup);
135
plars865695b2001-08-27 22:15:12 +0000136 TEST_PAUSE;
137
138 /*
139 * Create a temporary directory and cd into it.
140 * This helps to ensure that a unique msgkey is created.
141 * See ../lib/libipc.c for more information.
142 */
143 tst_tmpdir();
144
145 /* get a message key */
146 msgkey = getipckey();
147
148 /* make sure the initial # of bytes is 0 in our buffer */
149 qs_buf.msg_qbytes = 0x3000;
150
151 /* now we have a key, so let's create a message queue */
152 if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
153 tst_brkm(TBROK, cleanup, "Can't create message queue");
154 }
155
156 /* now stat the queue to get the default msg_qbytes value */
157 if ((msgctl(msg_q_1, IPC_STAT, &qs_buf)) == -1) {
158 tst_brkm(TBROK, cleanup, "Can't stat the message queue");
159 }
160
161 /* decrement msg_qbytes and copy its value */
162 qs_buf.msg_qbytes -= 1;
163 new_bytes = qs_buf.msg_qbytes;
164}
165
166/*
167 * cleanup() - performs all the ONE TIME cleanup for this test at completion
168 * or premature exit.
169 */
subrata_modak56207ce2009-03-23 13:35:39 +0000170void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000171{
172 /* if it exists, remove the message queue */
173 rm_queue(msg_q_1);
174
plars865695b2001-08-27 22:15:12 +0000175 tst_rmdir();
176
Garrett Cooperf6b06a12010-12-19 10:23:41 -0800177}