VM: simplify slab allocator
[minix.git] / test / ipc / shmdt / shmdt02.c
blob5741d5f5a88f46732521d7e698256c73046a2f97
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 * shmdt02.c
24 * DESCRIPTION
25 * shmdt02 - check for EINVAL error
27 * ALGORITHM
28 * loop if that option was specified
29 * call shmdt() using an invalid shared memory address
30 * check the errno value
31 * issue a PASS message if we get EINVAL
32 * otherwise, the tests fails
33 * issue a FAIL message
34 * call cleanup
36 * USAGE: <for command-line>
37 * shmdt02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
38 * where, -c n : Run n copies concurrently.
39 * -e : Turn on errno logging.
40 * -i n : Execute test n times.
41 * -I x : Execute test for x seconds.
42 * -P x : Pause for x seconds between iterations.
43 * -t : Turn on syscall timing.
45 * HISTORY
46 * 03/2001 - Written by Wayne Boyer
48 * RESTRICTIONS
49 * none
52 #include "ipcshm.h"
54 char *TCID = "shmdt02";
55 int TST_TOTAL = 1;
56 extern int Tst_count;
58 int exp_enos[] = {EINVAL, 0}; /* 0 terminated list of expected errnos */
60 int main(int ac, char **av)
62 int lc; /* loop counter */
63 char *msg; /* message returned from parse_opts */
64 int unshared; /* a local variable to use to produce */ /* the error in the shmdt() call */
66 /* parse standard options */
67 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
68 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
71 setup(); /* global setup */
73 /* The following loop checks looping state if -i option given */
75 for (lc = 0; TEST_LOOPING(lc); lc++) {
76 /* reset Tst_count in case we are looping */
77 Tst_count = 0;
80 * make the call using the TEST() macro - attempt to
81 * remove an invalid shared memory address
84 TEST(shmdt(&unshared));
86 if (TEST_RETURN != -1) {
87 tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
90 TEST_ERROR_LOG(TEST_ERRNO);
92 switch(TEST_ERRNO) {
93 case EINVAL:
94 tst_resm(TPASS, "expected failure - errno = %d : %s",
95 TEST_ERRNO, strerror(TEST_ERRNO));
96 break;
97 default:
98 tst_resm(TFAIL, "call failed with an unexpected error "
99 "- %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
104 cleanup();
106 /*NOTREACHED*/
107 return(0);
111 * setup() - performs all the ONE TIME setup for this test.
113 void
114 setup(void)
116 /* capture signals */
117 tst_sig(NOFORK, DEF_HANDLER, cleanup);
119 /* Set up the expected error numbers for -e option */
120 TEST_EXP_ENOS(exp_enos);
122 /* Pause if that option was specified */
123 TEST_PAUSE;
127 * cleanup() - performs all the ONE TIME cleanup for this test at completion
128 * or premature exit.
130 void
131 cleanup(void)
134 * print timing stats if that option was specified.
135 * print errno log if that option was specified.
137 TEST_CLEANUP;
139 /* exit with return code appropriate for results */
140 tst_exit();