mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
mDNS: Fix example test in CI using multiple retries
This commit is contained in:
parent
9ee3c8337d
commit
74721f524b
@ -26,10 +26,11 @@
|
||||
|
||||
static const char * TAG = "mdns-test";
|
||||
static char * generate_hostname(void);
|
||||
static const int RETRY_COUNT = 10;
|
||||
|
||||
#if CONFIG_MDNS_RESOLVE_TEST_SERVICES == 1
|
||||
static void query_mdns_host_with_gethostbyname(char * host);
|
||||
static void query_mdns_host_with_getaddrinfo(char * host);
|
||||
static esp_err_t query_mdns_host_with_gethostbyname(char * host);
|
||||
static esp_err_t query_mdns_host_with_getaddrinfo(char * host);
|
||||
#endif
|
||||
|
||||
static void initialise_mdns(void)
|
||||
@ -189,7 +190,7 @@ static void query_mdns_hosts_async(const char * host_name)
|
||||
}
|
||||
}
|
||||
|
||||
static void query_mdns_host(const char * host_name)
|
||||
static esp_err_t query_mdns_host(const char * host_name)
|
||||
{
|
||||
ESP_LOGI(TAG, "Query A: %s.local", host_name);
|
||||
|
||||
@ -200,13 +201,14 @@ static void query_mdns_host(const char * host_name)
|
||||
if(err){
|
||||
if(err == ESP_ERR_NOT_FOUND){
|
||||
ESP_LOGW(TAG, "%s: Host was not found!", esp_err_to_name(err));
|
||||
return;
|
||||
return err;
|
||||
}
|
||||
ESP_LOGE(TAG, "Query Failed: %s", esp_err_to_name(err));
|
||||
return;
|
||||
return err;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Query A: %s.local resolved to: " IPSTR, host_name, IP2STR(&addr));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void initialise_button(void)
|
||||
@ -241,11 +243,27 @@ static void check_button(void)
|
||||
|
||||
static void mdns_example_task(void *pvParameters)
|
||||
{
|
||||
int i = 0;
|
||||
const TickType_t xDelay = 1000 / portTICK_PERIOD_MS;
|
||||
#if CONFIG_MDNS_RESOLVE_TEST_SERVICES == 1
|
||||
/* Send initial queries that are started by CI tester */
|
||||
while (query_mdns_host("tinytester") != ESP_OK && i != RETRY_COUNT) {
|
||||
query_mdns_host("tinytester");
|
||||
i++;
|
||||
vTaskDelay(xDelay);
|
||||
}
|
||||
i = 0;
|
||||
while (query_mdns_host_with_gethostbyname("tinytester-lwip.local") != ESP_OK && i != RETRY_COUNT) {
|
||||
query_mdns_host_with_gethostbyname("tinytester-lwip.local");
|
||||
i++;
|
||||
vTaskDelay(xDelay);
|
||||
}
|
||||
i = 0;
|
||||
while (query_mdns_host_with_getaddrinfo("tinytester-lwip.local") != ESP_OK && i != RETRY_COUNT) {
|
||||
query_mdns_host_with_getaddrinfo("tinytester-lwip.local");
|
||||
i++;
|
||||
vTaskDelay(xDelay);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
@ -295,7 +313,7 @@ static char* generate_hostname(void)
|
||||
* @brief Executes gethostbyname and displays list of resolved addresses.
|
||||
* Note: This function is used only to test advertised mdns hostnames resolution
|
||||
*/
|
||||
static void query_mdns_host_with_gethostbyname(char * host)
|
||||
static esp_err_t query_mdns_host_with_gethostbyname(char * host)
|
||||
{
|
||||
struct hostent *res = gethostbyname(host);
|
||||
if (res) {
|
||||
@ -304,14 +322,16 @@ static void query_mdns_host_with_gethostbyname(char * host)
|
||||
ESP_LOGI(TAG, "gethostbyname: %s resolved to: %s", host, inet_ntoa(*(struct in_addr *) (res->h_addr_list[i])));
|
||||
i++;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Executes getaddrinfo and displays list of resolved addresses.
|
||||
* Note: This function is used only to test advertised mdns hostnames resolution
|
||||
*/
|
||||
static void query_mdns_host_with_getaddrinfo(char * host)
|
||||
static esp_err_t query_mdns_host_with_getaddrinfo(char * host)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo * res;
|
||||
@ -328,6 +348,8 @@ static void query_mdns_host_with_getaddrinfo(char * host)
|
||||
inet_ntoa(((struct sockaddr_in6 *) res->ai_addr)->sin6_addr));
|
||||
res = res->ai_next;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
@ -92,10 +92,10 @@ def mdns_server(esp_host):
|
||||
sock.sendto(get_dns_answer_to_mdns_lwip(TESTER_NAME_LWIP, dns.id), addr)
|
||||
if len(dns.an) > 0 and dns.an[0].type == dpkt.dns.DNS_A:
|
||||
console_log('Received answer from {}'.format(dns.an[0].name))
|
||||
if dns.an[0].name == esp_host + u'.local':
|
||||
if dns.an[0].name.startswith(esp_host + u'.local'):
|
||||
console_log('Received answer to esp32-mdns query: {}'.format(dns.__repr__()))
|
||||
esp_answered.set()
|
||||
if dns.an[0].name == esp_host + u'-delegated.local':
|
||||
if dns.an[0].name.startswith(esp_host + u'-delegated.local'):
|
||||
console_log('Received answer to esp32-mdns-delegate query: {}'.format(dns.__repr__()))
|
||||
esp_delegated_answered.set()
|
||||
except socket.timeout:
|
||||
|
Loading…
Reference in New Issue
Block a user