Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Mar 2021 14:05:19 GMT
From:      Alex Richardson <arichardson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d97a4cb221d5 - stable/13 - Fix two failing tests after ATF update
Message-ID:  <202103171405.12HE5J1x086035@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=d97a4cb221d5f52a92473a4709aa97f812739f34

commit d97a4cb221d5f52a92473a4709aa97f812739f34
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-02-15 22:11:30 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-03-17 12:22:15 +0000

    Fix two failing tests after ATF update
    
    Since https://github.com/freebsd/atf/commit/4581cefc1e3811dd3c926b5dd4b15fd63d2e19da
    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
    
    (cherry picked from commit 10fc4c3218381fef7189a5b8d46a757cd1989dff)
---
 contrib/netbsd-tests/lib/libc/sys/t_pipe2.c      |  8 +++++---
 contrib/netbsd-tests/lib/libc/sys/t_socketpair.c | 21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c b/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c
index 48f973488c7a..1b62fa630fd5 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c
@@ -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);
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c b/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c
index 246b584d496a..165a42971d64 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103171405.12HE5J1x086035>