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
25 * shmget02 - check for ENOENT, EEXIST and EINVAL errors
28 * create a shared memory segment with read & write permissions
29 * loop if that option was specified
30 * call shmget() using five different invalid cases
31 * check the errno value
32 * issue a PASS message if we get ENOENT, EEXIST or EINVAL
33 * otherwise, the tests fails
34 * issue a FAIL message
37 * USAGE: <for command-line>
38 * shmget02 [-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.
47 * 03/2001 - Written by Wayne Boyer
55 char *TCID
= "shmget02";
59 int exp_enos
[] = {ENOENT
, EEXIST
, EINVAL
, 0}; /* 0 terminated list of */
63 int shm_nonexisting_key
= -1;
72 /* EINVAL - size is 0 */
73 {&shmkey2
, 0, IPC_CREAT
| IPC_EXCL
| SHM_RW
, EINVAL
},
75 /* EINVAL - size is negative */
76 {&shmkey2
, -1, IPC_CREAT
| IPC_EXCL
| SHM_RW
, EINVAL
},
78 /* EINVAL - size is larger than created segment */
79 {(int *)&shmkey
, SHM_SIZE
* 2, SHM_RW
, EINVAL
},
81 /* EEXIST - the segment exists and IPC_CREAT | IPC_EXCL is given */
82 {(int *)&shmkey
, SHM_SIZE
, IPC_CREAT
| IPC_EXCL
| SHM_RW
, EEXIST
},
84 /* ENOENT - no segment exists for the key and IPC_CREAT is not given */
85 /* use shm_id_2 (-1) as the key */
86 {&shm_nonexisting_key
, SHM_SIZE
, SHM_RW
, ENOENT
}
89 int main(int ac
, char **av
)
91 int lc
; /* loop counter */
92 char *msg
; /* message returned from parse_opts */
95 /* parse standard options */
96 if ((msg
= parse_opts(ac
, av
, (option_t
*)NULL
, NULL
)) != (char *)NULL
){
97 tst_brkm(TBROK
, cleanup
, "OPTION PARSING ERROR - %s", msg
);
100 setup(); /* global setup */
102 /* The following loop checks looping state if -i option given */
104 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
105 /* reset Tst_count in case we are looping */
108 /* loop through the test cases */
109 for (i
=0; i
<TST_TOTAL
; i
++) {
111 * Look for a failure ...
114 TEST(shmget(*(TC
[i
].skey
), TC
[i
].size
, TC
[i
].flags
));
116 if (TEST_RETURN
!= -1) {
117 tst_resm(TFAIL
, "call succeeded unexpectedly");
121 TEST_ERROR_LOG(TEST_ERRNO
);
123 if (TEST_ERRNO
== TC
[i
].error
) {
124 tst_resm(TPASS
, "expected failure - errno = "
125 "%d : %s", TEST_ERRNO
,
126 strerror(TEST_ERRNO
));
128 tst_resm(TFAIL
, "call failed with an "
129 "unexpected error - %d : %s",
130 TEST_ERRNO
, strerror(TEST_ERRNO
));
143 * setup() - performs all the ONE TIME setup for this test.
148 /* capture signals */
149 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
151 /* Set up the expected error numbers for -e option */
152 TEST_EXP_ENOS(exp_enos
);
154 /* Pause if that option was specified */
158 * Create a temporary directory and cd into it.
159 * This helps to ensure that a unique msgkey is created.
160 * See ../lib/libipc.c for more information.
164 /* get an IPC resource key */
165 shmkey
= getipckey();
167 shmkey2
= shmkey
+ 1;
169 if ((shm_id_1
= shmget(shmkey
, SHM_SIZE
, IPC_CREAT
| IPC_EXCL
|
171 tst_brkm(TBROK
, cleanup
, "couldn't create shared memory "
172 "segment in setup()");
175 /* Make sure shm_nonexisting_key is a nonexisting key */
177 while(-1 != shmget(shm_nonexisting_key
,1,SHM_RD
)) {
178 shm_nonexisting_key
--;
186 * cleanup() - performs all the ONE TIME cleanup for this test at completion
192 /* if it exists, remove the shared memory resource */
195 /* Remove the temporary directory */
199 * print timing stats if that option was specified.
200 * print errno log if that option was specified.
204 /* exit with return code appropriate for results */