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