robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : socketcall03 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 21 | * EXECUTED BY : All user |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for socketcall(2) for bind(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 27 | * AUTHOR : sowmya adiga<sowmya.adiga@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 29 | * SIGNALS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 30 | * Uses SIGUSR1 to pause before test if option set. |
| 31 | * (See the parse_opts(3) man page). |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 32 | * |
| 33 | * DESCRIPTION |
| 34 | * This is a phase I test for the socketcall(2) system call. |
| 35 | * It is intended to provide a limited exposure of the system call. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 36 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 37 | * Setup: |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 38 | * Setup signal handling. |
| 39 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 40 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 41 | * Test: |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 42 | * Execute system call |
| 43 | * Check return code, if system call failed (return=-1) |
| 44 | * Log the errno and Issue a FAIL message. |
| 45 | * Otherwise, Issue a PASS message. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 46 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 47 | * Cleanup: |
| 48 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 50 | * USAGE: <for command-line> |
| 51 | * socketcall03 [-c n] [-e] [-i n] [-I x] [-p x] [-t] |
| 52 | * where, -c n : Run n copies concurrently |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 53 | * -e : Turn on errno logging. |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 54 | * -h : Show this help screen |
| 55 | * -i n : Execute test n times. |
| 56 | * -I x : Execute test for x seconds. |
| 57 | * -p : Pause for SIGUSR1 before starting |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 58 | * -P x : Pause for x seconds between iterations. |
| 59 | * -t : Turn on syscall timing. |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 60 | * |
| 61 | * RESTRICTIONS |
| 62 | * None |
| 63 | *****************************************************************************/ |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 64 | #include <stdio.h> |
| 65 | #include <stdlib.h> |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 66 | #include <errno.h> |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 67 | #include <sys/syscall.h> |
| 68 | #include <unistd.h> |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 69 | #include <sys/types.h> |
| 70 | #include <sys/socket.h> |
| 71 | #include <linux/net.h> |
| 72 | #include <sys/un.h> |
| 73 | #include <netinet/in.h> |
| 74 | |
| 75 | #include "test.h" |
| 76 | #include "usctest.h" |
| 77 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | char *TCID = "socketcall03"; /* Test program identifier. */ |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 79 | |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 80 | #ifdef __NR_socketcall |
| 81 | |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 82 | #define socketcall(call, args) syscall(__NR_socketcall, call, args) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 83 | |
| 84 | void setup(); |
| 85 | void cleanup(); |
| 86 | void setup1(void); |
| 87 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | int TST_TOTAL = 1; /* Total number of test cases. */ |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 89 | int s; |
| 90 | unsigned long args[3]; |
| 91 | struct sockaddr_in si; |
| 92 | |
| 93 | struct test_case_t { |
| 94 | int domain; |
| 95 | int type; |
| 96 | int pro; |
| 97 | int call; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | void (*setupfunc) (void); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 99 | char *desc; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | } TC = { |
| 101 | AF_INET, SOCK_STREAM, 6, SYS_BIND, setup1, "bind call"}; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 102 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 103 | int main(int ac, char **av) |
| 104 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 105 | int lc; |
| 106 | char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 108 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 109 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 110 | tst_exit(); |
| 111 | } |
| 112 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 113 | setup(); |
| 114 | |
| 115 | /* check looping state */ |
| 116 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 117 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 118 | tst_count = 0; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 119 | |
| 120 | TC.setupfunc(); |
| 121 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 122 | TEST(socketcall(TC.call, args)); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 123 | |
| 124 | /* check return code */ |
| 125 | |
| 126 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 127 | tst_resm(TFAIL | TERRNO, "socketcall() Failed " |
| 128 | " with return=%ld", TEST_RETURN); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 129 | } else { |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 130 | tst_resm(TPASS, "socketcall() passed " |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 131 | "for %s with return=%ld ", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | TC.desc, TEST_RETURN); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 133 | |
| 134 | close(s); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* cleanup and exit */ |
| 139 | cleanup(); |
| 140 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 141 | tst_exit(); |
| 142 | } |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 143 | |
| 144 | /*setup1()*/ |
| 145 | void setup1(void) |
| 146 | { |
| 147 | si.sin_family = AF_INET; |
| 148 | si.sin_addr.s_addr = htons(INADDR_ANY); |
| 149 | si.sin_port = 0; |
| 150 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | if ((s = socket(TC.domain, TC.type, TC.pro)) == -1) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 152 | tst_brkm(TBROK, NULL, "socket creation failed"); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 153 | } |
| 154 | args[0] = s; |
| 155 | args[1] = (unsigned long)&si; |
| 156 | args[2] = sizeof(si); |
| 157 | } |
| 158 | |
| 159 | /* setup() - performs all ONE TIME setup for this test. */ |
| 160 | void setup() |
| 161 | { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 162 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 163 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 164 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 165 | TEST_PAUSE; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 170 | * completion or premature exit. |
| 171 | */ |
| 172 | void cleanup() |
| 173 | { |
| 174 | TEST_CLEANUP; |
| 175 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 176 | } |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 177 | |
| 178 | #else |
| 179 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 180 | int TST_TOTAL = 0; /* Total number of test cases. */ |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 181 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 182 | int main() |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 183 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 184 | tst_resm(TPASS, "socket call test on this architecture disabled."); |
| 185 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 186 | tst_exit(); |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 189 | #endif |