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.
This commit is contained in:
Gleb Smirnoff 2024-04-14 10:19:20 -07:00
parent eac87a7a7e
commit 6655bec4e2
3 changed files with 30 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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();
}