subrata_modak | 768a081 | 2009-01-16 10:18:58 +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 | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: pipe2_01.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=ed8cae8ba01348bfd83333f4648dd807b04d7f08 */ |
| 28 | /* says: */ |
| 29 | /* This patch introduces the new syscall pipe2 which is like pipe but it also */ |
| 30 | /* takes an additional parameter which takes a flag value. This patch */ |
| 31 | /* implements the handling of O_CLOEXEC for the flag. I did not add support */ |
| 32 | /* for the new syscall for the architectures which have a special sys_pipe */ |
| 33 | /* implementation. I think the maintainers of those archs have the chance to */ |
| 34 | /* go with the unified implementation but that's up to them. */ |
| 35 | /* */ |
| 36 | /* The implementation introduces do_pipe_flags. I did that instead of */ |
| 37 | /* changing all callers of do_pipe because some of the callers are written in */ |
| 38 | /* assembler. I would probably screw up changing the assembly code. To avoid */ |
| 39 | /* breaking code do_pipe is now a small wrapper around do_pipe_flags. Once */ |
| 40 | /* all callers are changed over to do_pipe_flags the old do_pipe function can */ |
| 41 | /* be removed. */ |
| 42 | /* The following test must be adjusted for architectures other than x86 and */ |
| 43 | /* x86-64 and in case the syscall numbers changed. */ |
| 44 | /* */ |
| 45 | /* Usage: <for command-line> */ |
| 46 | /* pipe2_01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 47 | /* where, -c n : Run n copies concurrently. */ |
| 48 | /* -e : Turn on errno logging. */ |
| 49 | /* -i n : Execute test n times. */ |
| 50 | /* -I x : Execute test for x seconds. */ |
| 51 | /* -P x : Pause for x seconds between iterations. */ |
| 52 | /* -t : Turn on syscall timing. */ |
| 53 | /* */ |
| 54 | /* Total Tests: 1 */ |
| 55 | /* */ |
| 56 | /* Test Name: pipe2_01 */ |
| 57 | /* */ |
| 58 | /* Author: Ulrich Drepper <drepper@redhat.com> */ |
| 59 | /* */ |
| 60 | /* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */ |
| 61 | /* Ported to LTP */ |
| 62 | /* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */ |
| 63 | /******************************************************************************/ |
| 64 | #include <fcntl.h> |
| 65 | #include <stdio.h> |
| 66 | #include <unistd.h> |
| 67 | #include <sys/syscall.h> |
subrata_modak | c488f90 | 2009-02-23 07:17:33 +0000 | [diff] [blame] | 68 | #include <errno.h> |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 69 | |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 70 | #include "test.h" |
| 71 | #include "usctest.h" |
Cyril Hrubis | 98f8747 | 2014-01-08 13:32:41 +0100 | [diff] [blame] | 72 | #include "lapi/fcntl.h" |
subrata_modak | 115006c | 2009-02-04 06:16:40 +0000 | [diff] [blame] | 73 | #include "linux_syscall_numbers.h" |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 74 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 75 | char *TCID = "pipe2_01"; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 77 | int TST_TOTAL = 1; |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 78 | |
| 79 | /* Extern Global Functions */ |
| 80 | /******************************************************************************/ |
| 81 | /* */ |
| 82 | /* Function: cleanup */ |
| 83 | /* */ |
| 84 | /* Description: Performs all one time clean up for this test on successful */ |
| 85 | /* completion, premature exit or failure. Closes all temporary */ |
| 86 | /* files, removes all temporary directories exits the test with */ |
| 87 | /* appropriate return code by calling tst_exit() function. */ |
| 88 | /* */ |
| 89 | /* Input: None. */ |
| 90 | /* */ |
| 91 | /* Output: None. */ |
| 92 | /* */ |
| 93 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 94 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 95 | /* */ |
| 96 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 97 | void cleanup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 99 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | TEST_CLEANUP; |
| 101 | tst_rmdir(); |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 102 | |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +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 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 123 | void setup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 124 | { |
| 125 | /* Capture signals if any */ |
| 126 | /* Create temporary directories */ |
| 127 | TEST_PAUSE; |
| 128 | tst_tmpdir(); |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +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[2], i, coe; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 134 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 135 | const char *msg; |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 136 | |
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); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 140 | } |
| 141 | if ((tst_kvercmp(2, 6, 27)) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 142 | tst_brkm(TCONF, |
| 143 | NULL, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | "This test can only run on kernels that are 2.6.27 and higher"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | } |
| 146 | setup(); |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 147 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 149 | tst_count = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 150 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 151 | if (ltp_syscall(__NR_pipe2, fd, 0) != 0) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame^] | 152 | tst_brkm(TFAIL, cleanup, "pipe2(0) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 153 | } |
| 154 | for (i = 0; i < 2; ++i) { |
| 155 | coe = fcntl(fd[i], F_GETFD); |
| 156 | if (coe == -1) { |
| 157 | tst_brkm(TBROK, cleanup, |
| 158 | "fcntl failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 159 | } |
| 160 | if (coe & FD_CLOEXEC) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame^] | 161 | tst_brkm(TFAIL, |
| 162 | cleanup, "pipe2(0) set close-on-exit for fd[%d]", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 163 | i); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | close(fd[0]); |
| 167 | close(fd[1]); |
subrata_modak | 768a081 | 2009-01-16 10:18:58 +0000 | [diff] [blame] | 168 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 169 | if (ltp_syscall(__NR_pipe2, fd, O_CLOEXEC) != 0) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame^] | 170 | tst_brkm(TFAIL, cleanup, |
| 171 | "pipe2(O_CLOEXEC) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | } |
| 173 | for (i = 0; i < 2; ++i) { |
| 174 | coe = fcntl(fd[i], F_GETFD); |
| 175 | if (coe == -1) { |
| 176 | tst_brkm(TBROK, cleanup, |
| 177 | "fcntl failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 178 | } |
| 179 | if ((coe & FD_CLOEXEC) == 0) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame^] | 180 | tst_brkm(TFAIL, |
| 181 | cleanup, "pipe2(O_CLOEXEC) does not set close-on-exit for fd[%d]", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 182 | i); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | close(fd[0]); |
| 186 | close(fd[1]); |
| 187 | tst_resm(TPASS, "pipe2(O_CLOEXEC) PASSED"); |
| 188 | cleanup(); |
| 189 | } |
| 190 | } |
| 191 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 192 | } |