Repository navigation
testing/nettest: Add a test of Unix domain datagram sockets. - #3964
Merged
Merged
Conversation
This was referenced Nov 3, 2026
No test in apps covers connect() and poll() of Unix domain datagram sockets. Add the cmocka test cmocka_net_local_dgram (CONFIG_TESTING_NET_LOCAL_DGRAM). It has 20 cases: - connect() sets the destination, connect(AF_UNSPEC) removes it and a second connect() changes it. - send(), write() and sendto() with a NULL address go to the destination. getpeername() gives its name. - A connected socket takes datagrams from its peer only. - poll() and select() report POLLIN and POLLOUT. poll() wakes up when a datagram arrives. A datagram that is too large causes no POLLHUP. - recv() with MSG_DONTWAIT or O_NONBLOCK fails with EAGAIN. - connect() to a missing name fails with ENOENT, connect() to a regular file with ECONNREFUSED. send() after the receiver is closed fails with ECONNREFUSED. - connect() and send() to an abstract name. A watchdog (alarm()) stops the program if a case does not end. The optional argument is a writable directory for the socket names. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
apps-local-dgram-test-up
branch
from
November 4, 2026 09:33
6830185 to
8e415df
Compare
xiaoxiang781216
previously approved these changes
Nov 5, 2026
Add to cmocka_net_local_dgram the cases that work without connect() and poll() of a datagram socket, so that a change to these sockets shows what it breaks. The datagram cases use neither connect() nor poll(): - bind() errors, getsockname(), sendto(), recv() and recvfrom(), datagram limits and order, short reads, datagrams with no data or too large, MSG_DONTWAIT, MSG_PEEK, sendmsg() and recvmsg(). - Stream sockets: names, connect(AF_UNSPEC), two threads that send on one socket, and POLLHUP. - Pipes and FIFOs: POLLHUP and POLLERR. The second optional argument of the program is a cmocka filter, to run some of the cases. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Add to cmocka_net_local_dgram: - connect() to an address with no name fails. - poll() reports only what is true and what the caller asks for: an unbound and a bound socket, POLLIN until the last datagram is read, short reads, MSG_PEEK, an array of descriptors, one socket twice, a dup() of a socket, an abstract name. - poll() wakes up for send() and sendto(), for a series of datagrams and in two threads at once. It keeps its timeout and ends with EINTR. - ppoll(), select() and pselect() with all sets, and epoll, also when a socket joins a set unbound or closes in a set. - Another thread calls bind() or connect() during a poll(). - A failed send and many poll() calls leave nothing behind. - Two senders and one receiver: each datagram comes out whole, once and in the order of its sender. - A FIFO with buffer policy 1 gives no POLLHUP when its last writer closes: each send to a datagram socket closes one. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Nov 5, 2026
casaroli
marked this pull request as ready for review
November 6, 2026 07:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
No test in nuttx-apps covers
connect()andpoll()of Unix domain datagram sockets. This PR adds the cmocka testcmocka_net_local_dgramtotesting/nettest/local(CONFIG_TESTING_NET_LOCAL_DGRAM), next tocmocka_net_local. It has 75 cases, so review is by commit:connect(),send(),getpeername(),poll()andselect().bind()errors,getsockname(),sendto(),recv(),recvfrom(), datagram limits and order, short reads,MSG_DONTWAIT,MSG_PEEK,sendmsg()andrecvmsg(); names,connect(AF_UNSPEC), two senders andPOLLHUPof stream sockets;POLLHUPandPOLLERRof pipes and FIFOs. The datagram cases of this commit use neitherconnect()norpoll(), and they pass on master.connect()andpoll()must do: an empty name; whatpoll()reports for unbound and bound sockets, until the last datagram is read, for an array, one socket twice, adup(); wake ups, timeout andEINTR;ppoll(),select(),pselect()and epoll;bind()andconnect()by another thread during apoll(); two senders and one receiver; noPOLLHUPfrom a FIFO with buffer policy 1.Each case makes its own sockets in its setup, so a failed case does not change the next one. A watchdog (
alarm()) stops the program when a case does not end. The first optional argument is a writable directory for the socket names (defaultP_tmpdir). The second is a cmocka filter, to run some of the cases.Impact
New test only,
default yunderTESTING_NET_TEST, asTESTING_NET_LOCALandTESTING_NET_OTHERS. It depends onNET_LOCAL && NET_LOCAL_DGRAM,!DISABLE_PTHREADand!DISABLE_POSIX_TIMERS. No defconfig enablesTESTING_NET_TEST, so no CI build changes. No change to the other nettest programs. The nettest page in Documentation/applications/testing describes the programs in general; no change.Testing
QEMU qemu-armv8a with HVF, 1 CPU, with
NET,NET_LOCAL,NET_LOCAL_STREAM,NET_LOCAL_DGRAM,PIPES,NETDEV_LATEINIT,NET_SOCKOPTS, the cmocka options andCONFIG_TESTING_NET_LOCAL_DGRAM=y. knsh runs the test as an ELF in/system/bin(names in/system), nsh (flat) as a builtin (names in/tmp). Each case ran alone through the filter, with apache/nuttx#21418 merged on the same master:cmocka_net_local_dgramon knsh (kernel)connect()andpoll()fail withENOSYS), 1 does not endcmocka_net_local_dgramon nsh (flat)The case that does not end on master is the one with two senders: it uses
poll(), so nothing reads and the senders stay blocked.mps2-an500:knsh (protected build, Cortex-M7, QEMU TCG, names in a tmpfs on
/tmp) on apache/nuttx#21418: 75 PASS, ostest status 0.Builds with
CONFIG_TESTING_NET_LOCAL_DGRAM=yandEXTRAFLAGS="-Wno-cpp -Werror"on apache/nuttx#21418, each OK, no warning in the test: qemu-armv8a:nsh (make and CMake), rv-virt:nsh64, mps2-an500:knsh (protected). qemu-armv8a:nsh withCONFIG_NET_LOCAL_DGRAMoff, also with apache/nuttx#21494, which fixes the build of the kernel in that case: the option is off and nothing of the test is built.All cases also ran on Linux, built with the host libc: each passes, so the expected results are not specific to this implementation. One case, policy 1 of a FIFO, is NuttX only and is skipped there.
tools/checkpatch.sh -c -u -m -gpasses.