blob: 08b4c12f622c71ad5b13b0562c070539bb49947f [file] [log] [blame]
subrata_modak6eeb3832009-01-16 10:21:40 +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_modak6eeb3832009-01-16 10:21:40 +000019/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: inotify_init1_01.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=4006553b06306b34054529477b06b68a1c66249b */
28/* says: */
29/* This patch introduces the new syscall inotify_init1 (note: the 1 stands for*/
30/* the one parameter the syscall takes, as opposed to no parameter before). */
31/* The values accepted for this parameter are function-specific and defined in*/
32/* the inotify.h header. Here the values must match the O_* flags, though. */
33/* In this patch CLOEXEC support is introduced. */
34/* The following test must be adjusted for architectures other */
35/* than x86 and x86-64 and in case the syscall numbers changed. */
36/* */
37/* Usage: <for command-line> */
38/* inotify_init1_01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
39/* where, -c n : Run n copies concurrently. */
40/* -e : Turn on errno logging. */
41/* -i n : Execute test n times. */
42/* -I x : Execute test for x seconds. */
43/* -P x : Pause for x seconds between iterations. */
44/* -t : Turn on syscall timing. */
45/* */
46/* Total Tests: 1 */
47/* */
48/* Test Name: inotify_init1_01 */
49/* */
50/* Author: Ulrich Drepper <drepper@redhat.com> */
51/* */
52/* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */
53/* Ported to LTP */
54/* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */
55/******************************************************************************/
56#include <fcntl.h>
57#include <stdio.h>
58#include <unistd.h>
59#include <sys/syscall.h>
subrata_modakc488f902009-02-23 07:17:33 +000060#include <errno.h>
subrata_modak6eeb3832009-01-16 10:21:40 +000061
62/* Harness Specific Include Files. */
63#include "test.h"
64#include "usctest.h"
subrata_modak115006c2009-02-04 06:16:40 +000065#include "linux_syscall_numbers.h"
subrata_modak6eeb3832009-01-16 10:21:40 +000066
67#ifndef O_CLOEXEC
Wanlong Gao354ebb42012-12-07 10:10:04 +080068#define O_CLOEXEC 02000000
subrata_modak6eeb3832009-01-16 10:21:40 +000069#endif
70
subrata_modak6eeb3832009-01-16 10:21:40 +000071#define IN_CLOEXEC O_CLOEXEC
72
73/* Extern Global Variables */
subrata_modak6eeb3832009-01-16 10:21:40 +000074
75/* Global Variables */
subrata_modak56207ce2009-03-23 13:35:39 +000076char *TCID = "inotify_init1_01"; /* test program identifier. */
77int testno;
78int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modak6eeb3832009-01-16 10:21:40 +000079
80/* Extern Global Functions */
81/******************************************************************************/
82/* */
83/* Function: cleanup */
84/* */
85/* Description: Performs all one time clean up for this test on successful */
86/* completion, premature exit or failure. Closes all temporary */
87/* files, removes all temporary directories exits the test with */
88/* appropriate return code by calling tst_exit() function. */
89/* */
90/* Input: None. */
91/* */
92/* Output: None. */
93/* */
94/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
95/* On success - Exits calling tst_exit(). With '0' return code. */
96/* */
97/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +000098extern void cleanup()
99{
Garrett Cooper2c282152010-12-16 00:55:50 -0800100
subrata_modak56207ce2009-03-23 13:35:39 +0000101 TEST_CLEANUP;
102 tst_rmdir();
subrata_modak6eeb3832009-01-16 10:21:40 +0000103}
104
105/* Local Functions */
106/******************************************************************************/
107/* */
108/* Function: setup */
109/* */
110/* Description: Performs all one time setup for this test. This function is */
111/* typically used to capture signals, create temporary dirs */
112/* and temporary files that may be used in the course of this */
113/* test. */
114/* */
115/* Input: None. */
116/* */
117/* Output: None. */
118/* */
119/* Return: On failure - Exits by calling cleanup(). */
120/* On success - returns 0. */
121/* */
122/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000123void setup()
124{
125 /* Capture signals if any */
126 /* Create temporary directories */
127 TEST_PAUSE;
128 tst_tmpdir();
subrata_modak6eeb3832009-01-16 10:21:40 +0000129}
130
subrata_modak56207ce2009-03-23 13:35:39 +0000131int main(int argc, char *argv[])
132{
133 int fd, coe;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200134 int lc;
135 char *msg;
subrata_modak6eeb3832009-01-16 10:21:40 +0000136
subrata_modak56207ce2009-03-23 13:35:39 +0000137 /* Parse standard options given to run the test. */
Garrett Cooper084831a2010-11-22 15:26:44 -0800138 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +0000139 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Coopera9e49f12010-12-16 10:54:03 -0800140
subrata_modak56207ce2009-03-23 13:35:39 +0000141 if ((tst_kvercmp(2, 6, 27)) < 0) {
Garrett Cooper58843d22010-11-20 16:12:24 -0800142 tst_brkm(TCONF, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800143 "This test can only run on kernels that are 2.6.27 "
144 "and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000145 }
146 setup();
subrata_modak6eeb3832009-01-16 10:21:40 +0000147
subrata_modak56207ce2009-03-23 13:35:39 +0000148 for (lc = 0; TEST_LOOPING(lc); ++lc) {
149 Tst_count = 0;
150 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100151 fd = ltp_syscall(__NR_inotify_init1, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000152 if (fd == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800153 tst_brkm(TFAIL | TERRNO, cleanup,
154 "inotify_init1(0) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000155 }
156 coe = fcntl(fd, F_GETFD);
157 if (coe == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158 tst_brkm(TBROK | TERRNO, cleanup,
159 "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000160 }
161 if (coe & FD_CLOEXEC) {
Garrett Cooper58843d22010-11-20 16:12:24 -0800162 tst_brkm(TFAIL, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800163 "inotify_init1(0) set close-on-exit");
subrata_modak56207ce2009-03-23 13:35:39 +0000164 }
165 close(fd);
subrata_modak6eeb3832009-01-16 10:21:40 +0000166
Jan Stancek359980f2013-02-15 10:16:05 +0100167 fd = ltp_syscall(__NR_inotify_init1, IN_CLOEXEC);
subrata_modak56207ce2009-03-23 13:35:39 +0000168 if (fd == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800169 tst_brkm(TFAIL | TERRNO, cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000170 "inotify_init1(IN_CLOEXEC) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000171 }
172 coe = fcntl(fd, F_GETFD);
173 if (coe == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800174 tst_resm(TBROK | TERRNO, "fcntl failed");
Garrett Cooper58843d22010-11-20 16:12:24 -0800175 } else if ((coe & FD_CLOEXEC) == 0) {
subrata_modak56207ce2009-03-23 13:35:39 +0000176 tst_resm(TFAIL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800177 "inotify_init1(O_CLOEXEC) did not "
178 "set close-on-exit");
Garrett Cooper58843d22010-11-20 16:12:24 -0800179 } else {
180 close(fd);
181 tst_resm(TPASS, "inotify_init1(O_CLOEXEC) "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800182 "PASSED");
subrata_modak56207ce2009-03-23 13:35:39 +0000183 }
subrata_modak56207ce2009-03-23 13:35:39 +0000184 }
185 }
186 tst_exit();
Garrett Cooper084831a2010-11-22 15:26:44 -0800187 cleanup();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700188}