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., 14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15 * 16 */ 17/************************************************************************** 18 * 19 * TEST IDENTIFIER : socketcall02 20 * 21 * EXECUTED BY : All user 22 * 23 * TEST TITLE : Error test for socketcall(2) 24 * 25 * TEST CASE TOTAL : 1 26 * 27 * AUTHOR : sowmya adiga<sowmya.adiga@wipro.com> 28 * 29 * SIGNALS 30 * Uses SIGUSR1 to pause before test if option set. 31 * (See the parse_opts(3) man page). 32 * 33 * DESCRIPTION 34 * verify socketcall(2) returns -1 and sets errno 35 * appropriately if argument passed is invalid. 36 * 37 * 38 * Setup: 39 * Setup signal handling. 40 * Pause for SIGUSR1 if option specified. 41 * 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 50 * 51 * Cleanup: 52 * Print errno log and/or timing stats if options given 53 * 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 57 * -e : Turn on errno logging. 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 62 * -P x : Pause for x seconds between iterations. 63 * -t : Turn on syscall timing. 64 * 65 * RESTRICTIONS 66 * None 67 *****************************************************************************/ 68#include <stdio.h> 69#include <stdlib.h> 70#include <errno.h> 71#include <sys/syscall.h> 72#include <unistd.h> 73#include <sys/types.h> 74#include <sys/socket.h> 75#include <linux/net.h> 76#include <sys/un.h> 77#include <netinet/in.h> 78 79#include "test.h" 80 81char *TCID = "socketcall02"; 82 83#ifdef __NR_socketcall 84 85#define socketcall(call, args) syscall(__NR_socketcall, call, args) 86 87void setup(); 88void cleanup(); 89 90int TST_TOTAL = 1; 91 92struct test_case_t { 93 int call; 94 unsigned long args[3]; 95 int retval; 96 int experrno; 97 char *desc; 98} TC = { 99 -1, { 100PF_INET, SOCK_STREAM, 0}, -1, EINVAL, "invalid call"}; 101 102int main(int ac, char **av) 103{ 104 int lc; 105 106 tst_parse_opts(ac, av, NULL, NULL); 107 108 setup(); 109 110 /* check looping state */ 111 for (lc = 0; TEST_LOOPING(lc); lc++) { 112 113 tst_count = 0; 114 115 TEST(socketcall(TC.call, TC.args)); 116 117 /* check return code */ 118 if ((TEST_RETURN == -1) 119 && (TEST_ERRNO == TC.experrno)) { 120 tst_resm(TPASS, "socketcall() failed" 121 " as expected for %s", TC.desc); 122 } else { 123 tst_brkm(TFAIL, NULL, "socketcall()" 124 " Failed with wrong experrno" 125 " =%d got: errno=%d : %s", 126 TC.experrno, TEST_ERRNO, strerror(TEST_ERRNO)); 127 } 128 } 129 130 /* cleanup and exit */ 131 cleanup(); 132 133 tst_exit(); 134} 135 136/* setup() - performs all ONE TIME setup for this test. */ 137void setup(void) 138{ 139 140 tst_sig(NOFORK, DEF_HANDLER, cleanup); 141 142 TEST_PAUSE; 143} 144 145/* 146 * cleanup() - performs all ONE TIME cleanup for this test at 147 * completion or premature exit. 148 */ 149void cleanup(void) 150{ 151} 152 153#else 154 155int TST_TOTAL = 0; 156 157int main(void) 158{ 159 tst_resm(TPASS, "socket call test on this architecture disabled."); 160 tst_exit(); 161} 162 163#endif 164