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> |
| 58 | |
| 59 | /* Harness Specific Include Files. */ |
| 60 | #include "test.h" |
| 61 | #include "usctest.h" |
subrata_modak | 115006c | 2009-02-04 06:16:40 +0000 | [diff] [blame] | 62 | #include "linux_syscall_numbers.h" |
subrata_modak | fc49f1f | 2009-01-16 10:29:50 +0000 | [diff] [blame] | 63 | |
| 64 | #define SFD_NONBLOCK O_NONBLOCK |
| 65 | |
| 66 | /* Extern Global Variables */ |
| 67 | extern int Tst_count; /* counter for tst_xxx routines. */ |
| 68 | extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */ |
| 69 | |
| 70 | /* Global Variables */ |
| 71 | char *TCID = "signalfd4_02"; /* test program identifier. */ |
| 72 | int testno; |
| 73 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
| 74 | |
| 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 | /******************************************************************************/ |
| 93 | extern void cleanup() { |
| 94 | /* Remove tmp dir and all files in it */ |
| 95 | TEST_CLEANUP; |
| 96 | tst_rmdir(); |
| 97 | |
| 98 | /* Exit with appropriate return code. */ |
| 99 | tst_exit(); |
| 100 | } |
| 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 | /******************************************************************************/ |
| 120 | void setup() { |
| 121 | /* Capture signals if any */ |
| 122 | /* Create temporary directories */ |
| 123 | TEST_PAUSE; |
| 124 | tst_tmpdir(); |
| 125 | } |
| 126 | |
| 127 | int main (int argc, char *argv[]) { |
| 128 | sigset_t ss; |
| 129 | int fd, fl; |
| 130 | int lc; /* loop counter */ |
| 131 | char *msg; /* message returned from parse_opts */ |
| 132 | |
| 133 | /* Parse standard options given to run the test. */ |
| 134 | msg = parse_opts(argc, argv, (option_t *) NULL, NULL); |
| 135 | if (msg != (char *) NULL) { |
| 136 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 137 | tst_exit(); |
| 138 | } |
| 139 | if((tst_kvercmp(2, 6, 27)) < 0) { |
| 140 | tst_resm(TCONF, "This test can only run on kernels that are 2.6.27 and higher"); |
| 141 | tst_exit(); |
| 142 | } |
| 143 | setup(); |
| 144 | |
| 145 | /* Check looping state if -i option given */ |
| 146 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 147 | Tst_count = 0; |
| 148 | for (testno=0; testno < TST_TOTAL; ++testno) { |
| 149 | sigemptyset (&ss); |
| 150 | sigaddset (&ss, SIGUSR1); |
| 151 | fd = syscall (__NR_signalfd4, -1, &ss, 8, 0); |
| 152 | if (fd == -1) { |
| 153 | tst_resm(TFAIL, "signalfd4(0) failed"); |
| 154 | cleanup(); |
| 155 | tst_exit(); |
| 156 | } |
| 157 | fl = fcntl (fd, F_GETFL); |
| 158 | if (fl == -1) { |
| 159 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 160 | tst_exit(); |
| 161 | } |
| 162 | if (fl & O_NONBLOCK) { |
| 163 | tst_resm(TFAIL, "signalfd4(0) set non-blocking mode"); |
| 164 | cleanup(); |
| 165 | tst_exit(); |
| 166 | } |
| 167 | close (fd); |
| 168 | |
| 169 | fd = syscall (__NR_signalfd4, -1, &ss, 8, SFD_NONBLOCK); |
| 170 | if (fd == -1) { |
| 171 | tst_resm(TFAIL, "signalfd4(SFD_NONBLOCK) failed"); |
| 172 | cleanup(); |
| 173 | tst_exit(); |
| 174 | } |
| 175 | fl = fcntl (fd, F_GETFL); |
| 176 | if (fl == -1) { |
| 177 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 178 | tst_exit(); |
| 179 | } |
| 180 | if ((fl & O_NONBLOCK) == 0) { |
| 181 | tst_resm(TFAIL, "signalfd4(SFD_NONBLOCK) does not set non-blocking mode"); |
| 182 | cleanup(); |
| 183 | tst_exit(); |
| 184 | } |
| 185 | close (fd); |
| 186 | tst_resm(TPASS, "signalfd4(SFD_NONBLOCK) PASSED"); |
| 187 | cleanup(); |
| 188 | } |
| 189 | } |
| 190 | tst_exit(); |
| 191 | } |