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 * semget01 - test that semget() correclty creates a semaphore set
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.
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
38 * issue a PASS message
40 * issue a FAIL message
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.
53 * 03/2001 - Written by Wayne Boyer
63 char *TCID
= "semget01";
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 */
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
));
98 /* get the semaphore ID */
99 sem_id_1
= TEST_RETURN
;
101 if (STD_FUNCTIONAL_TEST
) {
102 check_functionality();
104 tst_resm(TPASS
, "semaphore was created");
109 * remove the semaphore that was created and mark the ID
112 if (sem_id_1
!= -1) {
125 * check_functionality() - check the functionality of the tested system call.
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");
140 if (un_arg
.buf
->sem_nsems
!= PSEMS
) {
141 tst_resm(TFAIL
, "# of semaphores in set != # given to create");
145 if (un_arg
.buf
->sem_perm
.cuid
!= geteuid()) {
146 tst_resm(TFAIL
, "semaphore uid != process uid");
150 tst_resm(TPASS
, "basic semaphore values are okay");
154 * setup() - performs all the ONE TIME setup for this test.
159 /* capture signals */
160 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
162 /* Pause if that option was specified */
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.
172 /* get an IPC resource key */
173 semkey
= getipckey();
177 * cleanup() - performs all the ONE TIME cleanup for this test at completion
183 /* if it exists, remove the semaphore resouce */
186 /* Remove the temporary directory */
190 * print timing stats if that option was specified.
191 * print errno log if that option was specified.
195 /* exit with return code appropriate for results */