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 <stdio.h>
54 #include <unistd.h>
55 #include <sys/syscall.h>
56 #include <errno.h>
57
58 #include "test.h"
59 #include "lapi/fcntl.h"
60 #include "lapi/syscalls.h"
61
62 #define IN_NONBLOCK O_NONBLOCK
63
64 char *TCID = "inotify_init1_02";
65 int testno;
66 int TST_TOTAL = 1;
67
68 /* Extern Global Functions */
69 /******************************************************************************/
70 /* */
71 /* Function: cleanup */
72 /* */
73 /* Description: Performs all one time clean up for this test on successful */
74 /* completion, premature exit or failure. Closes all temporary */
75 /* files, removes all temporary directories exits the test with */
76 /* appropriate return code by calling tst_exit() function. */
77 /* */
78 /* Input: None. */
79 /* */
80 /* Output: None. */
81 /* */
82 /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
83 /* On success - Exits calling tst_exit(). With '0' return code. */
84 /* */
85 /******************************************************************************/
cleanup(void)86 void cleanup(void)
87 {
88
89 tst_rmdir();
90 }
91
92 /* Local Functions */
93 /******************************************************************************/
94 /* */
95 /* Function: setup */
96 /* */
97 /* Description: Performs all one time setup for this test. This function is */
98 /* typically used to capture signals, create temporary dirs */
99 /* and temporary files that may be used in the course of this */
100 /* test. */
101 /* */
102 /* Input: None. */
103 /* */
104 /* Output: None. */
105 /* */
106 /* Return: On failure - Exits by calling cleanup(). */
107 /* On success - returns 0. */
108 /* */
109 /******************************************************************************/
setup(void)110 void setup(void)
111 {
112 /* Capture signals if any */
113 /* Create temporary directories */
114 TEST_PAUSE;
115 tst_tmpdir();
116 }
117
main(int argc,char * argv[])118 int main(int argc, char *argv[])
119 {
120 int fd, fl;
121 int lc;
122
123 tst_parse_opts(argc, argv, NULL, NULL);
124
125 if ((tst_kvercmp(2, 6, 27)) < 0) {
126 tst_brkm(TCONF, NULL,
127 "This test can only run on kernels that are 2.6.27 "
128 "and higher");
129 }
130 setup();
131
132 for (lc = 0; TEST_LOOPING(lc); ++lc) {
133 tst_count = 0;
134 for (testno = 0; testno < TST_TOTAL; ++testno) {
135 fd = ltp_syscall(__NR_inotify_init1, 0);
136 if (fd == -1) {
137 tst_brkm(TFAIL | TERRNO, cleanup,
138 "inotify_init1(0) failed");
139 }
140 fl = fcntl(fd, F_GETFL);
141 if (fl == -1) {
142 tst_brkm(TBROK | TERRNO, cleanup,
143 "fcntl failed");
144 }
145 if (fl & O_NONBLOCK) {
146 tst_brkm(TFAIL, cleanup,
147 "inotify_init1(0) set non-blocking "
148 "mode");
149 }
150 close(fd);
151
152 fd = ltp_syscall(__NR_inotify_init1, IN_NONBLOCK);
153 if (fd == -1) {
154 tst_brkm(TFAIL | TERRNO, cleanup,
155 "inotify_init1(IN_NONBLOCK) failed");
156 }
157 fl = fcntl(fd, F_GETFL);
158 if (fl == -1) {
159 tst_brkm(TBROK | TERRNO, cleanup,
160 "fcntl failed");
161 }
162 if ((fl & O_NONBLOCK) == 0) {
163 tst_brkm(TFAIL, cleanup,
164 "inotify_init1(IN_NONBLOCK) set "
165 "non-blocking mode");
166 }
167 close(fd);
168 tst_resm(TPASS, "inotify_init1(IN_NONBLOCK) PASSED");
169 }
170 }
171 tst_exit();
172 }
173