Skip to content
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

Feature Request: Add FileSystem abstraction #9

Open
AGlass0fMilk opened this issue Feb 12, 2021 · 3 comments
Open

Feature Request: Add FileSystem abstraction #9

AGlass0fMilk opened this issue Feb 12, 2021 · 3 comments

Comments

@AGlass0fMilk
Copy link

Hi USCRPL,

Thanks for all the work you've done with Mbed-OS!

I have been writing some logging utilities lately and wanted to be able to unit test stuff on my desktop to speed up the process.

My use case involves using Mbed's C++ file system API to take advantage of the mbed::FileHandle polymorphism; Using a mbed::FileHandle allows logging output to by dynamically redirected to non-volatile files or to a serial port or anything else subclassing mbed::FileHandle (eg: mbed::BufferedSerial, etc).

I'm on a time crunch, so I decided to simply write my logging stuff with the C file I/O API. This is already portable because Mbed redirects the C file I/O calls.

I think a nice approach for bench-testing Mbed applications that require realistic file system operations would be to implement an mbed::FileSystem that calls the standard C file I/O functions underneath. This would make Mbed's C++ filesystem API portable (at least to Linux).

I figured I would mention this here because it's the same end-goal: being able to build and bench-test Mbed-OS applications on a PC rather than target hardware.

@ProExpertProg
Copy link
Contributor

Hi! Thanks for submitting an issue.

I definitely think something like this would be on our future road map, but I'm not sure how much bandwidth we have right now. If you want, we would love it if you helped us with the implementation of this, if you'd be willing.

@AGlass0fMilk
Copy link
Author

Definitely, if I get some time I will contribute it.

@ladislas
Copy link

ladislas commented Apr 6, 2022

@AGlass0fMilk a bit late to the game, so it might not be relevant for you now, but we found ourselves in the same situation working on a simple logger using mbed::FileHandle

To be able to run the unit tests and check the output of the logger, we added a small abstraction on top of that to allow us to define a sink function which is the one responsible for actually printing stuff.

A default one is provided using mbed::BufferedSerial but it can be easily overridden in unit tests.

See here:

https://github.com/leka/LekaOS/blob/53b0de8009f9c6443c25261e71513ebfe0a55789/libs/LogKit/include/LogKit.h#L157-L160

Used here:

https://github.com/leka/LekaOS/blob/53b0de8009f9c6443c25261e71513ebfe0a55789/libs/LogKit/include/LogKit.h#L257

And for tests:

https://github.com/leka/LekaOS/blob/53b0de8009f9c6443c25261e71513ebfe0a55789/libs/LogKit/tests/LogKit_test_log.cpp#L20-L34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants