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 : socketcall02 |
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 : Error test for socketcall(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 | * verify socketcall(2) returns -1 and sets errno |
| 35 | * appropriately if argument passed is invalid. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 36 | * |
| 37 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 38 | * Setup: |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 39 | * Setup signal handling. |
| 40 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | * Test: |
| 43 | * Loop if the proper option is given. |
| 44 | * Execute system call. |
| 45 | * Check return code, If system call failed (return == -1) && |
| 46 | * (errno set == expected errno) |
| 47 | * Issue sys call pass with expected error |
| 48 | * otherwise |
| 49 | * Issue sys call fails with unexpected error |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 50 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 51 | * Cleanup: |
| 52 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 54 | * USAGE: <for command-line> |
| 55 | * socketcall02 [-c n] [-e] [-i n] [-I x] [-p x] [-t] |
| 56 | * where, -c n : Run n copies concurrently |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 57 | * -e : Turn on errno logging. |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 58 | * -h : Show this help screen |
| 59 | * -i n : Execute test n times. |
| 60 | * -I x : Execute test for x seconds. |
| 61 | * -p : Pause for SIGUSR1 before starting |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 62 | * -P x : Pause for x seconds between iterations. |
| 63 | * -t : Turn on syscall timing. |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 64 | * |
| 65 | * RESTRICTIONS |
| 66 | * None |
| 67 | *****************************************************************************/ |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 68 | #include <stdio.h> |
| 69 | #include <stdlib.h> |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 70 | #include <errno.h> |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 71 | #include <sys/syscall.h> |
| 72 | #include <unistd.h> |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 73 | #include <sys/types.h> |
| 74 | #include <sys/socket.h> |
| 75 | #include <linux/net.h> |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 76 | #include <sys/un.h> |
| 77 | #include <netinet/in.h> |
robbiew | afd4843 | 2004-03-15 21:04:43 +0000 | [diff] [blame] | 78 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 79 | #include "test.h" |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 80 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 81 | char *TCID = "socketcall02"; |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 82 | |
| 83 | #ifdef __NR_socketcall |
| 84 | |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 85 | #define socketcall(call, args) syscall(__NR_socketcall, call, args) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 86 | |
| 87 | void setup(); |
| 88 | void cleanup(); |
| 89 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 90 | int TST_TOTAL = 1; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 91 | |
| 92 | struct test_case_t { |
| 93 | int call; |
| 94 | unsigned long args[3]; |
| 95 | int retval; |
| 96 | int experrno; |
| 97 | char *desc; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | } TC = { |
| 99 | -1, { |
| 100 | PF_INET, SOCK_STREAM, 0}, -1, EINVAL, "invalid call"}; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 101 | |
| 102 | int main(int ac, char **av) |
| 103 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 104 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 105 | const char *msg; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 106 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 107 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 108 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 109 | } |
| 110 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 111 | setup(); |
| 112 | |
| 113 | /* check looping state */ |
| 114 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 115 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 116 | tst_count = 0; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 117 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | TEST(socketcall(TC.call, TC.args)); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 119 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 120 | /* check return code */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | if ((TEST_RETURN == -1) |
| 122 | && (TEST_ERRNO == TC.experrno)) { |
| 123 | tst_resm(TPASS, "socketcall() failed" |
| 124 | " as expected for %s", TC.desc); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 125 | } else { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 126 | tst_brkm(TFAIL, NULL, "socketcall()" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | " Failed with wrong experrno" |
| 128 | " =%d got: errno=%d : %s", |
| 129 | TC.experrno, TEST_ERRNO, strerror(TEST_ERRNO)); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
| 133 | /* cleanup and exit */ |
| 134 | cleanup(); |
| 135 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 136 | tst_exit(); |
| 137 | } |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 138 | |
| 139 | /* setup() - performs all ONE TIME setup for this test. */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 140 | void setup(void) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 141 | { |
| 142 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 143 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 144 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 145 | TEST_PAUSE; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 150 | * completion or premature exit. |
| 151 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 152 | void cleanup(void) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 153 | { |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 154 | } |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 155 | |
| 156 | #else |
| 157 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 158 | int TST_TOTAL = 0; |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 159 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 160 | int main(void) |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 161 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 162 | tst_resm(TPASS, "socket call test on this architecture disabled."); |
| 163 | tst_exit(); |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 166 | #endif |