1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * Test Name: socketpair01
22 *
23 * Test Description:
24 * Verify that socketpair() returns the proper errno for various failure cases
25 *
26 * Usage: <for command-line>
27 * socketpair01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
28 * where, -c n : Run n copies concurrently.
29 * -e : Turn on errno logging.
30 * -i n : Execute test n times.
31 * -I x : Execute test for x seconds.
32 * -P x : Pause for x seconds between iterations.
33 * -t : Turn on syscall timing.
34 *
35 * History
36 * 07/2001 John George
37 * -Ported
38 *
39 * Restrictions:
40 * None.
41 *
42 */
43
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <errno.h>
47
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <sys/un.h>
51
52 #include <netinet/in.h>
53
54 #include "test.h"
55
56 char *TCID = "socketpair01";
57 int testno;
58
59 int sv[2];
60
61 void setup(void), cleanup(void);
62
63 struct test_case_t { /* test case structure */
64 int domain; /* PF_INET, PF_UNIX, ... */
65 int type; /* SOCK_STREAM, SOCK_DGRAM ... */
66 int proto; /* protocol number (usually 0 = default) */
67 int *sv; /* socket descriptor vector */
68 int retval; /* syscall return value */
69 int experrno; /* expected errno */
70 char *desc;
71 } tdat[] = {
72 {
73 0, SOCK_STREAM, 0, sv, -1, EAFNOSUPPORT, "invalid domain"}, {
74 PF_INET, 75, 0, sv, -1, EINVAL, "invalid type"}, {
75 PF_UNIX, SOCK_DGRAM, 0, sv, 0, 0, "UNIX domain dgram"}, {
76 PF_INET, SOCK_RAW, 0, sv, -1, ESOCKTNOSUPPORT,
77 "raw open as non-root"},
78 #ifndef UCLINUX
79 /* Skip since uClinux does not implement memory protection */
80 {
81 PF_UNIX, SOCK_STREAM, 0, 0, -1, EFAULT, "bad aligned pointer"}, {
82 PF_UNIX, SOCK_STREAM, 0, (int *)7, -1, EFAULT,
83 "bad unaligned pointer"},
84 #endif
85 {
86 PF_INET, SOCK_DGRAM, 17, sv, -1, EOPNOTSUPP, "UDP socket"}, {
87 PF_INET, SOCK_DGRAM, 6, sv, -1, ESOCKTNOSUPPORT, "TCP dgram"}, {
88 PF_INET, SOCK_STREAM, 6, sv, -1, EOPNOTSUPP, "TCP socket"}, {
89 PF_INET, SOCK_STREAM, 1, sv, -1, ESOCKTNOSUPPORT, "ICMP stream"},};
90
91 int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
92
main(int argc,char * argv[])93 int main(int argc, char *argv[])
94 {
95 int lc;
96 int s;
97
98 tst_parse_opts(argc, argv, NULL, NULL);
99
100 setup();
101
102 for (lc = 0; TEST_LOOPING(lc); ++lc) {
103 tst_count = 0;
104 for (testno = 0; testno < TST_TOTAL; ++testno) {
105 TEST((s = socketpair(tdat[testno].domain,
106 tdat[testno].type,
107 tdat[testno].proto,
108 tdat[testno].sv)));
109 if (TEST_RETURN >= 0) {
110 TEST_RETURN = 0; /* > 0 equivalent */
111 } else {
112 }
113 if (TEST_RETURN != tdat[testno].retval ||
114 (TEST_RETURN &&
115 (TEST_ERRNO != tdat[testno].experrno
116 && TEST_ERRNO != EPROTONOSUPPORT))) {
117 tst_resm(TFAIL,
118 "%s ; returned"
119 " %d (expected %d), errno %d (expected"
120 " %d)", tdat[testno].desc, s,
121 tdat[testno].retval, TEST_ERRNO,
122 tdat[testno].experrno);
123 } else {
124 tst_resm(TPASS, "%s successful",
125 tdat[testno].desc);
126 }
127 (void)close(s);
128 }
129 }
130
131 cleanup();
132
133 tst_exit();
134 }
135
setup(void)136 void setup(void)
137 {
138
139 TEST_PAUSE;
140 }
141
cleanup(void)142 void cleanup(void)
143 {
144 }
145