Home | History | Annotate | Download | only in socketcall
      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	: socketcall04
     20  *
     21  *    EXECUTED BY	: All user
     22  *
     23  *    TEST TITLE	: Basic test for socketcall(2) for listen(2)
     24  *
     25  *    TEST CASE TOTAL	: 1
     26  *
     27  *    AUTHOR		: sowmya adiga<sowmya.adiga (at) 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  *	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.
     36  *
     37  *	Setup:
     38  *	  Setup signal handling.
     39  *	  Pause for SIGUSR1 if option specified.
     40  *
     41  *	Test:
     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.
     46  *
     47  *	Cleanup:
     48  *	  Print errno log and/or timing stats if options given
     49  *
     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
     53  *				-e   : Turn on errno logging.
     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
     58  *				-P x : Pause for x seconds between iterations.
     59  *				 t   : Turn on syscall timing.
     60  *
     61  * RESTRICTIONS
     62  * None
     63  *****************************************************************************/
     64 #include <stdio.h>
     65 #include <stdlib.h>
     66 #include <errno.h>
     67 #include <sys/syscall.h>
     68 #include <unistd.h>
     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 
     77 char *TCID = "socketcall04";
     78 
     79 #ifdef __NR_socketcall
     80 
     81 #define socketcall(call, args) syscall(__NR_socketcall, call, args)
     82 
     83 void setup();
     84 void cleanup();
     85 void setup1(void);
     86 
     87 int TST_TOTAL = 1;
     88 int i, s;
     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;
     97 	void (*setupfunc) (void);
     98 	char *desc;
     99 } TC = {
    100 AF_INET, SOCK_STREAM, 6, SYS_LISTEN, setup1, "listen call"};
    101 
    102 int 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 		TC.setupfunc();
    116 
    117 		TEST(socketcall(TC.call, args));
    118 
    119 		/* check return code */
    120 		if (TEST_RETURN == -1) {
    121 			tst_resm(TFAIL | TTERRNO, "socketcall() Failed "
    122 				 " with return=%ld", TEST_RETURN);
    123 		} else {
    124 			tst_resm(TPASS, "socketcall() passed "
    125 				 "for %s with return=%ld ",
    126 				 TC.desc, TEST_RETURN);
    127 			close(s);
    128 		}
    129 	}
    130 
    131 	/* cleanup and exit */
    132 	cleanup();
    133 
    134 	tst_exit();
    135 }
    136 
    137 /*setup1()*/
    138 void setup1(void)
    139 {
    140 	if ((s = socket(TC.domain, TC.type, TC.pro)) == -1) {
    141 		tst_brkm(TBROK, NULL, "socket creation failed");
    142 	}
    143 	args[0] = s;
    144 	args[1] = 1;
    145 }
    146 
    147 /* setup() - performs all ONE TIME setup for this test. */
    148 void setup(void)
    149 {
    150 
    151 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    152 
    153 	TEST_PAUSE;
    154 }
    155 
    156 /*
    157  * cleanup() - performs all ONE TIME cleanup for this test at
    158  *		completion or premature exit.
    159  */
    160 void cleanup(void)
    161 {
    162 }
    163 
    164 #else
    165 
    166 int TST_TOTAL = 0;
    167 
    168 int main(void)
    169 {
    170 	tst_resm(TPASS, "socket call test on this architecture disabled.");
    171 	tst_exit();
    172 }
    173 
    174 #endif
    175