subrata_modak | a9ba214 | 2009-01-16 10:33:26 +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 */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: timerfd03.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=6b1ef0e60d42f2fdaec26baee8327eb156347b4f */ |
| 28 | /* which says: */ |
| 29 | /* This patch adds support for the TFD_NONBLOCK flag to timerfd_create. 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 | /* timerfd03 [-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: timerfd03 */ |
| 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 <stdio.h> |
| 55 | #include <time.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 | a9ba214 | 2009-01-16 10:33:26 +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" |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 64 | |
| 65 | #ifndef O_CLOEXEC |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 66 | #define O_CLOEXEC 02000000 |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 69 | #define TFD_NONBLOCK O_NONBLOCK |
| 70 | |
| 71 | /* Extern Global Variables */ |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 72 | |
| 73 | /* Global Variables */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | char *TCID = "timerfd03"; /* test program identifier. */ |
| 75 | int testno; |
| 76 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 77 | |
| 78 | /* Extern Global Functions */ |
| 79 | /******************************************************************************/ |
| 80 | /* */ |
| 81 | /* Function: cleanup */ |
| 82 | /* */ |
| 83 | /* Description: Performs all one time clean up for this test on successful */ |
| 84 | /* completion, premature exit or failure. Closes all temporary */ |
| 85 | /* files, removes all temporary directories exits the test with */ |
| 86 | /* appropriate return code by calling tst_exit() function. */ |
| 87 | /* */ |
| 88 | /* Input: None. */ |
| 89 | /* */ |
| 90 | /* Output: None. */ |
| 91 | /* */ |
| 92 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 93 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 94 | /* */ |
| 95 | /******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | extern void cleanup() |
| 97 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 98 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 99 | TEST_CLEANUP; |
| 100 | tst_rmdir(); |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 101 | |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /* Local Functions */ |
| 105 | /******************************************************************************/ |
| 106 | /* */ |
| 107 | /* Function: setup */ |
| 108 | /* */ |
| 109 | /* Description: Performs all one time setup for this test. This function is */ |
| 110 | /* typically used to capture signals, create temporary dirs */ |
| 111 | /* and temporary files that may be used in the course of this */ |
| 112 | /* test. */ |
| 113 | /* */ |
| 114 | /* Input: None. */ |
| 115 | /* */ |
| 116 | /* Output: None. */ |
| 117 | /* */ |
| 118 | /* Return: On failure - Exits by calling cleanup(). */ |
| 119 | /* On success - returns 0. */ |
| 120 | /* */ |
| 121 | /******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 122 | void setup() |
| 123 | { |
| 124 | /* Capture signals if any */ |
| 125 | /* Create temporary directories */ |
| 126 | TEST_PAUSE; |
| 127 | tst_tmpdir(); |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 128 | } |
| 129 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | int main(int argc, char *argv[]) |
| 131 | { |
| 132 | int fd, fl; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 133 | int lc; |
| 134 | char *msg; |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 135 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | /* Parse standard options given to run the test. */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 137 | msg = parse_opts(argc, argv, NULL, NULL); |
| 138 | if (msg != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 140 | tst_exit(); |
| 141 | } |
| 142 | if ((tst_kvercmp(2, 6, 27)) < 0) { |
| 143 | tst_resm(TCONF, |
| 144 | "This test can only run on kernels that are 2.6.27 and higher"); |
| 145 | tst_exit(); |
| 146 | } |
| 147 | setup(); |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 148 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 150 | Tst_count = 0; |
| 151 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 152 | fd = ltp_syscall(__NR_timerfd_create, |
| 153 | CLOCK_REALTIME, 0); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 154 | if (fd == -1) { |
| 155 | tst_resm(TFAIL, "timerfd_create(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 | "timerfd_create(0) set non-blocking mode"); |
| 167 | cleanup(); |
| 168 | tst_exit(); |
| 169 | } |
| 170 | close(fd); |
subrata_modak | a9ba214 | 2009-01-16 10:33:26 +0000 | [diff] [blame] | 171 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 172 | fd = ltp_syscall(__NR_timerfd_create, CLOCK_REALTIME, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 173 | TFD_NONBLOCK); |
| 174 | if (fd == -1) { |
| 175 | tst_resm(TFAIL, |
| 176 | "timerfd_create(TFD_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 | "timerfd_create(TFD_NONBLOCK) set non-blocking mode"); |
| 188 | cleanup(); |
| 189 | tst_exit(); |
| 190 | } |
| 191 | close(fd); |
| 192 | tst_resm(TPASS, "timerfd_create(TFD_NONBLOCK) PASSED"); |
| 193 | cleanup(); |
| 194 | } |
| 195 | } |
| 196 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 197 | } |