Embedded testing framework?

I saw this post about unit testing embedded c code this weekend. I think it is an extremely useful idea to separate concerns like that to enable you to test your application logic separately from the actual hardware on a desktop PC.

Now this got me thinking: how do you currently handle testing in embedded Rust? Do the existing test support tools in the language allow for something like this or is this an opportunity for a crate?

I've been working on this for the last months. It isn't useful for unit testing, but I figured I should mention it, since it is related to testing on embedded devices: https://github.com/braun-embedded/lpc845-test-stand

More on topic, there's embedded-hal-mock, which is along the lines of what the article describes. I haven't used it yet (unfortunately), but I think the approach is promising.

1 Like

That is something we have been doing for many years now. My initial motivation for this was that I had been involved in moving old embedded C code to new platforms with different architectures. Always it showed up how sloppily that C was written especially with regard having it be portable. Endianness issues and the like. It seemed to me one got better quality C code if one insisted it ran on all the available architectures we had, ARM, Intel, PowerPC, Motorola 68000.

This turned out to have some nice side effects. The code ended up runnable on Linux, Mac and Windows, it could be used to build system simulations, offline configuration testing and so on. As well as just testing the code.

Being able to do all that for Rust embedded systems would be great.

1 Like

I've managed to get cargo test to run integration tests on-device via probe-run. I'm hoping to publish a blog post about that soon(tm).

3 Likes

I'm working on a project where the code interacts with fairly complex hardware and stubbing it all out would be too much pain, so I use an approach similar to https://os.phil-opp.com/testing/ to run my tests on-device (or in an emulator).