vm: fix region reporting bug
[minix.git] / test / ipc / semctl / semctl05.c
blob7418d3dd77f4213f3c4b99278b70c1951119d48f
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 * semctl05.c
24 * DESCRIPTION
25 * semctl05 - test for ERANGE error
27 * ALGORITHM
28 * create a semaphore set with read and alter permissions
29 * loop if that option was specified
30 * call semctl() with three different invalid cases
31 * check the errno value
32 * issue a PASS message if we get ERANGE
33 * otherwise, the tests fails
34 * issue a FAIL message
35 * call cleanup
37 * USAGE: <for command-line>
38 * semctl05 [-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 char *TCID = "semctl05";
56 int TST_TOTAL = 3;
57 extern int Tst_count;
59 #ifdef _XLC_COMPILER
60 #define SEMUN_CAST
61 #else
62 #define SEMUN_CAST (union semun)
63 #endif
65 int exp_enos[] = {ERANGE, 0}; /* 0 terminated list of expected errnos */
67 int sem_id_1 = -1;
69 #define BIGV 65535 /* a number ((2^16)-1) that should be larger */
70 /* than the maximum for a semaphore value */
72 #ifdef _XLC_COMPILER
73 #define SEMUN_CAST
74 #else
75 #define SEMUN_CAST (union semun)
76 #endif
79 unsigned short big_arr[] = {BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, BIGV,
80 BIGV, BIGV};
82 struct test_case_t {
83 int count;
84 int cmd;
85 union semun t_arg;
86 } TC[3];
88 void setup_test_case(void)
90 /* ERANGE - the value to set is less than zero - SETVAL */
91 /* {5, SETVAL, SEMUN_CAST -1}, */
92 TC[0].count = 5;
93 TC[0].cmd = SETVAL;
94 TC[0].t_arg.val = -1;
96 /* ERANGE - the values to set are too large, > semaphore max value */
97 /* {0, SETALL, SEMUN_CAST big_arr}, */
98 TC[1].count = 0;
99 TC[1].cmd = SETALL;
100 TC[1].t_arg.array = big_arr;
102 /* ERANGE - the value to set is too large, > semaphore max value */
103 /* {5, SETVAL, SEMUN_CAST BIGV} */
104 TC[2].count = 5;
105 TC[2].cmd = SETVAL;
106 TC[2].t_arg.val = BIGV;
109 int main(int ac, char **av)
111 int lc; /* loop counter */
112 char *msg; /* message returned from parse_opts */
113 int i;
115 /* parse standard options */
116 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
117 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
120 setup(); /* global setup */
122 /* The following loop checks looping state if -i option given */
124 for (lc = 0; TEST_LOOPING(lc); lc++) {
125 /* reset Tst_count in case we are looping */
126 Tst_count = 0;
128 for (i=0; i<TST_TOTAL; i++) {
130 TEST(semctl(sem_id_1, TC[i].count,
131 TC[i].cmd, TC[i].t_arg));
133 if (TEST_RETURN != -1) {
134 tst_resm(TFAIL, "call succeeded unexpectedly");
135 continue;
138 TEST_ERROR_LOG(TEST_ERRNO);
140 switch(TEST_ERRNO) {
141 case ERANGE:
142 tst_resm(TPASS, "expected failure - errno = "
143 "%d : %s", TEST_ERRNO,
144 strerror(TEST_ERRNO));
145 break;
146 default:
147 tst_resm(TFAIL, "unexpected error "
148 "- %d : %s", TEST_ERRNO,
149 strerror(TEST_ERRNO));
150 break;
155 cleanup();
157 /*NOTREACHED*/
158 return(0);
162 * setup() - performs all the ONE TIME setup for this test.
164 void
165 setup(void)
167 setup_test_case();
169 /* capture signals */
170 tst_sig(NOFORK, DEF_HANDLER, cleanup);
172 /* Set up the expected error numbers for -e option */
173 TEST_EXP_ENOS(exp_enos);
175 /* Pause if that option was specified */
176 TEST_PAUSE;
179 * Create a temporary directory and cd into it.
180 * This helps to ensure that a unique msgkey is created.
181 * See ../lib/libipc.c for more information.
183 tst_tmpdir();
185 /* get an IPC resource key */
186 semkey = getipckey();
188 /* create a semaphore set with read and alter permissions */
189 if ((sem_id_1 =
190 semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
191 tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
196 * cleanup() - performs all the ONE TIME cleanup for this test at completion
197 * or premature exit.
199 void
200 cleanup(void)
202 /* if it exists, remove the semaphore resouce */
203 rm_sema(sem_id_1);
205 /* Remove the temporary directory */
206 tst_rmdir();
209 * print timing stats if that option was specified.
210 * print errno log if that option was specified.
212 TEST_CLEANUP;
214 /* exit with return code appropriate for results */
215 tst_exit();