casaroli opened a new pull request, #4087: URL: https://github.com/apache/nuttx-apps/pull/4087
depends-on: apache/nuttx/pull/22029 ## Summary This PR adds 6 cases to `cmocka_net_tcp` (`testing/nettest/tcp`, new file `test_tcp_reset.c`) for a reset of the peer on an IPv4 TCP connection over the loopback address. They test apache/nuttx#22029. The peer makes the reset: it closes its socket with data unread (RFC 1122, 4.2.2.13), which sends a RST on master too. - `test_tcp_reset_recv`: the data that came before the reset is read first (`recvmsg()` with two buffers; the first one takes all the data). Then `recv()` gives `ECONNRESET`, then end-of-file. - `test_tcp_reset_recv_wait`: a `recv()` that waits when the peer resets the connection gives `ECONNRESET`; the next one gives end-of-file. - `test_tcp_reset_recv_waitall`: a `recv()` with `MSG_WAITALL` that waits gives the 5 bytes that came before the reset. The next `recv()` gives `ECONNRESET`, the one after it end-of-file. - `test_tcp_reset_send`: `send()` gives `ECONNRESET`, then `EPIPE`; without `MSG_NOSIGNAL`, `EPIPE` comes with one `SIGPIPE`. - `test_tcp_reset_poll`: with 5 bytes unread, `poll()` gives `POLLIN`, `POLLHUP` and `POLLERR` (no `POLLOUT`); `SO_ERROR` gives `ECONNRESET`, then 0; then `poll()` gives `POLLIN` and `POLLHUP`, and `recv()` the 5 bytes, then end-of-file. - `test_tcp_reset_refused`: a non-blocking `connect()` to a port without a listener. The RST refuses the connection: `poll()` gives `POLLERR` and `SO_ERROR` gives `ECONNREFUSED`, not `ECONNRESET`. `test_tcp_reset_refused` needs `CONFIG_NET_SOCKOPTS`; without it `test_tcp_reset_poll` checks `recv()` instead of `SO_ERROR`, and the sockets have no timeouts. The `SIGPIPE` check needs signals (`!CONFIG_DISABLE_ALL_SIGNALS`). With `CONFIG_NET_SOCKOPTS` every socket has a 10 s send and receive timeout, so a failing case does not hang. ## Impact Test only: `cmocka_net_tcp` has 6 more cases when `CONFIG_NET_IPv4` is set. 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 after the IPv6 ones, so this PR and apache/nuttx-apps#4086 (which adds `test_tcp_close.c`) merge in either 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), the default pools (8 connections, 16 devif callbacks), cmocka with `TESTING_NET_TCP`. knsh: kernel build, the program from `/system/bin`. nsh: flat build, the program as a builtin. 2 runs of `cmocka_net_tcp` in one boot (3 on 4 CPUs); the result is the same in each run. | Configuration | nuttx master fc8d354f9a1 | nuttx with apache/nuttx#22029 | |---|---|---| | qemu-armv8a:knsh, 1 CPU | 5 of the 6 new cases fail (`refused` passes) | 6 pass | | qemu-armv8a:knsh, 4 CPUs, dynamic pools | not run | 6 pass | | qemu-armv8a:nsh | 5 fail | 6 pass | | qemu-armv8a:nsh without `NET_TCP_WRITE_BUFFERS` | not run | 6 pass | | qemu-armv8a:nsh without `NET_SOCKOPTS` (5 cases) | the 5 fail | 5 pass | | qemu-armv8a:knsh with apache/nuttx#22025 too | not run | 6 pass | On master: `recv` gets 0 (end-of-file) where it expects -1 `ECONNRESET`; `recv_wait` gets `ENOTCONN`; `recv_waitall` gets 0; `send` gets `EPIPE` at once; `poll` reads `SO_ERROR` `ECONNREFUSED`. `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. Without `NET_SOCKOPTS`, `cmocka_net_tcp` does not link on apps master: `test_tcp_connect_ipv4.c` and `utils/nettest_tcpserver.c` call `setsockopt()`, which needs `NET_SOCKOPTS`. That run used a local change that puts those two calls under `CONFIG_NET_SOCKOPTS`; it is not in this PR. `test_tcp_reset.c` itself builds without `NET_SOCKOPTS`. Builds with `-Werror`: sim:tcpblaster with the test in the NuttX CI image (gcc 12, x86_64), qemu-armv8a:knsh and :nsh on macOS (aarch64-none-elf gcc 14.2). `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]
