vm: use arch_map2str to print pagefault info, to properly display code addrs
[minix.git] / test / ipc / semget / semget01.c
blobe23928c89649f52c37adcfbe8521d35800ccf667
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 * semget01.c
24 * DESCRIPTION
25 * semget01 - test that semget() correclty creates a semaphore set
27 * ALGORITHM
28 * loop if that option was specified
29 * call semget() to create the semaphore set
30 * check the return code
31 * if failure, issue a FAIL message.
32 * otherwise,
33 * if doing functionality testing
34 * stat the semaphore set
35 * if the number of primitive semaphores is correct and
36 * the semaphore uid == the process uid
37 * then,
38 * issue a PASS message
39 * otherwise
40 * issue a FAIL message
41 * call cleanup
43 * USAGE: <for command-line>
44 * semget01 [-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 "ipcsem.h"
60 #include "usctest.h"
63 char *TCID = "semget01";
64 int TST_TOTAL = 1;
65 extern int Tst_count;
67 int sem_id_1 = -1;
69 int main(int ac, char **av)
71 int lc; /* loop counter */
72 char *msg; /* message returned from parse_opts */
73 void check_functionality(void);
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;
89 * Use TEST macro to make the call
92 TEST(semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA));
94 if (TEST_RETURN == -1) {
95 tst_resm(TFAIL, "%s call failed - errno = %d : %s",
96 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
97 } else {
98 /* get the semaphore ID */
99 sem_id_1 = TEST_RETURN;
101 if (STD_FUNCTIONAL_TEST) {
102 check_functionality();
103 } else {
104 tst_resm(TPASS, "semaphore was created");
109 * remove the semaphore that was created and mark the ID
110 * as invalid.
112 if (sem_id_1 != -1) {
113 rm_sema(sem_id_1);
114 sem_id_1 = -1;
118 cleanup();
120 /*NOTREACHED*/
121 return(0);
125 * check_functionality() - check the functionality of the tested system call.
127 void
128 check_functionality(void)
130 struct semid_ds semary;
131 union semun un_arg; /* union defined in ipcsem.h */
133 /* STAT the semaphore */
134 un_arg.buf = &semary;
135 if (semctl(sem_id_1, 0, IPC_STAT, un_arg) == -1) {
136 tst_brkm(TBROK, cleanup, "Could not stat the semaphore");
137 return;
140 if (un_arg.buf->sem_nsems != PSEMS) {
141 tst_resm(TFAIL, "# of semaphores in set != # given to create");
142 return;
145 if (un_arg.buf->sem_perm.cuid != geteuid()) {
146 tst_resm(TFAIL, "semaphore uid != process uid");
147 return;
150 tst_resm(TPASS, "basic semaphore values are okay");
154 * setup() - performs all the ONE TIME setup for this test.
156 void
157 setup(void)
159 /* capture signals */
160 tst_sig(NOFORK, DEF_HANDLER, cleanup);
162 /* Pause if that option was specified */
163 TEST_PAUSE;
166 * Create a temporary directory and cd into it.
167 * This helps to ensure that a unique msgkey is created.
168 * See ../lib/libipc.c for more information.
170 tst_tmpdir();
172 /* get an IPC resource key */
173 semkey = getipckey();
177 * cleanup() - performs all the ONE TIME cleanup for this test at completion
178 * or premature exit.
180 void
181 cleanup(void)
183 /* if it exists, remove the semaphore resouce */
184 rm_sema(sem_id_1);
186 /* Remove the temporary directory */
187 tst_rmdir();
190 * print timing stats if that option was specified.
191 * print errno log if that option was specified.
193 TEST_CLEANUP;
195 /* exit with return code appropriate for results */
196 tst_exit();