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 |
| 13 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 14 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 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 : socketcall01 |
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 socket(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 : 4 |
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: |
| 42 | * Execute system call |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 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 | * socketcall01 [-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> |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 72 | #include <sys/un.h> |
| 73 | #include <netinet/in.h> |
robbiew | afd4843 | 2004-03-15 21:04:43 +0000 | [diff] [blame] | 74 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 75 | #include "test.h" |
| 76 | #include "usctest.h" |
| 77 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | char *TCID = "socketcall01"; /* 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 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | extern int Tst_count; /* TestCase counter for tst_* routine */ |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 88 | |
| 89 | struct test_case_t { |
| 90 | int call; |
| 91 | unsigned long args[3]; |
| 92 | char *desc; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 93 | } TC[] = { |
| 94 | { |
| 95 | SYS_SOCKET, { |
| 96 | PF_INET, SOCK_STREAM, 0}, "TCP stream"}, { |
| 97 | SYS_SOCKET, { |
| 98 | PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"}, { |
| 99 | SYS_SOCKET, { |
| 100 | AF_INET, SOCK_RAW, 6}, "Raw socket"}, { |
| 101 | SYS_SOCKET, { |
| 102 | PF_INET, SOCK_DGRAM, 17}, "UDP dgram"} |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 105 | int TST_TOTAL = sizeof(TC) / sizeof(TC[0]); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 106 | |
| 107 | int main(int ac, char **av) |
| 108 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | int lc; /* loop counter */ |
| 110 | char *msg; /* message returned from parse_opts */ |
| 111 | int i; /* s is socket descriptor */ |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 112 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame^] | 113 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 114 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 115 | tst_exit(); |
| 116 | } |
| 117 | |
| 118 | /* perform global setup for test */ |
| 119 | setup(); |
| 120 | |
| 121 | /* check looping state */ |
| 122 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 123 | |
| 124 | /* reset Tst_count in case we are looping. */ |
| 125 | Tst_count = 0; |
| 126 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | for (i = 0; i < TST_TOTAL; i++) { |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 128 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | TEST(socketcall(TC[i].call, TC[i].args)); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 130 | |
| 131 | /* check return code */ |
| 132 | if (TEST_RETURN == -1) { |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 133 | tst_resm(TFAIL|TTERRNO, "socketcall() Failed with" |
| 134 | " return=%ld", |
| 135 | TEST_RETURN); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 136 | } else { |
| 137 | tst_resm(TPASS, "socketcall() passed for" |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 138 | " :%s with return=%ld ", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | TC[i].desc, TEST_RETURN); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 140 | close(TEST_RETURN); |
| 141 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | } /* End for TEST_LOOPING */ |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 143 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 145 | /* cleanup and exit */ |
| 146 | cleanup(); |
| 147 | |
| 148 | return 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 149 | } /* End main */ |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 150 | |
| 151 | /* setup() - performs all ONE TIME setup for this test. */ |
| 152 | void setup() |
| 153 | { |
| 154 | |
| 155 | /* capture signals */ |
| 156 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 157 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | /* pause if that option was specified */ |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 159 | TEST_PAUSE; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 164 | * completion or premature exit. |
| 165 | */ |
| 166 | void cleanup() |
| 167 | { |
| 168 | TEST_CLEANUP; |
| 169 | |
| 170 | /* exit with return code appropriate for results */ |
| 171 | tst_exit(); |
| 172 | } |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 173 | |
| 174 | #else |
| 175 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 176 | int TST_TOTAL = 0; /* Total number of test cases. */ |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 177 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 178 | int main() |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 179 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 180 | tst_resm(TPASS, "socket call test on this architecture disabled."); |
| 181 | tst_exit(); |
| 182 | return 0; |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | #endif |