Skip to content

Commit a9a4e99

Browse files
committed
refactor(fs): Remove unused CI configuration and simplify test function signature
1 parent b67360f commit a9a4e99

File tree

3 files changed

+50
-34
lines changed

3 files changed

+50
-34
lines changed

tests/validation/fs/ci.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/validation/fs/fs.ino

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ public:
2222
};
2323

2424
/**
25-
* Generic wrapper for any FS implementation
26-
* it is not possible to just get the parent FS from the real implementation
27-
* since the VFSImpl does not have all the necessary methods for testing (usedBytes, format, etc)
25+
* The VFSImpl interface does not expose all methods needed for testing (such as usedBytes, format, etc.),
26+
* so we wrap the concrete implementations to provide a unified interface.
2827
*/
2928
template<typename Impl> class WrappedFS : public IFileSystem {
3029
public:
@@ -52,9 +51,6 @@ public:
5251
fs::FS &vfs() override {
5352
return *impl_;
5453
}
55-
uint8_t maxOpenFiles() const {
56-
return maxOpen_;
57-
}
5854

5955
private:
6056
Impl *impl_;
@@ -162,23 +158,48 @@ void test_dir_ops_and_list() {
162158
{
163159
File d = V.open(fileBasePath);
164160
TEST_ASSERT_TRUE_MESSAGE(d && d.isDirectory(), "open(/dir/a/b) not a directory");
161+
162+
auto getExpectedFile = [fileBasePath](int i) -> std::pair<String, String> {
163+
return {String(fileBasePath) + "/file" + String(i) + ".txt", "data:" + String(i)};
164+
};
165+
166+
bool found[numFiles] = {false};
165167
int count = 0;
168+
166169
while (true) {
167170
File e = d.openNextFile();
168171
if (!e) {
169172
break;
170173
}
171174

172-
String expectedPath = String(fileBasePath) + String("/file") + String(count) + String(".txt");
173-
TEST_ASSERT_EQUAL_STRING_MESSAGE(expectedPath.c_str(), e.path(), "File path mismatch");
175+
String path = e.path();
174176
String content = e.readString();
175-
String expectedContent = "data:" + String(count);
176-
TEST_ASSERT_EQUAL_STRING_MESSAGE(expectedContent.c_str(), content.c_str(), "File content mismatch");
177+
bool matched = false;
178+
179+
for (int i = 0; i < numFiles; ++i) {
180+
if (!found[i]) {
181+
auto [expectedPath, expectedContent] = getExpectedFile(i);
182+
if (path == expectedPath) {
183+
TEST_ASSERT_EQUAL_STRING_MESSAGE(expectedContent.c_str(), content.c_str(), "File content mismatch");
184+
found[i] = true;
185+
matched = true;
186+
break;
187+
}
188+
}
189+
}
190+
191+
TEST_ASSERT_TRUE_MESSAGE(matched, ("Unexpected file found: " + path).c_str());
177192
count++;
178193
e.close();
179194
}
195+
180196
d.close();
181197
TEST_ASSERT_EQUAL_INT_MESSAGE(numFiles, count, "File count mismatch in directory listing");
198+
199+
for (int i = 0; i < numFiles; ++i) {
200+
auto [expectedPath, _] = getExpectedFile(i);
201+
TEST_ASSERT_TRUE_MESSAGE(found[i], ("Expected file not found: " + expectedPath).c_str());
202+
}
182203
}
183204
}
184205

@@ -525,7 +546,6 @@ void test_error_cases() {
525546

526547
auto &V = gFS->vfs();
527548

528-
// Try to open non-existent file for reading
529549
TEST_ASSERT_FALSE(V.open("/nonexistent.txt", FILE_READ));
530550
TEST_ASSERT_FALSE(V.remove("/nonexistent.txt"));
531551
TEST_ASSERT_FALSE(V.rename("/nonexistent.txt", "/newname.txt"));
@@ -640,10 +660,14 @@ void test_directory_operations_edge_cases() {
640660
TEST_ASSERT_TRUE(V.mkdir("/test_dir"));
641661

642662
if (strcmp(gFS->name(), "spiffs") != 0) {
663+
// it should be fine to create again the same dir
643664
TEST_ASSERT_TRUE(V.mkdir("/test_dir"));
665+
666+
// creating nested dirs without parent should fail same as rmdir non-existent
644667
TEST_ASSERT_FALSE(V.mkdir("/deep/nested/path"));
645668
TEST_ASSERT_FALSE(V.rmdir("/nonexistent_dir"));
646669
}
670+
V.rmdir("/test_dir");
647671
}
648672

649673
void test_max_open_files_limit() {
@@ -656,18 +680,14 @@ void test_max_open_files_limit() {
656680

657681
// Create test files first
658682
{
659-
File f1 = V.open("/max1.txt", FILE_WRITE);
660-
File f2 = V.open("/max2.txt", FILE_WRITE);
661-
File f3 = V.open("/max3.txt", FILE_WRITE);
662-
TEST_ASSERT_TRUE(f1);
663-
TEST_ASSERT_TRUE(f2);
664-
TEST_ASSERT_TRUE(f3);
665-
f1.print("file1");
666-
f2.print("file2");
667-
f3.print("file3");
668-
f1.close();
669-
f2.close();
670-
f3.close();
683+
for (int i = 0; i < MAX_TEST_OPEN_FILES; ++i) {
684+
char path[16];
685+
snprintf(path, sizeof(path), "/max%d.txt", i + 1);
686+
File f = V.open(path, FILE_WRITE);
687+
TEST_ASSERT_TRUE(f);
688+
f.print("file" + String(i + 1));
689+
f.close();
690+
}
671691
}
672692

673693
// Open files up to the limit
@@ -700,17 +720,16 @@ void test_max_open_files_limit() {
700720
TEST_ASSERT_TRUE(newFile);
701721
newFile.close();
702722

703-
// Close remaining files
704-
for (int i = 1; i < MAX_TEST_OPEN_FILES; ++i) {
723+
// Cleanup test files
724+
for (int i = 0; i < MAX_TEST_OPEN_FILES; ++i) {
705725
if (files[i]) {
706726
files[i].close();
707727
}
708-
}
709728

710-
// Cleanup test files
711-
V.remove("/max1.txt");
712-
V.remove("/max2.txt");
713-
V.remove("/max3.txt");
729+
char path[16];
730+
snprintf(path, sizeof(path), "/max%d.txt", i + 1);
731+
V.remove(path);
732+
}
714733
}
715734

716735
// ---------------- Run the same test set over all FS ----------------

tests/validation/fs/test_fs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pytest_embedded_wokwi import Wokwi
21
from pytest_embedded import Dut
32

43

5-
def test_fs(dut: Dut, wokwi: Wokwi):
4+
def test_fs(dut: Dut):
65
dut.expect_unity_test_output(timeout=300)

0 commit comments

Comments
 (0)