blob: 31533048d07886be521d01ebb07c9b7b11067811 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
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.
9 *
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.
14 *
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
18 */
19
20/*
21 * NAME
22 * close02.c
23 *
24 * DESCRIPTION
25 * Check that an invalid file descriptor returns EBADF
26 *
27 * ALGORITHM
28 * loop if that option is specified
29 * call close using the TEST macro and passing in an invalid fd
30 * if the call succeedes
31 * issue a FAIL message
32 * else
33 * log the errno
34 * if the errno == EBADF
35 * issue a PASS message
36 * else
37 * issue a FAIL message
38 * cleanup
39 *
40 * USAGE: <for command-line>
41 * close02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
42 * where, -c n : Run n copies concurrently.
43 * -e : Turn on errno logging.
44 * -i n : Execute test n times.
45 * -I x : Execute test for x seconds.
46 * -P x : Pause for x seconds between iterations.
47 * -t : Turn on syscall timing.
48 *
49 * HISTORY
50 * 07/2001 Ported by Wayne Boyer
51 *
52 * RESTRICTIONS
53 * None
54 */
55
56#include <stdio.h>
57#include <errno.h>
robbiew2c945242002-11-11 19:01:25 +000058#include <sys/stat.h>
plars865695b2001-08-27 22:15:12 +000059#include "test.h"
60#include "usctest.h"
61
62void cleanup(void);
63void setup(void);
64
65int exp_enos[] = {EBADF, 0};
66
67char *TCID = "close02()";
68int TST_TOTAL = 1;
69extern int Tst_count;
70
robbiew2c945242002-11-11 19:01:25 +000071int
plars865695b2001-08-27 22:15:12 +000072main(int ac, char **av)
73{
74 int lc; /* loop counter */
75 char *msg; /* message returned from parse_opts */
76
77 /* parse standard options */
78 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
79 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
80 /*NOTREACHED*/
81 }
82
83 setup(); /* global setup */
84
85 /* set up expected errnos */
86 TEST_EXP_ENOS(exp_enos);
87
88 /* The following loop checks looping state if -i option given */
89 for (lc = 0; TEST_LOOPING(lc); lc++) {
90
91 /* reset Tst_count in case we are looping */
92 Tst_count = 0;
93
94 TEST(close(-1));
95
96 if (TEST_RETURN != -1) {
97 tst_resm(TFAIL, "Closed a non existent fildes");
98 } else {
99 TEST_ERROR_LOG(TEST_ERRNO);
100
101 if (TEST_ERRNO != EBADF) {
102 tst_resm(TFAIL, "close() FAILED to set errno "
103 "to EBADF on an invalid fd, got %d",
104 errno);
105 } else {
106 tst_resm(TPASS, "call returned EBADF");
107 }
108 }
109 }
110 cleanup();
robbiew2c945242002-11-11 19:01:25 +0000111
112 return 0;
plars865695b2001-08-27 22:15:12 +0000113 /*NOTREACHED*/
114}
115
116/*
117 * setup() - performs all ONE TIME setup for this test
118 */
119void
120setup(void)
121{
122 /* capture signals */
123 tst_sig(FORK, DEF_HANDLER, cleanup);
124
125 umask(0);
126
127 /* Pause if that option was specified */
128 TEST_PAUSE;
129}
130
131/*
132 * cleanup() - performs all the ONE TIME cleanup for this test at completion
133 * or premature exit.
134 */
135void
136cleanup(void)
137{
138 /*
139 * print timing status if that option was specified.
140 * print errno log if that option was specified
141 */
142 TEST_CLEANUP;
143
144 /* exit with return code appropriate for results */
145 tst_exit();
146}