blob: eb120a93fb7ee88a2bf03cf82d626eddce128ab9 [file] [log] [blame]
subrata_modak3a045372009-01-16 10:31:43 +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_modak3a045372009-01-16 10:31:43 +000019/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: eventfd2_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=e7d476dfdf0bcfed478a207aecfdc84f81efecaf */
28/* which says: */
29/* This patch adds support for the EFD_NONBLOCK flag to eventfd2. The */
30/* additional changes needed are minimal. The following test must be adjusted */
31/* or architectures other than x86 and x86-64 and in case the syscall numbers */
32/* changed. */
33/* */
34/* Usage: <for command-line> */
35/* eventfd2_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: eventfd2_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_modak3a045372009-01-16 10:31:43 +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_modak3a045372009-01-16 10:31:43 +000063
64#ifndef O_CLOEXEC
Wanlong Gao354ebb42012-12-07 10:10:04 +080065#define O_CLOEXEC 02000000
subrata_modak3a045372009-01-16 10:31:43 +000066#endif
67
subrata_modak3a045372009-01-16 10:31:43 +000068#define EFD_NONBLOCK O_NONBLOCK
69
70/* Extern Global Variables */
subrata_modak3a045372009-01-16 10:31:43 +000071
72/* Global Variables */
subrata_modak56207ce2009-03-23 13:35:39 +000073char *TCID = "eventfd2_02"; /* test program identifier. */
74int testno;
75int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modak3a045372009-01-16 10:31:43 +000076
77/* Extern Global Functions */
78/******************************************************************************/
79/* */
80/* Function: cleanup */
81/* */
82/* Description: Performs all one time clean up for this test on successful */
83/* completion, premature exit or failure. Closes all temporary */
84/* files, removes all temporary directories exits the test with */
85/* appropriate return code by calling tst_exit() function. */
86/* */
87/* Input: None. */
88/* */
89/* Output: None. */
90/* */
91/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
92/* On success - Exits calling tst_exit(). With '0' return code. */
93/* */
94/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +000095extern void cleanup()
96{
Garrett Cooper2c282152010-12-16 00:55:50 -080097
subrata_modak56207ce2009-03-23 13:35:39 +000098 TEST_CLEANUP;
99 tst_rmdir();
subrata_modak3a045372009-01-16 10:31:43 +0000100}
101
102/* Local Functions */
103/******************************************************************************/
104/* */
105/* Function: setup */
106/* */
107/* Description: Performs all one time setup for this test. This function is */
108/* typically used to capture signals, create temporary dirs */
109/* and temporary files that may be used in the course of this */
110/* test. */
111/* */
112/* Input: None. */
113/* */
114/* Output: None. */
115/* */
116/* Return: On failure - Exits by calling cleanup(). */
117/* On success - returns 0. */
118/* */
119/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000120void setup()
121{
122 /* Capture signals if any */
123 /* Create temporary directories */
124 TEST_PAUSE;
125 tst_tmpdir();
subrata_modak3a045372009-01-16 10:31:43 +0000126}
127
subrata_modak56207ce2009-03-23 13:35:39 +0000128int main(int argc, char *argv[])
129{
130 int fd, fl;
subrata_modak3a045372009-01-16 10:31:43 +0000131
subrata_modak56207ce2009-03-23 13:35:39 +0000132 if ((tst_kvercmp(2, 6, 27)) < 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800133 tst_brkm(TCONF, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800134 "This test can only run on kernels that are 2.6.27 and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000135 }
136 setup();
subrata_modak3a045372009-01-16 10:31:43 +0000137
Garrett Cooper53740502010-12-16 00:04:01 -0800138 Tst_count = 0;
Jan Stancek359980f2013-02-15 10:16:05 +0100139 fd = ltp_syscall(__NR_eventfd2, 1, 0);
Garrett Cooper53740502010-12-16 00:04:01 -0800140 if (fd == -1) {
141 tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000142 }
Garrett Cooper53740502010-12-16 00:04:01 -0800143 fl = fcntl(fd, F_GETFL);
144 if (fl == -1) {
145 tst_brkm(TBROK, cleanup, "fcntl failed");
146 }
147 if (fl & O_NONBLOCK) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800148 tst_brkm(TFAIL, cleanup, "eventfd2(0) sets non-blocking mode");
Garrett Cooper53740502010-12-16 00:04:01 -0800149 }
150 close(fd);
151
Jan Stancek359980f2013-02-15 10:16:05 +0100152 fd = ltp_syscall(__NR_eventfd2, 1, EFD_NONBLOCK);
Garrett Cooper53740502010-12-16 00:04:01 -0800153 if (fd == -1) {
154 tst_brkm(TFAIL, cleanup, "eventfd2(EFD_NONBLOCK) failed");
155 }
156 fl = fcntl(fd, F_GETFL);
157 if (fl == -1) {
158 tst_brkm(TBROK, cleanup, "fcntl failed");
159 }
160 if ((fl & O_NONBLOCK) == 0) {
161 tst_brkm(TFAIL, cleanup,
162 "eventfd2(EFD_NONBLOCK) didn't set non-blocking mode");
163 }
164 close(fd);
165 tst_resm(TPASS, "eventfd2(EFD_NONBLOCK) PASSED");
166
167 cleanup();
subrata_modak56207ce2009-03-23 13:35:39 +0000168 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700169}