Skip to content

Commit d7fe68d

Browse files
Fix SDFS tests
SDFS, SPIFFS, and LittleFS now all share the same common set of tests, greatly increasing the SDFS test coverage.
1 parent da1383c commit d7fe68d

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

tests/host/common/sdfs_mock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
#include "../../../libraries/SDFS/src/SDFS.h"
1818

1919
#define SDSIZE 16LL
20-
uint64_t _sdCardSizeB = SDSIZE * 1024LL * 1024LL;
21-
uint8_t _sdCard[SDSIZE * 1024LL * 1024LL];
20+
uint64_t _sdCardSizeB = 0;
21+
uint8_t *_sdCard = nullptr;

tests/host/common/sdfs_mock.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ class SDFSMock {
2828
~SDFSMock() { }
2929
};
3030

31-
#define SDFS_MOCK_DECLARE(size_kb, block_kb, page_b, storage) SDFSMock sdfs_mock(size_kb * 1024, block_kb * 1024, page_b, storage); SDFS.format();
31+
extern uint64_t _sdCardSizeB;
32+
extern uint8_t *_sdCard;
33+
34+
#define SDFS_MOCK_DECLARE(size_kb, block_kb, page_b, storage) \
35+
SDFS.end(); \
36+
SDFSMock sdfs_mock(size_kb * 1024, block_kb * 1024, page_b, storage); free(_sdCard); \
37+
_sdCardSizeB = size_kb ? 16 * 1024 * 1024 : 0; \
38+
if (_sdCardSizeB) _sdCard = (uint8_t*)calloc(_sdCardSizeB, 1); \
39+
else _sdCard = nullptr; \
40+
SDFS.setConfig(SDFSConfig().setAutoFormat(true));
3241
#define SDFS_MOCK_RESET() sdfs_mock.reset()
3342

3443
#endif /* spiffs_mock_hpp */

tests/host/fs/test_fs.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "../../../libraries/SDFS/src/SDFS.h"
2525
#include "../../../libraries/SD/src/SD.h"
2626

27+
#if 1
2728
namespace spiffs_test {
2829
#define FSTYPE SPIFFS
2930
#define TESTPRE "SPIFFS - "
@@ -89,13 +90,16 @@ TEST_CASE("LittleFS checks the config object passed in", "[fs]")
8990
}
9091

9192
};
92-
93+
#endif
9394
namespace sdfs_test {
9495
#define FSTYPE SDFS
9596
#define TESTPRE "SDFS - "
9697
#define TESTPAT "[sdfs]"
97-
// SDFS routines strip leading slashes before doing anything, so up to 31 char names are allowable
98-
#define TOOLONGFILENAME "/12345678901234567890123456789012"
98+
// SDFS supports long paths (MAXPATH)
99+
#define TOOLONGFILENAME "/" \
100+
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" \
101+
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" \
102+
"12345678901234567890123456789012345678901234567890123456"
99103
#define FS_MOCK_DECLARE SDFS_MOCK_DECLARE
100104
#define FS_MOCK_RESET SDFS_MOCK_RESET
101105
#define FS_HAS_DIRS
@@ -118,7 +122,7 @@ TEST_CASE("SDFS checks the config object passed in", "[fs]")
118122
REQUIRE_FALSE(SDFS.setConfig(f));
119123
REQUIRE_FALSE(SDFS.setConfig(s));
120124
REQUIRE(SDFS.setConfig(d));
121-
REQUIRE_FALSE(LittleFS.setConfig(l));
125+
REQUIRE_FALSE(SDFS.setConfig(l));
122126
}
123127

124128
};

tests/host/fs/test_fs.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ TEST_CASE(TESTPRE "Filesystem is empty after format", TESTPAT)
9696
REQUIRE(FSTYPE.begin());
9797
createFile("/1", "first");
9898
createFile("/2", "second");
99+
FSTYPE.end();
99100
REQUIRE(FSTYPE.format());
101+
REQUIRE(FSTYPE.begin());
100102
Dir root = FSTYPE.openDir("/");
101103
size_t count = 0;
102104
while (root.next()) {
@@ -161,6 +163,7 @@ TEST_CASE(TESTPRE "truncate", TESTPAT)
161163

162164
#ifdef FS_HAS_DIRS
163165

166+
#if FSTYPE != SDFS
164167
// We silently make subdirectories if they do not exist and silently remove
165168
// them when they're no longer needed, so make sure we can clean up after
166169
// ourselves. At some point we may drop this and go to normal POSIX mkdir
@@ -189,6 +192,7 @@ TEST_CASE(TESTPRE "Removing all files in a subdir removes that subdir", TESTPAT)
189192
REQUIRE(files.size() == 3);
190193
REQUIRE(files.find("subdir") == std::end(files));
191194
}
195+
#endif
192196

193197
// LittleFS openDir is slightly different than SPIFFS. In SPIFFS there
194198
// are no directories and "/" is just another character, so "/a/b/c" is a

0 commit comments

Comments
 (0)