remove extra mkfs.1
[minix.git] / test / ipc / semop / semop03.c
blob47a984510bb5955ddb467afe34e8be1b1aae5a98
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 * semop03.c
24 * DESCRIPTION
25 * semop03 - test for EFBIG error
27 * ALGORITHM
28 * create a semaphore set with read and alter permissions
29 * loop if that option was specified
30 * call semop() using two different invalid cases
31 * check the errno value
32 * issue a PASS message if we get EFBIG
33 * otherwise, the tests fails
34 * issue a FAIL message
35 * call cleanup
37 * USAGE: <for command-line>
38 * semop03 [-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 = "semop03";
56 int TST_TOTAL = 2;
57 extern int Tst_count;
59 int exp_enos[] = {EFBIG, 0}; /* 0 terminated list of expected errnos */
61 int sem_id_1 = -1;
63 struct sembuf s_buf;
65 int TC[] = {-1, PSEMS + 1}; /* negative and too many "primitive" semas */
67 int main(int ac, char **av)
69 int lc; /* loop counter */
70 char *msg; /* message returned from parse_opts */
71 int i;
73 /* parse standard options */
74 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) !=(char *)NULL){
75 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
78 setup(); /* global setup */
80 /* initialize two fields in the sembuf structure here */
81 s_buf.sem_op = 1; /* add this value to struct sem.semval */
82 s_buf.sem_flg = SEM_UNDO; /* undo when process exits */
84 /* The following loop checks looping state if -i option given */
86 for (lc = 0; TEST_LOOPING(lc); lc++) {
87 /* reset Tst_count in case we are looping */
88 Tst_count = 0;
90 for (i=0; i<TST_TOTAL; i++) {
92 /* initialize the last field in the sembuf */
93 /* structure to the test dependent value */
94 s_buf.sem_num = TC[i];
97 * use the TEST macro to make the call
100 TEST(semop(sem_id_1, &s_buf, 1));
102 if (TEST_RETURN != -1) {
103 tst_resm(TFAIL, "call succeeded unexpectedly");
104 continue;
107 TEST_ERROR_LOG(TEST_ERRNO);
109 switch(TEST_ERRNO) {
110 case EFBIG:
111 tst_resm(TPASS, "expected failure - errno = "
112 "%d : %s", TEST_ERRNO,
113 strerror(TEST_ERRNO));
114 break;
115 default:
116 tst_resm(TFAIL, "unexpected error - "
117 "%d : %s", TEST_ERRNO,
118 strerror(TEST_ERRNO));
119 break;
124 cleanup();
126 /*NOTREACHED*/
127 return(0);
131 * setup() - performs all the ONE TIME setup for this test.
133 void
134 setup(void)
136 /* capture signals */
137 tst_sig(NOFORK, DEF_HANDLER, cleanup);
139 /* Set up the expected error numbers for -e option */
140 TEST_EXP_ENOS(exp_enos);
142 /* Pause if that option was specified */
143 TEST_PAUSE;
146 * Create a temporary directory and cd into it.
147 * This helps to ensure that a unique msgkey is created.
148 * See ../lib/libipc.c for more information.
150 tst_tmpdir();
152 /* get an IPC resource key */
153 semkey = getipckey();
155 /* create a semaphore with read and alter permissions */
156 if ((sem_id_1 =
157 semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
158 tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
163 * cleanup() - performs all the ONE TIME cleanup for this test at completion
164 * or premature exit.
166 void
167 cleanup(void)
169 /* if it exists, remove the semaphore resource */
170 rm_sema(sem_id_1);
172 /* Remove the temporary directory */
173 tst_rmdir();
176 * print timing stats if that option was specified.
177 * print errno log if that option was specified.
179 TEST_CLEANUP;
181 /* exit with return code appropriate for results */
182 tst_exit();