1 /*
2 *
3 * Copyright (C) Bull S.A. 2005
4 * Copyright (c) International Business Machines Corp., 2004
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**********************************************************
22 *
23 * TEST IDENTIFIER : fcntl27
24 *
25 * EXECUTED BY : anyone
26 *
27 * TEST TITLE : Basic test for fcntl(2) using F_SETLEASE & F_RDLCK argument.
28 *
29 * TEST CASE TOTAL : 1
30 *
31 * WALL CLOCK TIME : 1
32 *
33 * CPU TYPES : ALL
34 *
35 * AUTHOR : Jacky Malcles
36 *
37 * TEST CASES
38 *
39 * 1.) fcntl(2) returns...(See Description)
40 *
41 * INPUT SPECIFICATIONS
42 * The standard options for system call tests are accepted.
43 * (See the parse_opts(3) man page).
44 *
45 * OUTPUT SPECIFICATIONS
46 *
47 * DURATION
48 * Terminates - with frequency and infinite modes.
49 *
50 * SIGNALS
51 * Uses SIGUSR1 to pause before test if option set.
52 * (See the parse_opts(3) man page).
53 *
54 * RESOURCES
55 * None
56 *
57 * ENVIRONMENTAL NEEDS
58 * No run-time environmental needs.
59 *
60 * SPECIAL PROCEDURAL REQUIREMENTS
61 * None
62 *
63 * INTERCASE DEPENDENCIES
64 * None
65 *
66 * DETAILED DESCRIPTION
67 * This is a Phase I test for the fcntl(2) system call. It is intended
68 * to provide a limited exposure of the system call, for now. It
69 * should/will be extended when full functional tests are written for
70 * fcntl(2).
71 *
72 * Setup:
73 * Setup signal handling.
74 * Pause for SIGUSR1 if option specified.
75 *
76 * Test:
77 * Loop if the proper options are given.
78 * Execute system call
79 * Check return code, if system call failed (return=-1)
80 * Log the errno and Issue a FAIL message.
81 * Otherwise, Issue a PASS message.
82 *
83 * Cleanup:
84 * Print errno log and/or timing stats if options given
85 *
86 *
87 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
88
89 #include <sys/types.h>
90 #include <sys/stat.h>
91 #include <fcntl.h>
92 #include <unistd.h>
93 #include <errno.h>
94 #include <string.h>
95 #include <signal.h>
96 #include "test.h"
97
98 void setup();
99 void cleanup();
100
101 char *TCID = "fcntl27";
102 int TST_TOTAL = 1;
103
104 char fname[255];
105 int fd;
106
main(int ac,char ** av)107 int main(int ac, char **av)
108 {
109 int lc, expected_result = -1;
110 /***************************************************************
111 * parse standard options
112 ***************************************************************/
113 tst_parse_opts(ac, av, NULL, NULL);
114
115 /***************************************************************
116 * perform global setup for test
117 ***************************************************************/
118 setup();
119
120 expected_result = -1;
121
122 /***************************************************************
123 * check looping state if -c option given
124 ***************************************************************/
125 for (lc = 0; TEST_LOOPING(lc); lc++) {
126
127 tst_count = 0;
128
129 #ifdef F_SETLEASE
130 /*
131 * Call fcntl(2) with F_SETLEASE & F_RDLCK argument on fname
132 */
133 TEST(fcntl(fd, F_SETLEASE, F_RDLCK));
134
135 /* check return code */
136 if (TEST_RETURN == expected_result) {
137 tst_resm(TPASS,
138 "fcntl(fd, F_SETLEASE, F_RDLCK) succeeded");
139 } else {
140 tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_RDLCK)"
141 " failed with errno %d : %s", fname,
142 TEST_ERRNO, strerror(TEST_ERRNO));
143 }
144 #else
145 tst_resm(TINFO, "F_SETLEASE not defined, skipping test");
146 #endif
147 }
148
149 /***************************************************************
150 * cleanup and exit
151 ***************************************************************/
152 cleanup();
153 tst_exit();
154
155 }
156
157 /***************************************************************
158 * setup() - performs all ONE TIME setup for this test.
159 ***************************************************************/
setup(void)160 void setup(void)
161 {
162
163 tst_sig(NOFORK, DEF_HANDLER, cleanup);
164
165 TEST_PAUSE;
166
167 tst_tmpdir();
168
169 sprintf(fname, "tfile_%d", getpid());
170 if ((fd = open(fname, O_RDWR | O_CREAT, 0777)) == -1) {
171 tst_brkm(TBROK, cleanup,
172 "open(%s, O_RDWR|O_CREAT,0777) Failed, errno=%d : %s",
173 fname, errno, strerror(errno));
174 }
175 }
176
177 /***************************************************************
178 * cleanup() - performs all ONE TIME cleanup for this test at
179 * completion or premature exit.
180 ***************************************************************/
cleanup(void)181 void cleanup(void)
182 {
183
184 /* close the file we've had open */
185 if (close(fd) == -1) {
186 tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno,
187 strerror(errno));
188 }
189
190 tst_rmdir();
191
192 }
193