blob: 5032bc2c1eed49be1ca55fd49959060b0840d81b [file] [log] [blame]
robbiewf9c0e012005-05-10 18:13:02 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiewf9c0e012005-05-10 18:13:02 +000019 */
20
21/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiewf9c0e012005-05-10 18:13:02 +000023 * TEST IDENTIFIER : fcntl27
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiewf9c0e012005-05-10 18:13:02 +000025 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiewf9c0e012005-05-10 18:13:02 +000027 * TEST TITLE : Basic test for fcntl(2) using F_SETLEASE & F_RDLCK argument.
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiewf9c0e012005-05-10 18:13:02 +000029 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000030 *
robbiewf9c0e012005-05-10 18:13:02 +000031 * WALL CLOCK TIME : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000032 *
subrata_modak56207ce2009-03-23 13:35:39 +000033 * CPU TYPES : ALL
subrata_modak4bb656a2009-02-26 12:02:09 +000034 *
subrata_modak56207ce2009-03-23 13:35:39 +000035 * AUTHOR : Jacky Malcles
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
robbiewf9c0e012005-05-10 18:13:02 +000037 * TEST CASES
subrata_modak4bb656a2009-02-26 12:02:09 +000038 *
subrata_modak56207ce2009-03-23 13:35:39 +000039 * 1.) fcntl(2) returns...(See Description)
Garrett Cooper2c282152010-12-16 00:55:50 -080040 *
robbiewf9c0e012005-05-10 18:13:02 +000041 * INPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000042 * The standard options for system call tests are accepted.
robbiewf9c0e012005-05-10 18:13:02 +000043 * (See the parse_opts(3) man page).
subrata_modak4bb656a2009-02-26 12:02:09 +000044 *
robbiewf9c0e012005-05-10 18:13:02 +000045 * OUTPUT SPECIFICATIONS
subrata_modak56207ce2009-03-23 13:35:39 +000046 *
robbiewf9c0e012005-05-10 18:13:02 +000047 * DURATION
subrata_modak56207ce2009-03-23 13:35:39 +000048 * Terminates - with frequency and infinite modes.
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
robbiewf9c0e012005-05-10 18:13:02 +000050 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000051 * Uses SIGUSR1 to pause before test if option set.
52 * (See the parse_opts(3) man page).
robbiewf9c0e012005-05-10 18:13:02 +000053 *
54 * RESOURCES
subrata_modak56207ce2009-03-23 13:35:39 +000055 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000056 *
robbiewf9c0e012005-05-10 18:13:02 +000057 * ENVIRONMENTAL NEEDS
58 * No run-time environmental needs.
subrata_modak4bb656a2009-02-26 12:02:09 +000059 *
robbiewf9c0e012005-05-10 18:13:02 +000060 * SPECIAL PROCEDURAL REQUIREMENTS
subrata_modak56207ce2009-03-23 13:35:39 +000061 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000062 *
robbiewf9c0e012005-05-10 18:13:02 +000063 * INTERCASE DEPENDENCIES
subrata_modak56207ce2009-03-23 13:35:39 +000064 * None
subrata_modak4bb656a2009-02-26 12:02:09 +000065 *
robbiewf9c0e012005-05-10 18:13:02 +000066 * 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).
subrata_modak4bb656a2009-02-26 12:02:09 +000071 *
subrata_modak56207ce2009-03-23 13:35:39 +000072 * Setup:
73 * Setup signal handling.
robbiewf9c0e012005-05-10 18:13:02 +000074 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000075 *
subrata_modak56207ce2009-03-23 13:35:39 +000076 * Test:
robbiewf9c0e012005-05-10 18:13:02 +000077 * Loop if the proper options are given.
subrata_modak56207ce2009-03-23 13:35:39 +000078 * Execute system call
robbiewf9c0e012005-05-10 18:13:02 +000079 * Check return code, if system call failed (return=-1)
subrata_modak56207ce2009-03-23 13:35:39 +000080 * Log the errno and Issue a FAIL message.
robbiewf9c0e012005-05-10 18:13:02 +000081 * Otherwise, Issue a PASS message.
subrata_modak4bb656a2009-02-26 12:02:09 +000082 *
subrata_modak56207ce2009-03-23 13:35:39 +000083 * Cleanup:
84 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000085 *
86 *
robbiewf9c0e012005-05-10 18:13:02 +000087 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
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"
robbiewf9c0e012005-05-10 18:13:02 +000097
vapieraa354722006-05-26 06:26:37 +000098void setup();
99void cleanup();
robbiewf9c0e012005-05-10 18:13:02 +0000100
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200101char *TCID = "fcntl27";
102int TST_TOTAL = 1;
robbiewf9c0e012005-05-10 18:13:02 +0000103
robbiewf9c0e012005-05-10 18:13:02 +0000104char fname[255];
105int fd;
106
subrata_modak56207ce2009-03-23 13:35:39 +0000107int main(int ac, char **av)
robbiewf9c0e012005-05-10 18:13:02 +0000108{
subrata_modak56207ce2009-03-23 13:35:39 +0000109 int lc, expected_result = -1; /* loop counter, expected */
110 /* result from system call */
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200111 const char *msg;
robbiewf9c0e012005-05-10 18:13:02 +0000112 /***************************************************************
113 * parse standard options
114 ***************************************************************/
Garrett Cooper45e285d2010-11-22 12:19:25 -0800115 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800116 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewf9c0e012005-05-10 18:13:02 +0000117
118 /***************************************************************
119 * perform global setup for test
120 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000121 setup();
robbiewf9c0e012005-05-10 18:13:02 +0000122
subrata_modak56207ce2009-03-23 13:35:39 +0000123 expected_result = -1;
mreed104f2a7082006-07-06 21:24:16 +0000124
robbiewf9c0e012005-05-10 18:13:02 +0000125 /***************************************************************
126 * check looping state if -c option given
127 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000128 for (lc = 0; TEST_LOOPING(lc); lc++) {
robbiewf9c0e012005-05-10 18:13:02 +0000129
Caspar Zhangd59a6592013-03-07 14:59:12 +0800130 tst_count = 0;
robbiewf9c0e012005-05-10 18:13:02 +0000131
robbiewe93a3242005-08-31 20:27:12 +0000132#ifdef F_SETLEASE
subrata_modak56207ce2009-03-23 13:35:39 +0000133 /*
134 * Call fcntl(2) with F_SETLEASE & F_RDLCK argument on fname
135 */
136 TEST(fcntl(fd, F_SETLEASE, F_RDLCK));
137
138 /* check return code */
139 if (TEST_RETURN == expected_result) {
subrata_modak56207ce2009-03-23 13:35:39 +0000140 tst_resm(TPASS,
141 "fcntl(fd, F_SETLEASE, F_RDLCK) succeeded");
142 } else {
143 tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_RDLCK)"
144 " failed with errno %d : %s", fname,
145 TEST_ERRNO, strerror(TEST_ERRNO));
146 }
vapier75467512007-09-24 05:34:19 +0000147#else
148 tst_resm(TINFO, "F_SETLEASE not defined, skipping test");
robbiewe93a3242005-08-31 20:27:12 +0000149#endif
Garrett Cooper2c282152010-12-16 00:55:50 -0800150 }
robbiewf9c0e012005-05-10 18:13:02 +0000151
152 /***************************************************************
153 * cleanup and exit
154 ***************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000155 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800156 tst_exit();
robbiewf9c0e012005-05-10 18:13:02 +0000157
Garrett Cooper2c282152010-12-16 00:55:50 -0800158}
robbiewf9c0e012005-05-10 18:13:02 +0000159
160/***************************************************************
161 * setup() - performs all ONE TIME setup for this test.
162 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400163void setup(void)
robbiewf9c0e012005-05-10 18:13:02 +0000164{
Garrett Cooper2c282152010-12-16 00:55:50 -0800165
subrata_modak56207ce2009-03-23 13:35:39 +0000166 tst_sig(NOFORK, DEF_HANDLER, cleanup);
robbiewf9c0e012005-05-10 18:13:02 +0000167
subrata_modak56207ce2009-03-23 13:35:39 +0000168 TEST_PAUSE;
robbiewf9c0e012005-05-10 18:13:02 +0000169
subrata_modak56207ce2009-03-23 13:35:39 +0000170 tst_tmpdir();
robbiewf9c0e012005-05-10 18:13:02 +0000171
subrata_modak56207ce2009-03-23 13:35:39 +0000172 sprintf(fname, "tfile_%d", getpid());
173 if ((fd = open(fname, O_RDWR | O_CREAT, 0777)) == -1) {
174 tst_brkm(TBROK, cleanup,
175 "open(%s, O_RDWR|O_CREAT,0777) Failed, errno=%d : %s",
176 fname, errno, strerror(errno));
177 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800178}
robbiewf9c0e012005-05-10 18:13:02 +0000179
180/***************************************************************
181 * cleanup() - performs all ONE TIME cleanup for this test at
subrata_modak56207ce2009-03-23 13:35:39 +0000182 * completion or premature exit.
robbiewf9c0e012005-05-10 18:13:02 +0000183 ***************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400184void cleanup(void)
robbiewf9c0e012005-05-10 18:13:02 +0000185{
robbiewf9c0e012005-05-10 18:13:02 +0000186
subrata_modak56207ce2009-03-23 13:35:39 +0000187 /* close the file we've had open */
188 if (close(fd) == -1) {
189 tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno,
190 strerror(errno));
191 }
robbiewf9c0e012005-05-10 18:13:02 +0000192
subrata_modak56207ce2009-03-23 13:35:39 +0000193 tst_rmdir();
robbiewf9c0e012005-05-10 18:13:02 +0000194
Chris Dearmanec6edca2012-10-17 19:54:01 -0700195}