From 228ad7ed75da04e3f17b6a31ff62ab3b1de96e4a Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 22 Dec 2018 07:03:11 +0100 Subject: [PATCH] tests/host: fixes and updates (#5537) (LEAmDNS, broken pipe, non blocking accepted sockets, digitalRead) --- libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp | 8 ++++---- tests/host/Makefile | 10 +++++++--- tests/host/common/Arduino.h | 1 + tests/host/common/ClientContextSocket.cpp | 3 ++- tests/host/common/HostWiring.cpp | 6 ++++++ tests/host/common/MockWiFiServerSocket.cpp | 10 +++++++++- tests/host/common/include/UdpContext.h | 10 ++++++++++ tests/host/common/mock.h | 12 ++++++++++++ 8 files changed, 51 insertions(+), 9 deletions(-) diff --git a/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp b/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp index a61459db0..f38049790 100644 --- a/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp +++ b/libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp @@ -1005,7 +1005,7 @@ bool MDNSResponder::_udpRead16(uint16_t& p_ru16Value) { bool bResult = false; if (_udpReadBuffer((unsigned char*)&p_ru16Value, sizeof(p_ru16Value))) { - p_ru16Value = ntohs(p_ru16Value); + p_ru16Value = lwip_ntohs(p_ru16Value); bResult = true; } return bResult; @@ -1019,7 +1019,7 @@ bool MDNSResponder::_udpRead32(uint32_t& p_ru32Value) { bool bResult = false; if (_udpReadBuffer((unsigned char*)&p_ru32Value, sizeof(p_ru32Value))) { - p_ru32Value = ntohl(p_ru32Value); + p_ru32Value = lwip_ntohl(p_ru32Value); bResult = true; } return bResult; @@ -1052,7 +1052,7 @@ bool MDNSResponder::_udpAppend8(uint8_t p_u8Value) { */ bool MDNSResponder::_udpAppend16(uint16_t p_u16Value) { - p_u16Value = htons(p_u16Value); + p_u16Value = lwip_htons(p_u16Value); return (_udpAppendBuffer((unsigned char*)&p_u16Value, sizeof(p_u16Value))); } @@ -1061,7 +1061,7 @@ bool MDNSResponder::_udpAppend16(uint16_t p_u16Value) { */ bool MDNSResponder::_udpAppend32(uint32_t p_u32Value) { - p_u32Value = htonl(p_u32Value); + p_u32Value = lwip_htonl(p_u32Value); return (_udpAppendBuffer((unsigned char*)&p_u32Value, sizeof(p_u32Value))); } diff --git a/tests/host/Makefile b/tests/host/Makefile index e778d9605..2c5d6c7cb 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -148,10 +148,10 @@ COVERAGE_FILES = $(OBJECTS:.o=.gc*) all: help -CI: +CI: # run CI $(MAKE) -f $(MAKEFILE) MKFLAGS=-Werror FORCE32=0 OPTZ=-O0 doCI -doCI: build-info $(OUTPUT_BINARY) valgrind test gcov # run CI +doCI: build-info $(OUTPUT_BINARY) valgrind test gcov test: $(OUTPUT_BINARY) # run host test for CI $(OUTPUT_BINARY) @@ -232,7 +232,11 @@ ARDUINO_LIBS := \ Parsing.cpp \ detail/mimetable.cpp \ ) \ - ESP8266mDNS/ESP8266mDNS.cpp \ + ESP8266mDNS/src/LEAmDNS.cpp \ + ESP8266mDNS/src/LEAmDNS_Control.cpp \ + ESP8266mDNS/src/LEAmDNS_Helpers.cpp \ + ESP8266mDNS/src/LEAmDNS_Structs.cpp \ + ESP8266mDNS/src/LEAmDNS_Transfer.cpp \ ArduinoOTA/ArduinoOTA.cpp \ DNSServer/src/DNSServer.cpp \ ESP8266AVRISP/src/ESP8266AVRISP.cpp \ diff --git a/tests/host/common/Arduino.h b/tests/host/common/Arduino.h index 9dc2b041b..84b8226a1 100644 --- a/tests/host/common/Arduino.h +++ b/tests/host/common/Arduino.h @@ -218,6 +218,7 @@ extern "C" { void loop(void); void yield(void); + void esp_yield(void); void optimistic_yield(uint32_t interval_us); #define digitalPinToPort(pin) (0) diff --git a/tests/host/common/ClientContextSocket.cpp b/tests/host/common/ClientContextSocket.cpp index b2b6906fd..8dd55ee62 100644 --- a/tests/host/common/ClientContextSocket.cpp +++ b/tests/host/common/ClientContextSocket.cpp @@ -135,7 +135,8 @@ size_t mockWrite (int sock, const uint8_t* data, size_t size, int timeout_ms) } if (ret) { - ret = ::write(sock, data, size); + //ret = ::write(sock, data, size); + ret = ::send(sock, data, size, MSG_NOSIGNAL); if (ret == -1) { fprintf(stderr, MOCK "ClientContext::read: write(%d): %s\n", sock, strerror(errno)); diff --git a/tests/host/common/HostWiring.cpp b/tests/host/common/HostWiring.cpp index 3d82cc795..b2887c032 100644 --- a/tests/host/common/HostWiring.cpp +++ b/tests/host/common/HostWiring.cpp @@ -69,3 +69,9 @@ void analogWriteRange(uint32_t range) { fprintf(stderr, MOCK "analogWriteRange(range=%d)\n", range); } + +int digitalRead(uint8_t pin) +{ + fprintf(stderr, MOCK "digitalRead(%d)\n", pin); + return 0; +} diff --git a/tests/host/common/MockWiFiServerSocket.cpp b/tests/host/common/MockWiFiServerSocket.cpp index 37ace3bf4..e5fefc932 100644 --- a/tests/host/common/MockWiFiServerSocket.cpp +++ b/tests/host/common/MockWiFiServerSocket.cpp @@ -36,6 +36,8 @@ #include #include #include +#include +#include #define int2pcb(x) ((tcp_pcb*)(intptr_t)(x)) #define pcb2int(x) ((int)(intptr_t)(x)) @@ -50,7 +52,13 @@ int serverAccept (int srvsock) n = sizeof(client); if ((clisock = accept(srvsock, (struct sockaddr*)&client, &n)) == -1) { - perror("accept()"); + perror(MOCK "accept()"); + exit(EXIT_FAILURE); + } + if (fcntl(clisock, F_SETFL, O_NONBLOCK) == -1) + { + fprintf(stderr, MOCK "ClientContext::accept: fcntl(O_NONBLOCK): %s\n", strerror(errno)); + close(clisock); exit(EXIT_FAILURE); } return clisock; diff --git a/tests/host/common/include/UdpContext.h b/tests/host/common/include/UdpContext.h index 4696ab7f7..572decbb3 100644 --- a/tests/host/common/include/UdpContext.h +++ b/tests/host/common/include/UdpContext.h @@ -79,14 +79,24 @@ public: _sock = -1; } +#if 0 void setMulticastInterface(const ip_addr_t& addr) { + (void)addr; + // user multicast, and this is how it works with posix: send to multicast address: + _dst.addr = staticMCastAddr; + } +#endif + void setMulticastInterface(const ip_addr_t* addr) + { + (void)addr; // user multicast, and this is how it works with posix: send to multicast address: _dst.addr = staticMCastAddr; } void setMulticastTTL(int ttl) { + (void)ttl; //fprintf(stderr, MOCK "TODO: UdpContext::setMulticastTTL\n"); } diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index a0768e083..d9c6cc3b8 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -36,6 +36,18 @@ #include #endif + +#ifdef __cplusplus +extern "C" { +#endif +//#include +char* itoa (int val, char *s, int radix); +char* ltoa (long val, char *s, int radix); +#ifdef __cplusplus +} +#endif + + // exotic typedefs used in the sdk #include