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 * semctl03 - test for EINVAL and EFAULT errors
28 * create a semaphore set with read and alter permissions
29 * loop if that option was specified
30 * call semctl() using four different invalid cases
31 * check the errno value
32 * issue a PASS message if we get EINVAL or EFAULT
33 * otherwise, the tests fails
34 * issue a FAIL message
37 * USAGE: <for command-line>
38 * semctl03 [-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
58 #define SEMUN_CAST (union semun)
61 char *TCID
= "semctl03";
68 #define SEMUN_CAST (union semun)
71 int exp_enos
[] = {EINVAL
, EFAULT
, 0};
76 struct semid_ds sem_ds
;
85 void setup_test_case(void)
87 /* EINVAL - the IPC command is not valid */
88 /* {&sem_id_1, -1, SEMUN_CAST &sem_ds, EINVAL}, */
89 TC
[0].sem_id
= &sem_id_1
;
91 TC
[0].arg
.buf
= &sem_ds
;
94 /* EINVAL - the semaphore ID is not valid */
95 /* {&bad_id, IPC_STAT, SEMUN_CAST &sem_ds, EINVAL}, */
96 TC
[1].sem_id
= &bad_id
;
97 TC
[1].ipc_cmd
= IPC_STAT
;
98 TC
[1].arg
.buf
= &sem_ds
;
102 /* EFAULT address can't be detected well in Minix. */
103 /* EFAULT - the union arg is invalid when expecting "ushort *array" */
104 /* {&sem_id_1, GETALL, SEMUN_CAST -1, EFAULT}, */
105 TC
[2].sem_id
= &sem_id_1
;
106 TC
[2].ipc_cmd
= GETALL
;
108 TC
[2].error
= EFAULT
;
110 /* EFAULT - the union arg is invalid when expecting */
111 /* "struct semid_ds *buf */
112 /* {&sem_id_1, IPC_SET, SEMUN_CAST -1, EFAULT} */
113 TC
[3].sem_id
= &sem_id_1
;
114 TC
[3].ipc_cmd
= IPC_SET
;
116 TC
[3].error
= EFAULT
;
120 int main(int ac
, char **av
)
122 int lc
; /* loop counter */
123 char *msg
; /* message returned from parse_opts */
126 /* parse standard options */
127 if ((msg
= parse_opts(ac
, av
, (option_t
*)NULL
, NULL
)) != (char *)NULL
){
128 tst_brkm(TBROK
, cleanup
, "OPTION PARSING ERROR - %s", msg
);
131 setup(); /* global setup */
133 /* The following loop checks looping state if -i option given */
135 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
136 /* reset Tst_count in case we are looping */
139 for (i
=0; i
<TST_TOTAL
; i
++) {
141 TEST(semctl(*(TC
[i
].sem_id
), 0, TC
[i
].ipc_cmd
,
144 if (TEST_RETURN
!= -1) {
145 tst_resm(TFAIL
, "call succeeded unexpectedly");
149 TEST_ERROR_LOG(TEST_ERRNO
);
151 if (TEST_ERRNO
== TC
[i
].error
) {
152 tst_resm(TPASS
, "expected failure - errno = %d"
154 strerror(TEST_ERRNO
));
156 tst_resm(TFAIL
, "unexpected error - %d : %s",
157 TEST_ERRNO
, strerror(TEST_ERRNO
));
169 * setup() - performs all the ONE TIME setup for this test.
176 /* capture signals */
177 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
179 /* Set up the expected error numbers for -e option */
180 TEST_EXP_ENOS(exp_enos
);
182 /* Pause if that option was specified */
186 * Create a temporary directory and cd into it.
187 * This helps to ensure that a unique msgkey is created.
188 * See ../lib/libipc.c for more information.
192 /* get an IPC resource key */
193 semkey
= getipckey();
195 /* create a semaphore set with read and alter permissions */
197 semget(semkey
, PSEMS
, IPC_CREAT
| IPC_EXCL
| SEM_RA
)) == -1) {
198 tst_brkm(TBROK
, cleanup
, "couldn't create semaphore in setup");
203 * cleanup() - performs all the ONE TIME cleanup for this test at completion
209 /* if it exists, remove the semaphore resouce */
212 /* Remove the temporary directory */
216 * print timing stats if that option was specified.
217 * print errno log if that option was specified.
221 /* exit with return code appropriate for results */