summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/sys/t_socketpair.c
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/sys/t_socketpair.c
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/sys/t_socketpair.c')
-rw-r--r--src/regress/lib/libc/sys/t_socketpair.c138
1 files changed, 0 insertions, 138 deletions
diff --git a/src/regress/lib/libc/sys/t_socketpair.c b/src/regress/lib/libc/sys/t_socketpair.c
deleted file mode 100644
index e24a166161..0000000000
--- a/src/regress/lib/libc/sys/t_socketpair.c
+++ /dev/null
@@ -1,138 +0,0 @@
1/* $OpenBSD: t_socketpair.c,v 1.2 2021/12/13 16:56:48 deraadt Exp $ */
2/* $NetBSD: t_socketpair.c,v 1.2 2017/01/13 20:04:52 christos Exp $ */
3
4/*-
5 * Copyright (c) 2011 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Christos Zoulas.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#include "macros.h"
41
42#include "atf-c.h"
43#include <fcntl.h>
44#include <unistd.h>
45#include <stdlib.h>
46#include <sys/socket.h>
47#include <sys/un.h>
48#include <errno.h>
49
50static void
51connected(int fd)
52{
53 struct sockaddr_un addr;
54 socklen_t len = (socklen_t)sizeof(addr);
55 ATF_REQUIRE(getpeername(fd, (struct sockaddr*)(void *)&addr,
56 &len) == 0);
57}
58
59static void
60run(int flags)
61{
62 int fd[2], i;
63
64 while ((i = open("/", O_RDONLY)) < 3)
65 ATF_REQUIRE(i != -1);
66
67 ATF_REQUIRE(closefrom(3) != -1);
68
69 ATF_REQUIRE(socketpair(AF_UNIX, SOCK_DGRAM | flags, 0, fd) == 0);
70
71 ATF_REQUIRE(fd[0] == 3);
72 ATF_REQUIRE(fd[1] == 4);
73
74 connected(fd[0]);
75 connected(fd[1]);
76
77 if (flags & SOCK_CLOEXEC) {
78 ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0);
79 ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) != 0);
80 } else {
81 ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) == 0);
82 ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) == 0);
83 }
84
85 if (flags & SOCK_NONBLOCK) {
86 ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) != 0);
87 ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) != 0);
88 } else {
89 ATF_REQUIRE((fcntl(fd[0], F_GETFL) & O_NONBLOCK) == 0);
90 ATF_REQUIRE((fcntl(fd[1], F_GETFL) & O_NONBLOCK) == 0);
91 }
92
93 ATF_REQUIRE(close(fd[0]) != -1);
94 ATF_REQUIRE(close(fd[1]) != -1);
95}
96
97ATF_TC(socketpair_basic);
98ATF_TC_HEAD(socketpair_basic, tc)
99{
100 atf_tc_set_md_var(tc, "descr", "A basic test of socketpair(2)");
101}
102
103ATF_TC_BODY(socketpair_basic, tc)
104{
105 run(0);
106}
107
108ATF_TC(socketpair_nonblock);
109ATF_TC_HEAD(socketpair_nonblock, tc)
110{
111 atf_tc_set_md_var(tc, "descr", "A non-blocking test of socketpair(2)");
112}
113
114ATF_TC_BODY(socketpair_nonblock, tc)
115{
116 run(SOCK_NONBLOCK);
117}
118
119ATF_TC(socketpair_cloexec);
120ATF_TC_HEAD(socketpair_cloexec, tc)
121{
122 atf_tc_set_md_var(tc, "descr", "A close-on-exec of socketpair(2)");
123}
124
125ATF_TC_BODY(socketpair_cloexec, tc)
126{
127 run(SOCK_CLOEXEC);
128}
129
130ATF_TP_ADD_TCS(tp)
131{
132
133 ATF_TP_ADD_TC(tp, socketpair_basic);
134 ATF_TP_ADD_TC(tp, socketpair_nonblock);
135 ATF_TP_ADD_TC(tp, socketpair_cloexec);
136
137 return atf_no_error();
138}