unstack, sort: cleanup and improvement
[minix.git] / test / ipc / semget / semget06.c
blobfed4b016c5a228a98b0a6421c8dcc1253e9ff9ce
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 * semget06.c
24 * DESCRIPTION
25 * semget06 - test for EINVAL error
27 * ALGORITHM
28 * loop if that option was specified
29 * call semget() using two different invalid cases - too many and too
30 * few primitive semaphores
31 * check the errno value
32 * issue a PASS message if we get EINVAL
33 * otherwise, the tests fails
34 * issue a FAIL message
35 * call cleanup
37 * USAGE: <for command-line>
38 * semget06 [-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 "../lib/ipcsem.h"
55 char *TCID = "semget06";
56 int TST_TOTAL = 2;
57 extern int Tst_count;
59 #define LARGENUM 1024 * 32
60 #define SMALLNUM -1
62 int exp_enos[] = {EINVAL, 0}; /* 0 terminated list of expected errnos */
64 int sem_id_1 = -1;
66 int num_sems[] = {LARGENUM, SMALLNUM};
69 int main(int ac, char **av)
71 int lc; /* loop counter */
72 char *msg; /* message returned from parse_opts */
73 int i;
75 /* parse standard options */
76 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
77 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
80 setup(); /* global setup */
82 /* The following loop checks looping state if -i option given */
84 for (lc = 0; TEST_LOOPING(lc); lc++) {
85 /* reset Tst_count in case we are looping */
86 Tst_count = 0;
88 /* loop through the test cases */
90 for (i=0; i<TST_TOTAL; i++) {
91 TEST(semget(semkey, num_sems[i],
92 IPC_CREAT | IPC_EXCL | SEM_RA));
94 if (TEST_RETURN != -1) {
95 sem_id_1 = TEST_RETURN;
96 tst_resm(TFAIL, "call succeeded");
97 continue;
100 TEST_ERROR_LOG(TEST_ERRNO);
102 switch(TEST_ERRNO) {
103 case EINVAL:
104 tst_resm(TPASS, "expected failure - errno "
105 "= %d : %s", TEST_ERRNO,
106 strerror(TEST_ERRNO));
107 break;
108 default:
109 tst_resm(TFAIL, "unexpected error - %d : %s",
110 TEST_ERRNO, strerror(TEST_ERRNO));
111 break;
116 cleanup();
118 /*NOTREACHED*/
119 return(0);
123 * setup() - performs all the ONE TIME setup for this test.
125 void
126 setup(void)
128 /* capture signals */
129 tst_sig(NOFORK, DEF_HANDLER, cleanup);
131 /* Set up the expected error numbers for -e option */
132 TEST_EXP_ENOS(exp_enos);
134 /* Pause if that option was specified */
135 TEST_PAUSE;
138 * Create a temporary directory and cd into it.
139 * This helps to ensure that a unique msgkey is created.
140 * See ../lib/libipc.c for more information.
142 tst_tmpdir();
144 /* get an IPC resource key */
145 semkey = getipckey();
149 * cleanup() - performs all the ONE TIME cleanup for this test at completion
150 * or premature exit.
152 void
153 cleanup(void)
155 /* if it exists, remove the semaphore resource */
156 rm_sema(sem_id_1);
158 /* Remove the temporary directory */
159 tst_rmdir();
162 * print timing stats if that option was specified.
163 * print errno log if that option was specified.
165 TEST_CLEANUP;
167 /* exit with return code appropriate for results */
168 tst_exit();