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 * semop04 - test for EAGAIN error
28 * create a semaphore set with read and alter permissions
29 * loop if that option was specified
30 * call semop() with two different invalid cases
31 * check the errno value
32 * issue a PASS message if we get EAGAIN
33 * otherwise, the tests fails
34 * issue a FAIL message
37 * USAGE: <for command-line>
38 * semop04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
39 * where, -c n : Run n copies concurrently.
40 * -e : Turn on errno logging.
41 * -i n : Execute test n times.
42 * -I x : Execute test for x seconds.
43 * -P x : Pause for x seconds between iterations.
44 * -t : Turn on syscall timing.
47 * 03/2001 - Written by Wayne Boyer
55 char *TCID
= "semop04";
59 int exp_enos
[] = {EAGAIN
, 0}; /* 0 terminated list of expected errnos */
72 /* EAGAIN sem_op = 0 */
73 {{1}, 0, IPC_NOWAIT
, 2, EAGAIN
},
75 /* EAGAIN sem_op = -1 */
76 {{0}, -1, IPC_NOWAIT
, 2, EAGAIN
}
79 int main(int ac
, char **av
)
81 int lc
; /* loop counter */
82 char *msg
; /* message returned from parse_opts */
83 int val
= 1; /* value for SETVAL */
87 /* parse standard options */
88 if ((msg
= parse_opts(ac
, av
, (option_t
*)NULL
, NULL
)) != (char *)NULL
){
89 tst_brkm(TBROK
, cleanup
, "OPTION PARSING ERROR - %s", msg
);
92 setup(); /* global setup */
94 /* The following loop checks looping state if -i option given */
96 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
97 /* reset Tst_count in case we are looping */
100 for (i
=0; i
<TST_TOTAL
; i
++) {
102 /* initialize the s_buf buffer */
103 s_buf
.sem_op
= TC
[i
].op
;
104 s_buf
.sem_flg
= TC
[i
].flg
;
105 s_buf
.sem_num
= TC
[i
].num
;
107 /* initialize all the primitive semaphores */
108 TC
[i
].get_arr
.val
= val
--;
109 if (semctl(sem_id_1
, TC
[i
].num
, SETVAL
, TC
[i
].get_arr
)
111 tst_brkm(TBROK
, cleanup
, "semctl() failed");
115 * make the call with the TEST macro
118 TEST(semop(sem_id_1
, &s_buf
, 1));
120 if (TEST_RETURN
!= -1) {
121 tst_resm(TFAIL
, "call succeeded unexpectedly");
125 TEST_ERROR_LOG(TEST_ERRNO
);
127 if (TEST_ERRNO
== TC
[i
].error
) {
128 tst_resm(TPASS
, "expected failure - errno = %d" " : %s", TEST_ERRNO
,
129 strerror(TEST_ERRNO
));
131 tst_resm(TFAIL
, "unexpected error - "
132 "%d : %s", TEST_ERRNO
,
133 strerror(TEST_ERRNO
));
145 * setup() - performs all the ONE TIME setup for this test.
150 /* capture signals */
151 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
153 /* Set up the expected error numbers for -e option */
154 TEST_EXP_ENOS(exp_enos
);
156 /* Pause if that option was specified */
160 * Create a temporary directory and cd into it.
161 * This helps to ensure that a unique msgkey is created.
162 * See ../lib/libipc.c for more information.
166 /* get an IPC resource key */
167 semkey
= getipckey();
169 /* create a semaphore set with read and alter permissions */
170 /* and PSEMS "primitive" semaphores */
172 semget(semkey
, PSEMS
, IPC_CREAT
| IPC_EXCL
| SEM_RA
)) == -1) {
173 tst_brkm(TBROK
, cleanup
, "couldn't create semaphore in setup");
178 * cleanup() - performs all the ONE TIME cleanup for this test at completion
184 /* if it exists, remove the semaphore resource */
187 /* Remove the temporary directory */
191 * print timing stats if that option was specified.
192 * print errno log if that option was specified.
196 /* exit with return code appropriate for results */