diff --git a/test/unit/tcp/tcp_helper.c b/test/unit/tcp/tcp_helper.c index cee94397..ff503db3 100644 --- a/test/unit/tcp/tcp_helper.c +++ b/test/unit/tcp/tcp_helper.c @@ -260,18 +260,21 @@ static err_t test_tcp_netif_output(struct netif *netif, struct pbuf *p, { struct test_tcp_txcounters *txcounters = (struct test_tcp_txcounters*)netif->state; LWIP_UNUSED_ARG(ipaddr); - txcounters->num_tx_calls++; - txcounters->num_tx_bytes += p->tot_len; - if (txcounters->copy_tx_packets) { - struct pbuf *p_copy = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); - err_t err; - EXPECT(p_copy != NULL); - err = pbuf_copy(p_copy, p); - EXPECT(err == ERR_OK); - if (txcounters->tx_packets == NULL) { - txcounters->tx_packets = p_copy; - } else { - pbuf_cat(txcounters->tx_packets, p_copy); + if (txcounters != NULL) + { + txcounters->num_tx_calls++; + txcounters->num_tx_bytes += p->tot_len; + if (txcounters->copy_tx_packets) { + struct pbuf *p_copy = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); + err_t err; + EXPECT(p_copy != NULL); + err = pbuf_copy(p_copy, p); + EXPECT(err == ERR_OK); + if (txcounters->tx_packets == NULL) { + txcounters->tx_packets = p_copy; + } else { + pbuf_cat(txcounters->tx_packets, p_copy); + } } } return ERR_OK; @@ -282,9 +285,11 @@ void test_tcp_init_netif(struct netif *netif, struct test_tcp_txcounters *txcoun { struct netif *n; memset(netif, 0, sizeof(struct netif)); - memset(txcounters, 0, sizeof(struct test_tcp_txcounters)); + if (txcounters != NULL) { + memset(txcounters, 0, sizeof(struct test_tcp_txcounters)); + netif->state = txcounters; + } netif->output = test_tcp_netif_output; - netif->state = txcounters; netif->flags |= NETIF_FLAG_UP; ip_addr_copy(netif->netmask, *netmask); ip_addr_copy(netif->ip_addr, *ip_addr); diff --git a/test/unit/tcp/test_tcp.c b/test/unit/tcp/test_tcp.c index 6fd5be50..81720984 100644 --- a/test/unit/tcp/test_tcp.c +++ b/test/unit/tcp/test_tcp.c @@ -45,8 +45,9 @@ tcp_setup(void) static void tcp_teardown(void) { - netif_list = NULL; tcp_remove_all(); + netif_list = NULL; + netif_default = NULL; } @@ -77,16 +78,19 @@ START_TEST(test_tcp_recv_inseq) struct tcp_pcb* pcb; struct pbuf* p; char data[] = {1, 2, 3, 4}; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t data_len; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; + struct test_tcp_txcounters txcounters; LWIP_UNUSED_ARG(_i); /* initialize local vars */ memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, &txcounters, &local_ip, &netmask); data_len = sizeof(data); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); diff --git a/test/unit/tcp/test_tcp_oos.c b/test/unit/tcp/test_tcp_oos.c index 764de1c4..612c4680 100644 --- a/test/unit/tcp/test_tcp_oos.c +++ b/test/unit/tcp/test_tcp_oos.c @@ -127,6 +127,8 @@ static void tcp_oos_teardown(void) { tcp_remove_all(); + netif_list = NULL; + netif_default = NULL; } @@ -146,7 +148,7 @@ START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ) 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t data_len; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; @@ -156,6 +158,8 @@ START_TEST(test_tcp_recv_ooseq_FIN_OOSEQ) memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, NULL, &local_ip, &netmask); data_len = sizeof(data); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); @@ -286,7 +290,7 @@ START_TEST(test_tcp_recv_ooseq_FIN_INSEQ) 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t data_len; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; @@ -296,6 +300,8 @@ START_TEST(test_tcp_recv_ooseq_FIN_INSEQ) memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, NULL, &local_ip, &netmask); data_len = sizeof(data); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); @@ -457,7 +463,7 @@ START_TEST(test_tcp_recv_ooseq_overrun_rxwin) struct test_tcp_counters counters; struct tcp_pcb* pcb; struct pbuf *pinseq, *p_ovr; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; int datalen = 0; @@ -471,6 +477,8 @@ START_TEST(test_tcp_recv_ooseq_overrun_rxwin) memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, NULL, &local_ip, &netmask); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); counters.expected_data_len = TCP_WND; @@ -547,7 +555,7 @@ START_TEST(test_tcp_recv_ooseq_max_bytes) struct test_tcp_counters counters; struct tcp_pcb* pcb; struct pbuf *p_ovr; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; int datalen = 0; @@ -561,6 +569,8 @@ START_TEST(test_tcp_recv_ooseq_max_bytes) memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, NULL, &local_ip, &netmask); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); counters.expected_data_len = TCP_WND; @@ -626,7 +636,7 @@ START_TEST(test_tcp_recv_ooseq_max_pbufs) struct test_tcp_counters counters; struct tcp_pcb* pcb; struct pbuf *p_ovr; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; int datalen = 0; @@ -640,6 +650,8 @@ START_TEST(test_tcp_recv_ooseq_max_pbufs) memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, NULL, &local_ip, &netmask); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); counters.expected_data_len = TCP_WND; @@ -727,7 +739,7 @@ static void test_tcp_recv_ooseq_double_FINs(int delay_packet) struct test_tcp_counters counters; struct tcp_pcb* pcb; struct pbuf *p_normal_fin, *p_data_after_fin, *p, *p_2nd_fin_ooseq; - ip_addr_t remote_ip, local_ip; + ip_addr_t remote_ip, local_ip, netmask; u16_t remote_port = 0x100, local_port = 0x101; struct netif netif; u32_t exp_rx_calls = 0, exp_rx_bytes = 0, exp_close_calls = 0, exp_oos_pbufs = 0, exp_oos_tcplen = 0; @@ -742,6 +754,8 @@ static void test_tcp_recv_ooseq_double_FINs(int delay_packet) memset(&netif, 0, sizeof(netif)); IP4_ADDR(&local_ip, 192, 168, 1, 1); IP4_ADDR(&remote_ip, 192, 168, 1, 2); + IP4_ADDR(&netmask, 255, 255, 255, 0); + test_tcp_init_netif(&netif, NULL, &local_ip, &netmask); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); counters.expected_data_len = TCP_WND;