subrata_modak | 5000375 | 2009-01-16 10:14:35 +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 | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
subrata_modak | fc40315 | 2009-02-05 10:54:19 +0000 | [diff] [blame] | 23 | /* File: epoll_create1_01.c */ |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 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=a0998b50c3f0b8fdd265c63e0032f86ebe377dbf */ |
| 28 | /* says: */ |
subrata_modak | fc40315 | 2009-02-05 10:54:19 +0000 | [diff] [blame] | 29 | /* This patch adds the new epoll_create1 syscall. It extends the old */ |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 30 | /* epoll_create syscall by one parameter which is meant to hold a flag value. */ |
| 31 | /* In this patch the only flag support is EPOLL_CLOEXEC which causes the */ |
| 32 | /* close-on-exec flag for the returned file descriptor to be set. A new name */ |
| 33 | /* EPOLL_CLOEXEC is introduced which in this implementation must have the same*/ |
| 34 | /* value as O_CLOEXEC. The following test must be adjusted for architectures */ |
| 35 | /* other than x86 and x86-64 and in case the syscall numbers changed. */ |
| 36 | /* */ |
| 37 | /* Usage: <for command-line> */ |
subrata_modak | fc40315 | 2009-02-05 10:54:19 +0000 | [diff] [blame] | 38 | /* epoll_create1_01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 39 | /* where, -c n : Run n copies concurrently. */ |
| 40 | /* -e : Turn on errno logging. */ |
| 41 | /* -i n : Execute test n times. */ |
| 42 | /* -I x : Execute test for x seconds. */ |
| 43 | /* -P x : Pause for x seconds between iterations. */ |
| 44 | /* -t : Turn on syscall timing. */ |
| 45 | /* */ |
| 46 | /* Total Tests: 1 */ |
| 47 | /* */ |
subrata_modak | fc40315 | 2009-02-05 10:54:19 +0000 | [diff] [blame] | 48 | /* Test Name: epoll_create1_01 */ |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 49 | /* */ |
| 50 | /* Author: Ulrich Drepper <drepper@redhat.com> */ |
| 51 | /* */ |
| 52 | /* History: Created - Jan 12 2009 - Ulrich Drepper <drepper@redhat.com> */ |
| 53 | /* Ported to LTP */ |
| 54 | /* - Jan 12 2009 - Subrata <subrata@linux.vnet.ibm.com> */ |
| 55 | /******************************************************************************/ |
| 56 | #include <fcntl.h> |
| 57 | #include <stdio.h> |
| 58 | #include <time.h> |
| 59 | #include <unistd.h> |
| 60 | #include <sys/syscall.h> |
subrata_modak | c488f90 | 2009-02-23 07:17:33 +0000 | [diff] [blame] | 61 | #include <errno.h> |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 62 | |
| 63 | /* Harness Specific Include Files. */ |
| 64 | #include "test.h" |
| 65 | #include "usctest.h" |
subrata_modak | 115006c | 2009-02-04 06:16:40 +0000 | [diff] [blame] | 66 | #include "linux_syscall_numbers.h" |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 67 | |
| 68 | #ifndef O_CLOEXEC |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 69 | #define O_CLOEXEC 02000000 |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #define EPOLL_CLOEXEC O_CLOEXEC |
| 73 | |
| 74 | /* Extern Global Variables */ |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 75 | |
| 76 | /* Global Variables */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | char *TCID = "epoll_create1_01"; /* test program identifier. */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 79 | |
| 80 | /* Extern Global Functions */ |
| 81 | /******************************************************************************/ |
| 82 | /* */ |
| 83 | /* Function: cleanup */ |
| 84 | /* */ |
| 85 | /* Description: Performs all one time clean up for this test on successful */ |
| 86 | /* completion, premature exit or failure. Closes all temporary */ |
| 87 | /* files, removes all temporary directories exits the test with */ |
| 88 | /* appropriate return code by calling tst_exit() function. */ |
| 89 | /* */ |
| 90 | /* Input: None. */ |
| 91 | /* */ |
| 92 | /* Output: None. */ |
| 93 | /* */ |
| 94 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 95 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 96 | /* */ |
| 97 | /******************************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | extern void cleanup() |
| 99 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 100 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | TEST_CLEANUP; |
| 102 | tst_rmdir(); |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +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 | 5000375 | 2009-01-16 10:14:35 +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 | int fd, coe; |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 134 | |
Garrett Cooper | 8dca422 | 2010-12-18 03:57:35 -0800 | [diff] [blame] | 135 | if ((tst_kvercmp(2, 6, 27)) < 0) |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 136 | tst_brkm(TCONF, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | "This test can only run on kernels that are 2.6.27 and " |
| 138 | "higher"); |
Garrett Cooper | 8dca422 | 2010-12-18 03:57:35 -0800 | [diff] [blame] | 139 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 140 | setup(); |
subrata_modak | 5000375 | 2009-01-16 10:14:35 +0000 | [diff] [blame] | 141 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 142 | fd = ltp_syscall(__NR_epoll_create1, 0); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 143 | if (fd == -1) { |
| 144 | tst_brkm(TFAIL, cleanup, "epoll_create1(0) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | } |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 146 | coe = fcntl(fd, F_GETFD); |
| 147 | if (coe == -1) { |
| 148 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 149 | } |
| 150 | if (coe & FD_CLOEXEC) { |
| 151 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 152 | "epoll_create1(0) set close-on-exec flag"); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 153 | } |
| 154 | close(fd); |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 155 | fd = ltp_syscall(__NR_epoll_create1, EPOLL_CLOEXEC); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 156 | if (fd == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 157 | tst_brkm(TFAIL, cleanup, "epoll_create1(EPOLL_CLOEXEC) failed"); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 158 | } |
| 159 | coe = fcntl(fd, F_GETFD); |
| 160 | if (coe == -1) { |
| 161 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 162 | } |
| 163 | if ((coe & FD_CLOEXEC) == 0) { |
| 164 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 165 | "epoll_create1(EPOLL_CLOEXEC) set close-on-exec flag"); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 166 | } |
| 167 | close(fd); |
| 168 | tst_resm(TPASS, "epoll_create1(EPOLL_CLOEXEC) PASSED"); |
| 169 | |
| 170 | cleanup(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 172 | } |