• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	: socketcall01
20  *
21  *    EXECUTED BY	: All user
22  *
23  *    TEST TITLE	: Basic test for socketcall(2) for socket(2)
24  *
25  *    TEST CASE TOTAL	: 4
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  *	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  *  socketcall01 [-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 = "socketcall01";
78 
79 #ifdef __NR_socketcall
80 
81 #define socketcall(call, args) syscall(__NR_socketcall, call, args)
82 
83 void setup();
84 void cleanup();
85 
86 struct test_case_t {
87 	int call;
88 	unsigned long args[3];
89 	char *desc;
90 } TC[] = {
91 	{
92 		SYS_SOCKET, {
93 	PF_INET, SOCK_STREAM, 0}, "TCP stream"}, {
94 		SYS_SOCKET, {
95 	PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"}, {
96 		SYS_SOCKET, {
97 	AF_INET, SOCK_RAW, 6}, "Raw socket"}, {
98 		SYS_SOCKET, {
99 	PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
100 };
101 
102 int TST_TOTAL = sizeof(TC) / sizeof(TC[0]);
103 
main(int ac,char ** av)104 int main(int ac, char **av)
105 {
106 	int lc;
107 	int i;			/* s is socket descriptor */
108 
109 	tst_parse_opts(ac, av, NULL, NULL);
110 
111 	setup();
112 
113 	/* check looping state */
114 	for (lc = 0; TEST_LOOPING(lc); lc++) {
115 
116 		tst_count = 0;
117 
118 		for (i = 0; i < TST_TOTAL; i++) {
119 
120 			TEST(socketcall(TC[i].call, TC[i].args));
121 
122 			/* check return code */
123 			if (TEST_RETURN == -1) {
124 				tst_resm(TFAIL | TTERRNO,
125 					 "socketcall() Failed with"
126 					 " return=%ld", TEST_RETURN);
127 			} else {
128 				tst_resm(TPASS, "socketcall() passed for"
129 					 " :%s with return=%ld ",
130 					 TC[i].desc, TEST_RETURN);
131 				close(TEST_RETURN);
132 			}
133 		}
134 	}
135 
136 	/* cleanup and exit */
137 	cleanup();
138 
139 	tst_exit();
140 }
141 
142 /* setup() - performs all ONE TIME setup for this test. */
setup(void)143 void setup(void)
144 {
145 
146 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
147 
148 	TEST_PAUSE;
149 }
150 
151 /*
152  * cleanup() - performs all ONE TIME cleanup for this test at
153  *		completion or premature exit.
154  */
cleanup(void)155 void cleanup(void)
156 {
157 }
158 
159 #else
160 
161 int TST_TOTAL = 0;
162 
main(void)163 int main(void)
164 {
165 	tst_resm(TPASS, "socket call test on this architecture disabled.");
166 	tst_exit();
167 }
168 
169 #endif
170