Skip to content

Commit cab1b35

Browse files
david-cermakespressif-bot
authored andcommitted
esp_netif: Add unit test to exercise default wifi setup/teardown cycle
1 parent 4051922 commit cab1b35

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

components/esp_netif/test/test_esp_netif.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,42 @@ TEST_CASE("esp_netif: convert ip address from string", "[esp_netif]")
310310
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_netif_str_to_ip6(NULL, &ipv6));
311311
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_netif_str_to_ip6(ipv6_src[0], NULL));
312312
}
313+
314+
TEST_CASE("esp_netif: create and destroy default wifi interfaces", "[esp_netif][leaks=0]")
315+
{
316+
// Helper constants to refer default STA and AP's params
317+
static const esp_netif_inherent_config_t default_sta_cfg = ESP_NETIF_INHERENT_DEFAULT_WIFI_STA();
318+
static const esp_netif_inherent_config_t default_ap_cfg = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
319+
320+
// create default station
321+
esp_netif_t *sta = esp_netif_create_default_wifi_sta();
322+
323+
// check it gets created and has default params
324+
TEST_ASSERT_NOT_NULL(sta);
325+
TEST_ASSERT_EQUAL_STRING(default_sta_cfg.if_desc, esp_netif_get_desc(sta));
326+
TEST_ASSERT_EQUAL(default_sta_cfg.route_prio, esp_netif_get_route_prio(sta));
327+
328+
// create default access point
329+
esp_netif_t *ap = esp_netif_create_default_wifi_ap();
330+
331+
// check it gets created and has default params
332+
TEST_ASSERT_NOT_NULL(ap);
333+
TEST_ASSERT_EQUAL_STRING(default_ap_cfg.if_desc, esp_netif_get_desc(ap));
334+
TEST_ASSERT_EQUAL(default_ap_cfg.route_prio, esp_netif_get_route_prio(ap));
335+
336+
// destroy the station
337+
esp_wifi_clear_default_wifi_driver_and_handlers(sta);
338+
esp_netif_destroy(sta);
339+
340+
// destroy the AP
341+
esp_wifi_clear_default_wifi_driver_and_handlers(ap);
342+
esp_netif_destroy(ap);
343+
344+
345+
// quick check on create-destroy cycle of the default station again
346+
sta = NULL;
347+
sta = esp_netif_create_default_wifi_sta();
348+
TEST_ASSERT_NOT_NULL(sta);
349+
esp_wifi_clear_default_wifi_driver_and_handlers(sta);
350+
esp_netif_destroy(sta);
351+
}

0 commit comments

Comments
 (0)