mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
littlefs: fixes for mock/emulation, use in FSBrowser example (#6211)
* littlefs: fixes for mock/emulation, use in FSBrowser example * emulation: makefile: integrate arch size into object file names
This commit is contained in:
parent
a78fb72302
commit
fc77f2e89c
@ -27,6 +27,10 @@
|
|||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
//FS* filesystem = &SPIFFS;
|
||||||
|
FS* filesystem = &LittleFS;
|
||||||
|
|
||||||
#define DBG_OUTPUT_PORT Serial
|
#define DBG_OUTPUT_PORT Serial
|
||||||
|
|
||||||
@ -94,11 +98,11 @@ bool handleFileRead(String path) {
|
|||||||
}
|
}
|
||||||
String contentType = getContentType(path);
|
String contentType = getContentType(path);
|
||||||
String pathWithGz = path + ".gz";
|
String pathWithGz = path + ".gz";
|
||||||
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) {
|
if (filesystem->exists(pathWithGz) || filesystem->exists(path)) {
|
||||||
if (SPIFFS.exists(pathWithGz)) {
|
if (filesystem->exists(pathWithGz)) {
|
||||||
path += ".gz";
|
path += ".gz";
|
||||||
}
|
}
|
||||||
File file = SPIFFS.open(path, "r");
|
File file = filesystem->open(path, "r");
|
||||||
server.streamFile(file, contentType);
|
server.streamFile(file, contentType);
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
@ -117,7 +121,7 @@ void handleFileUpload() {
|
|||||||
filename = "/" + filename;
|
filename = "/" + filename;
|
||||||
}
|
}
|
||||||
DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename);
|
DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename);
|
||||||
fsUploadFile = SPIFFS.open(filename, "w");
|
fsUploadFile = filesystem->open(filename, "w");
|
||||||
filename = String();
|
filename = String();
|
||||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
//DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
|
//DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
|
||||||
@ -141,10 +145,10 @@ void handleFileDelete() {
|
|||||||
if (path == "/") {
|
if (path == "/") {
|
||||||
return server.send(500, "text/plain", "BAD PATH");
|
return server.send(500, "text/plain", "BAD PATH");
|
||||||
}
|
}
|
||||||
if (!SPIFFS.exists(path)) {
|
if (!filesystem->exists(path)) {
|
||||||
return server.send(404, "text/plain", "FileNotFound");
|
return server.send(404, "text/plain", "FileNotFound");
|
||||||
}
|
}
|
||||||
SPIFFS.remove(path);
|
filesystem->remove(path);
|
||||||
server.send(200, "text/plain", "");
|
server.send(200, "text/plain", "");
|
||||||
path = String();
|
path = String();
|
||||||
}
|
}
|
||||||
@ -158,10 +162,10 @@ void handleFileCreate() {
|
|||||||
if (path == "/") {
|
if (path == "/") {
|
||||||
return server.send(500, "text/plain", "BAD 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");
|
return server.send(500, "text/plain", "FILE EXISTS");
|
||||||
}
|
}
|
||||||
File file = SPIFFS.open(path, "w");
|
File file = filesystem->open(path, "w");
|
||||||
if (file) {
|
if (file) {
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
@ -179,7 +183,7 @@ void handleFileList() {
|
|||||||
|
|
||||||
String path = server.arg("dir");
|
String path = server.arg("dir");
|
||||||
DBG_OUTPUT_PORT.println("handleFileList: " + path);
|
DBG_OUTPUT_PORT.println("handleFileList: " + path);
|
||||||
Dir dir = SPIFFS.openDir(path);
|
Dir dir = filesystem->openDir(path);
|
||||||
path = String();
|
path = String();
|
||||||
|
|
||||||
String output = "[";
|
String output = "[";
|
||||||
@ -192,7 +196,11 @@ void handleFileList() {
|
|||||||
output += "{\"type\":\"";
|
output += "{\"type\":\"";
|
||||||
output += (isDir) ? "dir" : "file";
|
output += (isDir) ? "dir" : "file";
|
||||||
output += "\",\"name\":\"";
|
output += "\",\"name\":\"";
|
||||||
output += String(entry.name()).substring(1);
|
if (entry.name()[0] == '/') {
|
||||||
|
output += &(entry.name()[1]);
|
||||||
|
} else {
|
||||||
|
output += entry.name();
|
||||||
|
}
|
||||||
output += "\"}";
|
output += "\"}";
|
||||||
entry.close();
|
entry.close();
|
||||||
}
|
}
|
||||||
@ -205,9 +213,9 @@ void setup(void) {
|
|||||||
DBG_OUTPUT_PORT.begin(115200);
|
DBG_OUTPUT_PORT.begin(115200);
|
||||||
DBG_OUTPUT_PORT.print("\n");
|
DBG_OUTPUT_PORT.print("\n");
|
||||||
DBG_OUTPUT_PORT.setDebugOutput(true);
|
DBG_OUTPUT_PORT.setDebugOutput(true);
|
||||||
SPIFFS.begin();
|
filesystem->begin();
|
||||||
{
|
{
|
||||||
Dir dir = SPIFFS.openDir("/");
|
Dir dir = filesystem->openDir("/");
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
String fileName = dir.fileName();
|
String fileName = dir.fileName();
|
||||||
size_t fileSize = dir.fileSize();
|
size_t fileSize = dir.fileSize();
|
||||||
|
@ -26,6 +26,7 @@ $(warning Cannot compile in 32 bit mode, switching to native mode)
|
|||||||
else
|
else
|
||||||
N32 = 32
|
N32 = 32
|
||||||
M32 = -m32
|
M32 = -m32
|
||||||
|
E32 = .32
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -106,9 +107,9 @@ MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) $(addprefix common/,\
|
|||||||
ArduinoMain.cpp \
|
ArduinoMain.cpp \
|
||||||
ArduinoMainUdp.cpp \
|
ArduinoMainUdp.cpp \
|
||||||
ArduinoMainSpiffs.cpp \
|
ArduinoMainSpiffs.cpp \
|
||||||
|
ArduinoMainLittlefs.cpp \
|
||||||
user_interface.cpp \
|
user_interface.cpp \
|
||||||
)
|
)
|
||||||
#(not in tree) ArduinoMainLittlefs.cpp
|
|
||||||
|
|
||||||
MOCK_C_FILES := $(addprefix common/,\
|
MOCK_C_FILES := $(addprefix common/,\
|
||||||
md5.c \
|
md5.c \
|
||||||
@ -163,10 +164,10 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou
|
|||||||
|
|
||||||
C_SOURCE_FILES = $(MOCK_C_FILES) $(CORE_C_FILES)
|
C_SOURCE_FILES = $(MOCK_C_FILES) $(CORE_C_FILES)
|
||||||
CPP_SOURCE_FILES = $(MOCK_CPP_FILES) $(CORE_CPP_FILES) $(TEST_CPP_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_CORE = $(MOCK_CPP_FILES:.cpp=.cpp$(E32).o) $(CORE_CPP_FILES:.cpp=.cpp$(E32).o)
|
||||||
CPP_OBJECTS_TESTS = $(TEST_CPP_FILES:.cpp=.cpp.o)
|
CPP_OBJECTS_TESTS = $(TEST_CPP_FILES:.cpp=.cpp$(E32).o)
|
||||||
|
|
||||||
CPP_OBJECTS = $(CPP_OBJECTS_CORE) $(CPP_OBJECTS_TESTS)
|
CPP_OBJECTS = $(CPP_OBJECTS_CORE) $(CPP_OBJECTS_TESTS)
|
||||||
|
|
||||||
@ -183,7 +184,10 @@ doCI: build-info $(OUTPUT_BINARY) valgrind test gcov
|
|||||||
test: $(OUTPUT_BINARY) # run host test for CI
|
test: $(OUTPUT_BINARY) # run host test for CI
|
||||||
$(OUTPUT_BINARY)
|
$(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)
|
rm -rf $(BINDIR)
|
||||||
|
|
||||||
clean-objects:
|
clean-objects:
|
||||||
@ -215,11 +219,11 @@ build-info: # show toolchain version
|
|||||||
-include $(BINDIR)/.*.d
|
-include $(BINDIR)/.*.d
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
|
|
||||||
%.c.o: %.c
|
%.c$(E32).o: %.c
|
||||||
$(VERBC) $(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
|
$(VERBC) $(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
|
||||||
|
|
||||||
.PRECIOUS: %.cpp.o
|
.PRECIOUS: %.cpp$(E32).o
|
||||||
%.cpp.o: %.cpp
|
%.cpp$(E32).o: %.cpp
|
||||||
$(VERBCXX) $(CXX) $(PREINCLUDES) $(CXXFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
|
$(VERBCXX) $(CXX) $(PREINCLUDES) $(CXXFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
|
||||||
|
|
||||||
$(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE)
|
$(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE)
|
||||||
@ -307,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)
|
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 += $(USERLIBDIRS)
|
||||||
INC_PATHS += -I$(INODIR)/..
|
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)
|
bin/fullcore.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU)
|
||||||
$(VERBAR) ar -rcu $@ $^
|
$(VERBAR) ar -rcu $@ $^
|
||||||
$(VERBAR) ranlib -c $@
|
$(VERBAR) ranlib -c $@
|
||||||
|
|
||||||
%: %.ino.cpp.o bin/fullcore.a
|
%: %.ino.cpp$(E32).o bin/fullcore.a
|
||||||
$(VERBLD) $(CXX) $(LDFLAGS) $< bin/fullcore.a $(LIBSSL) -o $@
|
$(VERBLD) $(CXX) $(LDFLAGS) $< bin/fullcore.a $(LIBSSL) -o $@
|
||||||
@echo "----> $@ <----"
|
@echo "----> $@ <----"
|
||||||
|
|
||||||
|
17
tests/host/common/ArduinoMainLittlefs.cpp
Normal file
17
tests/host/common/ArduinoMainLittlefs.cpp
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user