This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 306f70951 testing/nettest: Add a TCP case for the RST of a closed
backlog.
306f70951 is described below
commit 306f7095187edcc62f9a86eb97c544dac8c1bbf3
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 15:37:05 2026 +0100
testing/nettest: Add a TCP case for the RST of a closed backlog.
test_tcp_backlog_close_reset in cmocka_net_tcp (IPv4 on the loopback
address): two clients connect to a listener of backlog 4 and nobody
accepts them. The listener closes. Then recv() of each client must
give ECONNRESET within 3 s: the connections that wait in the backlog of
a closed listener get a RST. Without the RST the clients wait for data
that never comes. 3 rounds. It needs CONFIG_NET_SOCKOPTS (SO_RCVTIMEO).
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
testing/nettest/tcp/test_tcp.c | 5 +++
testing/nettest/tcp/test_tcp.h | 8 +++++
testing/nettest/tcp/test_tcp_backlog.c | 65 +++++++++++++++++++++++++++++++++-
3 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/testing/nettest/tcp/test_tcp.c b/testing/nettest/tcp/test_tcp.c
index 28beed55d..7f24e1bd0 100644
--- a/testing/nettest/tcp/test_tcp.c
+++ b/testing/nettest/tcp/test_tcp.c
@@ -194,6 +194,11 @@ int main(int argc, FAR char *argv[])
test_tcp_epoll_teardown),
# endif
# ifdef CONFIG_NET_TCPBACKLOG
+# ifdef CONFIG_NET_SOCKOPTS
+ cmocka_unit_test_setup_teardown(test_tcp_backlog_close_reset,
+ test_tcp_backlog_setup,
+ test_tcp_backlog_teardown),
+# endif
# ifdef CONFIG_NET_SOLINGER
cmocka_unit_test_setup_teardown(test_tcp_backlog_relisten_rst,
test_tcp_backlog_setup,
diff --git a/testing/nettest/tcp/test_tcp.h b/testing/nettest/tcp/test_tcp.h
index 9559cd1c6..ea3aa98cb 100644
--- a/testing/nettest/tcp/test_tcp.h
+++ b/testing/nettest/tcp/test_tcp.h
@@ -521,6 +521,14 @@ int test_tcp_backlog_setup(FAR void **state);
int test_tcp_backlog_teardown(FAR void **state);
+/****************************************************************************
+ * Name: test_tcp_backlog_close_reset
+ ****************************************************************************/
+
+# ifdef CONFIG_NET_SOCKOPTS
+void test_tcp_backlog_close_reset(FAR void **state);
+# endif
+
/****************************************************************************
* Name: test_tcp_backlog_relisten_rst
****************************************************************************/
diff --git a/testing/nettest/tcp/test_tcp_backlog.c
b/testing/nettest/tcp/test_tcp_backlog.c
index e11ed1805..c489e55eb 100644
--- a/testing/nettest/tcp/test_tcp_backlog.c
+++ b/testing/nettest/tcp/test_tcp_backlog.c
@@ -23,7 +23,8 @@
/* The backlog of an IPv4 TCP listener on the loopback address: listen()
* again on a listener with connections that wait in its backlog, and the
* close of a listener while connections to it come in. The race cases
- * pass when all their rounds end.
+ * pass when all their rounds end. The connections that wait in the
+ * backlog of a closed listener get a RST.
*/
/****************************************************************************
@@ -47,6 +48,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <cmocka.h>
#include "test_tcp.h"
@@ -66,6 +68,9 @@
#define TCP_BACKLOG_RACES 50 /* Rounds of a race case */
#define TCP_BACKLOG_BUSY 2 /* Clients that keep the input busy */
#define TCP_BACKLOG_MAXRACE 6 /* Clients of one race round */
+#define TCP_BACKLOG_RESETS 3 /* Rounds of the reset case */
+#define TCP_BACKLOG_PENDING 2 /* Pending connections of the reset case */
+#define TCP_BACKLOG_RCVTMO 3 /* s, SO_RCVTIMEO of the reset case */
/****************************************************************************
* Private Types
@@ -489,6 +494,64 @@ int test_tcp_backlog_teardown(FAR void **state)
return 0;
}
+/****************************************************************************
+ * Name: test_tcp_backlog_close_reset
+ *
+ * Description:
+ * The close of a listener ends the connections that wait in its backlog
+ * with a RST: two clients connect to a listener of backlog 4 and nobody
+ * accepts them; the listener closes. Then recv() of each client must
+ * give ECONNRESET within TCP_BACKLOG_RCVTMO s (without the RST it waits
+ * for data that never comes). TCP_BACKLOG_RESETS rounds.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_SOCKOPTS
+void test_tcp_backlog_close_reset(FAR void **state)
+{
+ FAR struct tcp_backlog_state_s *st = *state;
+ int clients[TCP_BACKLOG_PENDING];
+ struct sockaddr_in addr;
+ struct timeval tv;
+ int listener;
+ int round;
+ char c;
+ int i;
+
+ for (round = 0; round < TCP_BACKLOG_RESETS; round++)
+ {
+ listener = tcp_backlog_keep(st, tcp_backlog_listen(&addr, 4));
+ for (i = 0; i < TCP_BACKLOG_PENDING; i++)
+ {
+ clients[i] = tcp_backlog_keep(st, socket(AF_INET,
+ SOCK_STREAM |
+ SOCK_CLOEXEC, 0));
+ assert_return_code(connect(clients[i],
+ (FAR struct sockaddr *)&addr,
+ sizeof(addr)), errno);
+
+ tv.tv_sec = TCP_BACKLOG_RCVTMO;
+ tv.tv_usec = 0;
+ assert_return_code(setsockopt(clients[i], SOL_SOCKET,
+ SO_RCVTIMEO, &tv, sizeof(tv)),
+ errno);
+ }
+
+ /* Let the listener put both connections in its backlog */
+
+ usleep(100 * 1000);
+ tcp_backlog_fd(st, listener);
+
+ for (i = 0; i < TCP_BACKLOG_PENDING; i++)
+ {
+ assert_int_equal(recv(clients[i], &c, 1, 0), -1);
+ assert_int_equal(errno, ECONNRESET);
+ tcp_backlog_fd(st, clients[i]);
+ }
+ }
+}
+#endif
+
/****************************************************************************
* Name: test_tcp_backlog_relisten_rst
*