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

   depends-on: apache/nuttx/pull/21667
   
   ## Summary
   
   This PR adds 5 cases to `cmocka_net_tcp` (`testing/nettest/tcp`, new file 
`test_tcp_bind_listen.c`) for `bind()` with `SO_REUSEADDR` and `listen()` of 
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 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_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 with `EINVAL`.
   
   The three `bind()` cases need `CONFIG_NET_SOCKOPTS`. A teardown closes the 
sockets that a failed case leaves open, so that the next cases have free 
connections. Every port comes from `bind()` to port 0, so the cases do not 
collide with the test server on `CONFIG_TESTING_NET_TCP_PORT`.
   
   ## Impact
   
   Test only. `cmocka_net_tcp` has 5 more cases when `CONFIG_NET_IPv4` is set. 
No new Kconfig option (`TESTING_NET_TCP` is default y, as before). No defconfig 
in nuttx sets `TESTING_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 and `TESTING_NET_TCP`. 
knsh: kernel build, the program from `/system/bin`. nsh: flat build, the 
program as a builtin.
   
   | Configuration | nuttx master 03aea786390 | nuttx with apache/nuttx#21667 |
   |---|---|---|
   | qemu-armv8a:knsh | 7 run, 3 passed, 4 failed | 7 run, 7 passed |
   | qemu-armv8a:nsh | 7 run, 3 passed, 4 failed | 7 run, 7 passed |
   
   On master, `test_tcp_bind_reuseaddr_listener` passes (the behaviour does not 
change) and the 4 other new cases fail: `bind()` with `SO_REUSEADDR` gives 
`EADDRINUSE` (timewait, connected), `listen()` again gives `EADDRINUSE`, 
`listen()` on a connected socket returns 0.
   
   On Linux (Fedora 44, kernel 7.2, gcc, cmocka 1.1.5, the same sources): the 5 
new cases pass. The existing `test_tcp_connect_ipv4` fails there because its 
loopback server calls `select()` with `tv_sec = -1` (`EINVAL` on Linux); not 
changed by this PR.
   
   CMake (Ninja) build of qemu-armv8a:nsh with `NET_IPv4`, `NET_TCP`, 
`NET_SOCKOPTS` and the test: OK, no compiler warning.
   
   `tools/checkpatch.sh -c -u -m -g origin/master..HEAD` 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