This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 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 4b69ad82d testing/nettest: Add a TCP_CORK case.
4b69ad82d is described below

commit 4b69ad82db426e1c73e0da65c99d9c53f762ef59
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 15:38:43 2026 +0100

    testing/nettest: Add a TCP_CORK case.
    
    test_tcp_cork in cmocka_net_tcp (IPv4 on the loopback address):
    setsockopt(TCP_CORK) takes 1 and 0, getsockopt() gives the value back,
    and a byte sent while the socket is corked reaches the peer when the
    cork is removed.  It needs CONFIG_NET_TCPPROTO_OPTIONS.
    
    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_bind_listen.c | 50 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)

diff --git a/testing/nettest/tcp/test_tcp.c b/testing/nettest/tcp/test_tcp.c
index 7f24e1bd0..e879736f9 100644
--- a/testing/nettest/tcp/test_tcp.c
+++ b/testing/nettest/tcp/test_tcp.c
@@ -100,6 +100,11 @@ int main(int argc, FAR char *argv[])
       cmocka_unit_test_setup_teardown(test_tcp_accept_rcvtimeo,
                                       test_tcp_bind_listen_setup,
                                       test_tcp_bind_listen_teardown),
+#    ifdef CONFIG_NET_TCPPROTO_OPTIONS
+      cmocka_unit_test_setup_teardown(test_tcp_cork,
+                                      test_tcp_bind_listen_setup,
+                                      test_tcp_bind_listen_teardown),
+#    endif
 #    ifdef CONFIG_NET_TCP_WRITE_BUFFERS
       cmocka_unit_test_setup_teardown(test_tcp_sndtimeo_iob,
                                       test_tcp_sndtimeo_setup,
diff --git a/testing/nettest/tcp/test_tcp.h b/testing/nettest/tcp/test_tcp.h
index ea3aa98cb..685680604 100644
--- a/testing/nettest/tcp/test_tcp.h
+++ b/testing/nettest/tcp/test_tcp.h
@@ -221,6 +221,14 @@ void test_tcp_accept_inherit(FAR void **state);
 
 void test_tcp_accept_rcvtimeo(FAR void **state);
 
+/****************************************************************************
+ * Name: test_tcp_cork
+ ****************************************************************************/
+
+#    ifdef CONFIG_NET_TCPPROTO_OPTIONS
+void test_tcp_cork(FAR void **state);
+#    endif
+
 #    ifdef CONFIG_NET_TCP_WRITE_BUFFERS
 /****************************************************************************
  * Name: test_tcp_sndtimeo_setup
diff --git a/testing/nettest/tcp/test_tcp_bind_listen.c 
b/testing/nettest/tcp/test_tcp_bind_listen.c
index 3a9f30066..b379197de 100644
--- a/testing/nettest/tcp/test_tcp_bind_listen.c
+++ b/testing/nettest/tcp/test_tcp_bind_listen.c
@@ -562,6 +562,56 @@ void test_tcp_accept_rcvtimeo(FAR void **state)
   assert_int_equal(err, EAGAIN);
   assert_in_range(ms, TEST_ACCEPT_TIMEO - 50, TEST_ACCEPT_LATE - 500);
 }
+
+/****************************************************************************
+ * Name: test_tcp_cork
+ *
+ * Description:
+ *   setsockopt(TCP_CORK) takes 1 and 0, and getsockopt() gives the value
+ *   back.  A byte sent while the socket is corked reaches the peer when
+ *   the cork is removed.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_TCPPROTO_OPTIONS
+void test_tcp_cork(FAR void **state)
+{
+  FAR struct tcp_bl_state_s *st = *state;
+  int client = tcp_bl_socket(st, 0, false);
+  in_port_t port;
+  socklen_t len;
+  int listener;
+  int server;
+  int value;
+  int on = 1;
+  int off = 0;
+  char c = 'c';
+
+  listener = tcp_bl_listener(st, false, 1, &port);
+  assert_int_equal(tcp_bl_connect(client, port), 0);
+  server = tcp_bl_accept(st, listener);
+
+  assert_return_code(setsockopt(client, IPPROTO_TCP, TCP_CORK, &on,
+                                sizeof(on)), errno);
+  len = sizeof(value);
+  assert_return_code(getsockopt(client, IPPROTO_TCP, TCP_CORK, &value,
+                                &len), errno);
+  assert_int_equal(value, 1);
+
+  assert_int_equal(send(client, &c, 1, 0), 1);
+  assert_return_code(setsockopt(client, IPPROTO_TCP, TCP_CORK, &off,
+                                sizeof(off)), errno);
+  len = sizeof(value);
+  assert_return_code(getsockopt(client, IPPROTO_TCP, TCP_CORK, &value,
+                                &len), errno);
+  assert_int_equal(value, 0);
+
+  tcp_bl_wait(server, POLLIN);
+  c = 0;
+  assert_int_equal(recv(server, &c, 1, 0), 1);
+  assert_int_equal(c, 'c');
+}
+#endif
 #endif /* CONFIG_NET_SOCKOPTS */
 
 /****************************************************************************

Reply via email to