Enable syscall tests for UNIX sockets

This commit is contained in:
Ruihan Li 2025-06-25 15:10:59 +08:00 committed by Jianfeng Jiang
parent bef9304c85
commit 079be2f30f
5 changed files with 62 additions and 1 deletions

View File

@ -371,9 +371,26 @@ impl Socket for UnixStreamSocket {
}
let MessageHeader {
control_message, ..
control_message,
addr,
} = message_header;
// According to the Linux man pages, `EISCONN` _may_ be returned when the destination
// address is specified for a connection-mode socket. In practice, `sendmsg` on UNIX stream
// sockets will fail due to that. We follow the same behavior as the Linux implementation.
if addr.is_some() {
match self.state.read().as_ref() {
State::Init(_) | State::Listen(_) => return_errno_with_message!(
Errno::EOPNOTSUPP,
"sending to a specific address is not allowed on UNIX stream sockets"
),
State::Connected(_) => return_errno_with_message!(
Errno::EISCONN,
"sending to a specific address is not allowed on UNIX stream sockets"
),
}
}
if control_message.is_some() {
// TODO: Support sending control message
warn!("sending control message is not supported");

View File

@ -340,6 +340,16 @@ FN_TEST(send)
TEST_ERRNO(send(sk_listen, buf, 0, 0), ENOTCONN);
TEST_ERRNO(write(sk_listen, buf, 1), ENOTCONN);
TEST_ERRNO(write(sk_listen, buf, 0), ENOTCONN);
TEST_ERRNO(sendto(sk_unbound, buf, 1, 0, &LISTEN_ADDR, LISTEN_ADDRLEN),
EOPNOTSUPP);
TEST_ERRNO(sendto(sk_bound, buf, 1, 0, &LISTEN_ADDR2, LISTEN_ADDRLEN2),
EOPNOTSUPP);
TEST_ERRNO(sendto(sk_listen, buf, 1, 0, &BOUND_ADDR, BOUND_ADDRLEN),
EOPNOTSUPP);
TEST_ERRNO(sendto(sk_accepted, buf, 1, 0, &UNNAMED_ADDR,
UNNAMED_ADDRLEN),
EISCONN);
}
END_TEST()

View File

@ -50,6 +50,8 @@ TESTS ?= \
sigaltstack_test \
signalfd_test \
socket_netlink_route_test \
socket_unix_pair_test \
socket_unix_stream_test \
stat_test \
stat_times_test \
statfs_test \

View File

@ -0,0 +1,27 @@
# TODO: Support `SOCK_SEQPACKET` sockets
AllUnixDomainSockets/UnixSocketPairTest.BindToBadName/*
AllUnixDomainSockets/UnixSocketPairTest.BindToBadFamily/*
AllUnixDomainSockets/*/4
AllUnixDomainSockets/*/5
AllUnixDomainSockets/*/10
AllUnixDomainSockets/*/11
# TODO: Support `SOCK_DGRAM` sockets
AllUnixDomainSockets/*/2
AllUnixDomainSockets/*/3
AllUnixDomainSockets/*/8
AllUnixDomainSockets/*/9
# TODO: Support the `recvmmsg` system call
AllUnixDomainSockets/UnixSocketPairTest.RecvmmsgTimeoutAfterRecv/*
# TODO: Support `ioctl` operations on sockets
AllUnixDomainSockets/UnixSocketPairTest.TIOCINQSucceeds/*
AllUnixDomainSockets/UnixSocketPairTest.TIOCOUTQSucceeds/*
AllUnixDomainSockets/UnixSocketPairTest.NetdeviceIoctlsSucceed/*
# TODO: Fix operations on `/proc/*/fd/*`
AllUnixDomainSockets/UnixSocketPairTest.SocketReopenFromProcfs/*
# TODO: Support control messages
AllUnixDomainSockets/UnixSocketPairCmsgTest.*

View File

@ -0,0 +1,5 @@
# TODO: Support the `SO_RCVTIMEO` socket option
AllUnixDomainSockets/StreamUnixSocketPairTest.RecvmsgOneSideClosed/*
# TODO: Support `ECONNRESET` errors on UNIX sockets
AllUnixDomainSockets/StreamUnixSocketPairTest.ReadOneSideClosedWithUnreadData/*