blob: a2f940cc4b698324df907ff6dd5af044bf7e13ad [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 : socketcall04
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 listen(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 * socketcall04 [-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 = "socketcall04";
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;
subrata_modak56207ce2009-03-23 13:35:39 +000088int i, s;
robbiewe7c06512003-01-02 16:00:05 +000089unsigned 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_LISTEN, setup1, "listen 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;
robbiewe7c06512003-01-02 16:00:05 +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 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 tst_resm(TFAIL | TTERRNO, "socketcall() Failed "
125 " with return=%ld", TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000126 } else {
subrata_modak4bb656a2009-02-26 12:02:09 +0000127 tst_resm(TPASS, "socketcall() passed "
subrata_modak923b23f2009-11-02 13:57:16 +0000128 "for %s with return=%ld ",
subrata_modak56207ce2009-03-23 13:35:39 +0000129 TC.desc, TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000130 close(s);
131 }
132 }
133
134 /* cleanup and exit */
135 cleanup();
136
Garrett Cooper2c282152010-12-16 00:55:50 -0800137 tst_exit();
138}
robbiewe7c06512003-01-02 16:00:05 +0000139
140/*setup1()*/
141void setup1(void)
142{
subrata_modak56207ce2009-03-23 13:35:39 +0000143 if ((s = socket(TC.domain, TC.type, TC.pro)) == -1) {
Garrett Cooper53740502010-12-16 00:04:01 -0800144 tst_brkm(TBROK, NULL, "socket creation failed");
robbiewe7c06512003-01-02 16:00:05 +0000145 }
146 args[0] = s;
subrata_modakbdbaec52009-02-26 12:14:51 +0000147 args[1] = 1;
subrata_modak56207ce2009-03-23 13:35:39 +0000148}
robbiewe7c06512003-01-02 16:00:05 +0000149
150/* setup() - performs all ONE TIME setup for this test. */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400151void setup(void)
robbiewe7c06512003-01-02 16:00:05 +0000152{
153
robbiewe7c06512003-01-02 16:00:05 +0000154 tst_sig(NOFORK, DEF_HANDLER, cleanup);
155
robbiewe7c06512003-01-02 16:00:05 +0000156 TEST_PAUSE;
157}
158
159/*
160 * cleanup() - performs all ONE TIME cleanup for this test at
161 * completion or premature exit.
162 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400163void cleanup(void)
robbiewe7c06512003-01-02 16:00:05 +0000164{
robbiewe7c06512003-01-02 16:00:05 +0000165}
robbiew32260282003-03-11 16:19:28 +0000166
167#else
168
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200169int TST_TOTAL = 0;
robbiew32260282003-03-11 16:19:28 +0000170
Mike Frysingerc57fba52014-04-09 18:56:30 -0400171int main(void)
robbiew32260282003-03-11 16:19:28 +0000172{
subrata_modak56207ce2009-03-23 13:35:39 +0000173 tst_resm(TPASS, "socket call test on this architecture disabled.");
174 tst_exit();
robbiew32260282003-03-11 16:19:28 +0000175}
176
Chris Dearmanec6edca2012-10-17 19:54:01 -0700177#endif