4 #include "lwip/stats.h"
5 #include "tcp_helper.h"
7 #if !LWIP_STATS || !TCP_STATS || !MEMP_STATS
8 #error "This tests needs TCP- and MEMP-statistics enabled"
11 /* Setups/teardown functions */
28 /** Call tcp_new() and tcp_abort() and test memp stats */
29 START_TEST(test_tcp_new_abort
)
34 fail_unless(lwip_stats
.memp
[MEMP_TCP_PCB
].used
== 0);
37 fail_unless(pcb
!= NULL
);
39 fail_unless(lwip_stats
.memp
[MEMP_TCP_PCB
].used
== 1);
41 fail_unless(lwip_stats
.memp
[MEMP_TCP_PCB
].used
== 0);
46 /** Create an ESTABLISHED pcb and check if receive callback is called */
47 START_TEST(test_tcp_recv_inseq
)
49 struct test_tcp_counters counters
;
52 char data
[] = {1, 2, 3, 4};
53 struct ip_addr remote_ip
, local_ip
;
55 u16_t remote_port
= 0x100, local_port
= 0x101;
59 /* initialize local vars */
60 memset(&netif
, 0, sizeof(netif
));
61 IP4_ADDR(&local_ip
, 192, 168, 1, 1);
62 IP4_ADDR(&remote_ip
, 192, 168, 1, 2);
63 data_len
= sizeof(data
);
64 /* initialize counter struct */
65 memset(&counters
, 0, sizeof(counters
));
66 counters
.expected_data_len
= data_len
;
67 counters
.expected_data
= data
;
69 /* create and initialize the pcb */
70 pcb
= test_tcp_new_counters_pcb(&counters
);
71 EXPECT_RET(pcb
!= NULL
);
72 tcp_set_state(pcb
, ESTABLISHED
, &local_ip
, &remote_ip
, local_port
, remote_port
);
74 /* create a segment */
75 p
= tcp_create_rx_segment(pcb
, counters
.expected_data
, data_len
, 0, 0, 0);
78 /* pass the segment to tcp_input */
80 /* check if counters are as expected */
81 EXPECT(counters
.close_calls
== 0);
82 EXPECT(counters
.recv_calls
== 1);
83 EXPECT(counters
.recved_bytes
== data_len
);
84 EXPECT(counters
.err_calls
== 0);
87 /* make sure the pcb is freed */
88 EXPECT(lwip_stats
.memp
[MEMP_TCP_PCB
].used
== 1);
90 EXPECT(lwip_stats
.memp
[MEMP_TCP_PCB
].used
== 0);
95 /** Create the suite including all tests for this module */
103 return create_suite("TCP", tests
, sizeof(tests
)/sizeof(TFun
), tcp_setup
, tcp_teardown
);