mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 10:17:30 +02:00
fix(mdns): Make unit test executable with pytest
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
import re
|
||||
import select
|
||||
@ -8,8 +8,11 @@ import subprocess
|
||||
import time
|
||||
from threading import Event, Thread
|
||||
|
||||
import dpkt
|
||||
import dpkt.dns
|
||||
try:
|
||||
import dpkt
|
||||
import dpkt.dns
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def get_dns_query_for_esp(esp_host):
|
||||
|
@ -1,2 +1,7 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_REQUIRES cmock test_utils mdns)
|
||||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS ../.. "$ENV{IDF_PATH}/tools/unit-test-app/components")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(mdns_test)
|
||||
|
5
components/mdns/tests/unit_test/main/CMakeLists.txt
Normal file
5
components/mdns/tests/unit_test/main/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
idf_component_register(SRCS "test_mdns.c"
|
||||
REQUIRES test_utils
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity mdns)
|
@ -1,13 +1,16 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "mdns.h"
|
||||
#include "esp_event.h"
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "unity_fixture.h"
|
||||
#include "memory_checks.h"
|
||||
|
||||
#define MDNS_HOSTNAME "test-hostname"
|
||||
#define MDNS_DELEGATE_HOSTNAME "delegate-hostname"
|
||||
@ -16,6 +19,18 @@
|
||||
#define MDNS_SERVICE_PROTO "_tcp"
|
||||
#define MDNS_SERVICE_PORT 80
|
||||
|
||||
TEST_GROUP(mdns);
|
||||
|
||||
TEST_SETUP(mdns)
|
||||
{
|
||||
test_utils_record_free_mem();
|
||||
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(mdns)
|
||||
{
|
||||
test_utils_finish_and_evaluate_leaks(32, 64);
|
||||
}
|
||||
|
||||
static void yield_to_all_priorities(void)
|
||||
{
|
||||
@ -27,7 +42,7 @@ static void yield_to_all_priorities(void)
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("mdns api to fail in invalid state", "[mdns][leaks=64]")
|
||||
TEST(mdns, api_fails_with_invalid_state)
|
||||
{
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, mdns_init() );
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, mdns_hostname_set(MDNS_HOSTNAME) );
|
||||
@ -35,7 +50,7 @@ TEST_CASE("mdns api to fail in invalid state", "[mdns][leaks=64]")
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, mdns_service_add(MDNS_INSTANCE, MDNS_SERVICE_NAME, MDNS_SERVICE_PROTO, MDNS_SERVICE_PORT, NULL, 0) );
|
||||
}
|
||||
|
||||
TEST_CASE("mdns init and deinit", "[mdns][leaks=64]")
|
||||
TEST(mdns, init_deinit)
|
||||
{
|
||||
test_case_uses_tcpip();
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_create_default());
|
||||
@ -45,7 +60,7 @@ TEST_CASE("mdns init and deinit", "[mdns][leaks=64]")
|
||||
esp_event_loop_delete_default();
|
||||
}
|
||||
|
||||
TEST_CASE("mdns api return expected err-code and do not leak memory", "[mdns][leaks=64]")
|
||||
TEST(mdns, api_fails_with_expected_err)
|
||||
{
|
||||
mdns_txt_item_t serviceTxtData[CONFIG_MDNS_MAX_SERVICES] = { {NULL, NULL},
|
||||
};
|
||||
@ -91,7 +106,7 @@ TEST_CASE("mdns api return expected err-code and do not leak memory", "[mdns][le
|
||||
esp_event_loop_delete_default();
|
||||
}
|
||||
|
||||
TEST_CASE("mdns query api return expected err-code and do not leak memory", "[leaks=64]")
|
||||
TEST(mdns, query_api_fails_with_expected_err)
|
||||
{
|
||||
mdns_result_t *results = NULL;
|
||||
esp_ip6_addr_t addr6;
|
||||
@ -118,3 +133,16 @@ TEST_CASE("mdns query api return expected err-code and do not leak memory", "[le
|
||||
mdns_free();
|
||||
esp_event_loop_delete_default();
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(mdns)
|
||||
{
|
||||
RUN_TEST_CASE(mdns, api_fails_with_invalid_state)
|
||||
RUN_TEST_CASE(mdns, api_fails_with_expected_err)
|
||||
RUN_TEST_CASE(mdns, query_api_fails_with_expected_err)
|
||||
RUN_TEST_CASE(mdns, init_deinit)
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_MAIN(mdns);
|
||||
}
|
8
components/mdns/tests/unit_test/pytest_mdns.py
Normal file
8
components/mdns/tests/unit_test/pytest_mdns.py
Normal file
@ -0,0 +1,8 @@
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
def test_lwip(dut: Dut) -> None:
|
||||
dut.expect_unity_test_output()
|
2
components/mdns/tests/unit_test/sdkconfig.defaults
Normal file
2
components/mdns/tests/unit_test/sdkconfig.defaults
Normal file
@ -0,0 +1,2 @@
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
Reference in New Issue
Block a user