blob: 55c02a75f7b602a9e9c2ba21cacf166cff5e2fe5 [file] [log] [blame]
robbiewe7c06512003-01-02 16:00:05 +00001/*
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., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
15 *
16 */
17/**************************************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiewe7c06512003-01-02 16:00:05 +000019 * TEST IDENTIFIER : socketcall01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiewe7c06512003-01-02 16:00:05 +000021 * EXECUTED BY : All user
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiewe7c06512003-01-02 16:00:05 +000023 * TEST TITLE : Basic test for socketcall(2) for socket(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiewe7c06512003-01-02 16:00:05 +000025 * TEST CASE TOTAL : 4
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiewe7c06512003-01-02 16:00:05 +000027 * AUTHOR : sowmya adiga<sowmya.adiga@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiewe7c06512003-01-02 16:00:05 +000029 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000030 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
robbiewe7c06512003-01-02 16:00:05 +000032 *
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_modakbdbaec52009-02-26 12:14:51 +000036 *
subrata_modak56207ce2009-03-23 13:35:39 +000037 * Setup:
robbiewe7c06512003-01-02 16:00:05 +000038 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
subrata_modak56207ce2009-03-23 13:35:39 +000041 * Test:
42 * Execute system call
robbiewe7c06512003-01-02 16:00:05 +000043 * 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_modak4bb656a2009-02-26 12:02:09 +000046 *
subrata_modak56207ce2009-03-23 13:35:39 +000047 * Cleanup:
48 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
robbiewe7c06512003-01-02 16:00:05 +000050 * USAGE: <for command-line>
51 * socketcall01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
52 * where, -c n : Run n copies concurrently
subrata_modak56207ce2009-03-23 13:35:39 +000053 * -e : Turn on errno logging.
robbiewe7c06512003-01-02 16:00:05 +000054 * -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_modak56207ce2009-03-23 13:35:39 +000058 * -P x : Pause for x seconds between iterations.
59 * t : Turn on syscall timing.
robbiewe7c06512003-01-02 16:00:05 +000060 *
61 * RESTRICTIONS
62 * None
63 *****************************************************************************/
vapiere0ccc7d2006-02-24 02:15:00 +000064#include <stdio.h>
65#include <stdlib.h>
robbiewe7c06512003-01-02 16:00:05 +000066#include <errno.h>
vapiere0ccc7d2006-02-24 02:15:00 +000067#include <sys/syscall.h>
68#include <unistd.h>
robbiewe7c06512003-01-02 16:00:05 +000069#include <sys/types.h>
70#include <sys/socket.h>
71#include <linux/net.h>
vapiere0ccc7d2006-02-24 02:15:00 +000072#include <sys/un.h>
73#include <netinet/in.h>
robbiewafd48432004-03-15 21:04:43 +000074
robbiewe7c06512003-01-02 16:00:05 +000075#include "test.h"
76#include "usctest.h"
77
subrata_modak56207ce2009-03-23 13:35:39 +000078char *TCID = "socketcall01"; /* Test program identifier. */
vapiere0ccc7d2006-02-24 02:15:00 +000079
robbiew32260282003-03-11 16:19:28 +000080#ifdef __NR_socketcall
81
vapiere0ccc7d2006-02-24 02:15:00 +000082#define socketcall(call, args) syscall(__NR_socketcall, call, args)
robbiewe7c06512003-01-02 16:00:05 +000083
84void setup();
85void cleanup();
86
subrata_modak56207ce2009-03-23 13:35:39 +000087extern int Tst_count; /* TestCase counter for tst_* routine */
robbiewe7c06512003-01-02 16:00:05 +000088
89struct test_case_t {
90 int call;
91 unsigned long args[3];
92 char *desc;
subrata_modak56207ce2009-03-23 13:35:39 +000093} TC[] = {
94 {
95 SYS_SOCKET, {
96 PF_INET, SOCK_STREAM, 0}, "TCP stream"}, {
97 SYS_SOCKET, {
98 PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"}, {
99 SYS_SOCKET, {
100 AF_INET, SOCK_RAW, 6}, "Raw socket"}, {
101 SYS_SOCKET, {
102 PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
robbiewe7c06512003-01-02 16:00:05 +0000103};
104
subrata_modakbdbaec52009-02-26 12:14:51 +0000105int TST_TOTAL = sizeof(TC) / sizeof(TC[0]);
robbiewe7c06512003-01-02 16:00:05 +0000106
107int main(int ac, char **av)
108{
subrata_modak56207ce2009-03-23 13:35:39 +0000109 int lc; /* loop counter */
110 char *msg; /* message returned from parse_opts */
111 int i; /* s is socket descriptor */
robbiewe7c06512003-01-02 16:00:05 +0000112
Garrett Cooper45e285d2010-11-22 12:19:25 -0800113 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
robbiewe7c06512003-01-02 16:00:05 +0000114 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
115 tst_exit();
116 }
117
118 /* perform global setup for test */
119 setup();
120
121 /* check looping state */
122 for (lc = 0; TEST_LOOPING(lc); lc++) {
123
124 /* reset Tst_count in case we are looping. */
125 Tst_count = 0;
126
subrata_modak56207ce2009-03-23 13:35:39 +0000127 for (i = 0; i < TST_TOTAL; i++) {
robbiewe7c06512003-01-02 16:00:05 +0000128
subrata_modak56207ce2009-03-23 13:35:39 +0000129 TEST(socketcall(TC[i].call, TC[i].args));
robbiewe7c06512003-01-02 16:00:05 +0000130
131 /* check return code */
132 if (TEST_RETURN == -1) {
subrata_modak923b23f2009-11-02 13:57:16 +0000133 tst_resm(TFAIL|TTERRNO, "socketcall() Failed with"
134 " return=%ld",
135 TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000136 } else {
137 tst_resm(TPASS, "socketcall() passed for"
subrata_modak923b23f2009-11-02 13:57:16 +0000138 " :%s with return=%ld ",
subrata_modak56207ce2009-03-23 13:35:39 +0000139 TC[i].desc, TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000140 close(TEST_RETURN);
141 }
subrata_modak56207ce2009-03-23 13:35:39 +0000142 } /* End for TEST_LOOPING */
robbiewe7c06512003-01-02 16:00:05 +0000143 }
subrata_modak56207ce2009-03-23 13:35:39 +0000144
robbiewe7c06512003-01-02 16:00:05 +0000145 /* cleanup and exit */
146 cleanup();
147
148 return 0;
subrata_modak56207ce2009-03-23 13:35:39 +0000149} /* End main */
robbiewe7c06512003-01-02 16:00:05 +0000150
151/* setup() - performs all ONE TIME setup for this test. */
152void setup()
153{
154
155 /* capture signals */
156 tst_sig(NOFORK, DEF_HANDLER, cleanup);
157
subrata_modak56207ce2009-03-23 13:35:39 +0000158 /* pause if that option was specified */
robbiewe7c06512003-01-02 16:00:05 +0000159 TEST_PAUSE;
160}
161
162/*
163 * cleanup() - performs all ONE TIME cleanup for this test at
164 * completion or premature exit.
165 */
166void cleanup()
167{
168 TEST_CLEANUP;
169
170 /* exit with return code appropriate for results */
171 tst_exit();
172}
robbiew32260282003-03-11 16:19:28 +0000173
174#else
175
subrata_modak56207ce2009-03-23 13:35:39 +0000176int TST_TOTAL = 0; /* Total number of test cases. */
robbiew32260282003-03-11 16:19:28 +0000177
subrata_modak56207ce2009-03-23 13:35:39 +0000178int main()
robbiew32260282003-03-11 16:19:28 +0000179{
subrata_modak56207ce2009-03-23 13:35:39 +0000180 tst_resm(TPASS, "socket call test on this architecture disabled.");
181 tst_exit();
182 return 0;
robbiew32260282003-03-11 16:19:28 +0000183}
184
185#endif