sort: add -x hex sort feature back
[minix.git] / test / ipc / semop / semop04.c
blob8a5f3c32d80b1db2f04b2d0c460beab7a70f7640
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 * semop04.c
24 * DESCRIPTION
25 * semop04 - test for EAGAIN error
27 * ALGORITHM
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
35 * call cleanup
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.
46 * HISTORY
47 * 03/2001 - Written by Wayne Boyer
49 * RESTRICTIONS
50 * none
53 #include "ipcsem.h"
55 char *TCID = "semop04";
56 int TST_TOTAL = 2;
57 extern int Tst_count;
59 int exp_enos[] = {EAGAIN, 0}; /* 0 terminated list of expected errnos */
61 int sem_id_1 = -1;
63 struct sembuf s_buf;
65 struct test_case_t {
66 union semun get_arr;
67 short op;
68 short flg;
69 short num;
70 int error;
71 } TC[] = {
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 */
85 int i;
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 */
98 Tst_count = 0;
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)
110 == -1) {
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");
122 continue;
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));
130 } else {
131 tst_resm(TFAIL, "unexpected error - "
132 "%d : %s", TEST_ERRNO,
133 strerror(TEST_ERRNO));
138 cleanup();
140 /*NOTREACHED*/
141 return(0);
145 * setup() - performs all the ONE TIME setup for this test.
147 void
148 setup(void)
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 */
157 TEST_PAUSE;
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.
164 tst_tmpdir();
166 /* get an IPC resource key */
167 semkey = getipckey();
169 /* create a semaphore set with read and alter permissions */
170 /* and PSEMS "primitive" semaphores */
171 if ((sem_id_1 =
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
179 * or premature exit.
181 void
182 cleanup(void)
184 /* if it exists, remove the semaphore resource */
185 rm_sema(sem_id_1);
187 /* Remove the temporary directory */
188 tst_rmdir();
191 * print timing stats if that option was specified.
192 * print errno log if that option was specified.
194 TEST_CLEANUP;
196 /* exit with return code appropriate for results */
197 tst_exit();