blob: ddf8b8c3d41a5dbad69b1ebb9d7ec14948eb9f06 [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"
Richard Palethorpe817d8092017-07-24 14:48:25 +020061#include "lapi/syscalls.h"
Garrett Coopera9a04b52010-09-06 11:44:51 -070062#include "ltp_signal.h"
subrata_modakfc49f1f2009-01-16 10:29:50 +000063
64#define SFD_NONBLOCK O_NONBLOCK
65
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020066char *TCID = "signalfd4_02";
subrata_modak56207ce2009-03-23 13:35:39 +000067int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020068int TST_TOTAL = 1;
subrata_modakfc49f1f2009-01-16 10:29:50 +000069
70/* Extern Global Functions */
71/******************************************************************************/
72/* */
73/* Function: cleanup */
74/* */
75/* Description: Performs all one time clean up for this test on successful */
76/* completion, premature exit or failure. Closes all temporary */
77/* files, removes all temporary directories exits the test with */
78/* appropriate return code by calling tst_exit() function. */
79/* */
80/* Input: None. */
81/* */
82/* Output: None. */
83/* */
84/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
85/* On success - Exits calling tst_exit(). With '0' return code. */
86/* */
87/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040088void cleanup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000089{
Garrett Cooper2c282152010-12-16 00:55:50 -080090
subrata_modak56207ce2009-03-23 13:35:39 +000091 tst_rmdir();
subrata_modakfc49f1f2009-01-16 10:29:50 +000092
subrata_modakfc49f1f2009-01-16 10:29:50 +000093}
94
95/* Local Functions */
96/******************************************************************************/
97/* */
98/* Function: setup */
99/* */
100/* Description: Performs all one time setup for this test. This function is */
101/* typically used to capture signals, create temporary dirs */
102/* and temporary files that may be used in the course of this */
103/* test. */
104/* */
105/* Input: None. */
106/* */
107/* Output: None. */
108/* */
109/* Return: On failure - Exits by calling cleanup(). */
110/* On success - returns 0. */
111/* */
112/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400113void setup(void)
subrata_modak56207ce2009-03-23 13:35:39 +0000114{
115 /* Capture signals if any */
116 /* Create temporary directories */
117 TEST_PAUSE;
118 tst_tmpdir();
subrata_modakfc49f1f2009-01-16 10:29:50 +0000119}
120
subrata_modak56207ce2009-03-23 13:35:39 +0000121int main(int argc, char *argv[])
122{
123 sigset_t ss;
124 int fd, fl;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200125 int lc;
subrata_modakfc49f1f2009-01-16 10:29:50 +0000126
Cyril Hrubisd6d11d02015-03-09 17:35:43 +0100127 tst_parse_opts(argc, argv, NULL, NULL);
subrata_modak56207ce2009-03-23 13:35:39 +0000128 if ((tst_kvercmp(2, 6, 27)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100129 tst_brkm(TCONF,
130 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000131 "This test can only run on kernels that are 2.6.27 and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000132 }
133 setup();
subrata_modakfc49f1f2009-01-16 10:29:50 +0000134
subrata_modak56207ce2009-03-23 13:35:39 +0000135 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800136 tst_count = 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000137 for (testno = 0; testno < TST_TOTAL; ++testno) {
138 sigemptyset(&ss);
139 sigaddset(&ss, SIGUSR1);
Jan Stancek359980f2013-02-15 10:16:05 +0100140 fd = ltp_syscall(__NR_signalfd4, -1, &ss,
141 SIGSETSIZE, 0);
subrata_modak56207ce2009-03-23 13:35:39 +0000142 if (fd == -1) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100143 tst_brkm(TFAIL, cleanup,
144 "signalfd4(0) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000145 }
146 fl = fcntl(fd, F_GETFL);
147 if (fl == -1) {
148 tst_brkm(TBROK, cleanup, "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000149 }
150 if (fl & O_NONBLOCK) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100151 tst_brkm(TFAIL,
152 cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000153 "signalfd4(0) set non-blocking mode");
subrata_modak56207ce2009-03-23 13:35:39 +0000154 }
155 close(fd);
156
Jan Stancek359980f2013-02-15 10:16:05 +0100157 fd = ltp_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158 SFD_NONBLOCK);
subrata_modak56207ce2009-03-23 13:35:39 +0000159 if (fd == -1) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100160 tst_brkm(TFAIL,
161 cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000162 "signalfd4(SFD_NONBLOCK) failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000163 }
164 fl = fcntl(fd, F_GETFL);
165 if (fl == -1) {
166 tst_brkm(TBROK, cleanup, "fcntl failed");
subrata_modak56207ce2009-03-23 13:35:39 +0000167 }
168 if ((fl & O_NONBLOCK) == 0) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100169 tst_brkm(TFAIL,
170 cleanup,
subrata_modak56207ce2009-03-23 13:35:39 +0000171 "signalfd4(SFD_NONBLOCK) does not set non-blocking mode");
subrata_modak56207ce2009-03-23 13:35:39 +0000172 }
173 close(fd);
174 tst_resm(TPASS, "signalfd4(SFD_NONBLOCK) PASSED");
175 cleanup();
176 }
177 }
178 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700179}