vm: use arch_map2str to print pagefault info, to properly display code addrs
[minix.git] / test / ipc / shmget / shmget01.c
blob93fefd3987f56621bdee61023e40f262e35224a4
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 * shmget01.c
24 * DESCRIPTION
25 * shmget01 - test that shmget() correctly creates a shared memory segment
27 * ALGORITHM
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.
32 * otherwise,
33 * if doing functionality testing
34 * stat the shared memory resource
35 * check the size, creator pid and mode
36 * if correct,
37 * issue a PASS message
38 * otherwise
39 * issue a FAIL message
40 * else issue a PASS message
41 * call cleanup
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.
52 * HISTORY
53 * 03/2001 - Written by Wayne Boyer
55 * RESTRICTIONS
56 * none
59 #include "ipcshm.h"
61 char *TCID = "shmget01";
62 int TST_TOTAL = 1;
63 extern int Tst_count;
65 int shm_id_1 = -1;
67 int main(int ac, char **av)
69 int lc; /* loop counter */
70 char *msg; /* message returned from parse_opts */
71 struct shmid_ds buf;
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 */
84 Tst_count = 0;
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));
95 } else {
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 "
101 "functional test");
102 continue;
104 /* check the seqment size */
105 if (buf.shm_segsz != SHM_SIZE) {
106 tst_resm(TFAIL, "seqment size is not "
107 "correct");
108 continue;
110 /* check the pid of the creator */
111 if (buf.shm_cpid != getpid()) {
112 tst_resm(TFAIL, "creator pid is not "
113 "correct");
114 continue;
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 "
123 "correct");
124 continue;
126 /* if we get here, everything looks good */
127 tst_resm(TPASS, "size, pid & mode are correct");
128 } else {
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");
138 } else {
139 shm_id_1 = -1;
143 cleanup();
145 /*NOTREACHED*/
146 return(0);
150 * setup() - performs all the ONE TIME setup for this test.
152 void
153 setup(void)
155 /* capture signals */
156 tst_sig(NOFORK, DEF_HANDLER, cleanup);
158 /* Pause if that option was specified */
159 TEST_PAUSE;
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.
166 tst_tmpdir();
168 /* get an IPC resource key */
169 shmkey = getipckey();
173 * cleanup() - performs all the ONE TIME cleanup for this test at completion
174 * or premature exit.
176 void
177 cleanup(void)
179 /* if it exists, remove the shared memory resource */
180 rm_shm(shm_id_1);
182 /* Remove the temporary directory */
183 tst_rmdir();
186 * print timing stats if that option was specified.
187 * print errno log if that option was specified.
189 TEST_CLEANUP;
191 /* exit with return code appropriate for results */
192 tst_exit();