mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-25 01:37:22 +00:00
feat(esp_netif): Added new API to search in netif list
This commit is contained in:
@@ -129,6 +129,44 @@ TEST(esp_netif, create_delete_multiple_netifs)
|
||||
|
||||
}
|
||||
|
||||
static bool desc_matches_with(esp_netif_t *netif, void *ctx)
|
||||
{
|
||||
return strcmp(ctx, esp_netif_get_desc(netif)) == 0;
|
||||
}
|
||||
|
||||
TEST(esp_netif, find_netifs)
|
||||
{
|
||||
// Create some interfaces
|
||||
const char* if_keys[] = { "if1", "if2", "if3", "if4", "if5"};
|
||||
const int nr_of_netifs = sizeof(if_keys)/sizeof(char*);
|
||||
esp_netif_t *netifs[nr_of_netifs];
|
||||
|
||||
for (int i=0; i<nr_of_netifs; ++i) {
|
||||
// Create all interfaces, the same string is used as a key and as description
|
||||
esp_netif_inherent_config_t base_netif_config = { .if_key = if_keys[i], .if_desc = if_keys[i] };
|
||||
esp_netif_config_t cfg = { .base = &base_netif_config, .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA };
|
||||
netifs[i] = esp_netif_new(&cfg);
|
||||
TEST_ASSERT_NOT_NULL(netifs[i]);
|
||||
}
|
||||
|
||||
// not found
|
||||
esp_netif_t *found_netif = esp_netif_find_if(desc_matches_with, "not_present");
|
||||
TEST_ASSERT_EQUAL(found_netif, NULL);
|
||||
|
||||
// should find the same netif, as returned from esp_netif_get_handle_from_ifkey(), as the key is the same as description
|
||||
for (int i=0; i<nr_of_netifs; ++i) {
|
||||
found_netif = esp_netif_find_if(desc_matches_with, (void*)if_keys[i]);
|
||||
TEST_ASSERT_EQUAL(found_netif, esp_netif_get_handle_from_ifkey(if_keys[i]));
|
||||
}
|
||||
|
||||
// destroy one by one and check it's cannot be find per its description
|
||||
for (int i=0; i<nr_of_netifs; ++i) {
|
||||
esp_netif_destroy(netifs[i]);
|
||||
found_netif = esp_netif_find_if(desc_matches_with, (void*)if_keys[i]);
|
||||
TEST_ASSERT_EQUAL(found_netif, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_ENABLED
|
||||
TEST(esp_netif, dhcp_client_state_transitions_wifi_sta)
|
||||
{
|
||||
@@ -463,6 +501,7 @@ TEST_GROUP_RUNNER(esp_netif)
|
||||
RUN_TEST_CASE(esp_netif, convert_ip_addresses)
|
||||
RUN_TEST_CASE(esp_netif, get_from_if_key)
|
||||
RUN_TEST_CASE(esp_netif, create_delete_multiple_netifs)
|
||||
RUN_TEST_CASE(esp_netif, find_netifs)
|
||||
#ifdef CONFIG_ESP_WIFI_ENABLED
|
||||
RUN_TEST_CASE(esp_netif, create_custom_wifi_interfaces)
|
||||
RUN_TEST_CASE(esp_netif, create_destroy_default_wifi)
|
||||
|
Reference in New Issue
Block a user