-
Notifications
You must be signed in to change notification settings - Fork 101
Mocking of embedded-hal #70
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
Comments
What I noticed when trying to write a few tests is that it's not possible to reconfigure the mock if you pass it into a driver by-value. This probably ties into rust-embedded/embedded-hal#35 Right now I'm simply creating a new driver instance every time I want to change the return value: |
@dbrgn - generally whenever I worked with this in C, I would have some kind of global that would handle this, or provide access. I haven't tried to tackle this in Rust before. A couple ideas I have off the top of my head:
|
@jamesmunns I was thinking of using channels for the shared driver problem discussed in rust-embedded/embedded-hal#35, but AFAIK there's nothing like this available in |
@therealprof Can you just I'll try to make a test example |
This is a tiny impl, I'm going to take it further to try out what a mock impl would look like:
|
@jamesmunns Well, my question was related to using channels on |
Hey @therealprof, sorry, what I was trying to illustrate was that the channels would only be used by the test and |
@jamesmunns I just had a glimpse of hope that someone had an idea that would help to solve one of the most limiting problems we face on embedded rust today. If that's not you, that's okay. ;) |
My intent was definitely to facilitate testing of drivers, so while channels are a great idea that probably won't work with no_std... |
Your mock doesn't need to be |
@Nemo157 ah of course, you are right! 👍 |
I did something nasty:
https://github.com/susu/sx1278/blob/master/tests/test_radio_settings.rs Because it is a simulator, it is not really reusable. Maybe you can use the "pattern". |
Hey @dbrgn, do you feel that this issue should stay open? Or would discussions on this topic be better suited to live in the embedded-hal-mock space? |
I think |
What's the best way to test embedded-hal drivers without actual hardware access?
I think a "mocked" implementation of the embedded-hal traits would be very useful. I started with I2C and Delay:
https://github.com/dbrgn/embedded-hal-mock
The goal is to provide functions to mock certain outcomes:
Currently I only provide implementations for I2C and a no-op implementation of the
Delay
trait.Is this a good approach? If yes, contributions are welcome. (I'm also open to moving the crate/repo to another organization where more people can contribute.)
The text was updated successfully, but these errors were encountered: