blob: e6be4c26cc79994ffa7d3367fd05c5da8b3a10cf [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 * msgctl01.c
23 *
24 * DESCRIPTION
25 * msgctl01 - create a message queue, then issue the IPC_STAT command
26 * and RMID commands to test the functionality
27 *
28 * ALGORITHM
29 * create a message queue
30 * loop if that option was specified
31 * call msgctl() with the IPC_STAT command
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 max number of bytes on the queue is > 0,
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 * msgctl01 [-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 = "msgctl01";
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
robbiew23499f02002-11-18 19:54:58 +000070int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000071{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020072 int lc;
Cyril Hrubis74225622014-06-02 17:54:38 +020073 const char *msg;
plars865695b2001-08-27 22:15:12 +000074
Cyril Hrubis74225622014-06-02 17:54:38 +020075 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080076 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000077
subrata_modak56207ce2009-03-23 13:35:39 +000078 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000079
80 /* The following loop checks looping state if -i option given */
81
82 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080083 /* reset tst_count in case we are looping */
84 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000085
86 /*
87 * Get the msqid_ds structure values for the queue
88 */
subrata_modakbdbaec52009-02-26 12:14:51 +000089
plars865695b2001-08-27 22:15:12 +000090 TEST(msgctl(msg_q_1, IPC_STAT, &qs_buf));
subrata_modakbdbaec52009-02-26 12:14:51 +000091
plars865695b2001-08-27 22:15:12 +000092 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080093 tst_resm(TFAIL | TTERRNO, "msgctl() call failed");
plars865695b2001-08-27 22:15:12 +000094 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020095 if (qs_buf.msg_qbytes > 0) {
96 tst_resm(TPASS, "qs_buf.msg_qbytes is"
97 " a positive value");
plars865695b2001-08-27 22:15:12 +000098 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020099 tst_resm(TFAIL, "qs_buf.msg_qbytes did"
100 " not change");
plars865695b2001-08-27 22:15:12 +0000101 }
102 }
103
104 /*
105 * clean up things in case we are looping
106 */
107 qs_buf.msg_qbytes = 0x0000;
108 }
109
110 cleanup();
111
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800112 tst_exit();
plars865695b2001-08-27 22:15:12 +0000113}
114
115/*
116 * setup() - performs all the ONE TIME setup for this test.
117 */
subrata_modak56207ce2009-03-23 13:35:39 +0000118void setup(void)
plars865695b2001-08-27 22:15:12 +0000119{
Garrett Cooper2c282152010-12-16 00:55:50 -0800120
plars865695b2001-08-27 22:15:12 +0000121 tst_sig(NOFORK, DEF_HANDLER, cleanup);
122
plars865695b2001-08-27 22:15:12 +0000123 TEST_PAUSE;
124
125 /*
126 * Create a temporary directory and cd into it.
127 * This helps to ensure that a unique msgkey is created.
128 * See ../lib/libipc.c for more information.
129 */
130 tst_tmpdir();
131
132 /* get a message key */
133 msgkey = getipckey();
134
135 /* make sure the initial # of bytes is 0 in our buffer */
136 qs_buf.msg_qbytes = 0x0000;
137
138 /* now we have a key, so let's create a message queue */
139 if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
140 tst_brkm(TBROK, cleanup, "Can't create message queue");
141 }
142}
143
144/*
145 * cleanup() - performs all the ONE TIME cleanup for this test at completion
146 * or premature exit.
147 */
subrata_modak56207ce2009-03-23 13:35:39 +0000148void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000149{
150 /* if it exists, remove the message queue */
151 rm_queue(msg_q_1);
152
plars865695b2001-08-27 22:15:12 +0000153 tst_rmdir();
154
Chris Dearmanec6edca2012-10-17 19:54:01 -0700155}