From 3ad0f9a584106b85569c6366ef8117a664fd55f8 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Thu, 8 Feb 2024 09:00:23 -0800 Subject: [PATCH] tests/unix_passfd: add a comment for send_a_lot Explain why SOCK_DGRAM and SOCK_STREAM differ in this edge case. While here improve output in case of a failure. --- tests/sys/kern/unix_passfd_test.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c index 143ccd098583..74095859d899 100644 --- a/tests/sys/kern/unix_passfd_test.c +++ b/tests/sys/kern/unix_passfd_test.c @@ -657,11 +657,20 @@ ATF_TC_BODY(rights_creds_payload, tc) ATF_REQUIRE_MSG(len != -1 , "sendmsg failed: %s", strerror(errno)); #if TEST_PROTO == SOCK_STREAM ATF_REQUIRE_MSG((size_t)len < sendspace, - "sendmsg: %zd bytes sent", len); + "sendmsg: %zd bytes sent, expected < %lu", len, sendspace); #endif #if TEST_PROTO == SOCK_DGRAM + /* + * sendmsg(2) can't truncate datagrams, only recvmsg(2) can. There are + * two options for the kernel here: either accept the datagram with + * slight overcommit of the socket buffer space or return ENOBUFS for a + * datagram that is smaller or equal to the socket buffer space. Our + * implementation does overcommit. Explanation is simple: from our + * side we see space available, we have no idea that remote side has + * LOCAL_CREDS set. From our side we expect sendmsg(2) to succeed. + */ ATF_REQUIRE_MSG((size_t)len == sendspace, - "sendmsg: %zd bytes sent", len); + "sendmsg: %zd bytes sent, expected %lu", len, sendspace); #endif rlen = recvfd_payload(fd[1], &getfd, buf, len, CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + CMSG_SPACE(sizeof(int)), 0);