The branch main has been updated by glebius:

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

commit aab45f2aeec803d37514b574010cb5e7cfba8249
Author:     Gleb Smirnoff <[email protected]>
AuthorDate: 2025-09-28 14:49:31 +0000
Commit:     Gleb Smirnoff <[email protected]>
CommitDate: 2025-09-28 14:49:31 +0000

    tests/netlink: fix flaky netlink_sockets:sizes
    
    The problem is that fullsocket() creates a socket that has both send and
    receive buffers full and as we process messages from the receive buffer we
    allow the kernel to continue processing of the send buffer and a new
    message may arrive while the test expects that no new messages arrive.
    Fix that by creating a socket that has several messages in the receive
    buffer, but don't have any in the send buffer.
---
 tests/sys/netlink/netlink_socket.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/tests/sys/netlink/netlink_socket.c 
b/tests/sys/netlink/netlink_socket.c
index 3c2c5f857591..cee864bb9bab 100644
--- a/tests/sys/netlink/netlink_socket.c
+++ b/tests/sys/netlink/netlink_socket.c
@@ -211,9 +211,22 @@ ATF_TC_BODY(sizes, tc)
                .msg_controllen = sizeof(cbuf),
        };
        ssize_t ss;
-       int fd, size, rsize;
+       int fd, size, msize, rsize;
 
-       fd = fullsocket();
+       /*
+        * Create a socket with NMSGS messages in the receive buffer.
+        */
+#define        NMSGS 5
+       ATF_REQUIRE((fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) != -1);
+       ATF_REQUIRE(send(fd, &hdr, sizeof(hdr), 0) == sizeof(hdr));
+       ATF_REQUIRE(recv(fd, buf, sizeof(hdr), MSG_WAITALL | MSG_PEEK) ==
+           sizeof(hdr));
+       ATF_REQUIRE(ioctl(fd, FIONREAD, &msize) != -1);
+       for (u_int i = 0; i < NMSGS; i++)
+               ATF_REQUIRE(send(fd, &hdr, sizeof(hdr), 0) == sizeof(hdr));
+       do {
+               ATF_REQUIRE(ioctl(fd, FIONREAD, &rsize) != -1);
+       } while (rsize < msize * (NMSGS + 1));
 
        /*
         * Set NETLINK_MSG_INFO, so that later cmsg_check will check that any
@@ -264,6 +277,7 @@ ATF_TC_BODY(sizes, tc)
                .iov_len = sizeof(buf) < rsize ? sizeof(buf) : rsize,
        };
        ss = recvmsg(fd, &msg, 0);
+       ATF_REQUIRE(ss > hdr.nlmsg_len);
        ATF_REQUIRE(ss > NLMSG_LARGE * 9 || ss == rsize);
        cmsg_check(&msg);
 }

Reply via email to