Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulation on host: avoid closing STDIN #8577

Merged
merged 6 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions tests/host/common/ArduinoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/host/common/MockWiFiServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/host/sys/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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