Skip to content

Commit 952d3a5

Browse files
committed
testing/nettest: Add a TCP case with a lossy peer on a TUN device.
cmocka_net_tun plays a TCP peer on a TUN device. The link loses the first transmission of each segment: the peer opens a window of mss / 8 bytes, ignores a segment the first time and acknowledges it when it comes again. So each timeout of the server retransmits one segment, the peer acknowledges it, and the connection makes progress at each timeout. After TCP_MAXRTX + 2 such rounds the window opens. The server writes 8192 bytes in one send(): the case checks that each byte comes at its own sequence number, that the whole stream and the FIN come, and that the server does not reset the connection. The time limits come from CONFIG_NET_TCP_RTO. With TCP write buffers, NuttX freed a write buffer at its eighth retransmission, also when the peer had acknowledged a part of it at each timeout, and reset the connection at the next timeout. Data sent in between went out at the sequence numbers of the freed data. The case takes about 16 seconds. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent 6799fa3 commit 952d3a5

6 files changed

Lines changed: 917 additions & 0 deletions

File tree

‎testing/nettest/CMakeLists.txt‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,23 @@ if(CONFIG_TESTING_NET_TEST)
271271
${SRCS})
272272
endif()
273273

274+
if(CONFIG_TESTING_NET_TUN)
275+
set(SRCS ${CMAKE_CURRENT_LIST_DIR}/tun/test_tun.c
276+
${CMAKE_CURRENT_LIST_DIR}/tun/test_tun_tcp.c)
277+
278+
nuttx_add_application(
279+
NAME
280+
cmocka_net_tun
281+
PRIORITY
282+
${CONFIG_TESTING_NET_TEST_PRIORITY}
283+
STACKSIZE
284+
${CONFIG_TESTING_NET_TEST_STACKSIZE}
285+
MODULE
286+
${CONFIG_TESTING_NET_TEST}
287+
DEPENDS
288+
cmocka
289+
SRCS
290+
${SRCS})
291+
endif()
292+
274293
endif()

‎testing/nettest/Kconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,17 @@ config TESTING_NET_PKT
121121
lo comes back, and the reassembly timeout of an IPv4 fragment sent
122122
on lo does not stop the kernel (cmocka_net_pkt).
123123

124+
config TESTING_NET_TUN
125+
bool "Enable cmocka net TUN test"
126+
depends on NET_TUN && NET_TCP && NET_IPv4 && NET_TCPBACKLOG
127+
depends on NET_SOCKOPTS && !DISABLE_PTHREAD
128+
default y
129+
---help---
130+
Test TCP against a peer that the program plays on a TUN device
131+
(cmocka_net_tun). The link loses the first transmission of each
132+
segment, and the peer acknowledges each retransmission, so the
133+
connection makes progress at each timeout. The server must send
134+
the whole stream with each byte at its own sequence number, and
135+
must not reset the connection. The case takes about 30 seconds.
136+
124137
endif

‎testing/nettest/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,11 @@ PROGNAME += cmocka_net_pkt
134134
CSRCS += pkt/test_pkt_lo.c
135135
endif
136136

137+
ifeq ($(CONFIG_TESTING_NET_TUN),y)
138+
MAINSRC += tun/test_tun.c
139+
PROGNAME += cmocka_net_tun
140+
CSRCS += tun/test_tun_tcp.c
141+
endif
142+
137143
endif
138144
include $(APPDIR)/Application.mk

‎testing/nettest/tun/test_tun.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/****************************************************************************
2+
* apps/testing/nettest/tun/test_tun.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <setjmp.h>
28+
#include <stdarg.h>
29+
#include <stddef.h>
30+
#include <stdint.h>
31+
#include <cmocka.h>
32+
33+
#include "test_tun.h"
34+
35+
/****************************************************************************
36+
* Public Functions
37+
****************************************************************************/
38+
39+
int main(int argc, FAR char *argv[])
40+
{
41+
const struct CMUnitTest tun_tests[] =
42+
{
43+
cmocka_unit_test_setup_teardown(test_tun_tcp_lossy,
44+
test_tun_tcp_setup,
45+
test_tun_tcp_teardown),
46+
};
47+
48+
return cmocka_run_group_tests(tun_tests, NULL, NULL);
49+
}

‎testing/nettest/tun/test_tun.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/****************************************************************************
2+
* apps/testing/nettest/tun/test_tun.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __APPS_TESTING_NETTEST_TUN_TEST_TUN_H
24+
#define __APPS_TESTING_NETTEST_TUN_TEST_TUN_H
25+
26+
/****************************************************************************
27+
* Public Function Prototypes
28+
****************************************************************************/
29+
30+
/****************************************************************************
31+
* Name: test_tun_tcp_setup
32+
****************************************************************************/
33+
34+
int test_tun_tcp_setup(FAR void **state);
35+
36+
/****************************************************************************
37+
* Name: test_tun_tcp_teardown
38+
****************************************************************************/
39+
40+
int test_tun_tcp_teardown(FAR void **state);
41+
42+
/****************************************************************************
43+
* Name: test_tun_tcp_lossy
44+
****************************************************************************/
45+
46+
void test_tun_tcp_lossy(FAR void **state);
47+
48+
#endif /* __APPS_TESTING_NETTEST_TUN_TEST_TUN_H */

0 commit comments

Comments
 (0)