blob: 982cf6e6daf01b9346510ca63b35d0158c9c6ea9 [file] [log] [blame]
robbiewd0223fd2006-01-13 22:33:44 +00001/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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#include "usctest.h"
95
vapieraa354722006-05-26 06:26:37 +000096void setup();
97void cleanup();
robbiewd0223fd2006-01-13 22:33:44 +000098
99
100char *TCID="fcntl28"; /* Test program identifier. */
101int TST_TOTAL=1; /* Total number of test cases. */
102extern int Tst_count; /* Test Case counter for tst_* routines */
103
robbiewa75bf062006-03-09 20:31:51 +0000104int exp_enos[]={0};
robbiewd0223fd2006-01-13 22:33:44 +0000105
106char fname[255];
107int fd;
108
109int
110main(int ac, char **av)
111{
mreed104f2a7082006-07-06 21:24:16 +0000112 int lc,expected_result = -1; /* loop counter, expected resul*/
113 /* from system call */
114 char *msg; /* message returned from parse_opts */
115 int results; /* stores result of kernel comparison */
robbiewd0223fd2006-01-13 22:33:44 +0000116 /***************************************************************
117 * parse standard options
118 ***************************************************************/
119 if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL )
120 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
121
122 /***************************************************************
123 * perform global setup for test
124 ***************************************************************/
125 setup();
126
127 /* set the expected errnos... */
128 TEST_EXP_ENOS(exp_enos);
129
mreed104f2a7082006-07-06 21:24:16 +0000130 if ((results=tst_kvercmp(2,6,10)) >= 0)
131 {
132 expected_result = -1;
133 }
134 else if( ((results=tst_kvercmp(2,4,0)) >= 0)&&\
135 ((results=tst_kvercmp(2,6,0))< 0) )
136 {
137 expected_result = 1;
138 }
139 else if( ((results=tst_kvercmp(2,6,0)) >= 0)&&\
140 ((results=tst_kvercmp(2,6,10))< 0) )
141 {
142 expected_result = 0;
143 }
144 else
145 {
146 expected_result = -1;
147 }
148
robbiewd0223fd2006-01-13 22:33:44 +0000149 /***************************************************************
150 * check looping state if -c option given
151 ***************************************************************/
152 for (lc=0; TEST_LOOPING(lc); lc++) {
153
154 /* reset Tst_count in case we are looping. */
155 Tst_count=0;
156
157#ifdef F_SETLEASE
158 /*
159 * Call fcntl(2) with F_SETLEASE & F_RDLCK argument on fname
160 */
161 TEST(fcntl(fd, F_SETLEASE,F_RDLCK));
162
163 /* check return code */
mreed104f2a7082006-07-06 21:24:16 +0000164 if ( TEST_RETURN == expected_result ) {
robbiewd0223fd2006-01-13 22:33:44 +0000165 TEST_ERROR_LOG(TEST_ERRNO);
robbiewd0223fd2006-01-13 22:33:44 +0000166 tst_resm(TPASS,
robbiewa75bf062006-03-09 20:31:51 +0000167 "fcntl(fd, F_SETLEASE,F_RDLCK) succeeded");
168 }
169 else {
170 tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_RDLCK)"
vapiera5f54202006-04-23 03:53:13 +0000171 " failed with errno %d : %s", fname,
172 TEST_ERRNO, strerror(TEST_ERRNO));
robbiewa75bf062006-03-09 20:31:51 +0000173 }
174
vapier75467512007-09-24 05:34:19 +0000175#else
176 tst_resm(TINFO, "F_SETLEASE not defined, skipping test");
robbiewd0223fd2006-01-13 22:33:44 +0000177#endif
178 } /* End for TEST_LOOPING */
179
180 /***************************************************************
181 * cleanup and exit
182 ***************************************************************/
183 cleanup();
184
185 return 0;
186} /* End main */
187
188/***************************************************************
189 * setup() - performs all ONE TIME setup for this test.
190 ***************************************************************/
191void
192setup()
193{
194 /* capture signals */
195 tst_sig(NOFORK, DEF_HANDLER, cleanup);
196
197 /* Pause if that option was specified */
198 TEST_PAUSE;
199
200 /* make a temp directory and cd to it */
201 tst_tmpdir();
202
203 sprintf(fname,"tfile_%d",getpid());
robbiewa75bf062006-03-09 20:31:51 +0000204 if ((fd = open(fname,O_WRONLY|O_CREAT,0222)) == -1) {
robbiewd0223fd2006-01-13 22:33:44 +0000205 tst_brkm(TBROK, cleanup,
robbiewa75bf062006-03-09 20:31:51 +0000206 "open(%s, O_WRONLY|O_CREAT,0222) Failed, errno=%d : %s",
robbiewd0223fd2006-01-13 22:33:44 +0000207 fname, errno, strerror(errno));
208 }
209} /* End setup() */
210
211
212/***************************************************************
213 * cleanup() - performs all ONE TIME cleanup for this test at
214 * completion or premature exit.
215 ***************************************************************/
216void
217cleanup()
218{
219 /*
220 * print timing stats if that option was specified.
221 * print errno log if that option was specified.
222 */
223 TEST_CLEANUP;
224
225 /* close the file we've had open */
226 if (close(fd) == -1) {
227 tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, strerror(errno));
228 }
229
230 /* Remove tmp dir and all files in it */
231 tst_rmdir();
232
233 /* exit with return code appropriate for results */
234 tst_exit();
235} /* End cleanup() */
236