sort: add -x hex sort feature back
[minix.git] / test / ipc / semctl / semctl03.c
blob0e522549a31d0811dfd6ccc1bdf1a68119aa5f28
1 /*
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
21 * NAME
22 * semctl03.c
24 * DESCRIPTION
25 * semctl03 - test for EINVAL and EFAULT errors
27 * ALGORITHM
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
35 * call cleanup
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.
46 * HISTORY
47 * 03/2001 - Written by Wayne Boyer
49 * RESTRICTIONS
50 * none
53 #include "ipcsem.h"
55 #ifdef _XLC_COMPILER
56 #define SEMUN_CAST
57 #else
58 #define SEMUN_CAST (union semun)
59 #endif
61 char *TCID = "semctl03";
62 int TST_TOTAL = 2;
63 extern int Tst_count;
65 #ifdef _XLC_COMPILER
66 #define SEMUN_CAST
67 #else
68 #define SEMUN_CAST (union semun)
69 #endif
71 int exp_enos[] = {EINVAL, EFAULT, 0};
73 int sem_id_1 = -1;
74 int bad_id = -1;
76 struct semid_ds sem_ds;
78 struct test_case_t {
79 int *sem_id;
80 int ipc_cmd;
81 union semun arg;
82 int error;
83 } TC[4];
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;
90 TC[0].ipc_cmd = -1;
91 TC[0].arg.buf = &sem_ds;
92 TC[0].error = EINVAL;
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;
99 TC[1].error = EINVAL;
101 #if 0
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;
107 TC[2].arg.val = -1;
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;
115 TC[3].arg.val = -1;
116 TC[3].error = EFAULT;
117 #endif
120 int main(int ac, char **av)
122 int lc; /* loop counter */
123 char *msg; /* message returned from parse_opts */
124 int i;
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 */
137 Tst_count = 0;
139 for (i=0; i<TST_TOTAL; i++) {
141 TEST(semctl(*(TC[i].sem_id), 0, TC[i].ipc_cmd,
142 TC[i].arg));
144 if (TEST_RETURN != -1) {
145 tst_resm(TFAIL, "call succeeded unexpectedly");
146 continue;
149 TEST_ERROR_LOG(TEST_ERRNO);
151 if (TEST_ERRNO == TC[i].error) {
152 tst_resm(TPASS, "expected failure - errno = %d"
153 " : %s", TEST_ERRNO,
154 strerror(TEST_ERRNO));
155 } else {
156 tst_resm(TFAIL, "unexpected error - %d : %s",
157 TEST_ERRNO, strerror(TEST_ERRNO));
162 cleanup();
164 /*NOTREACHED*/
165 return(0);
169 * setup() - performs all the ONE TIME setup for this test.
171 void
172 setup(void)
174 setup_test_case();
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 */
183 TEST_PAUSE;
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.
190 tst_tmpdir();
192 /* get an IPC resource key */
193 semkey = getipckey();
195 /* create a semaphore set with read and alter permissions */
196 if ((sem_id_1 =
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
204 * or premature exit.
206 void
207 cleanup(void)
209 /* if it exists, remove the semaphore resouce */
210 rm_sema(sem_id_1);
212 /* Remove the temporary directory */
213 tst_rmdir();
216 * print timing stats if that option was specified.
217 * print errno log if that option was specified.
219 TEST_CLEANUP;
221 /* exit with return code appropriate for results */
222 tst_exit();