casaroli opened a new pull request, #4086:
URL: https://github.com/apache/nuttx-apps/pull/4086

   depends-on: apache/nuttx/pull/22025
   
   ## Summary
   
   This PR adds 5 cases to `cmocka_net_tcp` (`testing/nettest/tcp`, new file 
`test_tcp_close.c`) for the end of IPv4 TCP connections on the loopback 
address. They test the fixes of apache/nuttx#22025. Each case looks in 
`/proc/net/tcp` for the connections that it closed; these must be freed.
   
   - `test_tcp_close_shutdown_queued`: the client fills the window of the 
server and its own write queue with non-blocking `send()`, then calls 
`shutdown(SHUT_WR)`. The server must read every byte, in order, then EOF. 5 
rounds.
   - `test_tcp_close_shutdown_close`: the same, and the client closes its 
socket right after `shutdown()`. The server reads every byte and EOF, then 
resets the connection (`SO_LINGER` {1, 0}). Both connections must be freed 
within 3 s.
   - `test_tcp_close_netdown`: the client closes and waits for the server to 
close. The loopback device goes down and up (`SIOCSIFFLAGS`); 200 ms later the 
server resets the connection. The connection of the client must be freed within 
3 s: its close ends when the device goes down.
   - `test_tcp_close_unread`: both ends send to each other until neither takes 
more, then both close with data unread (RFC 1122, 4.2.2.13: a RST). Both 
connections must be freed within 3 s.
   - `test_tcp_close_timewait`: `CONFIG_NET_PREALLOC_DEVIF_CALLBACKS` / 3 + 1 
connections end in TIME_WAIT. Then a new client sends 16 KiB and closes at 
once: the server must read every byte, then EOF.
   
   `test_tcp_close_shutdown_close` and `test_tcp_close_netdown` need 
`CONFIG_NET_SOLINGER`; `test_tcp_close_netdown` also `CONFIG_NET_LOOPBACK`. 
Without `/proc/net/tcp` (`CONFIG_NET_STATISTICS`, procfs) the checks of the 
connection list pass. Every socket has a 10 s send and receive timeout, so a 
failing case does not hang the program. `test_tcp_close_unread` and 
`test_tcp_close_timewait` come last: on a kernel without the fixes their 
connections keep callbacks and buffers.
   
   ## Impact
   
   Test only: `cmocka_net_tcp` has 5 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.
   
   ## Testing
   
   qemu-armv8a under HVF, 1 CPU, TCP over the loopback device (`NET_IPv4`, 
`NET_TCP`, `NET_TCPBACKLOG`, `NET_LOOPBACK`, `NET_SOCKOPTS`, `NET_SOLINGER`, 
`NET_TCP_WRITE_BUFFERS`, `NET_STATISTICS` for `/proc/net/tcp`, 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.
   
   | Configuration | nuttx master fc8d354f9a1 | nuttx with apache/nuttx#22025 |
   |---|---|---|
   | qemu-armv8a:knsh, 3 runs in one boot | runs 1 and 2: the 5 new cases fail; 
run 3: `netdown`, `unread`, `timewait` (and `test_tcp_listen_again`) fail | 11 
passed in each run |
   | qemu-armv8a:nsh | the 5 new cases fail | 11 passed |
   | qemu-armv8a:knsh, dynamic connections (`NET_TCP_ALLOC_CONNS=1`) and 16 
callbacks, 3 runs | 4 of the 5 new cases fail in each run (`unread` passes: 
`close()` finds no callback and frees both connections at once) | run 1: 11 
passed; runs 2 and 3: `connect()` and `shutdown()` give `EBUSY` (see 
apache/nuttx#22025, "Not in this PR") |
   
   `test_tcp_connect_ipv4` fails in every run, on master too (see below).
   
   On master: `shutdown_queued` reads 32768 of 83132 bytes, then EOF; 
`shutdown_close` 30680 of 32764 bytes, then EOF; `netdown` leaves the 
connection of the client in `TCP_CLOSED` (state 00 in `/proc/net/tcp`); 
`unread` leaves both connections in ESTABLISHED with their unread data (after 
the program 8 of 64 IOBs are free on nsh); in `timewait` a `send()` of 512 
bytes returns -1. With this PR: no connection of the cases is left except the 
ones in TIME_WAIT, and all 64 IOBs are free after the program.
   
   `test_tcp_connect_ipv4` fails on master too, before these cases: its 
loopback server on `CONFIG_TESTING_NET_TCP_PORT` refuses the connection 
(`ECONNREFUSED`), and the group teardown then fails. Not changed by this PR.
   
   `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]

Reply via email to