subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 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 */ |
| 18 | /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 19 | /* */ |
| 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_modak | c488f90 | 2009-02-23 07:17:33 +0000 | [diff] [blame] | 58 | #include <errno.h> |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 59 | |
| 60 | /* Harness Specific Include Files. */ |
| 61 | #include "test.h" |
| 62 | #include "usctest.h" |
subrata_modak | 115006c | 2009-02-04 06:16:40 +0000 | [diff] [blame] | 63 | #include "linux_syscall_numbers.h" |
Garrett Cooper | a9a04b5 | 2010-09-06 11:44:51 -0700 | [diff] [blame] | 64 | #include "ltp_signal.h" |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 65 | |
| 66 | #define SFD_NONBLOCK O_NONBLOCK |
| 67 | |
| 68 | /* Extern Global Variables */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 69 | extern int Tst_count; /* counter for tst_xxx routines. */ |
| 70 | extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */ |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 71 | |
| 72 | /* Global Variables */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | char *TCID = "signalfd4_02"; /* test program identifier. */ |
| 74 | int testno; |
| 75 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 76 | |
| 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 95 | extern void cleanup() |
| 96 | { |
| 97 | /* Remove tmp dir and all files in it */ |
| 98 | TEST_CLEANUP; |
| 99 | tst_rmdir(); |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 100 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | /* Exit with appropriate return code. */ |
| 102 | tst_exit(); |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* Local Functions */ |
| 106 | /******************************************************************************/ |
| 107 | /* */ |
| 108 | /* Function: setup */ |
| 109 | /* */ |
| 110 | /* Description: Performs all one time setup for this test. This function is */ |
| 111 | /* typically used to capture signals, create temporary dirs */ |
| 112 | /* and temporary files that may be used in the course of this */ |
| 113 | /* test. */ |
| 114 | /* */ |
| 115 | /* Input: None. */ |
| 116 | /* */ |
| 117 | /* Output: None. */ |
| 118 | /* */ |
| 119 | /* Return: On failure - Exits by calling cleanup(). */ |
| 120 | /* On success - returns 0. */ |
| 121 | /* */ |
| 122 | /******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | void setup() |
| 124 | { |
| 125 | /* Capture signals if any */ |
| 126 | /* Create temporary directories */ |
| 127 | TEST_PAUSE; |
| 128 | tst_tmpdir(); |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 129 | } |
| 130 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | int main(int argc, char *argv[]) |
| 132 | { |
| 133 | sigset_t ss; |
| 134 | int fd, fl; |
| 135 | int lc; /* loop counter */ |
| 136 | char *msg; /* message returned from parse_opts */ |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 137 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | /* Parse standard options given to run the test. */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame^] | 139 | msg = parse_opts(argc, argv, NULL, NULL); |
| 140 | if (msg != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 141 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 142 | tst_exit(); |
| 143 | } |
| 144 | if ((tst_kvercmp(2, 6, 27)) < 0) { |
| 145 | tst_resm(TCONF, |
| 146 | "This test can only run on kernels that are 2.6.27 and higher"); |
| 147 | tst_exit(); |
| 148 | } |
| 149 | setup(); |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 150 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | /* Check looping state if -i option given */ |
| 152 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 153 | Tst_count = 0; |
| 154 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
| 155 | sigemptyset(&ss); |
| 156 | sigaddset(&ss, SIGUSR1); |
Garrett Cooper | a9a04b5 | 2010-09-06 11:44:51 -0700 | [diff] [blame] | 157 | fd = syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE, 0); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | if (fd == -1) { |
| 159 | tst_resm(TFAIL, "signalfd4(0) failed"); |
| 160 | cleanup(); |
| 161 | tst_exit(); |
| 162 | } |
| 163 | fl = fcntl(fd, F_GETFL); |
| 164 | if (fl == -1) { |
| 165 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 166 | tst_exit(); |
| 167 | } |
| 168 | if (fl & O_NONBLOCK) { |
| 169 | tst_resm(TFAIL, |
| 170 | "signalfd4(0) set non-blocking mode"); |
| 171 | cleanup(); |
| 172 | tst_exit(); |
| 173 | } |
| 174 | close(fd); |
| 175 | |
Garrett Cooper | a9a04b5 | 2010-09-06 11:44:51 -0700 | [diff] [blame] | 176 | fd = syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE, SFD_NONBLOCK); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | if (fd == -1) { |
| 178 | tst_resm(TFAIL, |
| 179 | "signalfd4(SFD_NONBLOCK) failed"); |
| 180 | cleanup(); |
| 181 | tst_exit(); |
| 182 | } |
| 183 | fl = fcntl(fd, F_GETFL); |
| 184 | if (fl == -1) { |
| 185 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 186 | tst_exit(); |
| 187 | } |
| 188 | if ((fl & O_NONBLOCK) == 0) { |
| 189 | tst_resm(TFAIL, |
| 190 | "signalfd4(SFD_NONBLOCK) does not set non-blocking mode"); |
| 191 | cleanup(); |
| 192 | tst_exit(); |
| 193 | } |
| 194 | close(fd); |
| 195 | tst_resm(TPASS, "signalfd4(SFD_NONBLOCK) PASSED"); |
| 196 | cleanup(); |
| 197 | } |
| 198 | } |
| 199 | tst_exit(); |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 200 | } |