Fix two failing tests after ATF update

Since 4581cefc1e
ATF opens the results file on startup. This fixes problems like
capsicumized tests not being able to open the file on exit.

However, this test closes all file descriptors just to check that
socketpair returns fd 3+4 and thereby also closes the ATF results file.
This then results in an EBADF when writing the result so the test is
reported as broken.

While system calls that create new file descriptors (must?) use the lowest
available file descriptor number, it does not seem useful to test this
property here. Drop the check for FD==3/4 to unbreak the testsuite.

We could also try to re-open the results file in ATF if we get a EBADF
error, but that will fail when running under Capsicum.

Reviewed By:	cem
Differential Revision: https://reviews.freebsd.org/D28683
This commit is contained in:
Alex Richardson 2021-02-15 22:11:30 +00:00
parent 0482d7c9e9
commit 10fc4c3218
2 changed files with 23 additions and 6 deletions

View File

@ -53,17 +53,19 @@ run(int flags)
while ((i = open("/", O_RDONLY)) < 3)
ATF_REQUIRE(i != -1);
#ifdef __FreeBSD__
closefrom(3);
#else
#ifdef __NetBSD__
/* This check is harmful since it closes atf's output file */
ATF_REQUIRE_MSG(closefrom(3) != -1, "closefrom failed: %s",
strerror(errno));
#endif
ATF_REQUIRE(pipe2(fd, flags) == 0);
#ifdef __NetBSD__
/* This check is harmful since it requires closing atf's output file */
ATF_REQUIRE(fd[0] == 3);
ATF_REQUIRE(fd[1] == 4);
#endif
if (flags & O_CLOEXEC) {
ATF_REQUIRE((fcntl(fd[0], F_GETFD) & FD_CLOEXEC) != 0);

View File

@ -63,16 +63,18 @@ run(int domain, int type, int flags)
while ((i = open("/", O_RDONLY)) < 3)
ATF_REQUIRE(i != -1);
#ifdef __FreeBSD__
closefrom(3);
#else
#ifdef __NetBSD__
/* This check is harmful since it closes atf's output file */
ATF_REQUIRE(closefrom(3) != -1);
#endif
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[1] == 4);
#endif
connected(fd[0]);
connected(fd[1]);
@ -125,12 +127,25 @@ ATF_TC_BODY(null_sv, tc)
{
int fd;
#ifdef __NetBSD__
/* This check is harmful since it closes atf's output file */
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(EFAULT, errno);
fd = open("/", O_RDONLY);
#ifdef __NetBSD__
ATF_REQUIRE_EQ_MSG(fd, 3,
"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);