• 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	: 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 
81 char *TCID = "socketcall02";
82 
83 #ifdef __NR_socketcall
84 
85 #define socketcall(call, args) syscall(__NR_socketcall, call, args)
86 
87 void setup();
88 void cleanup();
89 
90 int TST_TOTAL = 1;
91 
92 struct test_case_t {
93 	int call;
94 	unsigned long args[3];
95 	int retval;
96 	int experrno;
97 	char *desc;
98 } TC = {
99 	-1, {
100 PF_INET, SOCK_STREAM, 0}, -1, EINVAL, "invalid call"};
101 
main(int ac,char ** av)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 		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. */
setup(void)137 void 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  */
cleanup(void)149 void cleanup(void)
150 {
151 }
152 
153 #else
154 
155 int TST_TOTAL = 0;
156 
main(void)157 int main(void)
158 {
159 	tst_resm(TPASS, "socket call test on this architecture disabled.");
160 	tst_exit();
161 }
162 
163 #endif
164