Running your unsafe code test suite in Miri has just gotten even easier: Miri is now available as a
Huge thanks to @oli-obk and @mati865 who made this happen.
Miri can run your test suite in a very slow, interpreted mode that enables it to test for undefined behavior: if an out-of-bounds array access happens, uninitialized memory gets used the wrong way or a dangling raw pointer gets dereferenced, Miri will notice and tell you. However, Miri cannot execute all programs, and it also cannot detect all forms of misbehavior. For further information, please check out Miri’s README.
Installation (only on nightly toolchains) is now as simple as
rustup component add miri
After installing Miri, you can run your crate’s test suite in it with
cargo miri test.
I suggest you do
cargo clean first because Miri needs to build its own standard library, and rustc can get confused when crates built with different standard libraries get mixed.
If you have
#[should_panic] tests, try
cargo miri test -- -- -Zunstable-options --exclude-should-panic because Miri currently aborts execution on a panic.
There’s a lot of work left to be done, in particular to enable more programs to execute in Miri. Still, slowly but steadily, my vision of Miri as a practical tool to test for undefined behavior is actually becoming reality: the standard library and hashbrown have their test suites running in Miri under CI. I cannot express how glad it makes me to be able to contribute to the Rust ecosystem becoming a bit safer.
Maybe your crate is next?