Ver Fonte

test: unit: tcp: fix tcp state tests to not break other tests

On platform where check cannot fork (win32), the tcp_state tests crashed other tests.

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
Simon Goldschmidt há 2 anos atrás
pai
commit
9672405eb9
1 ficheiros alterados com 14 adições e 3 exclusões
  1. 14 3
      test/unit/tcp/test_tcp_state.c

+ 14 - 3
test/unit/tcp/test_tcp_state.c

@@ -68,7 +68,9 @@ create_listening_pcb(u16_t local_port, struct test_tcp_counters *counters)
   return lpcb;
 }
 
-/* Setups/teardown functions */
+/* Setup/teardown functions */
+static struct netif* old_netif_list;
+static struct netif* old_netif_default;
 
 static void
 tcp_state_setup(void)
@@ -82,16 +84,25 @@ tcp_state_setup(void)
   tcp_ticks = 0;
 
   test_tcp_timer = 0;
-  /* initialize local vars */
-  test_tcp_init_netif(&test_netif, &test_txcounters, &test_local_ip, &test_netmask);
+
+  old_netif_list = netif_list;
+  old_netif_default = netif_default;
+  netif_list = NULL;
+  netif_default = NULL;
   tcp_remove_all();
+  test_tcp_init_netif(&test_netif, &test_txcounters, &test_local_ip, &test_netmask);
   lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
 }
 
 static void
 tcp_state_teardown(void)
 {
+  netif_list = NULL;
+  netif_default = NULL;
   tcp_remove_all();
+  /* restore netif_list for next tests (e.g. loopif) */
+  netif_list = old_netif_list;
+  netif_default = old_netif_default;
   lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
 }