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 : socketcall04 |
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 listen(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 | * socketcall04 [-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" |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 76 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 77 | char *TCID = "socketcall04"; |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 78 | |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 79 | #ifdef __NR_socketcall |
| 80 | |
vapier | e0ccc7d | 2006-02-24 02:15:00 +0000 | [diff] [blame] | 81 | #define socketcall(call, args) syscall(__NR_socketcall, call, args) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 82 | |
| 83 | void setup(); |
| 84 | void cleanup(); |
| 85 | void setup1(void); |
| 86 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 87 | int TST_TOTAL = 1; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | int i, s; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 89 | unsigned long args[3]; |
| 90 | struct sockaddr_in si; |
| 91 | |
| 92 | struct test_case_t { |
| 93 | int domain; |
| 94 | int type; |
| 95 | int pro; |
| 96 | int call; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | void (*setupfunc) (void); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 98 | char *desc; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 99 | } TC = { |
| 100 | AF_INET, SOCK_STREAM, 6, SYS_LISTEN, setup1, "listen call"}; |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 101 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 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 | |
| 118 | TC.setupfunc(); |
| 119 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | TEST(socketcall(TC.call, args)); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 121 | |
| 122 | /* check return code */ |
| 123 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 124 | tst_resm(TFAIL | TTERRNO, "socketcall() Failed " |
| 125 | " with return=%ld", TEST_RETURN); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 126 | } else { |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 127 | tst_resm(TPASS, "socketcall() passed " |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 128 | "for %s with return=%ld ", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | TC.desc, TEST_RETURN); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 130 | close(s); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* cleanup and exit */ |
| 135 | cleanup(); |
| 136 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 137 | tst_exit(); |
| 138 | } |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 139 | |
| 140 | /*setup1()*/ |
| 141 | void setup1(void) |
| 142 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 143 | if ((s = socket(TC.domain, TC.type, TC.pro)) == -1) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 144 | tst_brkm(TBROK, NULL, "socket creation failed"); |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 145 | } |
| 146 | args[0] = s; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 147 | args[1] = 1; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | } |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 149 | |
| 150 | /* setup() - performs all ONE TIME setup for this test. */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 151 | void setup(void) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 152 | { |
| 153 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 154 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 155 | |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 156 | TEST_PAUSE; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 161 | * completion or premature exit. |
| 162 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 163 | void cleanup(void) |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 164 | { |
robbiew | e7c0651 | 2003-01-02 16:00:05 +0000 | [diff] [blame] | 165 | } |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 166 | |
| 167 | #else |
| 168 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 169 | int TST_TOTAL = 0; |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 170 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 171 | int main(void) |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 172 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 173 | tst_resm(TPASS, "socket call test on this architecture disabled."); |
| 174 | tst_exit(); |
robbiew | 3226028 | 2003-03-11 16:19:28 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 177 | #endif |