Skip to content

testing/nettest: Add a test of Unix domain datagram sockets. - #3964

Draft
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:apps-local-dgram-test-up
Draft

casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:apps-local-dgram-test-up

Conversation

@casaroli

@casaroli casaroli commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

No test in nuttx-apps covers connect() and poll() of Unix domain datagram sockets. This PR adds the cmocka test cmocka_net_local_dgram to testing/nettest/local (CONFIG_TESTING_NET_LOCAL_DGRAM), next to cmocka_net_local.

The 20 cases: connect() to a bound socket; getpeername(); send(), write() and sendto() with a NULL address go to the peer; poll(POLLIN) with no datagram, after a send and while a thread sends after 200 ms; no POLLHUP when a datagram is too large; poll(POLLOUT); select(); recv(MSG_DONTWAIT) and O_NONBLOCK on an empty socket (EAGAIN); a connected socket takes datagrams from its peer only; connect(AF_UNSPEC) removes the peer; a second connect() changes it; ENOENT for a missing name; ECONNREFUSED for a regular file and after the receiver is closed; an abstract name.

Each case makes its own sockets in its setup, so a failed case does not change the next one. A watchdog (alarm(), 10 s) stops the program when a case does not end. The optional argument is a writable directory for the socket names (default P_tmpdir).

depends-on: apache/nuttx/pull/21416

Impact

New test only, default y under TESTING_NET_TEST, as TESTING_NET_LOCAL and TESTING_NET_OTHERS. It depends on NET_LOCAL && NET_LOCAL_DGRAM, !DISABLE_PTHREAD and !DISABLE_POSIX_TIMERS. No defconfig enables TESTING_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 and CONFIG_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):

nuttx master 6569424cfa6 apache/nuttx#21416
cmocka_net_local_dgram on knsh (kernel) 2 PASS (dontwait, nonblock), 6 FAIL, 12 setup errors: connect() fails with ENOSYS 20/20 PASS
cmocka_net_local_dgram on nsh (flat) 2 PASS (dontwait, nonblock), 6 FAIL, 12 setup errors: connect() fails with ENOSYS 20/20 PASS
ostest on knsh and nsh status 0 status 0

mps2-an500:knsh (protected build, Cortex-M7, QEMU TCG, names in a tmpfs on /tmp) on apache/nuttx#21416: 20/20 PASS, ostest status 0.

Builds with CONFIG_TESTING_NET_LOCAL_DGRAM=y and EXTRAFLAGS="-Wno-cpp -Werror" on apache/nuttx#21416, each OK, no warning in the test: qemu-armv8a:nsh (make and CMake), rv-virt:nsh64, mps2-an500:knsh (protected). qemu-armv8a:nsh with CONFIG_NET_LOCAL_DGRAM off: the option is off and nothing of the test is built. On master the test also builds and runs; only the cases fail.

tools/checkpatch.sh -c -u -m -g passes.

Comment thread testing/nettest/Kconfig Resolved
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
casaroli force-pushed the apps-local-dgram-test-up branch from 6830185 to 8e415df Compare November 4, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants