subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 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 */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 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> |
subrata_modak | c488f90 | 2009-02-23 07:17:33 +0000 | [diff] [blame] | 57 | #include <errno.h> |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 58 | |
| 59 | /* Harness Specific Include Files. */ |
| 60 | #include "test.h" |
| 61 | #include "usctest.h" |
subrata_modak | 115006c | 2009-02-04 06:16:40 +0000 | [diff] [blame] | 62 | #include "linux_syscall_numbers.h" |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 63 | |
| 64 | #ifndef O_CLOEXEC |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 65 | #define O_CLOEXEC 02000000 |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 68 | #define IN_NONBLOCK O_NONBLOCK |
| 69 | |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 70 | /* Global Variables */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | char *TCID = "inotify_init1_02"; /* test program identifier. */ |
| 72 | int testno; |
| 73 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 74 | |
| 75 | /* Extern Global Functions */ |
| 76 | /******************************************************************************/ |
| 77 | /* */ |
| 78 | /* Function: cleanup */ |
| 79 | /* */ |
| 80 | /* Description: Performs all one time clean up for this test on successful */ |
| 81 | /* completion, premature exit or failure. Closes all temporary */ |
| 82 | /* files, removes all temporary directories exits the test with */ |
| 83 | /* appropriate return code by calling tst_exit() function. */ |
| 84 | /* */ |
| 85 | /* Input: None. */ |
| 86 | /* */ |
| 87 | /* Output: None. */ |
| 88 | /* */ |
| 89 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 90 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 91 | /* */ |
| 92 | /******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 93 | extern void cleanup() |
| 94 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 95 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | TEST_CLEANUP; |
| 97 | tst_rmdir(); |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* Local Functions */ |
| 101 | /******************************************************************************/ |
| 102 | /* */ |
| 103 | /* Function: setup */ |
| 104 | /* */ |
| 105 | /* Description: Performs all one time setup for this test. This function is */ |
| 106 | /* typically used to capture signals, create temporary dirs */ |
| 107 | /* and temporary files that may be used in the course of this */ |
| 108 | /* test. */ |
| 109 | /* */ |
| 110 | /* Input: None. */ |
| 111 | /* */ |
| 112 | /* Output: None. */ |
| 113 | /* */ |
| 114 | /* Return: On failure - Exits by calling cleanup(). */ |
| 115 | /* On success - returns 0. */ |
| 116 | /* */ |
| 117 | /******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | void setup() |
| 119 | { |
| 120 | /* Capture signals if any */ |
| 121 | /* Create temporary directories */ |
| 122 | TEST_PAUSE; |
| 123 | tst_tmpdir(); |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 124 | } |
| 125 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | int main(int argc, char *argv[]) |
| 127 | { |
| 128 | int fd, fl; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 129 | int lc; |
| 130 | char *msg; |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 131 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | /* Parse standard options given to run the test. */ |
Garrett Cooper | 084831a | 2010-11-22 15:26:44 -0800 | [diff] [blame] | 133 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 134 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 135 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | if ((tst_kvercmp(2, 6, 27)) < 0) { |
Garrett Cooper | f5f23a3 | 2010-11-20 16:06:10 -0800 | [diff] [blame] | 137 | tst_brkm(TCONF, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 138 | "This test can only run on kernels that are 2.6.27 " |
| 139 | "and higher"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 140 | } |
| 141 | setup(); |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 142 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 143 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 144 | Tst_count = 0; |
| 145 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 146 | fd = ltp_syscall(__NR_inotify_init1, 0); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 147 | if (fd == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 148 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 149 | "inotify_init1(0) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 150 | } |
| 151 | fl = fcntl(fd, F_GETFL); |
| 152 | if (fl == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 153 | tst_brkm(TBROK | TERRNO, cleanup, |
| 154 | "fcntl failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 155 | } |
| 156 | if (fl & O_NONBLOCK) { |
Garrett Cooper | 084831a | 2010-11-22 15:26:44 -0800 | [diff] [blame] | 157 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 158 | "inotify_init1(0) set non-blocking " |
| 159 | "mode"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 160 | } |
| 161 | close(fd); |
subrata_modak | 66ec125 | 2009-01-16 10:36:22 +0000 | [diff] [blame] | 162 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 163 | fd = ltp_syscall(__NR_inotify_init1, IN_NONBLOCK); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 164 | if (fd == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 165 | tst_brkm(TFAIL | TERRNO, cleanup, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 166 | "inotify_init1(IN_NONBLOCK) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 167 | } |
| 168 | fl = fcntl(fd, F_GETFL); |
| 169 | if (fl == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 170 | tst_brkm(TBROK | TERRNO, cleanup, |
| 171 | "fcntl failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | } |
| 173 | if ((fl & O_NONBLOCK) == 0) { |
Garrett Cooper | 084831a | 2010-11-22 15:26:44 -0800 | [diff] [blame] | 174 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 175 | "inotify_init1(IN_NONBLOCK) set " |
| 176 | "non-blocking mode"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | } |
| 178 | close(fd); |
| 179 | tst_resm(TPASS, "inotify_init1(IN_NONBLOCK) PASSED"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | tst_exit(); |
Garrett Cooper | ae2e6ac | 2010-12-19 10:03:27 -0800 | [diff] [blame] | 183 | } |