blob: 72d8fff3100ec741ba1377e3bcab3ff29da52109 [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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiewe7c06512003-01-02 16:00:05 +000015 *
16 */
17/**************************************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiewe7c06512003-01-02 16:00:05 +000019 * TEST IDENTIFIER : socketcall03
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 bind(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiewe7c06512003-01-02 16:00:05 +000025 * TEST CASE TOTAL : 1
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:
robbiewe7c06512003-01-02 16:00:05 +000042 * 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.
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 * socketcall03 [-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>
72#include <sys/un.h>
73#include <netinet/in.h>
74
75#include "test.h"
76#include "usctest.h"
77
subrata_modak56207ce2009-03-23 13:35:39 +000078char *TCID = "socketcall03"; /* 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();
86void setup1(void);
87
subrata_modak56207ce2009-03-23 13:35:39 +000088int TST_TOTAL = 1; /* Total number of test cases. */
robbiewe7c06512003-01-02 16:00:05 +000089int s;
90unsigned long args[3];
91struct sockaddr_in si;
92
93struct test_case_t {
94 int domain;
95 int type;
96 int pro;
97 int call;
subrata_modak56207ce2009-03-23 13:35:39 +000098 void (*setupfunc) (void);
robbiewe7c06512003-01-02 16:00:05 +000099 char *desc;
subrata_modak56207ce2009-03-23 13:35:39 +0000100} TC = {
101AF_INET, SOCK_STREAM, 6, SYS_BIND, setup1, "bind call"};
robbiewe7c06512003-01-02 16:00:05 +0000102
subrata_modak56207ce2009-03-23 13:35:39 +0000103int main(int ac, char **av)
104{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200105 int lc;
106 char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000107
Garrett Cooper45e285d2010-11-22 12:19:25 -0800108 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
robbiewe7c06512003-01-02 16:00:05 +0000109 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
110 tst_exit();
111 }
112
robbiewe7c06512003-01-02 16:00:05 +0000113 setup();
114
115 /* check looping state */
116 for (lc = 0; TEST_LOOPING(lc); lc++) {
117
Caspar Zhangd59a6592013-03-07 14:59:12 +0800118 tst_count = 0;
robbiewe7c06512003-01-02 16:00:05 +0000119
120 TC.setupfunc();
121
subrata_modak56207ce2009-03-23 13:35:39 +0000122 TEST(socketcall(TC.call, args));
robbiewe7c06512003-01-02 16:00:05 +0000123
124 /* check return code */
125
126 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800127 tst_resm(TFAIL | TERRNO, "socketcall() Failed "
128 " with return=%ld", TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000129 } else {
subrata_modak4bb656a2009-02-26 12:02:09 +0000130 tst_resm(TPASS, "socketcall() passed "
subrata_modak923b23f2009-11-02 13:57:16 +0000131 "for %s with return=%ld ",
subrata_modak56207ce2009-03-23 13:35:39 +0000132 TC.desc, TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000133
134 close(s);
135 }
136 }
137
138 /* cleanup and exit */
139 cleanup();
140
Garrett Cooper2c282152010-12-16 00:55:50 -0800141 tst_exit();
142}
robbiewe7c06512003-01-02 16:00:05 +0000143
144/*setup1()*/
145void setup1(void)
146{
147 si.sin_family = AF_INET;
148 si.sin_addr.s_addr = htons(INADDR_ANY);
149 si.sin_port = 0;
150
subrata_modak56207ce2009-03-23 13:35:39 +0000151 if ((s = socket(TC.domain, TC.type, TC.pro)) == -1) {
Garrett Cooper53740502010-12-16 00:04:01 -0800152 tst_brkm(TBROK, NULL, "socket creation failed");
robbiewe7c06512003-01-02 16:00:05 +0000153 }
154 args[0] = s;
155 args[1] = (unsigned long)&si;
156 args[2] = sizeof(si);
157}
158
159/* setup() - performs all ONE TIME setup for this test. */
160void setup()
161{
subrata_modakbdbaec52009-02-26 12:14:51 +0000162
robbiewe7c06512003-01-02 16:00:05 +0000163 tst_sig(NOFORK, DEF_HANDLER, cleanup);
164
robbiewe7c06512003-01-02 16:00:05 +0000165 TEST_PAUSE;
166}
167
168/*
169 * cleanup() - performs all ONE TIME cleanup for this test at
170 * completion or premature exit.
171 */
172void cleanup()
173{
174 TEST_CLEANUP;
175
robbiewe7c06512003-01-02 16:00:05 +0000176}
robbiew32260282003-03-11 16:19:28 +0000177
178#else
179
subrata_modak56207ce2009-03-23 13:35:39 +0000180int TST_TOTAL = 0; /* Total number of test cases. */
robbiew32260282003-03-11 16:19:28 +0000181
subrata_modak56207ce2009-03-23 13:35:39 +0000182int main()
robbiew32260282003-03-11 16:19:28 +0000183{
subrata_modak56207ce2009-03-23 13:35:39 +0000184 tst_resm(TPASS, "socket call test on this architecture disabled.");
185 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800186 tst_exit();
robbiew32260282003-03-11 16:19:28 +0000187}
188
Chris Dearmanec6edca2012-10-17 19:54:01 -0700189#endif