aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2025-09-28 14:49:31 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2025-09-28 14:49:31 +0000
commitaab45f2aeec803d37514b574010cb5e7cfba8249 (patch)
treed4f6e7daf38bc3ece018fea96eda610d15109593
parentc1d5fc4e0cfc63d23379457ac0b51c59c60b27c7 (diff)
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.
-rw-r--r--tests/sys/netlink/netlink_socket.c18
1 files 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);
}