mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-07 20:00:53 +00:00
refactor(unity): made unity runner compatible with Linux target
This commit is contained in:
@@ -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()
|
||||
|
||||
|
@@ -7,11 +7,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/time.h>
|
||||
#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);
|
||||
|
Reference in New Issue
Block a user