1 /*
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
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
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"
60
61 #include "ipcmsg.h"
62
63 char *TCID = "msgctl01";
64 int TST_TOTAL = 1;
65
66 int msg_q_1 = -1; /* to hold the message queue id */
67
68 struct msqid_ds qs_buf;
69
main(int ac,char ** av)70 int main(int ac, char **av)
71 {
72 int lc;
73
74 tst_parse_opts(ac, av, NULL, NULL);
75
76 setup(); /* global setup */
77
78 /* The following loop checks looping state if -i option given */
79
80 for (lc = 0; TEST_LOOPING(lc); lc++) {
81 /* reset tst_count in case we are looping */
82 tst_count = 0;
83
84 /*
85 * Get the msqid_ds structure values for the queue
86 */
87
88 TEST(msgctl(msg_q_1, IPC_STAT, &qs_buf));
89
90 if (TEST_RETURN == -1) {
91 tst_resm(TFAIL | TTERRNO, "msgctl() call failed");
92 } else {
93 if (qs_buf.msg_qbytes > 0) {
94 tst_resm(TPASS, "qs_buf.msg_qbytes is"
95 " a positive value");
96 } else {
97 tst_resm(TFAIL, "qs_buf.msg_qbytes did"
98 " not change");
99 }
100 }
101
102 /*
103 * clean up things in case we are looping
104 */
105 qs_buf.msg_qbytes = 0x0000;
106 }
107
108 cleanup();
109
110 tst_exit();
111 }
112
113 /*
114 * setup() - performs all the ONE TIME setup for this test.
115 */
setup(void)116 void setup(void)
117 {
118
119 tst_sig(NOFORK, DEF_HANDLER, cleanup);
120
121 TEST_PAUSE;
122
123 /*
124 * Create a temporary directory and cd into it.
125 * This helps to ensure that a unique msgkey is created.
126 * See ../lib/libipc.c for more information.
127 */
128 tst_tmpdir();
129
130 /* get a message key */
131 msgkey = getipckey();
132
133 /* make sure the initial # of bytes is 0 in our buffer */
134 qs_buf.msg_qbytes = 0x0000;
135
136 /* now we have a key, so let's create a message queue */
137 if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
138 tst_brkm(TBROK, cleanup, "Can't create message queue");
139 }
140 }
141
142 /*
143 * cleanup() - performs all the ONE TIME cleanup for this test at completion
144 * or premature exit.
145 */
cleanup(void)146 void cleanup(void)
147 {
148 /* if it exists, remove the message queue */
149 rm_queue(msg_q_1);
150
151 tst_rmdir();
152
153 }
154