From b080c50713fad40a7c002292129a9f6cafde5926 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 20 May 2022 16:54:27 +0200 Subject: [PATCH] emulation on host: avoid closing STDIN (#8577) - avoid closing STDIN - less verbose during compilation - better handling user directories - missing str{,n}case_P declarations --- tests/host/Makefile | 7 ++++--- tests/host/common/ArduinoMain.cpp | 10 ++++++++-- tests/host/common/MockWiFiServerSocket.cpp | 2 +- tests/host/sys/pgmspace.h | 2 ++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index 1686d5c79..82222ad29 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -374,9 +374,10 @@ ssl: # download source and build BearSSL cd ../../tools/sdk/ssl && $(MAKE) native$(N32) ULIBPATHS = $(shell echo $(ULIBDIRS) | sed 's,:, ,g') -USERLIBDIRS = $(shell test -z "$(ULIBPATHS)" || for d in $(ULIBPATHS); do for dd in $$d $$d/src $$d/src/libmad; do test -d $$dd && { echo -I$$dd; echo "userlib: using directory '$$dd'" 1>&2; } done; done) -USERLIBSRCS = $(shell test -z "$(ULIBPATHS)" || for d in $(ULIBPATHS); do for ss in $$d/*.cpp $$d/src/*.cpp $$d/src/libmad/*.c; do test -r $$ss && echo $$ss; done; done) -INC_PATHS += $(USERLIBDIRS) +USERLIBDIRS = $(shell test -z "$(ULIBPATHS)" || for d in $(ULIBPATHS); do for dd in $$d $$d/utility $$d/src $$d/src/utility; do test -d $$dd && echo $$dd; done; done) +USERLIBSRCS := $(shell test -z "$(USERLIBDIRS)" || for d in $(USERLIBDIRS); do for ss in $$d/*.c $$d/*.cpp; do test -r $$ss && echo $$ss; done; done) +USERLIBINCS = $(shell for d in $(USERLIBDIRS); do echo -I$$d; done) +INC_PATHS += $(USERLIBINCS) INC_PATHS += -I$(INODIR)/.. CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIBSRCS:.cpp=.cpp.o) $(USERCXXSOURCES:.cpp=.cpp.o) C_OBJECTS_CORE_EMU = $(USERCSOURCES:.c=.c.o) diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index ca03af9dd..692ea97b0 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -115,8 +115,14 @@ static int mock_stop_uart(void) static uint8_t mock_read_uart(void) { - uint8_t ch = 0; - return (read(STDIN, &ch, 1) == 1) ? ch : 0; + uint8_t ch = 0; + int ret = read(STDIN, &ch, 1); + if (ret == -1) + { + perror("read(STDIN,1)"); + return 0; + } + return (ret == 1) ? ch : 0; } void help(const char* argv0, int exitcode) diff --git a/tests/host/common/MockWiFiServerSocket.cpp b/tests/host/common/MockWiFiServerSocket.cpp index 1dd50b644..0023c6e2a 100644 --- a/tests/host/common/MockWiFiServerSocket.cpp +++ b/tests/host/common/MockWiFiServerSocket.cpp @@ -129,7 +129,7 @@ bool WiFiServer::hasClient() void WiFiServer::close() { - if (pcb2int(_listen_pcb) >= 0) + if (pcb2int(_listen_pcb) >= 3) // 0=stdin 1=stdout 2=stderr ::close(pcb2int(_listen_pcb)); _listen_pcb = int2pcb(-1); } diff --git a/tests/host/sys/pgmspace.h b/tests/host/sys/pgmspace.h index 6ccd881a8..ef878eaaf 100644 --- a/tests/host/sys/pgmspace.h +++ b/tests/host/sys/pgmspace.h @@ -75,10 +75,12 @@ inline int vsnprintf_P(char* str, size_t size, const char* format, va_list ap) #define memmove_P memmove #define strncpy_P strncpy #define strcmp_P strcmp +#define strcasecmp_P strcasecmp #define memccpy_P memccpy #define snprintf_P snprintf #define sprintf_P sprintf #define strncmp_P strncmp +#define strncasecmp_P strncasecmp #define strcat_P strcat #endif