1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Sketch emulation on host (#5342)

* WIP compile examples on host with 'make examples'

* WIP bufferize tcp input

* WIP Makefile

* WIP network to rework, tcp/udp to factorize, udp addresses broken

* minor changes to the core

* WIP basic udp working

* WIP mdns

* WIP mcast receiving, not sending

* WIP mdns OK

* beta version

* SSL + doc

* update travis host test command

* licenses

* typo

* doc: arduino builder is not around: declare functions before calling them

* fix with latest SSL PR, compile in 32 bits mode

* fix make clean

* make -m32 optional

* 32bits compiler ability tester

* WIP

* WIP (fix 1 vtable error, still another one to hunt with using spiffs)

* example astyle

* fix os_printf_plus

* load / save mock spiffs

* fix style

* fix using spiffs/mock

* don't mess ram

* update doc

* remove leftover

* optimization -Os except for CI, rename ARCH32 to FORCE32

* revert useless cast (not even compiled)

* remove unused function

* use proper type for pointer arithmetics

* makefile: sketch object and cpp file moved to bin/ directories
easier to clean, and IDE don't like them

* changes for review

* make use of %zd

* less verbose makefile by default (option)

* update readme
This commit is contained in:
david gauchard
2018-11-20 21:51:45 +01:00
committed by Develo
parent b504881be4
commit 74ca42f829
51 changed files with 3760 additions and 96 deletions

View File

@ -1,7 +1,12 @@
BINARY_DIRECTORY := bin
BINDIR := bin
LCOV_DIRECTORY := lcov
OUTPUT_BINARY := $(BINARY_DIRECTORY)/host_tests
OUTPUT_BINARY := $(BINDIR)/host_tests
CORE_PATH := ../../cores/esp8266
FORCE32 ?= 1
OPTZ ?= -Os
V ?= 0
MAKEFILE = $(word 1, $(MAKEFILE_LIST))
# I wasn't able to build with clang when -coverage flag is enabled, forcing GCC on OS X
ifeq ($(shell uname -s),Darwin)
@ -13,6 +18,36 @@ VALGRIND ?= valgrind
LCOV ?= lcov
GENHTML ?= genhtml
ifeq ($(FORCE32),1)
ABILITY32 = $(shell echo 'int main(){return sizeof(long);}'|$(CXX) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$?; rm -f sizeoflong;)
ifneq ($(ABILITY32),4)
$(warning Cannot compile in 32 bit mode, switching to native mode)
else
N32 = 32
M32 = -m32
endif
endif
ifeq ($(N32),32)
$(warning compiling in 32 bits mode)
else
$(warning compiling in native mode)
endif
ifeq ($(V), 0)
VERBC = @echo "C $@";
VERBCXX = @echo "C++ $@";
VERBLD = @echo "LD $@";
VERBAR = @echo "AR $@";
else
VERBC =
VERBCXX =
VERBLD =
VERBAR =
endif
$(shell mkdir -p $(BINDIR))
CORE_CPP_FILES := $(addprefix $(CORE_PATH)/,\
StreamString.cpp \
Stream.cpp \
@ -31,12 +66,24 @@ CORE_C_FILES := $(addprefix $(CORE_PATH)/,\
spiffs/spiffs_gc.c \
spiffs/spiffs_hydrogen.c \
spiffs/spiffs_nucleus.c \
libb64/cencode.c \
)
MOCK_CPP_FILES := $(addprefix common/,\
MOCK_CPP_FILES_COMMON := $(addprefix common/,\
Arduino.cpp \
spiffs_mock.cpp \
WMath.cpp \
MockSerial.cpp \
MockTools.cpp \
)
MOCK_CPP_FILES := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\
ArduinoCatch.cpp \
)
MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\
ArduinoMain.cpp \
user_interface.cpp \
)
MOCK_C_FILES := $(addprefix common/,\
@ -44,21 +91,40 @@ MOCK_C_FILES := $(addprefix common/,\
noniso.c \
)
INC_PATHS += $(addprefix -I, \
INC_PATHS := $(addprefix -I,\
common \
$(CORE_PATH) \
)
INC_PATHS += $(addprefix -I,\
$(shell echo ../../libraries/*/src) \
$(shell echo ../../libraries/*) \
../../tools/sdk/include \
../../tools/sdk/lwip2/include \
)
TEST_CPP_FILES := \
fs/test_fs.cpp \
core/test_pgmspace.cpp \
core/test_md5builder.cpp \
core/test_string.cpp
CXXFLAGS += -std=c++11 -Wall -Werror -coverage -O0 -fno-common -g
CFLAGS += -std=c99 -Wall -Werror -coverage -O0 -fno-common -g
LDFLAGS += -coverage -O0
PREINCLUDES := \
-include common/mock.h \
-include common/c_types.h \
ifneq ($(D),)
OPTZ=-O0
DEBUG += -DDEBUG_ESP_PORT=Serial
DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_MDNS
endif
CXXFLAGS += $(DEBUG) -std=c++11 -Wall -Werror -coverage $(OPTZ) -fno-common -g $(M32)
CFLAGS += -std=c99 -Wall -Werror -coverage $(OPTZ) -fno-common -g $(M32)
LDFLAGS += -coverage $(OPTZ) -g $(M32)
VALGRINDFLAGS += --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999
CXXFLAGS += -Wno-error=format-security # cores/esp8266/Print.cpp:42:24: error: format not a string literal and no format arguments [-Werror=format-security] -- (os_printf_plus(not_the_best_way))
#CXXFLAGS += -Wno-format-security # cores/esp8266/Print.cpp:42:40: warning: format not a string literal and no format arguments [-Wformat-security] -- (os_printf_plus(not_the_best_way))
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
@ -74,21 +140,23 @@ CPP_OBJECTS = $(CPP_OBJECTS_CORE) $(CPP_OBJECTS_TESTS)
OBJECTS = $(C_OBJECTS) $(CPP_OBJECTS)
COVERAGE_FILES = $(OBJECTS:.o=.gc*)
all: build-info $(OUTPUT_BINARY) valgrind test gcov
all: help
test: $(OUTPUT_BINARY)
CI: build-info $(OUTPUT_BINARY) valgrind test gcov # run CI
test: $(OUTPUT_BINARY) # run host test for CI
$(OUTPUT_BINARY)
clean: clean-objects clean-coverage
rm -rf $(BINARY_DIRECTORY)
clean: clean-objects clean-coverage # clean everything
rm -rf $(BINDIR)
clean-objects:
rm -rf $(OBJECTS)
rm -rf $(C_OBJECTS) $(CPP_OBJECTS_CORE) $(CPP_OBJECTS_CORE_EMU) $(CPP_OBJECTS_TESTS)
clean-coverage:
rm -rf $(COVERAGE_FILES) $(LCOV_DIRECTORY) *.gcov
gcov: test
gcov: test # run coverage for CI
find $(CORE_PATH) -name "*.gcno" -exec $(GCOV) -r -pb {} +
valgrind: $(OUTPUT_BINARY)
@ -98,7 +166,7 @@ valgrind: $(OUTPUT_BINARY)
$(LCOV) --directory $(CORE_PATH) --capture --output-file $(LCOV_DIRECTORY)/app.info
$(GENHTML) $(LCOV_DIRECTORY)/app.info -o $(LCOV_DIRECTORY)
build-info:
build-info: # show toolchain version
@echo "-------- build tools info --------"
@echo "CC: " $(CC)
$(CC) -v
@ -108,18 +176,147 @@ build-info:
$(GCOV) -v
@echo "----------------------------------"
$(BINARY_DIRECTORY):
mkdir -p $@
-include $(BINDIR)/.*.d
.SUFFIXES:
$(C_OBJECTS): %.c.o: %.c
$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
%.c.o: %.c
$(VERBC) $(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
$(CPP_OBJECTS): %.cpp.o: %.cpp
$(CXX) $(CXXFLAGS) $(INC_PATHS) -c -o $@ $<
.PRECIOUS: %.cpp.o
%.cpp.o: %.cpp
$(VERBCXX) $(CXX) $(PREINCLUDES) $(CXXFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
$(BINARY_DIRECTORY)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE)
ar -rcu $@ $(C_OBJECTS) $(CPP_OBJECTS_CORE)
$(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE)
ar -rcu $@ $^
ranlib -c $@
$(OUTPUT_BINARY): $(BINARY_DIRECTORY) $(CPP_OBJECTS_TESTS) $(BINARY_DIRECTORY)/core.a
$(CXX) $(LDFLAGS) $(CPP_OBJECTS_TESTS) $(BINARY_DIRECTORY)/core.a $(LIBS) -o $(OUTPUT_BINARY)
$(OUTPUT_BINARY): $(CPP_OBJECTS_TESTS) $(BINDIR)/core.a
$(VERBLD) $(CXX) $(LDFLAGS) $^ -o $@
#################################################
# building ino sources
ARDUINO_LIBS := \
$(addprefix $(CORE_PATH)/,\
IPAddress.cpp \
Updater.cpp \
) \
$(addprefix ../../libraries/,\
$(addprefix ESP8266WiFi/src/,\
ESP8266WiFi.cpp \
ESP8266WiFiAP.cpp \
ESP8266WiFiGeneric.cpp \
ESP8266WiFiMulti.cpp \
ESP8266WiFiSTA-WPS.cpp \
ESP8266WiFiSTA.cpp \
ESP8266WiFiScan.cpp \
WiFiClient.cpp \
WiFiUdp.cpp \
WiFiClientSecureBearSSL.cpp \
WiFiServerSecureBearSSL.cpp \
BearSSLHelpers.cpp \
CertStoreBearSSL.cpp \
) \
$(addprefix ESP8266WebServer/src/,\
ESP8266WebServer.cpp \
Parsing.cpp \
detail/mimetable.cpp \
) \
ESP8266mDNS/ESP8266mDNS.cpp \
ArduinoOTA/ArduinoOTA.cpp \
DNSServer/src/DNSServer.cpp \
ESP8266AVRISP/src/ESP8266AVRISP.cpp \
ESP8266HTTPClient/src/ESP8266HTTPClient.cpp \
) \
MOCK_ARDUINO_LIBS := \
common/ClientContextSocket.cpp \
common/ClientContextTools.cpp \
common/MockWiFiServerSocket.cpp \
common/MockWiFiServer.cpp \
common/UdpContextSocket.cpp \
common/HostWiring.cpp \
common/MockEsp.cpp \
common/MockEEPROM.cpp \
common/MockSPI.cpp \
CPP_SOURCES_CORE_EMU = \
$(MOCK_CPP_FILES_EMU) \
$(CORE_CPP_FILES) \
$(MOCK_ARDUINO_LIBS) \
$(ARDUINO_LIBS) \
LIBSSLFILE = ../../tools/sdk/ssl/bearssl/build$(N32)/libbearssl.a
ifeq (,$(wildcard $(LIBSSLFILE)))
LIBSSL =
else
LIBSSL = $(LIBSSLFILE)
endif
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; do test -r $$ss && echo $$ss; done; done)
INC_PATHS += $(USERLIBDIRS)
CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIBSRCS:.cpp=.cpp.o)
bin/fullcore.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU)
$(VERBAR) ar -rcu $@ $^
$(VERBAR) ranlib -c $@
%: %.ino.cpp.o bin/fullcore.a
$(VERBLD) $(CXX) $(LDFLAGS) $< bin/fullcore.a $(LIBSSL) -o $@
@echo "----> $@ <----"
#################################################
# are we in primary make call ?
ifeq ($(INO),)
%: %.ino
@# recursive 'make' with paths
$(MAKE) -f $(MAKEFILE) INODIR=$(dir $@) INO=$(notdir $@) $(BINDIR)/$(notdir $@)/$(notdir $@)
@# see below the new build rule with fixed output path outside from core location
#####################
# recursive call on ino targer
else
$(BINDIR)/$(INO)/$(INO).ino.cpp:
@# arduino builder would come around here (.ino -> .ino.cpp)
@mkdir -p $(BINDIR)/$(INO); \
( \
echo "#include \"$(INODIR)/$(INO).ino\""; \
for i in $(INODIR)/*.ino; do \
test "$$i" = $(INODIR)/$(INO).ino || echo "#include \"$$i\""; \
done; \
) > $(BINDIR)/$(INO)/$(INO).ino.cpp
endif # recursive
#####################
#################################################
.PHONY: list
list: # show core example list
@for dir in ../../libraries/*/examples; do \
exampledir=$${dir%/*}; \
exampledirname=$${exampledir##*/}; \
for subdir in $$dir/*; do \
exname=$${subdir##*/}; \
echo "$$subdir/$$exname"; \
done; \
done; \
#################################################
# help
.PHONY: help
help:
@cat README.txt
@echo ""
@echo "Make rules:"
@echo ""
@sed -rne 's,([^: \t]*):[^=#]*#[\t ]*(.*),\1 - \2,p' $(MAKEFILE)
@echo ""