-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg: add SPIFFS support #5625
pkg: add SPIFFS support #5625
Conversation
The patch for the const buffer in spiffs_write should be upstreamed, if possible. I don't see a reason for why a source buffer in a write situation should be writable. |
@gebart I agree, I'll open a PR on the upstream project, but I wanted to have something working. |
opendir/readdir/closedir support added. No support for mkdir/rmdir as SPIFFS does not support directory, but has a flat structure and I'm not 100% sure about the behavior of readdir. Still TODO: find a better way to use spiffs_config.h. Some part of this file should be set in a common part instead of in the board. |
How about since all defines in spiffs_config.h are already surrounded by |
just realized that the above idea will cause problems with missing files. We could just add |
for reference: pellepl/spiffs#94 |
Added rename support and rebased on top of #5616 |
2d53838
to
9535de5
Compare
vfs_dirent_t entry; | ||
res = vfs_readdir(&dirp, &entry); | ||
TEST_ASSERT(res == 1); | ||
TEST_ASSERT_EQUAL_STRING("/test0.txt", &(entry.d_name[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of these files may not be the same order as the order in which they were created. It is also possible that there are other files left over from previous runs or failed tests in the same run which interfere with this check. The test should only verify that all the created files are reported back by readdir
, the order should be irrelevant.
There's a problem with the unit test: Running it after a failed run may have left files around in the SPIFFS file system, so there should be some clean up at the beginning of each test to ensure that no leftover files are interfering with the outcome. |
66e0fe4
to
2a85197
Compare
Unit tests improved. |
rebased on top of #5616 |
80eae7b
to
65dc155
Compare
Done, thanks @kaspar030 |
Unittests seem OK now |
The unit tests take ages to run on Mulle with a real SPI NOR flash memory. Will do some more investigation. |
@vincent-d what's the run time length on your platform? |
@gebart the write2 test was initially there to ensure erase works correctly, so we need to fill the whole memory before the first erase actually happen, that's why it takes ages... Maybe we should just remove that test |
@vincent-d I think it makes sense as a test, but it slows down the execution of the unit tests too much. Maybe only enable it on native for now? I think it would be great if we had a separate benchmark test for spiffs, to compare read/write speeds between commits and between platforms. The write2 test could be a part of that kind of application as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments on the unit tests.
The write2 test needs some comment describing what it does.
vfs_umount(&_test_spiffs_mount); | ||
} | ||
|
||
static void test_spiffs_mount_umount(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be renamed to match the other tests. tests_spiffs_mount_umount
(pluralis "tests")
|
||
static void test_spiffs_teardown(void) | ||
{ | ||
vfs_mount(&_test_spiffs_mount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of mounting and unmounting going on, what do you think about mounting in the setup phase, saving the result to a file-global (i.e. static global) variable and just checking the variable inside the mount_unmount test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unmount would need to be tested inside the mount_unmount test though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could mount in the test_spiffs_setup
, unmount in the test_spiffs_teardown
and change the mount_unmount test to a unmount_mount. What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that would work I guess. I forgot, do we handle unmounting an already unmounted fs in VFS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess either the fs implementation or removing the mountpoint from the list will fail, but it will fail silently.
vfs_unlink("/test-spiffs/test0.txt"); | ||
vfs_unlink("/test-spiffs/test1.txt"); | ||
vfs_unlink("/test-spiffs/a/test2.txt"); | ||
vfs_umount(&_test_spiffs_mount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and a flag variable to tell whether we need to unmount or not.
TEST_ASSERT(mp >= 0); | ||
|
||
int res; | ||
for (int j = 0; j < 5; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a comment explaining what we want to test.
I don't really see how the magic numbers in this test ensure that we fill the memory and need to erase sectors..
TEST_ASSERT_EQUAL_INT(sizeof(buf), res); | ||
} | ||
|
||
res = vfs_lseek(fd, 0, SEEK_SET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line necessary?
For the write2 test, I used the magic numbers with my memory. But I already reduced them to avoid the timeout on native, which does not really make sense, I agree. |
Fix unittests
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, OK to squash
This implements basic features with the VFS interface
Squashed |
Did another test run on Mulle and native, both work fine. |
Murdock is fine, go! |
Thanks, @vincent-d! Finally RIOT has a file system out of the box! 🎉 |
Great! Thanks @gebart |
This PR adds support for SPIFFS as a package based on @gebart recent VFS work.
This is still WIP and all functions are not implemented right now.
Some unit tests may be used to test it.
This is based on
#5616and uses#5624for the low level.