Skip to content

testing/nettest: Add a TCP case with an answer after a half-close. - #4105

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:tcp-input-fixes-test-up
Nov 23, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:tcp-input-fixes-test-up

Conversation

@casaroli

@casaroli casaroli commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A new case of cmocka_net_tcp, test_tcp_halfclose_answer: over the loopback address, a client sends a 100-byte request, calls shutdown(SHUT_WR) and reads a 16 KiB answer to its end. The server reads the request to the end of file, sends the answer and closes. The client must get all the answer and then end of file within 10 s.

On NuttX master the client sends each segment of the answer back after its FIN, and the transfer never ends; apache/nuttx#22144 fixes it (its first fix). The other fixes of apache/nuttx#22144 have TUN cases (test_tun_tcp_ackahead, _wndedge, _synrto, _connect_sndtimeo); they build on the TUN test of #4101 and come when it merges.

Impact

Only testing/nettest/tcp: one new source file, built with CONFIG_NET_IPv4, and its lines in Makefile and CMakeLists.txt. No new Kconfig option. The case has its own listener on a free port: it does not use the loopback server of the group.

Testing

qemu-armv8a under HVF, TCP write buffers, NuttX master c51b1af1ee2:

NuttX master with apache/nuttx#22144
knsh, 4 CPUs the case does not end: the loopback work thread stays in one poll of the device with the device locked, and recv() of the client waits for that lock PASS
flat nsh, 1 CPU FAIL: 16344 of 16384 bytes, no end of file after 10 s PASS

All other cases of cmocka_net_tcp give the same result on both, except flat nsh test_tcp_reset_send, which fails on both (the SIGPIPE goes to another thread).

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

@cederom

cederom commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Points to raise:

  1. It only covers commit 1 and the ACK loop that commit 2 breaks. Nothing tests the first-SYN timing or the SO_SNDTIMEO connect. If apps#4101 covers those, link it from both PRs; if not, ask for a test.
  2. The testing/nettest: Fix select() of the loopback server. #4103 dependency is unclear. This case doesn't use nettest_tcpserver. Ask what exactly needs testing/nettest: Fix select() of the loopback server. #4103 (perhaps the group setup).
  3. On master it hangs nsh instead of failing. The ACK storm over the loopback device blocks the board. The PR has to stay a draft until 22144 has merged, or a CI run will stall instead of reporting a failure.
  4. Trivial: the time limit only compares tv_sec, so it can run up to about 11 s. Fine for a test.

Verdict: I'd ask for the window check in commit 2 before approving 22144. Everything else there is nits plus the Impact note. 4105 can be approved once the dependency question is answered and 22144 has merged.

test_tcp_halfclose_answer: over 127.0.0.1 the client sends 100 bytes
and calls shutdown(SHUT_WR); the server reads them and end-of-file, then
a thread sends a 16 KiB answer and closes the socket.  The client must
read the whole answer, in order, then end-of-file, within 10 seconds.
The case does not use the loopback server of the group.  It needs
CONFIG_NET_SOCKOPTS.

On nuttx master the client sends each segment of the answer back after
its FIN, and it does not get the end of the answer.  In a flat build
with one CPU the case fails after 10 s.  With 4 CPUs the loopback work
thread can stay in one poll of the device, with the device locked: then
recv() of the client waits for that lock, the case does not end and nsh
does not come back.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli force-pushed the tcp-input-fixes-test-up branch from fe99fc4 to afd955c Compare November 22, 2026 22:28
@casaroli

Copy link
Copy Markdown
Contributor Author
  1. The other fixes have TUN cases (test_tun_tcp_ackahead, _wndedge, _synrto, _connect_sndtimeo). They build on the TUN test of testing/nettest: Add a TCP case with a lossy peer on a TUN device. #4101 and come when it merges; both bodies now say so.
  2. Done: the case has its own listener and does not need testing/nettest: Fix select() of the loopback server. #4103.
  3. On master with 4 CPUs (knsh) the loopback work thread stays in one poll of the device and keeps the device locked. recv() of the client waits for that lock, so no time limit in the case can end it; the other three CPUs are idle. In a flat build with 1 CPU the case fails after 10 s. The PR stays a draft until #22144 merges.
  4. Done.

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli :-)

@casaroli
casaroli marked this pull request as ready for review November 23, 2026 12:02
@xiaoxiang781216
xiaoxiang781216 merged commit 2f111b1 into apache:master Nov 23, 2026
51 checks passed
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.

3 participants