Changeset View
Changeset View
Standalone View
Standalone View
contrib/netbsd-tests/lib/libc/sys/t_socketpair.c
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
run(int domain, int type, int flags) | run(int domain, int type, int flags) | ||||
{ | { | ||||
int fd[2], i; | int fd[2], i; | ||||
while ((i = open("/", O_RDONLY)) < 3) | while ((i = open("/", O_RDONLY)) < 3) | ||||
ATF_REQUIRE(i != -1); | ATF_REQUIRE(i != -1); | ||||
#ifdef __FreeBSD__ | #ifdef __NetBSD__ | ||||
closefrom(3); | /* This check is harmful since it closes atf's output file */ | ||||
#else | |||||
ATF_REQUIRE(closefrom(3) != -1); | ATF_REQUIRE(closefrom(3) != -1); | ||||
#endif | #endif | ||||
ATF_REQUIRE(socketpair(domain, type | flags, 0, fd) == 0); | ATF_REQUIRE(socketpair(domain, type | flags, 0, fd) == 0); | ||||
#if __NetBSD__ | |||||
/* This check is harmful since it requires closing atf's output file */ | |||||
ATF_REQUIRE(fd[0] == 3); | ATF_REQUIRE(fd[0] == 3); | ||||
ATF_REQUIRE(fd[1] == 4); | ATF_REQUIRE(fd[1] == 4); | ||||
#endif | |||||
connected(fd[0]); | connected(fd[0]); | ||||
connected(fd[1]); | connected(fd[1]); | ||||
if (flags & SOCK_CLOEXEC) { | if (flags & SOCK_CLOEXEC) { | ||||
ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0); | ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0); | ||||
ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) != 0); | ATF_REQUIRE((fcntl(fd[1], F_GETFD) & FD_CLOEXEC) != 0); | ||||
} else { | } else { | ||||
Show All 36 Lines | ATF_TC_HEAD(null_sv, tc) | ||||
atf_tc_set_md_var(tc, "descr", | atf_tc_set_md_var(tc, "descr", | ||||
"socketpair(2) should fail without return storage"); | "socketpair(2) should fail without return storage"); | ||||
} | } | ||||
ATF_TC_BODY(null_sv, tc) | ATF_TC_BODY(null_sv, tc) | ||||
{ | { | ||||
int fd; | int fd; | ||||
#ifdef __NetBSD__ | |||||
/* This check is harmful since it closes atf's output file */ | |||||
closefrom(3); | closefrom(3); | ||||
#else | |||||
int lowfd = open("/", O_RDONLY); | |||||
ATF_REQUIRE(lowfd > 0); | |||||
ATF_REQUIRE_EQ(0, close(lowfd)); | |||||
#endif | |||||
ATF_REQUIRE_EQ(socketpair(AF_UNIX, SOCK_DGRAM, 0, NULL), -1); | ATF_REQUIRE_EQ(socketpair(AF_UNIX, SOCK_DGRAM, 0, NULL), -1); | ||||
ATF_REQUIRE_EQ(EFAULT, errno); | ATF_REQUIRE_EQ(EFAULT, errno); | ||||
fd = open("/", O_RDONLY); | fd = open("/", O_RDONLY); | ||||
#ifdef __NetBSD__ | |||||
ATF_REQUIRE_EQ_MSG(fd, 3, | ATF_REQUIRE_EQ_MSG(fd, 3, | ||||
"socketpair(..., NULL) allocated descriptors"); | "socketpair(..., NULL) allocated descriptors"); | ||||
#else | |||||
ATF_REQUIRE_EQ_MSG(fd, lowfd, | |||||
"socketpair(..., NULL) allocated descriptors: fd=%d, lowfd=%d", | |||||
fd, lowfd); | |||||
#endif | |||||
} | } | ||||
ATF_TC(socketpair_basic); | ATF_TC(socketpair_basic); | ||||
ATF_TC_HEAD(socketpair_basic, tc) | ATF_TC_HEAD(socketpair_basic, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "A basic test of socketpair(2)"); | atf_tc_set_md_var(tc, "descr", "A basic test of socketpair(2)"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |