3 * Copyright (c) International Business Machines Corp., 2001
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * msgctl02 - create a message queue, then issue the IPC_SET command
26 * to lower the msg_qbytes value.
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
35 * if doing functionality testing
36 * if the msg_qbytes value is the new value
37 * issue a PASS message
39 * issue a FAIL message
40 * else issue a PASS message
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.
53 * 03/2001 - Written by Wayne Boyer
64 char *TCID
= "msgctl02";
68 int msg_q_1
= -1; /* to hold the message queue id */
70 struct msqid_ds qs_buf
;
72 unsigned long int new_bytes
;
74 int main(int ac
, char **av
)
76 int lc
; /* loop counter */
77 char *msg
; /* message returned from parse_opts */
79 /* parse standard options */
80 if ((msg
= parse_opts(ac
, av
, (option_t
*)NULL
, NULL
)) != (char *)NULL
){
81 tst_brkm(TBROK
, cleanup
, "OPTION PARSING ERROR - %s", msg
);
84 setup(); /* global setup */
86 /* The following loop checks looping state if -i option given */
88 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
89 /* reset Tst_count in case we are looping */
93 * Set the msqid_ds structure values for the queue
96 TEST(msgctl(msg_q_1
, IPC_SET
, &qs_buf
));
98 if (TEST_RETURN
== -1) {
99 tst_resm(TFAIL
, "%s call failed - errno = %d"
100 " : %s", TCID
, TEST_ERRNO
,
101 strerror(TEST_ERRNO
));
103 if (STD_FUNCTIONAL_TEST
) {
105 /* do a stat to get current queue values */
106 if ((msgctl(msg_q_1
, IPC_STAT
, &qs_buf
) == -1)){
107 tst_resm(TBROK
, "stat on queue failed");
111 if (qs_buf
.msg_qbytes
== new_bytes
) {
112 tst_resm(TPASS
, "qs_buf.msg_qbytes is"
113 " the new value - %d",
116 tst_resm(TFAIL
, "qs_buf.msg_qbytes "
117 "value is not expected");
118 tst_resm(TINFO
, "expected - %d, "
119 "received - %d", new_bytes
,
123 tst_resm(TPASS
, "msgctl() call succeeded");
128 * decrement by one the msq_qbytes value
130 qs_buf
.msg_qbytes
-= 1;
131 new_bytes
= qs_buf
.msg_qbytes
;
141 * setup() - performs all the ONE TIME setup for this test.
146 /* capture signals */
147 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
149 /* Pause if that option was specified */
153 * Create a temporary directory and cd into it.
154 * This helps to ensure that a unique msgkey is created.
155 * See ../lib/libipc.c for more information.
159 /* get a message key */
160 msgkey
= getipckey();
162 /* make sure the initial # of bytes is 0 in our buffer */
163 qs_buf
.msg_qbytes
= 0x3000;
165 /* now we have a key, so let's create a message queue */
166 if ((msg_q_1
= msgget(msgkey
, IPC_CREAT
| IPC_EXCL
| MSG_RW
)) == -1) {
167 tst_brkm(TBROK
, cleanup
, "Can't create message queue");
170 /* now stat the queue to get the default msg_qbytes value */
171 if ((msgctl(msg_q_1
, IPC_STAT
, &qs_buf
)) == -1) {
172 tst_brkm(TBROK
, cleanup
, "Can't stat the message queue");
175 /* decrement msg_qbytes and copy its value */
176 qs_buf
.msg_qbytes
-= 1;
177 new_bytes
= qs_buf
.msg_qbytes
;
181 * cleanup() - performs all the ONE TIME cleanup for this test at completion
187 /* if it exists, remove the message queue */
190 /* Remove the temporary directory */
194 * print timing stats if that option was specified.
195 * print errno log if that option was specified.
199 /* exit with return code appropriate for results */