diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index d33564b05a..776f68c2b8 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -382,7 +382,7 @@ test_esp_system: script: - cd ${IDF_PATH}/components/esp_system/host_test/test_esp_system/ - idf.py build - - timeout 5 build/test_esp_system.elf | tee log.txt || true + - echo "*" | timeout 5 build/test_esp_system.elf | tee log.txt || true - grep "6 Tests 0 Failures 0 Ignored" log.txt test_esp_timer_cxx: diff --git a/components/esp_system/host_test/test_esp_system/main/esp_system_test.c b/components/esp_system/host_test/test_esp_system/main/esp_system_test.c index 1ea98c7579..738542500c 100644 --- a/components/esp_system/host_test/test_esp_system/main/esp_system_test.c +++ b/components/esp_system/host_test/test_esp_system/main/esp_system_test.c @@ -7,6 +7,7 @@ #include #include #include "unity.h" +#include "unity_test_runner.h" #include "esp_system.h" @@ -40,12 +41,12 @@ static void cleanup(void) esp_unregister_shutdown_handler(action); } -void test_reset_reason(void) +TEST_CASE("reset_reason", "[esp_system]") { TEST_ASSERT_EQUAL(ESP_RST_POWERON, esp_reset_reason()); } -void test_unregister_handler_works(void) +TEST_CASE("unregister_handler_works", "[esp_system]") { token = 0; // for some reason, the handlers are executed in reverse order of adding handlers, so we always @@ -64,7 +65,7 @@ void test_unregister_handler_works(void) TEST_ASSERT_EQUAL(0, token); } -void test_register_shutdown_handler_twice_fails(void) +TEST_CASE("register_shutdown_handler_twice_fails", "[esp_system]") { TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(jump_back_shutdown_handler)); TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, esp_register_shutdown_handler(jump_back_shutdown_handler)); @@ -72,7 +73,7 @@ void test_register_shutdown_handler_twice_fails(void) cleanup(); } -void test_register_shutdown_handler_works(void) +TEST_CASE("register_shutdown_handler_works", "[esp_system]") { token = 0; TEST_ASSERT_EQUAL(esp_register_shutdown_handler(jump_back_shutdown_handler), ESP_OK); @@ -87,7 +88,7 @@ void test_register_shutdown_handler_works(void) TEST_ASSERT_EQUAL(1, token); } -void test_register_too_many_shutdown_handler_fails(void) +TEST_CASE("register_too_many_shutdown_handler_fails", "[esp_system]") { TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_0)); TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_1)); @@ -100,7 +101,7 @@ void test_register_too_many_shutdown_handler_fails(void) cleanup(); } -void test_heap_size_stubs(void) +TEST_CASE("heap_size_stubs", "[esp_system]") { TEST_ASSERT_EQUAL(47000, esp_get_free_heap_size()); TEST_ASSERT_EQUAL(47000, esp_get_free_internal_heap_size()); @@ -109,12 +110,6 @@ void test_heap_size_stubs(void) void app_main(void) { - UNITY_BEGIN(); - RUN_TEST(test_reset_reason); - RUN_TEST(test_unregister_handler_works); - RUN_TEST(test_register_shutdown_handler_twice_fails); - RUN_TEST(test_register_shutdown_handler_works); - RUN_TEST(test_register_too_many_shutdown_handler_fails); - RUN_TEST(test_heap_size_stubs); - UNITY_END(); + printf("Running esp_system host test app"); + unity_run_menu(); } diff --git a/components/esp_system/host_test/test_esp_system/sdkconfig.defaults b/components/esp_system/host_test/test_esp_system/sdkconfig.defaults index a3f33f136b..9b39f10b99 100644 --- a/components/esp_system/host_test/test_esp_system/sdkconfig.defaults +++ b/components/esp_system/host_test/test_esp_system/sdkconfig.defaults @@ -1,2 +1 @@ CONFIG_IDF_TARGET="linux" -CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n diff --git a/components/unity/CMakeLists.txt b/components/unity/CMakeLists.txt index ff521fa1d4..c70df0fad6 100644 --- a/components/unity/CMakeLists.txt +++ b/components/unity/CMakeLists.txt @@ -15,9 +15,9 @@ endif() if(CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER) list(APPEND srcs "unity_runner.c") - # Note the following files are not compatible with the Linux target. - # On Linux, these are masked because we also don't use the IDF test runner there - list(APPEND srcs "unity_utils_freertos.c" "unity_utils_cache.c") + if(NOT "${target}" STREQUAL "linux") + list(APPEND srcs "unity_utils_freertos.c" "unity_utils_cache.c") + endif() list(APPEND requires "freertos") endif() diff --git a/components/unity/unity_port_linux.c b/components/unity/unity_port_linux.c index a295879c33..80bf1ec349 100644 --- a/components/unity/unity_port_linux.c +++ b/components/unity/unity_port_linux.c @@ -7,11 +7,11 @@ #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) @@ -25,6 +25,43 @@ void unity_flush(void) fsync(fileno(stdout)); } +static void esp_unity_readline(char* dst, size_t len) +{ + /* Read line from console with support for echoing and backspaces */ + size_t write_index = 0; + for (;;) { + char c = 0; + int result = fgetc(stdin); + if (result == EOF) { + continue; + } + c = (char) result; + if (c == '\r' || c == '\n') { + /* Add null terminator and return on newline */ + unity_putc('\n'); + dst[write_index] = '\0'; + return; + } else if (c == '\b') { + if (write_index > 0) { + /* Delete previously entered character */ + write_index--; + unity_putc('\b'); + unity_putc(' '); + unity_putc('\b'); + } + } else if (len > 0 && write_index < len - 1 && !iscntrl(c)) { + /* Write a max of len - 1 characters to allow for null terminator */ + unity_putc(c); + dst[write_index++] = c; + } + } +} + +void unity_gets(char *dst, size_t len) +{ + esp_unity_readline(dst, len); +} + void unity_exec_time_start(void) { gettimeofday(&s_test_start, NULL);