mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
refactor(unity): made unity runner compatible with Linux target
This commit is contained in:
parent
4ded1ea4cf
commit
1e7daf316a
@ -382,7 +382,7 @@ test_esp_system:
|
|||||||
script:
|
script:
|
||||||
- cd ${IDF_PATH}/components/esp_system/host_test/test_esp_system/
|
- cd ${IDF_PATH}/components/esp_system/host_test/test_esp_system/
|
||||||
- idf.py build
|
- 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
|
- grep "6 Tests 0 Failures 0 Ignored" log.txt
|
||||||
|
|
||||||
test_esp_timer_cxx:
|
test_esp_timer_cxx:
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
#include "unity_test_runner.h"
|
||||||
|
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
|
|
||||||
@ -40,12 +41,12 @@ static void cleanup(void)
|
|||||||
esp_unregister_shutdown_handler(action);
|
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());
|
TEST_ASSERT_EQUAL(ESP_RST_POWERON, esp_reset_reason());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_unregister_handler_works(void)
|
TEST_CASE("unregister_handler_works", "[esp_system]")
|
||||||
{
|
{
|
||||||
token = 0;
|
token = 0;
|
||||||
// for some reason, the handlers are executed in reverse order of adding handlers, so we always
|
// 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);
|
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_OK, esp_register_shutdown_handler(jump_back_shutdown_handler));
|
||||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, 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();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_register_shutdown_handler_works(void)
|
TEST_CASE("register_shutdown_handler_works", "[esp_system]")
|
||||||
{
|
{
|
||||||
token = 0;
|
token = 0;
|
||||||
TEST_ASSERT_EQUAL(esp_register_shutdown_handler(jump_back_shutdown_handler), ESP_OK);
|
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);
|
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_0));
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, esp_register_shutdown_handler(dummy_shutdown_handler_1));
|
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();
|
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_heap_size());
|
||||||
TEST_ASSERT_EQUAL(47000, esp_get_free_internal_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)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
printf("Running esp_system host test app");
|
||||||
RUN_TEST(test_reset_reason);
|
unity_run_menu();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1 @@
|
|||||||
CONFIG_IDF_TARGET="linux"
|
CONFIG_IDF_TARGET="linux"
|
||||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
|
||||||
|
@ -15,9 +15,9 @@ endif()
|
|||||||
|
|
||||||
if(CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER)
|
if(CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER)
|
||||||
list(APPEND srcs "unity_runner.c")
|
list(APPEND srcs "unity_runner.c")
|
||||||
# Note the following files are not compatible with the Linux target.
|
if(NOT "${target}" STREQUAL "linux")
|
||||||
# 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")
|
list(APPEND srcs "unity_utils_freertos.c" "unity_utils_cache.c")
|
||||||
|
endif()
|
||||||
list(APPEND requires "freertos")
|
list(APPEND requires "freertos")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
|
||||||
static struct timeval s_test_start, s_test_stop;
|
static struct timeval s_test_start, s_test_stop;
|
||||||
|
|
||||||
void unity_putc(int c)
|
void unity_putc(int c)
|
||||||
@ -25,6 +25,43 @@ void unity_flush(void)
|
|||||||
fsync(fileno(stdout));
|
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)
|
void unity_exec_time_start(void)
|
||||||
{
|
{
|
||||||
gettimeofday(&s_test_start, NULL);
|
gettimeofday(&s_test_start, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user