Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMocking of embedded-hal #70
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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: https://github.com/dbrgn/sgp30-rs/blob/0b8d54fd34bbee2ac79258982b3bfb61c919ec6b/src/lib.rs#L180-L202 |
This comment has been minimized.
This comment has been minimized.
|
@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:
|
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
@therealprof Can you just I'll try to make a test example |
This comment has been minimized.
This comment has been minimized.
|
This is a tiny impl, I'm going to take it further to try out what a mock impl would look like:
|
This comment has been minimized.
This comment has been minimized.
|
@jamesmunns Well, my question was related to using channels on |
This comment has been minimized.
This comment has been minimized.
|
Hey @therealprof, sorry, what I was trying to illustrate was that the channels would only be used by the test and |
This comment has been minimized.
This comment has been minimized.
|
@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. ;) |
This comment has been minimized.
This comment has been minimized.
|
My intent was definitely to facilitate testing of drivers, so while channels are a great idea that probably won't work with no_std... |
This comment has been minimized.
This comment has been minimized.
Nemo157
commented
Mar 30, 2018
|
Your mock doesn't need to be |
This comment has been minimized.
This comment has been minimized.
|
@Nemo157 ah of course, you are right! |
This comment has been minimized.
This comment has been minimized.
susu
commented
Apr 4, 2018
|
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". |
This comment has been minimized.
This comment has been minimized.
|
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? |
jamesmunns
added
the
feb-2019-cleanup
label
Feb 4, 2019
This comment has been minimized.
This comment has been minimized.
|
I think |
dbrgn commentedMar 25, 2018
•
edited
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
Delaytrait.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.)