From 559d1685c6a22c7c7c4b46752bd5360f8a8969ba Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 19 Jun 2019 15:12:36 +0200 Subject: [PATCH 1/6] emulation: add fake cont_yield (temporarily disable littleFS mock due to missing file) --- tests/host/Makefile | 3 ++- tests/host/common/Arduino.cpp | 6 ++++++ tests/host/common/ArduinoMain.cpp | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index 1c4cc451de..0619136fca 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -106,8 +106,9 @@ MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\ ArduinoMain.cpp \ ArduinoMainUdp.cpp \ ArduinoMainSpiffs.cpp \ - ArduinoMainLittlefs.cpp \ user_interface.cpp \ + + #(not in tree) ArduinoMainLittlefs.cpp ) MOCK_C_FILES := $(addprefix common/,\ diff --git a/tests/host/common/Arduino.cpp b/tests/host/common/Arduino.cpp index 830ab3480a..5192028e73 100644 --- a/tests/host/common/Arduino.cpp +++ b/tests/host/common/Arduino.cpp @@ -63,3 +63,9 @@ extern "C" void delayMicroseconds(unsigned int us) { usleep(us); } + +#include "cont.h" +cont_t* g_pcont = NULL; +extern "C" void cont_yield(cont_t*) +{ +} diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index b0fb164ef0..8d9830826e 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -152,7 +152,7 @@ static struct option options[] = void cleanup () { mock_stop_spiffs(); - mock_stop_littlefs(); +// mock_stop_littlefs(); mock_stop_uart(); } @@ -239,7 +239,7 @@ int main (int argc, char* const argv []) name += "-littlefs"; name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC); name += "KB"; - mock_start_littlefs(name, littlefs_kb); +// mock_start_littlefs(name, littlefs_kb); } // setup global global_ipv4_netfmt From 5f69ad4e056de98b07b09fc1b19d9bd985a77d74 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 20 Jun 2019 00:46:25 +0200 Subject: [PATCH 2/6] littlefs: fixes for mock/emulation, use in FSBrowser example --- .../examples/FSBrowser/FSBrowser.ino | 31 ++++++++++++------- tests/host/Makefile | 2 +- tests/host/common/ArduinoMain.cpp | 4 +-- tests/host/common/ArduinoMainLittlefs.cpp | 17 ++++++++++ 4 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 tests/host/common/ArduinoMainLittlefs.cpp diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino index cf1c3786d9..8296bba92f 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino @@ -27,6 +27,10 @@ #include #include #include +#include + +//FS* filesystem = &SPIFFS; +FS* filesystem = &LittleFS; #define DBG_OUTPUT_PORT Serial @@ -94,11 +98,11 @@ bool handleFileRead(String path) { } String contentType = getContentType(path); String pathWithGz = path + ".gz"; - if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { - if (SPIFFS.exists(pathWithGz)) { + if (filesystem->exists(pathWithGz) || filesystem->exists(path)) { + if (filesystem->exists(pathWithGz)) { path += ".gz"; } - File file = SPIFFS.open(path, "r"); + File file = filesystem->open(path, "r"); server.streamFile(file, contentType); file.close(); return true; @@ -117,7 +121,7 @@ void handleFileUpload() { filename = "/" + filename; } DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename); - fsUploadFile = SPIFFS.open(filename, "w"); + fsUploadFile = filesystem->open(filename, "w"); filename = String(); } else if (upload.status == UPLOAD_FILE_WRITE) { //DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize); @@ -141,10 +145,10 @@ void handleFileDelete() { if (path == "/") { return server.send(500, "text/plain", "BAD PATH"); } - if (!SPIFFS.exists(path)) { + if (!filesystem->exists(path)) { return server.send(404, "text/plain", "FileNotFound"); } - SPIFFS.remove(path); + filesystem->remove(path); server.send(200, "text/plain", ""); path = String(); } @@ -158,10 +162,10 @@ void handleFileCreate() { if (path == "/") { return server.send(500, "text/plain", "BAD PATH"); } - if (SPIFFS.exists(path)) { + if (filesystem->exists(path)) { return server.send(500, "text/plain", "FILE EXISTS"); } - File file = SPIFFS.open(path, "w"); + File file = filesystem->open(path, "w"); if (file) { file.close(); } else { @@ -179,7 +183,7 @@ void handleFileList() { String path = server.arg("dir"); DBG_OUTPUT_PORT.println("handleFileList: " + path); - Dir dir = SPIFFS.openDir(path); + Dir dir = filesystem->openDir(path); path = String(); String output = "["; @@ -192,7 +196,10 @@ void handleFileList() { output += "{\"type\":\""; output += (isDir) ? "dir" : "file"; output += "\",\"name\":\""; - output += String(entry.name()).substring(1); + if (entry.name()[0] == '/') + output += String(entry.name()).substring(1); + else + output += entry.name(); output += "\"}"; entry.close(); } @@ -205,9 +212,9 @@ void setup(void) { DBG_OUTPUT_PORT.begin(115200); DBG_OUTPUT_PORT.print("\n"); DBG_OUTPUT_PORT.setDebugOutput(true); - SPIFFS.begin(); + filesystem->begin(); { - Dir dir = SPIFFS.openDir("/"); + Dir dir = filesystem->openDir("/"); while (dir.next()) { String fileName = dir.fileName(); size_t fileSize = dir.fileSize(); diff --git a/tests/host/Makefile b/tests/host/Makefile index 8344222ef2..1c4cc451de 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -106,9 +106,9 @@ MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\ ArduinoMain.cpp \ ArduinoMainUdp.cpp \ ArduinoMainSpiffs.cpp \ + ArduinoMainLittlefs.cpp \ user_interface.cpp \ ) - #(not in tree) ArduinoMainLittlefs.cpp MOCK_C_FILES := $(addprefix common/,\ md5.c \ diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 8d9830826e..b0fb164ef0 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -152,7 +152,7 @@ static struct option options[] = void cleanup () { mock_stop_spiffs(); -// mock_stop_littlefs(); + mock_stop_littlefs(); mock_stop_uart(); } @@ -239,7 +239,7 @@ int main (int argc, char* const argv []) name += "-littlefs"; name += String(littlefs_kb > 0? littlefs_kb: -littlefs_kb, DEC); name += "KB"; -// mock_start_littlefs(name, littlefs_kb); + mock_start_littlefs(name, littlefs_kb); } // setup global global_ipv4_netfmt diff --git a/tests/host/common/ArduinoMainLittlefs.cpp b/tests/host/common/ArduinoMainLittlefs.cpp new file mode 100644 index 0000000000..bf040a2fc5 --- /dev/null +++ b/tests/host/common/ArduinoMainLittlefs.cpp @@ -0,0 +1,17 @@ + +#include "littlefs_mock.h" + +LittleFSMock* littlefs_mock = nullptr; + +void mock_start_littlefs (const String& fname, size_t size_kb, size_t block_kb, size_t page_b) +{ + littlefs_mock = new LittleFSMock(size_kb * 1024, block_kb * 1024, page_b, fname); +} + +void mock_stop_littlefs () +{ + if (littlefs_mock) + delete littlefs_mock; + littlefs_mock = nullptr; +} + From bc949afa091b88f656cf8aa0f84ae08aa33f5cec Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 19 Jun 2019 19:01:20 +0200 Subject: [PATCH 3/6] emulation: add fake cont_yield (#6210) * emulation: add fake cont_yield (temporarily disable littleFS mock due to missing file) * fix makefile --- tests/host/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/host/Makefile b/tests/host/Makefile index 0619136fca..99507f9bad 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -110,6 +110,7 @@ MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\ #(not in tree) ArduinoMainLittlefs.cpp ) + #(not in tree) ArduinoMainLittlefs.cpp MOCK_C_FILES := $(addprefix common/,\ md5.c \ From e1c7c8c5237d72104def68fa28412dc14c13817f Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 20 Jun 2019 09:57:42 +0200 Subject: [PATCH 4/6] example style --- .../ESP8266WebServer/examples/FSBrowser/FSBrowser.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino index 8296bba92f..b03675ba37 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino @@ -196,10 +196,11 @@ void handleFileList() { output += "{\"type\":\""; output += (isDir) ? "dir" : "file"; output += "\",\"name\":\""; - if (entry.name()[0] == '/') - output += String(entry.name()).substring(1); - else - output += entry.name(); + if (entry.name()[0] == '/') { + output += &(entry.name[1]); + } else { + output += entry.name(); + } output += "\"}"; entry.close(); } From 7cc551f66e67a9ee9e07d59c7d877523463229fe Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 20 Jun 2019 11:29:56 +0200 Subject: [PATCH 5/6] fix example --- libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino index b03675ba37..69065c43d5 100644 --- a/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino +++ b/libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino @@ -197,7 +197,7 @@ void handleFileList() { output += (isDir) ? "dir" : "file"; output += "\",\"name\":\""; if (entry.name()[0] == '/') { - output += &(entry.name[1]); + output += &(entry.name()[1]); } else { output += entry.name(); } From 13dfdcc5ddc7925ab3de7c515be8026e5c2aca08 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Thu, 20 Jun 2019 14:23:55 +0200 Subject: [PATCH 6/6] emulation: makefile: integrate arch size into object file names --- tests/host/Makefile | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index 99507f9bad..19444e6c40 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -26,6 +26,7 @@ $(warning Cannot compile in 32 bit mode, switching to native mode) else N32 = 32 M32 = -m32 +E32 = .32 endif endif @@ -106,11 +107,9 @@ MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\ ArduinoMain.cpp \ ArduinoMainUdp.cpp \ ArduinoMainSpiffs.cpp \ + ArduinoMainLittlefs.cpp \ user_interface.cpp \ - - #(not in tree) ArduinoMainLittlefs.cpp ) - #(not in tree) ArduinoMainLittlefs.cpp MOCK_C_FILES := $(addprefix common/,\ md5.c \ @@ -165,10 +164,10 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou C_SOURCE_FILES = $(MOCK_C_FILES) $(CORE_C_FILES) CPP_SOURCE_FILES = $(MOCK_CPP_FILES) $(CORE_CPP_FILES) $(TEST_CPP_FILES) -C_OBJECTS = $(C_SOURCE_FILES:.c=.c.o) +C_OBJECTS = $(C_SOURCE_FILES:.c=.c$(E32).o) -CPP_OBJECTS_CORE = $(MOCK_CPP_FILES:.cpp=.cpp.o) $(CORE_CPP_FILES:.cpp=.cpp.o) -CPP_OBJECTS_TESTS = $(TEST_CPP_FILES:.cpp=.cpp.o) +CPP_OBJECTS_CORE = $(MOCK_CPP_FILES:.cpp=.cpp$(E32).o) $(CORE_CPP_FILES:.cpp=.cpp$(E32).o) +CPP_OBJECTS_TESTS = $(TEST_CPP_FILES:.cpp=.cpp$(E32).o) CPP_OBJECTS = $(CPP_OBJECTS_CORE) $(CPP_OBJECTS_TESTS) @@ -185,7 +184,10 @@ doCI: build-info $(OUTPUT_BINARY) valgrind test gcov test: $(OUTPUT_BINARY) # run host test for CI $(OUTPUT_BINARY) -clean: clean-objects clean-coverage # clean everything +clean: + make FORCE32=0 cleanarch; make FORCE32=1 cleanarch + +cleanarch: clean-objects clean-coverage # clean everything rm -rf $(BINDIR) clean-objects: @@ -217,11 +219,11 @@ build-info: # show toolchain version -include $(BINDIR)/.*.d .SUFFIXES: -%.c.o: %.c +%.c$(E32).o: %.c $(VERBC) $(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $< -.PRECIOUS: %.cpp.o -%.cpp.o: %.cpp +.PRECIOUS: %.cpp$(E32).o +%.cpp$(E32).o: %.cpp $(VERBCXX) $(CXX) $(PREINCLUDES) $(CXXFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $< $(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE) @@ -309,13 +311,13 @@ USERLIBDIRS = $(shell test -z "$(ULIBPATHS)" || for d in $(ULIBPATHS); do for dd 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) INC_PATHS += -I$(INODIR)/.. -CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIBSRCS:.cpp=.cpp.o) +CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp$(E32).o) $(USERLIBSRCS:.cpp=.cpp$(E32).o) bin/fullcore.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU) $(VERBAR) ar -rcu $@ $^ $(VERBAR) ranlib -c $@ -%: %.ino.cpp.o bin/fullcore.a +%: %.ino.cpp$(E32).o bin/fullcore.a $(VERBLD) $(CXX) $(LDFLAGS) $< bin/fullcore.a $(LIBSSL) -o $@ @echo "----> $@ <----"