Repository navigation
testing/nettest: Add TCP bind() and listen() cases - #4021
Merged
Merged
Conversation
Six cases in cmocka_net_tcp (IPv4 on the loopback address), with the rules of Linux: - test_tcp_bind_reuseaddr_timewait: a server closes first, so its connection stays in TIME_WAIT. bind() of the port fails with EADDRINUSE without SO_REUSEADDR and succeeds with it. - test_tcp_bind_reuseaddr_connected: a connection stays after its listener closed. bind() with SO_REUSEADDR succeeds only if the listener had SO_REUSEADDR too. - test_tcp_bind_reuseaddr_listener: bind() of the port of a listener fails with EADDRINUSE, also with SO_REUSEADDR. - test_tcp_accept_inherit: an accepted socket has the SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT values of its listener, and its MSS is not larger than TCP_MAXSEG of the listener. - test_tcp_listen_again: listen() on a listening socket returns 0, sets the new backlog and keeps the connection in the queue. - test_tcp_listen_connected: listen() on a connected socket fails with EINVAL. The three bind() cases and test_tcp_accept_inherit need CONFIG_NET_SOCKOPTS. Its TCP_MAXSEG check needs CONFIG_NET_TCPPROTO_OPTIONS and its TCP_KEEP* checks need CONFIG_NET_TCP_KEEPALIVE. A teardown closes the sockets that a failed case leaves open. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
apps-tcp-bind-listen-test-up
branch
from
November 11, 2026 08:55
57aec16 to
0efd6e0
Compare
xiaoxiang781216
approved these changes
Nov 11, 2026
casaroli
marked this pull request as ready for review
November 11, 2026 19:21
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s):
CI run: https://github.com/apache/nuttx-apps/actions/runs/43086412455 |
casaroli
marked this pull request as draft
November 12, 2026 14:09
casaroli
marked this pull request as ready for review
November 12, 2026 14:09
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s):
CI run: https://github.com/apache/nuttx-apps/actions/runs/43234342242 |
GUIDINGLI
approved these changes
Nov 13, 2026
casaroli
marked this pull request as draft
November 13, 2026 09:31
casaroli
marked this pull request as ready for review
November 13, 2026 09:31
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s):
CI run: https://github.com/apache/nuttx-apps/actions/runs/43401992847 |
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.
depends-on: /pull/4033
Summary
This PR adds 6 cases to
cmocka_net_tcp(testing/nettest/tcp, new filetest_tcp_bind_listen.c) forbind()withSO_REUSEADDR,listen()and the options of an accepted socket, for IPv4 TCP sockets on the loopback address. The expected results are the ones of Linux:test_tcp_bind_reuseaddr_timewait: a server closes its connection first, so the connection stays in TIME_WAIT.bind()of the port fails withEADDRINUSEwithoutSO_REUSEADDRand succeeds with it.test_tcp_bind_reuseaddr_connected: a connection stays after its listener closed.bind()withSO_REUSEADDRsucceeds only if the listener hadSO_REUSEADDRtoo.test_tcp_bind_reuseaddr_listener:bind()of the port of a listener fails withEADDRINUSE, also withSO_REUSEADDR.test_tcp_accept_inherit: the listener setsSO_KEEPALIVE,TCP_MAXSEG1000,TCP_KEEPIDLE,TCP_KEEPINTVLandTCP_KEEPCNT.getsockopt()on the accepted socket gives the sameSO_KEEPALIVEandTCP_KEEP*values, and an MSS of at most 1000.test_tcp_listen_again:listen()on a listening socket returns 0, sets the new backlog and keeps the connection in the queue.test_tcp_listen_connected:listen()on a connected or accepted socket fails withEINVAL.The three
bind()cases andtest_tcp_accept_inheritneedCONFIG_NET_SOCKOPTS; itsTCP_MAXSEGcheck needsCONFIG_NET_TCPPROTO_OPTIONSand itsTCP_KEEP*checks needCONFIG_NET_TCP_KEEPALIVE. A teardown closes the sockets that a failed case leaves open, so that the next cases have free connections. Every port comes frombind()to port 0, so the cases do not collide with the test server onCONFIG_TESTING_NET_TCP_PORT.Impact
Test only.
cmocka_net_tcphas 6 more cases whenCONFIG_NET_IPv4is set. No new Kconfig option (TESTING_NET_TCPis default y, as before). No defconfig in nuttx setsTESTING_NET_TEST, so CI does not run this test.Testing
qemu-armv8a, HVF, 1 CPU, with
NET_IPv4,NET_IPv6,NET_LOOPBACK,NET_TCP,NET_TCPBACKLOG,NET_SOCKOPTS, cmocka andTESTING_NET_TCP; "+KA" addsNET_TCP_WRITE_BUFFERS,NET_TCP_KEEPALIVE(withNET_TCPPROTO_OPTIONS) andNET_SOLINGER. knsh: kernel build, the program from/system/bin. nsh: flat build, the program as a builtin.On master,
test_tcp_bind_reuseaddr_listenerpasses (the behaviour does not change) and the 5 other new cases fail:bind()withSO_REUSEADDRgivesEADDRINUSE(timewait, connected),SO_KEEPALIVEof the accepted socket is 0 (accept inherit),listen()again givesEADDRINUSE,listen()on a connected socket returns 0.On Linux (Fedora 44, kernel 7.2, gcc, cmocka 1.1.5, the same sources, with and without the
TCP_MAXSEGandTCP_KEEP*checks): the 6 new cases pass. The existingtest_tcp_connect_ipv4fails there because its loopback server callsselect()withtv_sec = -1(EINVALon Linux); not changed by this PR.CMake (Ninja) build of qemu-armv8a:nsh with
NET_IPv4,NET_TCP,NET_SOCKOPTS,NET_TCP_KEEPALIVEand the test: OK, no compiler warning.tools/checkpatch.sh -c -u -m -g origin/master..HEADpasses.