]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
TCP unit tests: fix that ip.rterr stats are increased (some unit tests had no netif...
authorgoldsimon <goldsimon@gmx.de>
Sun, 25 Mar 2012 15:12:02 +0000 (17:12 +0200)
committergoldsimon <goldsimon@gmx.de>
Sun, 25 Mar 2012 15:12:02 +0000 (17:12 +0200)
test/unit/tcp/tcp_helper.c
test/unit/tcp/test_tcp.c
test/unit/tcp/test_tcp_oos.c

index cee94397207f1830dbd2178f0fdd52d1cfe0adaf..ff503db3df9d622723b06f8f4ed1f77b48f04a3f 100644 (file)
@@ -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);
index 6fd5be50683d71e00b099665a32460d5cbad57fa..81720984530614cad760185f807586a5740714d1 100644 (file)
@@ -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));
index 764de1c433dc7c9604ebeffe5ca4a76628b86944..612c4680b8084a2487136df03c1bbd87e80ca9b5 100644 (file)
@@ -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;