blob: 8df55ba8da38010f00ed451911b322cc9a9bc6a0 [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
60/* Harness Specific Include Files. */
61#include "test.h"
62#include "usctest.h"
subrata_modak115006c2009-02-04 06:16:40 +000063#include "linux_syscall_numbers.h"
Garrett Coopera9a04b52010-09-06 11:44:51 -070064#include "ltp_signal.h"
subrata_modakfc49f1f2009-01-16 10:29:50 +000065
66#define SFD_NONBLOCK O_NONBLOCK
67
68/* Extern Global Variables */
subrata_modakfc49f1f2009-01-16 10:29:50 +000069
70/* Global Variables */
subrata_modak56207ce2009-03-23 13:35:39 +000071char *TCID = "signalfd4_02"; /* test program identifier. */
72int testno;
73int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modakfc49f1f2009-01-16 10:29:50 +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_modakfc49f1f2009-01-16 10:29:50 +000098
subrata_modakfc49f1f2009-01-16 10:29:50 +000099}
100
101/* Local Functions */
102/******************************************************************************/
103/* */
104/* Function: setup */
105/* */
106/* Description: Performs all one time setup for this test. This function is */
107/* typically used to capture signals, create temporary dirs */
108/* and temporary files that may be used in the course of this */
109/* test. */
110/* */
111/* Input: None. */
112/* */
113/* Output: None. */
114/* */
115/* Return: On failure - Exits by calling cleanup(). */
116/* On success - returns 0. */
117/* */
118/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000119void setup()
120{
121 /* Capture signals if any */
122 /* Create temporary directories */
123 TEST_PAUSE;
124 tst_tmpdir();
subrata_modakfc49f1f2009-01-16 10:29:50 +0000125}
126
subrata_modak56207ce2009-03-23 13:35:39 +0000127int main(int argc, char *argv[])
128{
129 sigset_t ss;
130 int fd, fl;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200131 int lc;
132 char *msg;
subrata_modakfc49f1f2009-01-16 10:29:50 +0000133
subrata_modak56207ce2009-03-23 13:35:39 +0000134 /* Parse standard options given to run the test. */
Garrett Cooper45e285d2010-11-22 12:19:25 -0800135 msg = parse_opts(argc, argv, NULL, NULL);
136 if (msg != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000137 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
138 tst_exit();
139 }
140 if ((tst_kvercmp(2, 6, 27)) < 0) {
141 tst_resm(TCONF,
142 "This test can only run on kernels that are 2.6.27 and higher");
143 tst_exit();
144 }
145 setup();
subrata_modakfc49f1f2009-01-16 10:29:50 +0000146
subrata_modak56207ce2009-03-23 13:35:39 +0000147 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800148 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000149 for (testno = 0; testno < TST_TOTAL; ++testno) {
150 sigemptyset(&ss);
151 sigaddset(&ss, SIGUSR1);
Jan Stancek359980f2013-02-15 10:16:05 +0100152 fd = ltp_syscall(__NR_signalfd4, -1, &ss,
153 SIGSETSIZE, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000154 if (fd == -1) {
155 tst_resm(TFAIL, "signalfd4(0) failed");
156 cleanup();
157 tst_exit();
158 }
159 fl = fcntl(fd, F_GETFL);
160 if (fl == -1) {
161 tst_brkm(TBROK, cleanup, "fcntl failed");
162 tst_exit();
163 }
164 if (fl & O_NONBLOCK) {
165 tst_resm(TFAIL,
166 "signalfd4(0) set non-blocking mode");
167 cleanup();
168 tst_exit();
169 }
170 close(fd);
171
Jan Stancek359980f2013-02-15 10:16:05 +0100172 fd = ltp_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800173 SFD_NONBLOCK);
subrata_modak56207ce2009-03-23 13:35:39 +0000174 if (fd == -1) {
175 tst_resm(TFAIL,
176 "signalfd4(SFD_NONBLOCK) failed");
177 cleanup();
178 tst_exit();
179 }
180 fl = fcntl(fd, F_GETFL);
181 if (fl == -1) {
182 tst_brkm(TBROK, cleanup, "fcntl failed");
183 tst_exit();
184 }
185 if ((fl & O_NONBLOCK) == 0) {
186 tst_resm(TFAIL,
187 "signalfd4(SFD_NONBLOCK) does not set non-blocking mode");
188 cleanup();
189 tst_exit();
190 }
191 close(fd);
192 tst_resm(TPASS, "signalfd4(SFD_NONBLOCK) PASSED");
193 cleanup();
194 }
195 }
196 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700197}