blob: b58792d4fe176085d037497c54363012b0248c72 [file] [log] [blame]
subrata_modakee6d57b2009-01-16 10:10:17 +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_modakee6d57b2009-01-16 10:10:17 +000019/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: eventfd2_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=b087498eb5605673b0f260a7620d91818cd72304 */
28/* says: */
29/* This patch adds the new eventfd2 syscall. It extends the old eventfd */
30/* syscall by one parameter which is meant to hold a flag value. In this */
31/* patch the only flag support is EFD_CLOEXEC which causes the close-on-exec */
32/* flag for the returned file descriptor to be set. A new name EFD_CLOEXEC is */
33/* introduced which in this implementation must have the same value as */
34/* O_CLOEXEC. The following test must be adjusted for architectures other than*/
35/* x86 and x86-64 and in case the syscall numbers changed. */
36/* */
37/* Usage: <for command-line> */
38/* eventfd2_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: eventfd2_01 */
49/* */
50/* Author: Ulrich Drepper <drepper@redhat.com> */
51/* */
52/* History: Created - Jan 08 2009 - Ulrich Drepper <drepper@redhat.com> */
53/* Ported to LTP */
54/* - Jan 08 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_modakee6d57b2009-01-16 10:10:17 +000061
subrata_modakee6d57b2009-01-16 10:10:17 +000062#include "test.h"
Cyril Hrubis98f87472014-01-08 13:32:41 +010063#include "lapi/fcntl.h"
subrata_modak115006c2009-02-04 06:16:40 +000064#include "linux_syscall_numbers.h"
subrata_modakee6d57b2009-01-16 10:10:17 +000065
subrata_modakee6d57b2009-01-16 10:10:17 +000066#define EFD_CLOEXEC O_CLOEXEC
67
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020068char *TCID = "eventfd2_01";
subrata_modak56207ce2009-03-23 13:35:39 +000069int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020070int TST_TOTAL = 1;
subrata_modakee6d57b2009-01-16 10:10:17 +000071
72/* Extern Global Functions */
73/******************************************************************************/
74/* */
75/* Function: cleanup */
76/* */
77/* Description: Performs all one time clean up for this test on successful */
78/* completion, premature exit or failure. Closes all temporary */
79/* files, removes all temporary directories exits the test with */
80/* appropriate return code by calling tst_exit() function. */
81/* */
82/* Input: None. */
83/* */
84/* Output: None. */
85/* */
86/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
87/* On success - Exits calling tst_exit(). With '0' return code. */
88/* */
89/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040090void cleanup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000091{
Garrett Cooper2c282152010-12-16 00:55:50 -080092
subrata_modak56207ce2009-03-23 13:35:39 +000093 tst_rmdir();
subrata_modakee6d57b2009-01-16 10:10:17 +000094}
95
96/* Local Functions */
97/******************************************************************************/
98/* */
99/* Function: setup */
100/* */
101/* Description: Performs all one time setup for this test. This function is */
102/* typically used to capture signals, create temporary dirs */
103/* and temporary files that may be used in the course of this */
104/* test. */
105/* */
106/* Input: None. */
107/* */
108/* Output: None. */
109/* */
110/* Return: On failure - Exits by calling cleanup(). */
111/* On success - returns 0. */
112/* */
113/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400114void setup(void)
subrata_modak56207ce2009-03-23 13:35:39 +0000115{
116 /* Capture signals if any */
117 /* Create temporary directories */
118 TEST_PAUSE;
119 tst_tmpdir();
subrata_modakee6d57b2009-01-16 10:10:17 +0000120}
121
subrata_modak56207ce2009-03-23 13:35:39 +0000122int main(int argc, char *argv[])
123{
124 int fd, coe;
subrata_modakee6d57b2009-01-16 10:10:17 +0000125
subrata_modak56207ce2009-03-23 13:35:39 +0000126 if ((tst_kvercmp(2, 6, 27)) < 0) {
Garrett Coopera4f4cec2011-02-13 18:25:49 -0800127 tst_brkm(TCONF, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800128 "This test can only run on kernels that are 2.6.27 and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000129 }
130 setup();
subrata_modakee6d57b2009-01-16 10:10:17 +0000131
Jan Stancek359980f2013-02-15 10:16:05 +0100132 fd = ltp_syscall(__NR_eventfd2, 1, 0);
Garrett Cooper53740502010-12-16 00:04:01 -0800133 if (fd == -1) {
134 tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000135 }
Garrett Cooper53740502010-12-16 00:04:01 -0800136 coe = fcntl(fd, F_GETFD);
137 if (coe == -1) {
138 tst_brkm(TBROK, cleanup, "fcntl failed");
139 }
140 if (coe & FD_CLOEXEC) {
141 tst_brkm(TFAIL, cleanup, "eventfd2(0) set close-on-exec flag");
142 }
143 close(fd);
144
Jan Stancek359980f2013-02-15 10:16:05 +0100145 fd = ltp_syscall(__NR_eventfd2, 1, EFD_CLOEXEC);
Garrett Cooper53740502010-12-16 00:04:01 -0800146 if (fd == -1) {
147 tst_brkm(TFAIL, cleanup, "eventfd2(EFD_CLOEXEC) failed");
148 }
149 coe = fcntl(fd, F_GETFD);
150 if (coe == -1) {
151 tst_brkm(TBROK, cleanup, "fcntl failed");
152 }
153 if ((coe & FD_CLOEXEC) == 0) {
154 tst_brkm(TFAIL, cleanup,
155 "eventfd2(EFD_CLOEXEC) does not set close-on-exec flag");
156 }
157 close(fd);
158 tst_resm(TPASS, "eventfd2(EFD_CLOEXEC) Passed");
159 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000160 tst_exit();
Garrett Coopera4f4cec2011-02-13 18:25:49 -0800161}