From 7f7d689a7b2072f5365658238328c013f50ccc10 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 20 May 2022 15:04:41 +0200 Subject: [PATCH 1/6] emulation on host: handle src/utility/ and avoid closing STDIN --- tests/host/Makefile | 4 ++-- tests/host/common/ArduinoMain.cpp | 7 +++++-- tests/host/common/MockWiFiServerSocket.cpp | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index 1686d5c791..c207020672 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -374,8 +374,8 @@ 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) +USERLIBDIRS = $(shell test -z "$(ULIBPATHS)" || for d in $(ULIBPATHS); do for dd in $$d $$d/src; 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/utility/*.cpp; do test -r $$ss && echo $$ss; done; done) INC_PATHS += $(USERLIBDIRS) INC_PATHS += -I$(INODIR)/.. CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIBSRCS:.cpp=.cpp.o) $(USERCXXSOURCES:.cpp=.cpp.o) diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index ca03af9ddd..b0887b4318 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -113,10 +113,13 @@ static int mock_stop_uart(void) return (0); } -static uint8_t mock_read_uart(void) +uint8_t mock_read_uart(void) { uint8_t ch = 0; - return (read(STDIN, &ch, 1) == 1) ? ch : 0; + int ret = read(STDIN, &ch, 1); + if (ret == -1) + perror("read(STDIN,1)"); + 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 1dd50b644f..e77af8ff97 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); } From 95019b6db74c60bf72a7859ff348456f7d8f5809 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 20 May 2022 15:11:48 +0200 Subject: [PATCH 2/6] revert 'static' removal --- tests/host/common/ArduinoMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index b0887b4318..5fa4cdb6c9 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -113,7 +113,7 @@ static int mock_stop_uart(void) return (0); } -uint8_t mock_read_uart(void) +static uint8_t mock_read_uart(void) { uint8_t ch = 0; int ret = read(STDIN, &ch, 1); From c206b3c5e77883b9b0f598f83b89799e900c0866 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 20 May 2022 15:33:51 +0200 Subject: [PATCH 3/6] less verbose compilation on host --- tests/host/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index c207020672..a1745129bb 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -374,8 +374,8 @@ 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; 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/utility/*.cpp; do test -r $$ss && echo $$ss; done; done) +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 -I$$dd; done; done) +USERLIBSRCS = $(shell test -z "$(ULIBPATHS)" || for d in $(USERLIBDIRS); do for ss in $$d/*.cpp; do test -r $$ss && echo $$ss; done; done) INC_PATHS += $(USERLIBDIRS) INC_PATHS += -I$(INODIR)/.. CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIBSRCS:.cpp=.cpp.o) $(USERCXXSOURCES:.cpp=.cpp.o) From 6d1803fd938981ea8954207c63c0d08b1881b522 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 20 May 2022 15:53:18 +0200 Subject: [PATCH 4/6] better handle directories --- tests/host/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index a1745129bb..82222ad299 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/utility $$d/src $$d/src/utility; do test -d $$dd && echo -I$$dd; done; done) -USERLIBSRCS = $(shell test -z "$(ULIBPATHS)" || for d in $(USERLIBDIRS); do for ss in $$d/*.cpp; 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) From 6d2456fbfd54f55e7e97bf5db705948752e00686 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 20 May 2022 16:17:16 +0200 Subject: [PATCH 5/6] missing str*case*_P declarations --- tests/host/sys/pgmspace.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/host/sys/pgmspace.h b/tests/host/sys/pgmspace.h index 6ccd881a8c..ef878eaaff 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 From e751dc53bb4a8342c70e5c39a647585fcc73f59e Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Fri, 20 May 2022 16:25:23 +0200 Subject: [PATCH 6/6] style --- tests/host/common/ArduinoMain.cpp | 7 +++++-- tests/host/common/MockWiFiServerSocket.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 5fa4cdb6c9..692ea97b0e 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -115,10 +115,13 @@ static int mock_stop_uart(void) static uint8_t mock_read_uart(void) { - uint8_t ch = 0; - int ret = read(STDIN, &ch, 1); + uint8_t ch = 0; + int ret = read(STDIN, &ch, 1); if (ret == -1) + { perror("read(STDIN,1)"); + return 0; + } return (ret == 1) ? ch : 0; } diff --git a/tests/host/common/MockWiFiServerSocket.cpp b/tests/host/common/MockWiFiServerSocket.cpp index e77af8ff97..0023c6e2a1 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) >= 3) // 0=stdin 1=stdout 2=stderr + if (pcb2int(_listen_pcb) >= 3) // 0=stdin 1=stdout 2=stderr ::close(pcb2int(_listen_pcb)); _listen_pcb = int2pcb(-1); }