Add mingw gcc and g++ tests

This commit is contained in:
cpq committed 2020-12-25 19:24:51 +00:00
1 parent e1fd82bc46
commit 55f5f74658
4 files changed
+46 -31

No files matched your search

+10 -1
View File
@@ -6,6 +6,7 @@ SSL ?= MBEDTLS
CDIR ?= $(realpath $(CURDIR)) CDIR ?= $(realpath $(CURDIR))
VC98 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc98 VC98 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc98
VC2017 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc2017 VC2017 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc2017
MINGW = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/mingw
GCC = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) mdashnet/cc2 GCC = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) mdashnet/cc2
VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS) VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS)
CLANG ?= clang # /usr/local/opt/llvm\@9/bin/clang CLANG ?= clang # /usr/local/opt/llvm\@9/bin/clang
@@ -30,7 +31,7 @@ CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
endif endif
all: mg_prefix test test++ ex vc98 vc2017 linux linux++ infer fuzz all: mg_prefix test test++ ex vc98 vc2017 mingw mingw++ linux linux++ infer fuzz
ex: ex:
@for X in $(EXAMPLES); do $(MAKE) -C $$X $(EXAMPLE_TARGET); done @for X in $(EXAMPLES); do $(MAKE) -C $$X $(EXAMPLE_TARGET); done
@@ -77,6 +78,14 @@ vc2017: Makefile mongoose.c mongoose.h test/unit_test.c
$(VC2017) wine64 cl mongoose.c test/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe $(VC2017) wine64 cl mongoose.c test/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe
$(VC2017) wine64 $@.exe $(VC2017) wine64 $@.exe
mingw: Makefile mongoose.c mongoose.h test/unit_test.c
$(MINGW) i686-w64-mingw32-gcc mongoose.c test/unit_test.c -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe
$(VC98) wine test.exe
mingw++: Makefile mongoose.c mongoose.h test/unit_test.c
$(MINGW) i686-w64-mingw32-g++ mongoose.c test/unit_test.c -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe
# Note: for some reason, a binary built with mingw g++, fails to run
#linux: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) #linux: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6)
linux: CFLAGS += -fsanitize=address,undefined linux: CFLAGS += -fsanitize=address,undefined
linux: Makefile mongoose.c mongoose.h test/unit_test.c linux: Makefile mongoose.c mongoose.h test/unit_test.c
+18 -15
View File
@@ -821,7 +821,6 @@ typedef struct win32_dir {
int gettimeofday(struct timeval *tv, void *tz) { int gettimeofday(struct timeval *tv, void *tz) {
FILETIME ft; FILETIME ft;
unsigned __int64 tmpres = 0; unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (tv != NULL) { if (tv != NULL) {
GetSystemTimeAsFileTime(&ft); GetSystemTimeAsFileTime(&ft);
@@ -833,6 +832,7 @@ int gettimeofday(struct timeval *tv, void *tz) {
tv->tv_sec = (long) (tmpres / 1000000UL); tv->tv_sec = (long) (tmpres / 1000000UL);
tv->tv_usec = (long) (tmpres % 1000000UL); tv->tv_usec = (long) (tmpres % 1000000UL);
} }
(void) tz;
return 0; return 0;
} }
@@ -864,7 +864,7 @@ DIR *opendir(const char *name) {
if (name == NULL) { if (name == NULL) {
SetLastError(ERROR_BAD_ARGUMENTS); SetLastError(ERROR_BAD_ARGUMENTS);
} else if ((d = malloc(sizeof(*d))) == NULL) { } else if ((d = (DIR *) malloc(sizeof(*d))) == NULL) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
} else { } else {
to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0])); to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0]));
@@ -2496,7 +2496,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len,
#if MG_ENABLE_IPV6 #if MG_ENABLE_IPV6
if (c->peer.is_ip6) slen = sizeof(usa.sin6); if (c->peer.is_ip6) slen = sizeof(usa.sin6);
#endif #endif
n = recvfrom(FD(c), buf, len, 0, &usa.sa, &slen); n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
if (n > 0) { if (n > 0) {
if (c->peer.is_ip6) { if (c->peer.is_ip6) {
#if MG_ENABLE_IPV6 #if MG_ENABLE_IPV6
@@ -2509,7 +2509,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len,
} }
} }
} else { } else {
n = recv(FD(c), buf, len, MSG_NONBLOCKING); n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
} }
*fail = (n == 0) || (n < 0 && mg_sock_failed()); *fail = (n == 0) || (n < 0 && mg_sock_failed());
return n; return n;
@@ -2524,9 +2524,9 @@ static int mg_sock_send(struct mg_connection *c, const void *buf, int len,
#if MG_ENABLE_IPV6 #if MG_ENABLE_IPV6
if (c->peer.is_ip6) slen = sizeof(usa.sin6); if (c->peer.is_ip6) slen = sizeof(usa.sin6);
#endif #endif
n = sendto(FD(c), buf, len, 0, &usa.sa, slen); n = sendto(FD(c), (char *) buf, len, 0, &usa.sa, slen);
} else { } else {
n = send(FD(c), buf, len, MSG_NONBLOCKING); n = send(FD(c), (char *) buf, len, MSG_NONBLOCKING);
} }
*fail = (n == 0) || (n < 0 && mg_sock_failed()); *fail = (n == 0) || (n < 0 && mg_sock_failed());
return n; return n;
@@ -2610,18 +2610,18 @@ SOCKET mg_open_listener(const char *url) {
// SO_REUSEADDR was designed for, and leads to hard-to-track failure // SO_REUSEADDR was designed for, and leads to hard-to-track failure
// scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless // scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless
// SO_EXCLUSIVEADDRUSE is supported and set on a socket. // SO_EXCLUSIVEADDRUSE is supported and set on a socket.
!setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) && !setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) &&
#endif #endif
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE) #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
!setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on, !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
sizeof(on)) && sizeof(on)) &&
#endif #endif
bind(fd, &usa.sa, slen) == 0 && bind(fd, &usa.sa, slen) == 0 &&
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit // NOTE(lsm): FreeRTOS uses backlog value as a connection limit
(type == SOCK_DGRAM || listen(fd, 128) == 0)) { (type == SOCK_DGRAM || listen(fd, 128) == 0)) {
mg_set_non_blocking_mode(fd); mg_set_non_blocking_mode(fd);
} else if (fd >= 0) { } else if (fd != INVALID_SOCKET) {
LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO)); LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO));
closesocket(fd); closesocket(fd);
fd = INVALID_SOCKET; fd = INVALID_SOCKET;
@@ -2692,22 +2692,25 @@ static void setsockopts(struct mg_connection *c) {
#if MG_ARCH == MG_ARCH_FREERTOS #if MG_ARCH == MG_ARCH_FREERTOS
FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT); FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
#else #else
int on = 1, cnt = 3, intvl = 20; int on = 1;
#if !defined(SOL_TCP) #if !defined(SOL_TCP)
#define SOL_TCP IPPROTO_TCP #define SOL_TCP IPPROTO_TCP
#endif #endif
setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (void *) &on, sizeof(on)); setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (char *) &on, sizeof(on));
#if defined(TCP_QUICKACK) #if defined(TCP_QUICKACK)
setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (void *) &on, sizeof(on)); setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (char *) &on, sizeof(on));
#endif #endif
setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (void *) &on, sizeof(on)); setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on));
#if ESP32 || ESP8266 || defined(__linux__) #if ESP32 || ESP8266 || defined(__linux__)
int idle = 60; int idle = 60;
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
#endif #endif
#ifndef _WIN32 #ifndef _WIN32
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); {
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); int cnt = 3, intvl = 20;
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl));
}
#endif #endif
#endif #endif
} }
+2 -2
View File
@@ -427,7 +427,6 @@ typedef struct win32_dir {
int gettimeofday(struct timeval *tv, void *tz) { int gettimeofday(struct timeval *tv, void *tz) {
FILETIME ft; FILETIME ft;
unsigned __int64 tmpres = 0; unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (tv != NULL) { if (tv != NULL) {
GetSystemTimeAsFileTime(&ft); GetSystemTimeAsFileTime(&ft);
@@ -439,6 +438,7 @@ int gettimeofday(struct timeval *tv, void *tz) {
tv->tv_sec = (long) (tmpres / 1000000UL); tv->tv_sec = (long) (tmpres / 1000000UL);
tv->tv_usec = (long) (tmpres % 1000000UL); tv->tv_usec = (long) (tmpres % 1000000UL);
} }
(void) tz;
return 0; return 0;
} }
@@ -470,7 +470,7 @@ DIR *opendir(const char *name) {
if (name == NULL) { if (name == NULL) {
SetLastError(ERROR_BAD_ARGUMENTS); SetLastError(ERROR_BAD_ARGUMENTS);
} else if ((d = malloc(sizeof(*d))) == NULL) { } else if ((d = (DIR *) malloc(sizeof(*d))) == NULL) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY); SetLastError(ERROR_NOT_ENOUGH_MEMORY);
} else { } else {
to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0])); to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0]));
+16 -13
View File
@@ -87,7 +87,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len,
#if MG_ENABLE_IPV6 #if MG_ENABLE_IPV6
if (c->peer.is_ip6) slen = sizeof(usa.sin6); if (c->peer.is_ip6) slen = sizeof(usa.sin6);
#endif #endif
n = recvfrom(FD(c), buf, len, 0, &usa.sa, &slen); n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen);
if (n > 0) { if (n > 0) {
if (c->peer.is_ip6) { if (c->peer.is_ip6) {
#if MG_ENABLE_IPV6 #if MG_ENABLE_IPV6
@@ -100,7 +100,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len,
} }
} }
} else { } else {
n = recv(FD(c), buf, len, MSG_NONBLOCKING); n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING);
} }
*fail = (n == 0) || (n < 0 && mg_sock_failed()); *fail = (n == 0) || (n < 0 && mg_sock_failed());
return n; return n;
@@ -115,9 +115,9 @@ static int mg_sock_send(struct mg_connection *c, const void *buf, int len,
#if MG_ENABLE_IPV6 #if MG_ENABLE_IPV6
if (c->peer.is_ip6) slen = sizeof(usa.sin6); if (c->peer.is_ip6) slen = sizeof(usa.sin6);
#endif #endif
n = sendto(FD(c), buf, len, 0, &usa.sa, slen); n = sendto(FD(c), (char *) buf, len, 0, &usa.sa, slen);
} else { } else {
n = send(FD(c), buf, len, MSG_NONBLOCKING); n = send(FD(c), (char *) buf, len, MSG_NONBLOCKING);
} }
*fail = (n == 0) || (n < 0 && mg_sock_failed()); *fail = (n == 0) || (n < 0 && mg_sock_failed());
return n; return n;
@@ -201,18 +201,18 @@ SOCKET mg_open_listener(const char *url) {
// SO_REUSEADDR was designed for, and leads to hard-to-track failure // SO_REUSEADDR was designed for, and leads to hard-to-track failure
// scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless // scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless
// SO_EXCLUSIVEADDRUSE is supported and set on a socket. // SO_EXCLUSIVEADDRUSE is supported and set on a socket.
!setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) && !setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) &&
#endif #endif
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE) #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
!setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on, !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on,
sizeof(on)) && sizeof(on)) &&
#endif #endif
bind(fd, &usa.sa, slen) == 0 && bind(fd, &usa.sa, slen) == 0 &&
// NOTE(lsm): FreeRTOS uses backlog value as a connection limit // NOTE(lsm): FreeRTOS uses backlog value as a connection limit
(type == SOCK_DGRAM || listen(fd, 128) == 0)) { (type == SOCK_DGRAM || listen(fd, 128) == 0)) {
mg_set_non_blocking_mode(fd); mg_set_non_blocking_mode(fd);
} else if (fd >= 0) { } else if (fd != INVALID_SOCKET) {
LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO)); LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO));
closesocket(fd); closesocket(fd);
fd = INVALID_SOCKET; fd = INVALID_SOCKET;
@@ -283,22 +283,25 @@ static void setsockopts(struct mg_connection *c) {
#if MG_ARCH == MG_ARCH_FREERTOS #if MG_ARCH == MG_ARCH_FREERTOS
FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT); FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
#else #else
int on = 1, cnt = 3, intvl = 20; int on = 1;
#if !defined(SOL_TCP) #if !defined(SOL_TCP)
#define SOL_TCP IPPROTO_TCP #define SOL_TCP IPPROTO_TCP
#endif #endif
setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (void *) &on, sizeof(on)); setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (char *) &on, sizeof(on));
#if defined(TCP_QUICKACK) #if defined(TCP_QUICKACK)
setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (void *) &on, sizeof(on)); setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (char *) &on, sizeof(on));
#endif #endif
setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (void *) &on, sizeof(on)); setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on));
#if ESP32 || ESP8266 || defined(__linux__) #if ESP32 || ESP8266 || defined(__linux__)
int idle = 60; int idle = 60;
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
#endif #endif
#ifndef _WIN32 #ifndef _WIN32
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); {
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); int cnt = 3, intvl = 20;
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl));
}
#endif #endif
#endif #endif
} }