From e6801912c5c4861f828ab1f447280628bba9a5d7 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 27 May 2019 16:06:48 +0200 Subject: [PATCH] mdns: added initial suite of api unit tests --- components/mdns/test/CMakeLists.txt | 3 + components/mdns/test/component.mk | 4 + components/mdns/test/test_mdns.c | 99 +++++++++++++++++++ .../partition_table_unit_test_app.csv | 2 +- 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 components/mdns/test/CMakeLists.txt create mode 100644 components/mdns/test/component.mk create mode 100644 components/mdns/test/test_mdns.c diff --git a/components/mdns/test/CMakeLists.txt b/components/mdns/test/CMakeLists.txt new file mode 100644 index 000000000..7e694470f --- /dev/null +++ b/components/mdns/test/CMakeLists.txt @@ -0,0 +1,3 @@ +set(COMPONENT_SRCDIRS ".") +set(COMPONENT_PRIV_REQUIRES unity test_utils mdns) +register_component() \ No newline at end of file diff --git a/components/mdns/test/component.mk b/components/mdns/test/component.mk new file mode 100644 index 000000000..5be873488 --- /dev/null +++ b/components/mdns/test/component.mk @@ -0,0 +1,4 @@ +# +#Component Makefile +# +COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive \ No newline at end of file diff --git a/components/mdns/test/test_mdns.c b/components/mdns/test/test_mdns.c new file mode 100644 index 000000000..6ae5e835f --- /dev/null +++ b/components/mdns/test/test_mdns.c @@ -0,0 +1,99 @@ +#include "test_utils.h" +#include "mdns.h" +#include "unity.h" + + +#define MDNS_HOSTNAME "test-hostname" +#define MDNS_INSTANCE "test-instance" +#define MDNS_SERVICE_NAME "_http" +#define MDNS_SERVICE_PROTO "_tcp" +#define MDNS_SERVICE_PORT 80 + + +static void yield_to_all_priorities(void) +{ + // Lower the test-task priority before testing to ensure other tasks got executed on forced context switch + size_t test_task_prio_before = uxTaskPriorityGet(NULL); + vTaskPrioritySet(NULL, tskIDLE_PRIORITY); + taskYIELD(); // Let the RTOS to switch context + vTaskPrioritySet(NULL, test_task_prio_before); +} + + +TEST_CASE("mdns api to fail in invalid state", "[mdns][leaks=64]") +{ + TEST_ASSERT_NOT_EQUAL(ESP_OK, mdns_init() ); + TEST_ASSERT_NOT_EQUAL(ESP_OK, mdns_hostname_set(MDNS_HOSTNAME) ); + TEST_ASSERT_NOT_EQUAL(ESP_OK, mdns_instance_name_set(MDNS_INSTANCE) ); + 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_case_uses_tcpip(); + TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_create_default()); + TEST_ASSERT_EQUAL(ESP_OK, mdns_init() ); + yield_to_all_priorities(); // Make sure that mdns task has executed to complete initialization + mdns_free(); + esp_event_loop_delete_default(); +} + +TEST_CASE("mdns api return expected err-code and do not leak memory", "[mdns][leaks=64]") +{ + mdns_txt_item_t serviceTxtData[CONFIG_MDNS_MAX_SERVICES] = { {NULL, NULL}, + }; + for (int i=0; i