casaroli opened a new pull request, #4095:
URL: https://github.com/apache/nuttx-apps/pull/4095
depends-on: apache/nuttx/pull/22077
## Summary
This PR adds 8 cases to `cmocka_net_tcp` (`testing/nettest/tcp`, new file
`test_tcp_closewait.c`) for a peer that closes (FIN) or resets (RST) an IPv4
TCP connection over the loopback address before `accept()` or `connect()`
returns. They test apache/nuttx#22077. The expected results are the ones of
Linux (checked with a host program on Linux 7.2).
- `test_tcp_closewait_accept_data`: the client connects, sends 5 bytes and
closes before `accept()`. `accept()` succeeds, `recv()` gives the 5 bytes, then
end-of-file.
- `test_tcp_closewait_accept`: the same without data: `recv()` gives
end-of-file.
- `test_tcp_closewait_accept_half`: the client only shuts down its writing
side. `recv()` on the accepted socket gives end-of-file, and a `send()` from it
reaches the client.
- `test_tcp_closewait_connect`: the server accepts and closes at once,
before the `connect()` of the client returns. `connect()` succeeds, `recv()`
gives end-of-file.
- `test_tcp_closewait_rst_accept`: the client resets the connection to an
`accept()` that waits, before `accept()` returns. `accept()` succeeds, `recv()`
gives `ECONNRESET`, then end-of-file, and `send()` gives `EPIPE`.
- `test_tcp_closewait_rst_accept_data`: the same with 5 bytes before the
RST: `recv()` gives the 5 bytes, `SO_ERROR` gives `ECONNRESET` (without
`CONFIG_NET_SOCKOPTS`: `recv()`), then `recv()` gives end-of-file.
- `test_tcp_closewait_rst_connect`: the server accepts and resets the
connection before the `connect()` of the client returns. `connect()` fails with
`ECONNRESET`, `recv()` gives `ENOTCONN` and `SO_ERROR` is 0.
- `test_tcp_closewait_rst_race`: 20 rounds of a reset 0 to 4 ms after
`connect()`, around the return of `accept()`. `accept()` succeeds, and after
the RST `send()` fails with `ECONNRESET` or `EPIPE`.
The reset cases need `CONFIG_NET_SOLINGER`: a close with `SO_LINGER` {1, 0}
makes the RST. The cases that need one thread to run before the other run the
two threads at two priorities, on one CPU with `CONFIG_SMP`. With
`CONFIG_NET_SOCKOPTS` the sockets of the cases have a 10 s send and receive
timeout, so a failing case does not hang.
## Impact
Test only: `cmocka_net_tcp` has 8 more cases when `CONFIG_NET_IPv4` is set
(4 of them need `CONFIG_NET_SOLINGER`). No new Kconfig option. No defconfig in
nuttx sets `TESTING_NET_TEST`, so CI does not run this test.
The new lines in `test_tcp.c`, `test_tcp.h`, `Makefile` and `CMakeLists.txt`
are in their own `CONFIG_NET_IPv4` blocks, so this PR, apache/nuttx-apps#4086
and apache/nuttx-apps#4087 merge in any order without a conflict (checked with
`git merge-tree`).
## Testing
qemu-armv8a under HVF, TCP over the loopback device (`NET_IPv4`, `NET_TCP`,
`NET_TCPBACKLOG`, `NET_LOOPBACK`, `NET_SOCKOPTS`, `NET_SOLINGER`,
`NET_TCP_WRITE_BUFFERS`, 64 IOBs), cmocka with `TESTING_NET_TCP`; the default
pools (8 connections, 16 devif callbacks) unless "dynamic". knsh: kernel build,
the program from `/system/bin`. nsh: flat build, the program as a builtin. 2
runs of `cmocka_net_tcp` per boot; the result is the same in each run.
| Configuration | nuttx master 84abb4756d3 | nuttx with apache/nuttx#22077 |
|---|---|---|
| qemu-armv8a:knsh, 1 CPU | the 8 new cases fail | 8 pass |
| qemu-armv8a:knsh, 1 CPU, dynamic pools | not run | 8 pass |
| qemu-armv8a:nsh (flat) | the 8 new cases fail | 8 pass |
| qemu-armv8a:knsh, 4 CPUs | an assertion of the close path
(`tcp_conn.c:820`) in the first run | 8 pass |
| qemu-armv8a:knsh, 4 CPUs, with apache/nuttx#22025, 4 runs | #22025 alone:
7 of 8 fail | 8 pass in each run |
On master: `accept()` and `connect()` give `ENOTCONN` in the `accept*`,
`connect`, `rst_accept` and `rst_race` cases; `rst_connect` gets `ENOTCONN`
instead of `ECONNRESET`; in `rst_accept_data` the last `recv()` gives `EAGAIN`
(the socket still looks connected) instead of end-of-file.
`test_tcp_connect_ipv4` (an older case) fails in every run, on master too:
its loopback server refuses the connection (`ECONNREFUSED`), and the group
teardown then fails. Not changed by this PR.
The expected results were checked on Linux 7.2 (Fedora 44, x86_64) with a
host program that makes the same events: `accept()` gives the socket after a
RST, `recv()` gives `ECONNRESET` once (after the data that came first), then 0,
and `send()` `EPIPE`; `connect()` gives `ECONNRESET` (the client stopped with
`SIGSTOP` in `connect()` while the RST came, over a loopback device with a 200
ms delay), then `recv()` `ENOTCONN` and `SO_ERROR` 0; after a FIN `accept()`
and `connect()` succeed and `recv()` gives 0.
Builds: qemu-armv8a:knsh and :nsh on macOS (aarch64-none-elf gcc 14.2), 1
and 4 CPUs: no compiler warning.
`tools/checkpatch.sh -c -u -m -g` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]