subrata_modak | 974ca6d | 2009-01-16 10:34:52 +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 | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: pipe2_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=be61a86d7237dd80510615f38ae21d6e1e98660c */ |
| 28 | /* which says: */ |
| 29 | /* This patch adds O_NONBLOCK support to pipe2. It is minimally more involved*/ |
| 30 | /* than the patches for eventfd et.al but still trivial. The interfaces of */ |
| 31 | /* the create_write_pipe and create_read_pipe helper functions were changed */ |
| 32 | /* and the one other caller as well. */ |
| 33 | /* The following test must be adjusted for architectures other than x86 and */ |
| 34 | /* x86-64 and in case the syscall numbers changed. */ |
| 35 | /* */ |
| 36 | /* Usage: <for command-line> */ |
| 37 | /* pipe2_02 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 38 | /* where, -c n : Run n copies concurrently. */ |
| 39 | /* -e : Turn on errno logging. */ |
| 40 | /* -i n : Execute test n times. */ |
| 41 | /* -I x : Execute test for x seconds. */ |
| 42 | /* -P x : Pause for x seconds between iterations. */ |
| 43 | /* -t : Turn on syscall timing. */ |
| 44 | /* */ |
| 45 | /* Total Tests: 1 */ |
| 46 | /* */ |
| 47 | /* Test Name: pipe2_02 */ |
| 48 | /* */ |
| 49 | /* Author: Ulrich Drepper <drepper@redhat.com> */ |
| 50 | /* */ |
| 51 | /* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */ |
| 52 | /* Ported to LTP */ |
| 53 | /* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */ |
| 54 | /******************************************************************************/ |
| 55 | #include <fcntl.h> |
| 56 | #include <stdio.h> |
| 57 | #include <unistd.h> |
| 58 | #include <sys/syscall.h> |
subrata_modak | c488f90 | 2009-02-23 07:17:33 +0000 | [diff] [blame] | 59 | #include <errno.h> |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 60 | |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 61 | #include "test.h" |
Cyril Hrubis | 98f8747 | 2014-01-08 13:32:41 +0100 | [diff] [blame] | 62 | #include "lapi/fcntl.h" |
subrata_modak | 115006c | 2009-02-04 06:16:40 +0000 | [diff] [blame] | 63 | #include "linux_syscall_numbers.h" |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 64 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 65 | char *TCID = "pipe2_02"; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 66 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 67 | int TST_TOTAL = 1; |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 68 | |
| 69 | /* Extern Global Functions */ |
| 70 | /******************************************************************************/ |
| 71 | /* */ |
| 72 | /* Function: cleanup */ |
| 73 | /* */ |
| 74 | /* Description: Performs all one time clean up for this test on successful */ |
| 75 | /* completion, premature exit or failure. Closes all temporary */ |
| 76 | /* files, removes all temporary directories exits the test with */ |
| 77 | /* appropriate return code by calling tst_exit() function. */ |
| 78 | /* */ |
| 79 | /* Input: None. */ |
| 80 | /* */ |
| 81 | /* Output: None. */ |
| 82 | /* */ |
| 83 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 84 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 85 | /* */ |
| 86 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 87 | void cleanup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | tst_rmdir(); |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 91 | |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* Local Functions */ |
| 95 | /******************************************************************************/ |
| 96 | /* */ |
| 97 | /* Function: setup */ |
| 98 | /* */ |
| 99 | /* Description: Performs all one time setup for this test. This function is */ |
| 100 | /* typically used to capture signals, create temporary dirs */ |
| 101 | /* and temporary files that may be used in the course of this */ |
| 102 | /* test. */ |
| 103 | /* */ |
| 104 | /* Input: None. */ |
| 105 | /* */ |
| 106 | /* Output: None. */ |
| 107 | /* */ |
| 108 | /* Return: On failure - Exits by calling cleanup(). */ |
| 109 | /* On success - returns 0. */ |
| 110 | /* */ |
| 111 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 112 | void setup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | { |
| 114 | /* Capture signals if any */ |
| 115 | /* Create temporary directories */ |
| 116 | TEST_PAUSE; |
| 117 | tst_tmpdir(); |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 118 | } |
| 119 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | int main(int argc, char *argv[]) |
| 121 | { |
| 122 | int fds[2], fl, i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 123 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 124 | const char *msg; |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 125 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 126 | msg = parse_opts(argc, argv, NULL, NULL); |
| 127 | if (msg != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 128 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | } |
| 130 | if ((tst_kvercmp(2, 6, 27)) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 131 | tst_brkm(TCONF, |
| 132 | NULL, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 133 | "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] | 134 | } |
| 135 | setup(); |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 136 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 137 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 138 | tst_count = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 140 | if (ltp_syscall(__NR_pipe2, fds, 0) == -1) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame] | 141 | tst_brkm(TFAIL, cleanup, "pipe2(0) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | } |
| 143 | for (i = 0; i < 2; ++i) { |
| 144 | fl = fcntl(fds[i], F_GETFL); |
| 145 | if (fl == -1) { |
| 146 | tst_brkm(TBROK, cleanup, |
| 147 | "fcntl failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | } |
| 149 | if (fl & O_NONBLOCK) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame] | 150 | tst_brkm(TFAIL, |
| 151 | cleanup, "pipe2(0) set non-blocking mode for fds[%d]", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 152 | i); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 153 | } |
| 154 | close(fds[i]); |
| 155 | } |
subrata_modak | 974ca6d | 2009-01-16 10:34:52 +0000 | [diff] [blame] | 156 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 157 | if (ltp_syscall(__NR_pipe2, fds, O_NONBLOCK) == -1) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame] | 158 | tst_brkm(TFAIL, cleanup, |
| 159 | "pipe2(O_NONBLOCK) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 160 | } |
| 161 | for (i = 0; i < 2; ++i) { |
| 162 | fl = fcntl(fds[i], F_GETFL); |
| 163 | if (fl == -1) { |
| 164 | tst_brkm(TBROK, cleanup, |
| 165 | "fcntl failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 166 | } |
| 167 | if ((fl & O_NONBLOCK) == 0) { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame] | 168 | tst_brkm(TFAIL, |
| 169 | cleanup, "pipe2(O_NONBLOCK) does not set non-blocking mode for fds[%d]\n", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 170 | i); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | } |
| 172 | close(fds[i]); |
| 173 | } |
| 174 | tst_resm(TPASS, "pipe2(O_NONBLOCK) PASSED"); |
| 175 | cleanup(); |
| 176 | } |
| 177 | } |
| 178 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 179 | } |