blob: 0be1c53b7f58376d49fd28c0d59b06530ac82e5c [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 : socketcall02
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 : Error test for socketcall(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 * verify socketcall(2) returns -1 and sets errno
35 * appropriately if argument passed is invalid.
subrata_modakbdbaec52009-02-26 12:14:51 +000036 *
37 *
subrata_modak56207ce2009-03-23 13:35:39 +000038 * Setup:
robbiewe7c06512003-01-02 16:00:05 +000039 * Setup signal handling.
40 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
subrata_modak56207ce2009-03-23 13:35:39 +000042 * Test:
43 * Loop if the proper option is given.
44 * Execute system call.
45 * Check return code, If system call failed (return == -1) &&
46 * (errno set == expected errno)
47 * Issue sys call pass with expected error
48 * otherwise
49 * Issue sys call fails with unexpected error
subrata_modak4bb656a2009-02-26 12:02:09 +000050 *
subrata_modak56207ce2009-03-23 13:35:39 +000051 * Cleanup:
52 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
robbiewe7c06512003-01-02 16:00:05 +000054 * USAGE: <for command-line>
55 * socketcall02 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
56 * where, -c n : Run n copies concurrently
subrata_modak56207ce2009-03-23 13:35:39 +000057 * -e : Turn on errno logging.
robbiewe7c06512003-01-02 16:00:05 +000058 * -h : Show this help screen
59 * -i n : Execute test n times.
60 * -I x : Execute test for x seconds.
61 * -p : Pause for SIGUSR1 before starting
subrata_modak56207ce2009-03-23 13:35:39 +000062 * -P x : Pause for x seconds between iterations.
63 * -t : Turn on syscall timing.
robbiewe7c06512003-01-02 16:00:05 +000064 *
65 * RESTRICTIONS
66 * None
67 *****************************************************************************/
vapiere0ccc7d2006-02-24 02:15:00 +000068#include <stdio.h>
69#include <stdlib.h>
robbiewe7c06512003-01-02 16:00:05 +000070#include <errno.h>
vapiere0ccc7d2006-02-24 02:15:00 +000071#include <sys/syscall.h>
72#include <unistd.h>
robbiewe7c06512003-01-02 16:00:05 +000073#include <sys/types.h>
74#include <sys/socket.h>
75#include <linux/net.h>
vapiere0ccc7d2006-02-24 02:15:00 +000076#include <sys/un.h>
77#include <netinet/in.h>
robbiewafd48432004-03-15 21:04:43 +000078
robbiewe7c06512003-01-02 16:00:05 +000079#include "test.h"
robbiew32260282003-03-11 16:19:28 +000080
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020081char *TCID = "socketcall02";
robbiew32260282003-03-11 16:19:28 +000082
83#ifdef __NR_socketcall
84
vapiere0ccc7d2006-02-24 02:15:00 +000085#define socketcall(call, args) syscall(__NR_socketcall, call, args)
robbiewe7c06512003-01-02 16:00:05 +000086
87void setup();
88void cleanup();
89
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020090int TST_TOTAL = 1;
robbiewe7c06512003-01-02 16:00:05 +000091
92struct test_case_t {
93 int call;
94 unsigned long args[3];
95 int retval;
96 int experrno;
97 char *desc;
subrata_modak56207ce2009-03-23 13:35:39 +000098} TC = {
99 -1, {
100PF_INET, SOCK_STREAM, 0}, -1, EINVAL, "invalid call"};
robbiewe7c06512003-01-02 16:00:05 +0000101
102int 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
subrata_modak56207ce2009-03-23 13:35:39 +0000118 TEST(socketcall(TC.call, TC.args));
robbiewe7c06512003-01-02 16:00:05 +0000119
robbiewe7c06512003-01-02 16:00:05 +0000120 /* check return code */
subrata_modak56207ce2009-03-23 13:35:39 +0000121 if ((TEST_RETURN == -1)
122 && (TEST_ERRNO == TC.experrno)) {
123 tst_resm(TPASS, "socketcall() failed"
124 " as expected for %s", TC.desc);
robbiewe7c06512003-01-02 16:00:05 +0000125 } else {
Garrett Cooper53740502010-12-16 00:04:01 -0800126 tst_brkm(TFAIL, NULL, "socketcall()"
subrata_modak56207ce2009-03-23 13:35:39 +0000127 " Failed with wrong experrno"
128 " =%d got: errno=%d : %s",
129 TC.experrno, TEST_ERRNO, strerror(TEST_ERRNO));
robbiewe7c06512003-01-02 16:00:05 +0000130 }
131 }
132
133 /* cleanup and exit */
134 cleanup();
135
Garrett Cooper2c282152010-12-16 00:55:50 -0800136 tst_exit();
137}
robbiewe7c06512003-01-02 16:00:05 +0000138
139/* setup() - performs all ONE TIME setup for this test. */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400140void setup(void)
robbiewe7c06512003-01-02 16:00:05 +0000141{
142
robbiewe7c06512003-01-02 16:00:05 +0000143 tst_sig(NOFORK, DEF_HANDLER, cleanup);
144
robbiewe7c06512003-01-02 16:00:05 +0000145 TEST_PAUSE;
146}
147
148/*
149 * cleanup() - performs all ONE TIME cleanup for this test at
150 * completion or premature exit.
151 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400152void cleanup(void)
robbiewe7c06512003-01-02 16:00:05 +0000153{
robbiewe7c06512003-01-02 16:00:05 +0000154}
robbiew32260282003-03-11 16:19:28 +0000155
156#else
157
Cyril Hrubisfdce7d52013-04-04 18:35:48 +0200158int TST_TOTAL = 0;
robbiew32260282003-03-11 16:19:28 +0000159
Mike Frysingerc57fba52014-04-09 18:56:30 -0400160int main(void)
robbiew32260282003-03-11 16:19:28 +0000161{
subrata_modak56207ce2009-03-23 13:35:39 +0000162 tst_resm(TPASS, "socket call test on this architecture disabled.");
163 tst_exit();
robbiew32260282003-03-11 16:19:28 +0000164}
165
Chris Dearmanec6edca2012-10-17 19:54:01 -0700166#endif