From a8ebd8ad04c2fa1ff30289ac76d6ae8265642cde Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 15 Aug 2022 18:09:45 +0200 Subject: [PATCH] unity: add linux port This allows using unity fixture in Linux host tests --- components/unity/CMakeLists.txt | 9 ++-- components/unity/unity_port_linux.c | 42 +++++++++++++++++++ .../mqtt/ssl_ds/main/idf_component.yml | 4 +- 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 components/unity/unity_port_linux.c diff --git a/components/unity/CMakeLists.txt b/components/unity/CMakeLists.txt index 91fe15e65a..ff521fa1d4 100644 --- a/components/unity/CMakeLists.txt +++ b/components/unity/CMakeLists.txt @@ -32,6 +32,7 @@ if(NOT "${target}" STREQUAL "linux") list(APPEND srcs "unity_port_esp32.c") list(APPEND srcs "port/esp/unity_utils_memory_esp.c") else() + list(APPEND srcs "unity_port_linux.c") list(APPEND srcs "port/linux/unity_utils_memory_linux.c") endif() @@ -43,10 +44,8 @@ if(CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER) idf_component_optional_requires(PRIVATE spi_flash) endif() -if(NOT "${target}" STREQUAL "linux") - target_compile_definitions(${COMPONENT_LIB} PUBLIC - -DUNITY_INCLUDE_CONFIG_H - ) -endif() +target_compile_definitions(${COMPONENT_LIB} PUBLIC + -DUNITY_INCLUDE_CONFIG_H +) target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-const-variable) diff --git a/components/unity/unity_port_linux.c b/components/unity/unity_port_linux.c new file mode 100644 index 0000000000..a295879c33 --- /dev/null +++ b/components/unity/unity_port_linux.c @@ -0,0 +1,42 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include +#include +#include "unity.h" +#include "sdkconfig.h" + + +static struct timeval s_test_start, s_test_stop; + +void unity_putc(int c) +{ + putc(c, stdout); +} + +void unity_flush(void) +{ + fflush(stdout); + fsync(fileno(stdout)); +} + +void unity_exec_time_start(void) +{ + gettimeofday(&s_test_start, NULL); +} + +void unity_exec_time_stop(void) +{ + gettimeofday(&s_test_stop, NULL); +} + +uint32_t unity_exec_time_get_ms(void) +{ + return (uint32_t) (((s_test_stop.tv_sec * 1000000ULL + s_test_stop.tv_usec) - + (s_test_start.tv_sec * 1000000ULL + s_test_start.tv_usec)) / 1000); +} diff --git a/examples/protocols/mqtt/ssl_ds/main/idf_component.yml b/examples/protocols/mqtt/ssl_ds/main/idf_component.yml index 9c8c93c360..8dd90a3b08 100644 --- a/examples/protocols/mqtt/ssl_ds/main/idf_component.yml +++ b/examples/protocols/mqtt/ssl_ds/main/idf_component.yml @@ -1,5 +1,3 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp_secure_cert_mgr: - version: "~3.0.3" - service_url: "https://api.staging.components.espressif.tools" + espressif/esp_secure_cert_mgr: "^2.0.2"