Skip to content

Commit 228ad7e

Browse files
d-a-vdevyte
authored andcommitted
tests/host: fixes and updates (esp8266#5537)
(LEAmDNS, broken pipe, non blocking accepted sockets, digitalRead)
1 parent 2388102 commit 228ad7e

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

libraries/ESP8266mDNS/src/LEAmDNS_Transfer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ bool MDNSResponder::_udpRead16(uint16_t& p_ru16Value) {
10051005
bool bResult = false;
10061006

10071007
if (_udpReadBuffer((unsigned char*)&p_ru16Value, sizeof(p_ru16Value))) {
1008-
p_ru16Value = ntohs(p_ru16Value);
1008+
p_ru16Value = lwip_ntohs(p_ru16Value);
10091009
bResult = true;
10101010
}
10111011
return bResult;
@@ -1019,7 +1019,7 @@ bool MDNSResponder::_udpRead32(uint32_t& p_ru32Value) {
10191019
bool bResult = false;
10201020

10211021
if (_udpReadBuffer((unsigned char*)&p_ru32Value, sizeof(p_ru32Value))) {
1022-
p_ru32Value = ntohl(p_ru32Value);
1022+
p_ru32Value = lwip_ntohl(p_ru32Value);
10231023
bResult = true;
10241024
}
10251025
return bResult;
@@ -1052,7 +1052,7 @@ bool MDNSResponder::_udpAppend8(uint8_t p_u8Value) {
10521052
*/
10531053
bool MDNSResponder::_udpAppend16(uint16_t p_u16Value) {
10541054

1055-
p_u16Value = htons(p_u16Value);
1055+
p_u16Value = lwip_htons(p_u16Value);
10561056
return (_udpAppendBuffer((unsigned char*)&p_u16Value, sizeof(p_u16Value)));
10571057
}
10581058

@@ -1061,7 +1061,7 @@ bool MDNSResponder::_udpAppend16(uint16_t p_u16Value) {
10611061
*/
10621062
bool MDNSResponder::_udpAppend32(uint32_t p_u32Value) {
10631063

1064-
p_u32Value = htonl(p_u32Value);
1064+
p_u32Value = lwip_htonl(p_u32Value);
10651065
return (_udpAppendBuffer((unsigned char*)&p_u32Value, sizeof(p_u32Value)));
10661066
}
10671067

tests/host/Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ COVERAGE_FILES = $(OBJECTS:.o=.gc*)
148148

149149
all: help
150150

151-
CI:
151+
CI: # run CI
152152
$(MAKE) -f $(MAKEFILE) MKFLAGS=-Werror FORCE32=0 OPTZ=-O0 doCI
153153

154-
doCI: build-info $(OUTPUT_BINARY) valgrind test gcov # run CI
154+
doCI: build-info $(OUTPUT_BINARY) valgrind test gcov
155155

156156
test: $(OUTPUT_BINARY) # run host test for CI
157157
$(OUTPUT_BINARY)
@@ -232,7 +232,11 @@ ARDUINO_LIBS := \
232232
Parsing.cpp \
233233
detail/mimetable.cpp \
234234
) \
235-
ESP8266mDNS/ESP8266mDNS.cpp \
235+
ESP8266mDNS/src/LEAmDNS.cpp \
236+
ESP8266mDNS/src/LEAmDNS_Control.cpp \
237+
ESP8266mDNS/src/LEAmDNS_Helpers.cpp \
238+
ESP8266mDNS/src/LEAmDNS_Structs.cpp \
239+
ESP8266mDNS/src/LEAmDNS_Transfer.cpp \
236240
ArduinoOTA/ArduinoOTA.cpp \
237241
DNSServer/src/DNSServer.cpp \
238242
ESP8266AVRISP/src/ESP8266AVRISP.cpp \

tests/host/common/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ extern "C" {
218218
void loop(void);
219219

220220
void yield(void);
221+
void esp_yield(void);
221222
void optimistic_yield(uint32_t interval_us);
222223

223224
#define digitalPinToPort(pin) (0)

tests/host/common/ClientContextSocket.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ size_t mockWrite (int sock, const uint8_t* data, size_t size, int timeout_ms)
135135
}
136136
if (ret)
137137
{
138-
ret = ::write(sock, data, size);
138+
//ret = ::write(sock, data, size);
139+
ret = ::send(sock, data, size, MSG_NOSIGNAL);
139140
if (ret == -1)
140141
{
141142
fprintf(stderr, MOCK "ClientContext::read: write(%d): %s\n", sock, strerror(errno));

tests/host/common/HostWiring.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ void analogWriteRange(uint32_t range)
6969
{
7070
fprintf(stderr, MOCK "analogWriteRange(range=%d)\n", range);
7171
}
72+
73+
int digitalRead(uint8_t pin)
74+
{
75+
fprintf(stderr, MOCK "digitalRead(%d)\n", pin);
76+
return 0;
77+
}

tests/host/common/MockWiFiServerSocket.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <sys/socket.h>
3737
#include <poll.h>
3838
#include <unistd.h>
39+
#include <fcntl.h>
40+
#include <errno.h>
3941

4042
#define int2pcb(x) ((tcp_pcb*)(intptr_t)(x))
4143
#define pcb2int(x) ((int)(intptr_t)(x))
@@ -50,7 +52,13 @@ int serverAccept (int srvsock)
5052
n = sizeof(client);
5153
if ((clisock = accept(srvsock, (struct sockaddr*)&client, &n)) == -1)
5254
{
53-
perror("accept()");
55+
perror(MOCK "accept()");
56+
exit(EXIT_FAILURE);
57+
}
58+
if (fcntl(clisock, F_SETFL, O_NONBLOCK) == -1)
59+
{
60+
fprintf(stderr, MOCK "ClientContext::accept: fcntl(O_NONBLOCK): %s\n", strerror(errno));
61+
close(clisock);
5462
exit(EXIT_FAILURE);
5563
}
5664
return clisock;

tests/host/common/include/UdpContext.h

+10
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,24 @@ class UdpContext
7979
_sock = -1;
8080
}
8181

82+
#if 0
8283
void setMulticastInterface(const ip_addr_t& addr)
8384
{
85+
(void)addr;
86+
// user multicast, and this is how it works with posix: send to multicast address:
87+
_dst.addr = staticMCastAddr;
88+
}
89+
#endif
90+
void setMulticastInterface(const ip_addr_t* addr)
91+
{
92+
(void)addr;
8493
// user multicast, and this is how it works with posix: send to multicast address:
8594
_dst.addr = staticMCastAddr;
8695
}
8796

8897
void setMulticastTTL(int ttl)
8998
{
99+
(void)ttl;
90100
//fprintf(stderr, MOCK "TODO: UdpContext::setMulticastTTL\n");
91101
}
92102

tests/host/common/mock.h

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
#include <vector>
3737
#endif
3838

39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
//#include <stdlib_noniso.h>
44+
char* itoa (int val, char *s, int radix);
45+
char* ltoa (long val, char *s, int radix);
46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
50+
3951
// exotic typedefs used in the sdk
4052

4153
#include <stdint.h>

0 commit comments

Comments
 (0)