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 * shmget01 - test that shmget() correctly creates a shared memory segment
28 * loop if that option was specified
29 * use the TEST() macro to call shmget()
30 * check the return code
31 * if failure, issue a FAIL message.
33 * if doing functionality testing
34 * stat the shared memory resource
35 * check the size, creator pid and mode
37 * issue a PASS message
39 * issue a FAIL message
40 * else issue a PASS message
43 * USAGE: <for command-line>
44 * shmget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
45 * where, -c n : Run n copies concurrently.
46 * -f : Turn off functionality Testing.
47 * -i n : Execute test n times.
48 * -I x : Execute test for x seconds.
49 * -P x : Pause for x seconds between iterations.
50 * -t : Turn on syscall timing.
53 * 03/2001 - Written by Wayne Boyer
61 char *TCID
= "shmget01";
67 int main(int ac
, char **av
)
69 int lc
; /* loop counter */
70 char *msg
; /* message returned from parse_opts */
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 /* The following loop checks looping state if -i option given */
82 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
83 /* reset Tst_count in case we are looping */
87 * Use TEST macro to make the call
90 TEST(shmget(shmkey
, SHM_SIZE
, (IPC_CREAT
| IPC_EXCL
| SHM_RW
)));
92 if (TEST_RETURN
== -1) {
93 tst_resm(TFAIL
, "%s call failed - errno = %d : %s",
94 TCID
, TEST_ERRNO
, strerror(TEST_ERRNO
));
96 shm_id_1
= TEST_RETURN
;
97 if (STD_FUNCTIONAL_TEST
) {
98 /* do a STAT and check some info */
99 if (shmctl(shm_id_1
, IPC_STAT
, &buf
) == -1) {
100 tst_resm(TBROK
, "shmctl failed in "
104 /* check the seqment size */
105 if (buf
.shm_segsz
!= SHM_SIZE
) {
106 tst_resm(TFAIL
, "seqment size is not "
110 /* check the pid of the creator */
111 if (buf
.shm_cpid
!= getpid()) {
112 tst_resm(TFAIL
, "creator pid is not "
117 * check the mode of the seqment
118 * mask out all but the lower 9 bits
120 if ((buf
.shm_perm
.mode
& MODE_MASK
) !=
121 ((SHM_RW
) & MODE_MASK
)) {
122 tst_resm(TFAIL
, "segment mode is not "
126 /* if we get here, everything looks good */
127 tst_resm(TPASS
, "size, pid & mode are correct");
129 tst_resm(TPASS
, "call succeeded");
134 * clean up things in case we are looping
136 if (shmctl(shm_id_1
, IPC_RMID
, NULL
) == -1) {
137 tst_resm(TBROK
, "couldn't remove shared memory");
150 * setup() - performs all the ONE TIME setup for this test.
155 /* capture signals */
156 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
158 /* Pause if that option was specified */
162 * Create a temporary directory and cd into it.
163 * This helps to ensure that a unique msgkey is created.
164 * See ../lib/libipc.c for more information.
168 /* get an IPC resource key */
169 shmkey
= getipckey();
173 * cleanup() - performs all the ONE TIME cleanup for this test at completion
179 /* if it exists, remove the shared memory resource */
182 /* Remove the temporary directory */
186 * print timing stats if that option was specified.
187 * print errno log if that option was specified.
191 /* exit with return code appropriate for results */