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 * semget03 - test for ENOENT error
28 * loop if that option was specified
29 * call semget() with a valid key but with no associated semaphore set
30 * and IPC_CREAT is not asserted
31 * check the errno value
32 * issue a PASS message if we get ENOENT
33 * otherwise, the tests fails
34 * issue a FAIL message
37 * USAGE: <for command-line>
38 * semget03 [-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
53 #include "../lib/ipcsem.h"
55 char *TCID
= "semget03";
59 int exp_enos
[] = {ENOENT
, 0}; /* 0 terminated list of expected errnos */
63 int main(int ac
, char **av
)
65 int lc
; /* loop counter */
66 char *msg
; /* message returned from parse_opts */
68 /* parse standard options */
69 if ((msg
= parse_opts(ac
, av
, (option_t
*)NULL
, NULL
)) != (char *)NULL
){
70 tst_brkm(TBROK
, cleanup
, "OPTION PARSING ERROR - %s", msg
);
73 setup(); /* global setup */
75 /* The following loop checks looping state if -i option given */
77 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
78 /* reset Tst_count in case we are looping */
81 /* use the TEST macro to make the call */
83 TEST(semget(semkey
, PSEMS
, SEM_RA
));
85 if (TEST_RETURN
!= -1) {
86 sem_id_1
= TEST_RETURN
;
87 tst_resm(TFAIL
, "call succeeded when error expected");
91 TEST_ERROR_LOG(TEST_ERRNO
);
95 tst_resm(TPASS
, "expected failure - errno "
96 "= %d : %s", TEST_ERRNO
, strerror(TEST_ERRNO
));
99 tst_resm(TFAIL
, "unexpected error - %d : %s",
100 TEST_ERRNO
, strerror(TEST_ERRNO
));
112 * setup() - performs all the ONE TIME setup for this test.
117 /* capture signals */
118 tst_sig(NOFORK
, DEF_HANDLER
, cleanup
);
120 /* Set up the expected error numbers for -e option */
121 TEST_EXP_ENOS(exp_enos
);
123 /* Pause if that option was specified */
127 * Create a temporary directory and cd into it.
128 * This helps to ensure that a unique msgkey is created.
129 * See ../lib/libipc.c for more information.
133 /* get an IPC resource key */
134 semkey
= getipckey();
138 * cleanup() - performs all the ONE TIME cleanup for this test at completion
144 /* if it exists, remove the semaphore resource */
147 /* Remove the temporary directory */
151 * print timing stats if that option was specified.
152 * print errno log if that option was specified.
156 /* exit with return code appropriate for results */