blob: 0b80685792470527a2b31bc963380c1e34b8ef0a [file] [log] [blame]
subrata_modak66ec1252009-01-16 10:36:22 +00001/******************************************************************************/
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 Gao4548c6c2012-10-19 18:03:36 +080018/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modak66ec1252009-01-16 10:36:22 +000019/* */
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_modakc488f902009-02-23 07:17:33 +000057#include <errno.h>
subrata_modak66ec1252009-01-16 10:36:22 +000058
59/* Harness Specific Include Files. */
60#include "test.h"
61#include "usctest.h"
subrata_modak115006c2009-02-04 06:16:40 +000062#include "linux_syscall_numbers.h"
subrata_modak66ec1252009-01-16 10:36:22 +000063
64#ifndef O_CLOEXEC
Wanlong Gao354ebb42012-12-07 10:10:04 +080065#define O_CLOEXEC 02000000
subrata_modak66ec1252009-01-16 10:36:22 +000066#endif
67
subrata_modak66ec1252009-01-16 10:36:22 +000068#define IN_NONBLOCK O_NONBLOCK
69
subrata_modak66ec1252009-01-16 10:36:22 +000070/* Global Variables */
subrata_modak56207ce2009-03-23 13:35:39 +000071char *TCID = "inotify_init1_02"; /* test program identifier. */
72int testno;
73int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modak66ec1252009-01-16 10:36:22 +000074
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_modak56207ce2009-03-23 13:35:39 +000093extern void cleanup()
94{
Garrett Cooper2c282152010-12-16 00:55:50 -080095
subrata_modak56207ce2009-03-23 13:35:39 +000096 TEST_CLEANUP;
97 tst_rmdir();
subrata_modak66ec1252009-01-16 10:36:22 +000098}
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_modak56207ce2009-03-23 13:35:39 +0000118void setup()
119{
120 /* Capture signals if any */
121 /* Create temporary directories */
122 TEST_PAUSE;
123 tst_tmpdir();
subrata_modak66ec1252009-01-16 10:36:22 +0000124}
125
subrata_modak56207ce2009-03-23 13:35:39 +0000126int main(int argc, char *argv[])
127{
128 int fd, fl;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200129 int lc;
130 char *msg;
subrata_modak66ec1252009-01-16 10:36:22 +0000131
subrata_modak56207ce2009-03-23 13:35:39 +0000132 /* Parse standard options given to run the test. */
Garrett Cooper084831a2010-11-22 15:26:44 -0800133 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +0000134 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Coopera9e49f12010-12-16 10:54:03 -0800135
subrata_modak56207ce2009-03-23 13:35:39 +0000136 if ((tst_kvercmp(2, 6, 27)) < 0) {
Garrett Cooperf5f23a32010-11-20 16:06:10 -0800137 tst_brkm(TCONF, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800138 "This test can only run on kernels that are 2.6.27 "
139 "and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000140 }
141 setup();
subrata_modak66ec1252009-01-16 10:36:22 +0000142
subrata_modak56207ce2009-03-23 13:35:39 +0000143 for (lc = 0; TEST_LOOPING(lc); ++lc) {
144 Tst_count = 0;
145 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100146 fd = ltp_syscall(__NR_inotify_init1, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000147 if (fd == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800148 tst_brkm(TFAIL | TERRNO, cleanup,
149 "inotify_init1(0) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000150 }
151 fl = fcntl(fd, F_GETFL);
152 if (fl == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800153 tst_brkm(TBROK | TERRNO, cleanup,
154 "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000155 }
156 if (fl & O_NONBLOCK) {
Garrett Cooper084831a2010-11-22 15:26:44 -0800157 tst_brkm(TFAIL, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158 "inotify_init1(0) set non-blocking "
159 "mode");
subrata_modak56207ce2009-03-23 13:35:39 +0000160 }
161 close(fd);
subrata_modak66ec1252009-01-16 10:36:22 +0000162
Jan Stancek359980f2013-02-15 10:16:05 +0100163 fd = ltp_syscall(__NR_inotify_init1, IN_NONBLOCK);
subrata_modak56207ce2009-03-23 13:35:39 +0000164 if (fd == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800165 tst_brkm(TFAIL | TERRNO, cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000166 "inotify_init1(IN_NONBLOCK) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000167 }
168 fl = fcntl(fd, F_GETFL);
169 if (fl == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800170 tst_brkm(TBROK | TERRNO, cleanup,
171 "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000172 }
173 if ((fl & O_NONBLOCK) == 0) {
Garrett Cooper084831a2010-11-22 15:26:44 -0800174 tst_brkm(TFAIL, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800175 "inotify_init1(IN_NONBLOCK) set "
176 "non-blocking mode");
subrata_modak56207ce2009-03-23 13:35:39 +0000177 }
178 close(fd);
179 tst_resm(TPASS, "inotify_init1(IN_NONBLOCK) PASSED");
subrata_modak56207ce2009-03-23 13:35:39 +0000180 }
181 }
182 tst_exit();
Garrett Cooperae2e6ac2010-12-19 10:03:27 -0800183}