• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************/
2 /*                                                                            */
3 /* Copyright (c) Ulrich Drepper <drepper@redhat.com>                          */
4 /* Copyright (c) International Business Machines  Corp., 2009                 */
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 /* File:        inotify_init1_02.c                                            */
24 /*                                                                            */
25 /* Description: This Program tests the new system call introduced in 2.6.27.  */
26 /*              Ulrich´s comment as in:                                       */
27 /* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=510df2dd482496083e1c3b1a8c9b6afd5fa4c7d7 */
28 /* which says:                                                                */
29 /* This patch adds non-blocking support for inotify_init1.  The additional    */
30 /* changes needed are minimal. The following test must be adjusted for        */
31 /* architectures other than x86 and x86-64 and in case the syscall numbers    */
32 /* changed.                                                                   */
33 /*                                                                            */
34 /* Usage:  <for command-line>                                                 */
35 /* inotify_init1_02 [-c n] [-e][-i n] [-I x] [-p x] [-t]                      */
36 /*      where,  -c n : Run n copies concurrently.                             */
37 /*              -e   : Turn on errno logging.                                 */
38 /*              -i n : Execute test n times.                                  */
39 /*              -I x : Execute test for x seconds.                            */
40 /*              -P x : Pause for x seconds between iterations.                */
41 /*              -t   : Turn on syscall timing.                                */
42 /*                                                                            */
43 /* Total Tests: 1                                                             */
44 /*                                                                            */
45 /* Test Name:   inotify_init1_02                                              */
46 /*                                                                            */
47 /* Author:      Ulrich Drepper <drepper@redhat.com>                           */
48 /*                                                                            */
49 /* History:     Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>   */
50 /*              Ported to LTP                                                 */
51 /*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
52 /******************************************************************************/
53 #include <fcntl.h>
54 #include <stdio.h>
55 #include <unistd.h>
56 #include <sys/syscall.h>
57 #include <errno.h>
58 
59 #include "test.h"
60 #include "lapi/fcntl.h"
61 #include "lapi/syscalls.h"
62 
63 #define IN_NONBLOCK O_NONBLOCK
64 
65 char *TCID = "inotify_init1_02";
66 int testno;
67 int TST_TOTAL = 1;
68 
69 /* Extern Global Functions */
70 /******************************************************************************/
71 /*                                                                            */
72 /* Function:    cleanup                                                       */
73 /*                                                                            */
74 /* Description: Performs all one time clean up for this test on successful    */
75 /*              completion,  premature exit or  failure. Closes all temporary */
76 /*              files, removes all temporary directories exits the test with  */
77 /*              appropriate return code by calling tst_exit() function.       */
78 /*                                                                            */
79 /* Input:       None.                                                         */
80 /*                                                                            */
81 /* Output:      None.                                                         */
82 /*                                                                            */
83 /* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
84 /*              On success - Exits calling tst_exit(). With '0' return code.  */
85 /*                                                                            */
86 /******************************************************************************/
cleanup(void)87 void cleanup(void)
88 {
89 
90 	tst_rmdir();
91 }
92 
93 /* Local  Functions */
94 /******************************************************************************/
95 /*                                                                            */
96 /* Function:    setup                                                         */
97 /*                                                                            */
98 /* Description: Performs all one time setup for this test. This function is   */
99 /*              typically used to capture signals, create temporary dirs      */
100 /*              and temporary files that may be used in the course of this    */
101 /*              test.                                                         */
102 /*                                                                            */
103 /* Input:       None.                                                         */
104 /*                                                                            */
105 /* Output:      None.                                                         */
106 /*                                                                            */
107 /* Return:      On failure - Exits by calling cleanup().                      */
108 /*              On success - returns 0.                                       */
109 /*                                                                            */
110 /******************************************************************************/
setup(void)111 void setup(void)
112 {
113 	/* Capture signals if any */
114 	/* Create temporary directories */
115 	TEST_PAUSE;
116 	tst_tmpdir();
117 }
118 
main(int argc,char * argv[])119 int main(int argc, char *argv[])
120 {
121 	int fd, fl;
122 	int lc;
123 
124 	tst_parse_opts(argc, argv, NULL, NULL);
125 
126 	if ((tst_kvercmp(2, 6, 27)) < 0) {
127 		tst_brkm(TCONF, NULL,
128 			 "This test can only run on kernels that are 2.6.27 "
129 			 "and higher");
130 	}
131 	setup();
132 
133 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
134 		tst_count = 0;
135 		for (testno = 0; testno < TST_TOTAL; ++testno) {
136 			fd = ltp_syscall(__NR_inotify_init1, 0);
137 			if (fd == -1) {
138 				tst_brkm(TFAIL | TERRNO, cleanup,
139 					 "inotify_init1(0) failed");
140 			}
141 			fl = fcntl(fd, F_GETFL);
142 			if (fl == -1) {
143 				tst_brkm(TBROK | TERRNO, cleanup,
144 					 "fcntl failed");
145 			}
146 			if (fl & O_NONBLOCK) {
147 				tst_brkm(TFAIL, cleanup,
148 					 "inotify_init1(0) set non-blocking "
149 					 "mode");
150 			}
151 			close(fd);
152 
153 			fd = ltp_syscall(__NR_inotify_init1, IN_NONBLOCK);
154 			if (fd == -1) {
155 				tst_brkm(TFAIL | TERRNO, cleanup,
156 					 "inotify_init1(IN_NONBLOCK) failed");
157 			}
158 			fl = fcntl(fd, F_GETFL);
159 			if (fl == -1) {
160 				tst_brkm(TBROK | TERRNO, cleanup,
161 					 "fcntl failed");
162 			}
163 			if ((fl & O_NONBLOCK) == 0) {
164 				tst_brkm(TFAIL, cleanup,
165 					 "inotify_init1(IN_NONBLOCK) set "
166 					 "non-blocking mode");
167 			}
168 			close(fd);
169 			tst_resm(TPASS, "inotify_init1(IN_NONBLOCK) PASSED");
170 		}
171 	}
172 	tst_exit();
173 }
174