blob: 49ee1c2c13fe1755535f81161571e93ee174d513 [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"
robbiewe7c06512003-01-02 16:00:05 +000076
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020077char *TCID = "socketcall03";
vapiere0ccc7d2006-02-24 02:15:00 +000078
robbiew32260282003-03-11 16:19:28 +000079#ifdef __NR_socketcall
80
vapiere0ccc7d2006-02-24 02:15:00 +000081#define socketcall(call, args) syscall(__NR_socketcall, call, args)
robbiewe7c06512003-01-02 16:00:05 +000082
83void setup();
84void cleanup();
85void setup1(void);
86
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020087int TST_TOTAL = 1;
robbiewe7c06512003-01-02 16:00:05 +000088int s;
89unsigned long args[3];
90struct sockaddr_in si;
91
92struct test_case_t {
93 int domain;
94 int type;
95 int pro;
96 int call;
subrata_modak56207ce2009-03-23 13:35:39 +000097 void (*setupfunc) (void);
robbiewe7c06512003-01-02 16:00:05 +000098 char *desc;
subrata_modak56207ce2009-03-23 13:35:39 +000099} TC = {
100AF_INET, SOCK_STREAM, 6, SYS_BIND, setup1, "bind call"};
robbiewe7c06512003-01-02 16:00:05 +0000101
subrata_modak56207ce2009-03-23 13:35:39 +0000102int main(int ac, char **av)
103{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200104 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200105 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000106
Garrett Cooper45e285d2010-11-22 12:19:25 -0800107 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
robbiewe7c06512003-01-02 16:00:05 +0000108 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewe7c06512003-01-02 16:00:05 +0000109 }
110
robbiewe7c06512003-01-02 16:00:05 +0000111 setup();
112
113 /* check looping state */
114 for (lc = 0; TEST_LOOPING(lc); lc++) {
115
Caspar Zhangd59a6592013-03-07 14:59:12 +0800116 tst_count = 0;
robbiewe7c06512003-01-02 16:00:05 +0000117
118 TC.setupfunc();
119
subrata_modak56207ce2009-03-23 13:35:39 +0000120 TEST(socketcall(TC.call, args));
robbiewe7c06512003-01-02 16:00:05 +0000121
122 /* check return code */
123
124 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800125 tst_resm(TFAIL | TERRNO, "socketcall() Failed "
126 " with return=%ld", TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000127 } else {
subrata_modak4bb656a2009-02-26 12:02:09 +0000128 tst_resm(TPASS, "socketcall() passed "
subrata_modak923b23f2009-11-02 13:57:16 +0000129 "for %s with return=%ld ",
subrata_modak56207ce2009-03-23 13:35:39 +0000130 TC.desc, TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000131
132 close(s);
133 }
134 }
135
136 /* cleanup and exit */
137 cleanup();
138
Garrett Cooper2c282152010-12-16 00:55:50 -0800139 tst_exit();
140}
robbiewe7c06512003-01-02 16:00:05 +0000141
142/*setup1()*/
143void setup1(void)
144{
145 si.sin_family = AF_INET;
146 si.sin_addr.s_addr = htons(INADDR_ANY);
147 si.sin_port = 0;
148
subrata_modak56207ce2009-03-23 13:35:39 +0000149 if ((s = socket(TC.domain, TC.type, TC.pro)) == -1) {
Garrett Cooper53740502010-12-16 00:04:01 -0800150 tst_brkm(TBROK, NULL, "socket creation failed");
robbiewe7c06512003-01-02 16:00:05 +0000151 }
152 args[0] = s;
153 args[1] = (unsigned long)&si;
154 args[2] = sizeof(si);
155}
156
157/* setup() - performs all ONE TIME setup for this test. */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400158void setup(void)
robbiewe7c06512003-01-02 16:00:05 +0000159{
subrata_modakbdbaec52009-02-26 12:14:51 +0000160
robbiewe7c06512003-01-02 16:00:05 +0000161 tst_sig(NOFORK, DEF_HANDLER, cleanup);
162
robbiewe7c06512003-01-02 16:00:05 +0000163 TEST_PAUSE;
164}
165
166/*
167 * cleanup() - performs all ONE TIME cleanup for this test at
168 * completion or premature exit.
169 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400170void cleanup(void)
robbiewe7c06512003-01-02 16:00:05 +0000171{
robbiewe7c06512003-01-02 16:00:05 +0000172}
robbiew32260282003-03-11 16:19:28 +0000173
174#else
175
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200176int TST_TOTAL = 0;
robbiew32260282003-03-11 16:19:28 +0000177
Mike Frysingerc57fba52014-04-09 18:56:30 -0400178int main(void)
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();
robbiew32260282003-03-11 16:19:28 +0000182}
183
Chris Dearmanec6edca2012-10-17 19:54:01 -0700184#endif