git: 6655bec4e268 - main - tests/unix_stream: test that send(2) of zero bytes is successful

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Sun, 14 Apr 2024 17:21:42 UTC
The branch main has been updated by glebius:

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

commit 6655bec4e268eeb779f5e57e5914761cf86b5f8a
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-04-14 17:19:20 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-04-14 17:19:20 +0000

    tests/unix_stream: test that send(2) of zero bytes is successful
    
    Put this simple test into an existing file.  We don't have a designated
    file for all unix/stream tests.  There is extensive unix_seqpacket_test,
    but (at least right now) unix/seqpacket is not a superset of unix/stream,
    but a different implementation.  We have one file that does one test for
    unix/stream - unix_socketpair_test.  So rename it to unix_stream and start
    collecting all unix/stream tests in it.
---
 ObsoleteFiles.inc                                  |  3 ++
 tests/sys/kern/Makefile                            |  2 +-
 .../kern/{unix_socketpair_test.c => unix_stream.c} | 32 ++++++++++++++++++----
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index e7d62afdd764..50f426085eff 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -51,6 +51,9 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20240414: unix_socketpair_test renamed
+OLD_FILES+=usr/tests/sys/kern/unix_socketpair_test
+
 # 20240406: new clang import which bumps version from 17 to 18
 OLD_FILES+=usr/lib/clang/17/include/__clang_cuda_builtin_vars.h
 OLD_FILES+=usr/lib/clang/17/include/__clang_cuda_cmath.h
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index bc42f53a2849..c5107ce8f9fe 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -50,7 +50,7 @@ ATF_TESTS_C+=	unix_passfd_stream
 TEST_METADATA.unix_passfd_stream+=	is_exclusive="true"
 ATF_TESTS_C+=	unix_seqpacket_test
 TEST_METADATA.unix_seqpacket_test+=	timeout="15"
-ATF_TESTS_C+=	unix_socketpair_test
+ATF_TESTS_C+=	unix_stream
 ATF_TESTS_C+=	waitpid_nohang
 ATF_TESTS_C+=	pdeathsig
 ATF_TESTS_C+=	sigsys
diff --git a/tests/sys/kern/unix_socketpair_test.c b/tests/sys/kern/unix_stream.c
similarity index 83%
rename from tests/sys/kern/unix_socketpair_test.c
rename to tests/sys/kern/unix_stream.c
index b994b791a2ed..d57cfad020fa 100644
--- a/tests/sys/kern/unix_socketpair_test.c
+++ b/tests/sys/kern/unix_stream.c
@@ -37,23 +37,30 @@
 
 #include <atf-c.h>
 
+static void
+do_socketpair(int *sv)
+{
+	int s;
+
+	s = socketpair(PF_LOCAL, SOCK_STREAM, 0, sv);
+	ATF_REQUIRE_EQ(0, s);
+	ATF_REQUIRE(sv[0] >= 0);
+	ATF_REQUIRE(sv[1] >= 0);
+	ATF_REQUIRE(sv[0] != sv[1]);
+}
+
 /* getpeereid(3) should work with stream sockets created via socketpair(2) */
 ATF_TC_WITHOUT_HEAD(getpeereid);
 ATF_TC_BODY(getpeereid, tc)
 {
 	int sv[2];
-	int s;
 	uid_t real_euid, euid;
 	gid_t real_egid, egid;
 
 	real_euid = geteuid();
 	real_egid = getegid();
 
-	s = socketpair(PF_LOCAL, SOCK_STREAM, 0, sv);
-	ATF_CHECK_EQ(0, s);
-	ATF_CHECK(sv[0] >= 0);
-	ATF_CHECK(sv[1] >= 0);
-	ATF_CHECK(sv[0] != sv[1]);
+	do_socketpair(sv);
 
 	ATF_REQUIRE_EQ(0, getpeereid(sv[0], &euid, &egid));
 	ATF_CHECK_EQ(real_euid, euid);
@@ -67,10 +74,23 @@ ATF_TC_BODY(getpeereid, tc)
 	close(sv[1]);
 }
 
+/* Sending zero bytes should succeed (once regressed in aba79b0f4a3f). */
+ATF_TC_WITHOUT_HEAD(send_0);
+ATF_TC_BODY(send_0, tc)
+{
+	int sv[2];
+
+	do_socketpair(sv);
+	ATF_REQUIRE(send(sv[0], sv, 0, 0) == 0);
+	close(sv[0]);
+	close(sv[1]);
+}
+
 
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, getpeereid);
+	ATF_TP_ADD_TC(tp, send_0);
 
 	return atf_no_error();
 }