blob: ff75d0b98b198653c98e2b92703c8c8e76e9f605 [file] [log] [blame]
subrata_modakfc49f1f2009-01-16 10:29:50 +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_modakfc49f1f2009-01-16 10:29:50 +000019/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: signalfd4_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=5fb5e04926a54bc1c22bba7ca166840f4476196f */
28/* which says: */
29/* This patch adds support for the SFD_NONBLOCK flag to signalfd4. The */
30/* additional changes needed are minimal. The following test must be adjusted */
31/* for architectures other than x86 and x86-64 and in case the syscall numbers*/
32/* changed. */
33/* */
34/* Usage: <for command-line> */
35/* signalfd4_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: signalfd4_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 <signal.h>
55#include <stdio.h>
56#include <unistd.h>
57#include <sys/syscall.h>
subrata_modakc488f902009-02-23 07:17:33 +000058#include <errno.h>
subrata_modakfc49f1f2009-01-16 10:29:50 +000059
subrata_modakfc49f1f2009-01-16 10:29:50 +000060#include "test.h"
61#include "usctest.h"
subrata_modak115006c2009-02-04 06:16:40 +000062#include "linux_syscall_numbers.h"
Garrett Coopera9a04b52010-09-06 11:44:51 -070063#include "ltp_signal.h"
subrata_modakfc49f1f2009-01-16 10:29:50 +000064
65#define SFD_NONBLOCK O_NONBLOCK
66
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020067char *TCID = "signalfd4_02";
subrata_modak56207ce2009-03-23 13:35:39 +000068int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020069int TST_TOTAL = 1;
subrata_modakfc49f1f2009-01-16 10:29:50 +000070
71/* Extern Global Functions */
72/******************************************************************************/
73/* */
74/* Function: cleanup */
75/* */
76/* Description: Performs all one time clean up for this test on successful */
77/* completion, premature exit or failure. Closes all temporary */
78/* files, removes all temporary directories exits the test with */
79/* appropriate return code by calling tst_exit() function. */
80/* */
81/* Input: None. */
82/* */
83/* Output: None. */
84/* */
85/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
86/* On success - Exits calling tst_exit(). With '0' return code. */
87/* */
88/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040089void cleanup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000090{
Garrett Cooper2c282152010-12-16 00:55:50 -080091
subrata_modak56207ce2009-03-23 13:35:39 +000092 TEST_CLEANUP;
93 tst_rmdir();
subrata_modakfc49f1f2009-01-16 10:29:50 +000094
subrata_modakfc49f1f2009-01-16 10:29:50 +000095}
96
97/* Local Functions */
98/******************************************************************************/
99/* */
100/* Function: setup */
101/* */
102/* Description: Performs all one time setup for this test. This function is */
103/* typically used to capture signals, create temporary dirs */
104/* and temporary files that may be used in the course of this */
105/* test. */
106/* */
107/* Input: None. */
108/* */
109/* Output: None. */
110/* */
111/* Return: On failure - Exits by calling cleanup(). */
112/* On success - returns 0. */
113/* */
114/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400115void setup(void)
subrata_modak56207ce2009-03-23 13:35:39 +0000116{
117 /* Capture signals if any */
118 /* Create temporary directories */
119 TEST_PAUSE;
120 tst_tmpdir();
subrata_modakfc49f1f2009-01-16 10:29:50 +0000121}
122
subrata_modak56207ce2009-03-23 13:35:39 +0000123int main(int argc, char *argv[])
124{
125 sigset_t ss;
126 int fd, fl;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200127 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200128 const char *msg;
subrata_modakfc49f1f2009-01-16 10:29:50 +0000129
Garrett Cooper45e285d2010-11-22 12:19:25 -0800130 msg = parse_opts(argc, argv, NULL, NULL);
131 if (msg != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000132 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak56207ce2009-03-23 13:35:39 +0000133 }
134 if ((tst_kvercmp(2, 6, 27)) < 0) {
135 tst_resm(TCONF,
136 "This test can only run on kernels that are 2.6.27 and higher");
137 tst_exit();
138 }
139 setup();
subrata_modakfc49f1f2009-01-16 10:29:50 +0000140
subrata_modak56207ce2009-03-23 13:35:39 +0000141 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800142 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000143 for (testno = 0; testno < TST_TOTAL; ++testno) {
144 sigemptyset(&ss);
145 sigaddset(&ss, SIGUSR1);
Jan Stancek359980f2013-02-15 10:16:05 +0100146 fd = ltp_syscall(__NR_signalfd4, -1, &ss,
147 SIGSETSIZE, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000148 if (fd == -1) {
149 tst_resm(TFAIL, "signalfd4(0) failed");
150 cleanup();
151 tst_exit();
152 }
153 fl = fcntl(fd, F_GETFL);
154 if (fl == -1) {
155 tst_brkm(TBROK, cleanup, "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000156 }
157 if (fl & O_NONBLOCK) {
158 tst_resm(TFAIL,
159 "signalfd4(0) set non-blocking mode");
160 cleanup();
161 tst_exit();
162 }
163 close(fd);
164
Jan Stancek359980f2013-02-15 10:16:05 +0100165 fd = ltp_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 SFD_NONBLOCK);
subrata_modak56207ce2009-03-23 13:35:39 +0000167 if (fd == -1) {
168 tst_resm(TFAIL,
169 "signalfd4(SFD_NONBLOCK) failed");
170 cleanup();
171 tst_exit();
172 }
173 fl = fcntl(fd, F_GETFL);
174 if (fl == -1) {
175 tst_brkm(TBROK, cleanup, "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000176 }
177 if ((fl & O_NONBLOCK) == 0) {
178 tst_resm(TFAIL,
179 "signalfd4(SFD_NONBLOCK) does not set non-blocking mode");
180 cleanup();
181 tst_exit();
182 }
183 close(fd);
184 tst_resm(TPASS, "signalfd4(SFD_NONBLOCK) PASSED");
185 cleanup();
186 }
187 }
188 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700189}