blob: 01ad0f57aca319e3e61e9bcebb9b8f10824e686e [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 : 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"
robbiewe7c06512003-01-02 16:00:05 +000076
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020077char *TCID = "socketcall01";
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();
85
robbiewe7c06512003-01-02 16:00:05 +000086struct test_case_t {
87 int call;
88 unsigned long args[3];
89 char *desc;
subrata_modak56207ce2009-03-23 13:35:39 +000090} TC[] = {
91 {
92 SYS_SOCKET, {
93 PF_INET, SOCK_STREAM, 0}, "TCP stream"}, {
94 SYS_SOCKET, {
95 PF_UNIX, SOCK_DGRAM, 0}, "unix domain dgram"}, {
96 SYS_SOCKET, {
97 AF_INET, SOCK_RAW, 6}, "Raw socket"}, {
98 SYS_SOCKET, {
99 PF_INET, SOCK_DGRAM, 17}, "UDP dgram"}
robbiewe7c06512003-01-02 16:00:05 +0000100};
101
subrata_modakbdbaec52009-02-26 12:14:51 +0000102int TST_TOTAL = sizeof(TC) / sizeof(TC[0]);
robbiewe7c06512003-01-02 16:00:05 +0000103
104int main(int ac, char **av)
105{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200106 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200107 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000108 int i; /* s is socket descriptor */
robbiewe7c06512003-01-02 16:00:05 +0000109
Garrett Cooper45e285d2010-11-22 12:19:25 -0800110 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
robbiewe7c06512003-01-02 16:00:05 +0000111 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewe7c06512003-01-02 16:00:05 +0000112 }
113
robbiewe7c06512003-01-02 16:00:05 +0000114 setup();
115
116 /* check looping state */
117 for (lc = 0; TEST_LOOPING(lc); lc++) {
118
Caspar Zhangd59a6592013-03-07 14:59:12 +0800119 tst_count = 0;
robbiewe7c06512003-01-02 16:00:05 +0000120
subrata_modak56207ce2009-03-23 13:35:39 +0000121 for (i = 0; i < TST_TOTAL; i++) {
robbiewe7c06512003-01-02 16:00:05 +0000122
subrata_modak56207ce2009-03-23 13:35:39 +0000123 TEST(socketcall(TC[i].call, TC[i].args));
robbiewe7c06512003-01-02 16:00:05 +0000124
125 /* check return code */
126 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800127 tst_resm(TFAIL | TTERRNO,
128 "socketcall() Failed with"
129 " return=%ld", TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000130 } else {
131 tst_resm(TPASS, "socketcall() passed for"
subrata_modak923b23f2009-11-02 13:57:16 +0000132 " :%s with return=%ld ",
subrata_modak56207ce2009-03-23 13:35:39 +0000133 TC[i].desc, TEST_RETURN);
robbiewe7c06512003-01-02 16:00:05 +0000134 close(TEST_RETURN);
135 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800136 }
robbiewe7c06512003-01-02 16:00:05 +0000137 }
subrata_modak56207ce2009-03-23 13:35:39 +0000138
robbiewe7c06512003-01-02 16:00:05 +0000139 /* cleanup and exit */
140 cleanup();
141
Garrett Cooper2c282152010-12-16 00:55:50 -0800142 tst_exit();
143}
robbiewe7c06512003-01-02 16:00:05 +0000144
145/* setup() - performs all ONE TIME setup for this test. */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400146void setup(void)
robbiewe7c06512003-01-02 16:00:05 +0000147{
148
robbiewe7c06512003-01-02 16:00:05 +0000149 tst_sig(NOFORK, DEF_HANDLER, cleanup);
150
robbiewe7c06512003-01-02 16:00:05 +0000151 TEST_PAUSE;
152}
153
154/*
155 * cleanup() - performs all ONE TIME cleanup for this test at
156 * completion or premature exit.
157 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400158void cleanup(void)
robbiewe7c06512003-01-02 16:00:05 +0000159{
robbiewe7c06512003-01-02 16:00:05 +0000160}
robbiew32260282003-03-11 16:19:28 +0000161
162#else
163
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200164int TST_TOTAL = 0;
robbiew32260282003-03-11 16:19:28 +0000165
Mike Frysingerc57fba52014-04-09 18:56:30 -0400166int main(void)
robbiew32260282003-03-11 16:19:28 +0000167{
subrata_modak56207ce2009-03-23 13:35:39 +0000168 tst_resm(TPASS, "socket call test on this architecture disabled.");
169 tst_exit();
robbiew32260282003-03-11 16:19:28 +0000170}
171
Chris Dearmanec6edca2012-10-17 19:54:01 -0700172#endif