subrata_modak | e2a743e | 2009-01-16 10:26:41 +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 | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 19 | /* */ |
| 20 | /******************************************************************************/ |
| 21 | /******************************************************************************/ |
| 22 | /* */ |
| 23 | /* File: socketpair02.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=77d2720059618b9b6e827a8b73831eb6c6fad63c */ |
| 28 | /* */ |
| 29 | /* Usage: <for command-line> */ |
| 30 | /* socketpair02 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 31 | /* where, -c n : Run n copies concurrently. */ |
| 32 | /* -e : Turn on errno logging. */ |
| 33 | /* -i n : Execute test n times. */ |
| 34 | /* -I x : Execute test for x seconds. */ |
| 35 | /* -P x : Pause for x seconds between iterations. */ |
| 36 | /* -t : Turn on syscall timing. */ |
| 37 | /* */ |
| 38 | /* Total Tests: 1 */ |
| 39 | /* */ |
| 40 | /* Test Name: socketpair02 */ |
| 41 | /* */ |
| 42 | /* Author: Ulrich Drepper <drepper@redhat.com> */ |
| 43 | /* */ |
| 44 | /* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */ |
| 45 | /* Ported to LTP */ |
| 46 | /* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */ |
| 47 | /******************************************************************************/ |
| 48 | #include <fcntl.h> |
| 49 | #include <pthread.h> |
| 50 | #include <stdio.h> |
| 51 | #include <unistd.h> |
| 52 | #include <netinet/in.h> |
| 53 | #include <sys/socket.h> |
| 54 | #include <sys/syscall.h> |
| 55 | |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 56 | #include "test.h" |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 57 | |
subrata_modak | 8d4fee7 | 2009-01-27 14:48:38 +0000 | [diff] [blame] | 58 | #ifndef SOCK_NONBLOCK |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 59 | #define SOCK_NONBLOCK O_NONBLOCK |
subrata_modak | 8d4fee7 | 2009-01-27 14:48:38 +0000 | [diff] [blame] | 60 | #endif |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 61 | |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 62 | int TST_TOTAL = 2; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 63 | char *TCID = "socketpair02"; |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 64 | |
| 65 | /* Extern Global Functions */ |
| 66 | /******************************************************************************/ |
| 67 | /* */ |
| 68 | /* Function: cleanup */ |
| 69 | /* */ |
| 70 | /* Description: Performs all one time clean up for this test on successful */ |
| 71 | /* completion, premature exit or failure. Closes all temporary */ |
| 72 | /* files, removes all temporary directories exits the test with */ |
| 73 | /* appropriate return code by calling tst_exit() function. */ |
| 74 | /* */ |
| 75 | /* Input: None. */ |
| 76 | /* */ |
| 77 | /* Output: None. */ |
| 78 | /* */ |
| 79 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
| 80 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 81 | /* */ |
| 82 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 83 | void cleanup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 84 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 85 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | tst_rmdir(); |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* Local Functions */ |
| 90 | /******************************************************************************/ |
| 91 | /* */ |
| 92 | /* Function: setup */ |
| 93 | /* */ |
| 94 | /* Description: Performs all one time setup for this test. This function is */ |
| 95 | /* typically used to capture signals, create temporary dirs */ |
| 96 | /* and temporary files that may be used in the course of this */ |
| 97 | /* test. */ |
| 98 | /* */ |
| 99 | /* Input: None. */ |
| 100 | /* */ |
| 101 | /* Output: None. */ |
| 102 | /* */ |
| 103 | /* Return: On failure - Exits by calling cleanup(). */ |
| 104 | /* On success - returns 0. */ |
| 105 | /* */ |
| 106 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 107 | void setup(void) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 108 | { |
| 109 | /* Capture signals if any */ |
| 110 | /* Create temporary directories */ |
| 111 | TEST_PAUSE; |
| 112 | tst_tmpdir(); |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 113 | } |
| 114 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | int main(int argc, char *argv[]) |
| 116 | { |
| 117 | int fds[2], fl, i; |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 118 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | if ((tst_kvercmp(2, 6, 27)) < 0) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 120 | tst_brkm(TCONF, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | "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] | 122 | } |
| 123 | setup(); |
subrata_modak | e2a743e | 2009-01-16 10:26:41 +0000 | [diff] [blame] | 124 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 125 | if (socketpair(PF_UNIX, SOCK_STREAM, 0, fds) == -1) { |
| 126 | tst_brkm(TFAIL, cleanup, "socketpair(0) failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | } |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 128 | for (i = 0; i < (sizeof(fds) / sizeof(fds[0])); i++) { |
| 129 | fl = fcntl(fds[i], F_GETFL); |
| 130 | if (fl == -1) { |
| 131 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 132 | } |
| 133 | if (fl & O_NONBLOCK) { |
| 134 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 135 | "socketpair(0) set non-blocking mode for fds[%d]", |
| 136 | i); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 137 | } |
| 138 | close(fds[i]); |
| 139 | } |
| 140 | |
| 141 | if (socketpair(PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds) == -1) { |
| 142 | tst_brkm(TFAIL, cleanup, "socketpair(SOCK_NONBLOCK) failed"); |
| 143 | } |
| 144 | for (i = 0; i < (sizeof(fds) / sizeof(fds[0])); i++) { |
| 145 | fl = fcntl(fds[i], F_GETFL); |
| 146 | if (fl == -1) { |
| 147 | tst_brkm(TBROK, cleanup, "fcntl failed"); |
| 148 | } |
| 149 | if ((fl & O_NONBLOCK) == 0) { |
| 150 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 151 | "socketpair(SOCK_NONBLOCK) didn't set non-blocking " |
| 152 | "mode for fds[%d]", i); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 153 | } |
| 154 | close(fds[i]); |
| 155 | } |
| 156 | tst_resm(TPASS, "socketpair(SOCK_NONBLOCK) PASSED"); |
| 157 | cleanup(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | tst_exit(); |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 159 | } |