OpenDevicePartnership / OpenDevicePartnership/patina

Consider running unit tests (or a subset of them) under Miri

Open
#560 2 comments 0 reactions 1 assignee View on GitHub

@garybeihl is already working on this.

Since Dec 3, 2025.

paired-programming state:help-wanted urgency:medium
Dominant language
Rust
Stars
544
Forks
54
Avg merge
1d 8h
Merged PRs (30d)
30

Description

This was converted to an issue to track adding miri support to nightly builds. Might entail also fixing things, etc.


Discussed in https://github.com/OpenDevicePartnership/patina/discussions/546

Originally posted by wesleywiser June 19, 2025
This would help find issues like #530 and #544. Miri is a dynamic analysis (like ASAN or valgrind) so it likely won't find every instance of UB in your code but will help you with any code that is covered by your unit tests and does not run into the platform limitations the tool has.

When investigating #544, I was able to run the tool locally by finding a nightly toolchain that corresponds to Rust 1.85 (such as nightly-2025-01-03), installing it and then running whichever unit tests, you want. For example:

> rustup toolchain install nightly-2025-01-03 --component miri
> cargo +nightly-2025-01-03 miri test -- create_fill_check_test
...
error: Undefined Behavior: attempting a write access using <326320> at alloc132202[0x50], but that tag does not exist in the borrow stack for this location
   --> components\patina_adv_logger\src\memory_log.rs:294:9
    |
294 | /         ptr::write_volatile::<Self>(
295 | |             address as *mut Self,
296 | |             Self::new(log_entry.phase, log_entry.level, log_entry.timestamp, log_entry.data.len() as u16),      
297 | |         );
    | |         ^
    | |         |
    | |_________attempting a write access using <326320> at alloc132202[0x50], but that tag does not exist in the borrow stack for this location
    |           this error occurs as part of an access at alloc132202[0x50..0x68]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <326320> was created by a SharedReadOnly retag at offsets [0x18..0x7c]
   --> components\patina_adv_logger\src\memory_log.rs:181:33
    |
181 |         let address = unsafe { (self as *const AdvLoggerInfo).byte_offset(current_offset as isize) };
    |                                 ^^^^
    = note: BACKTRACE (of the first span) on thread `memory_log::tests::create_fill_check_test`:
    = note: inside `memory_log::AdvLoggerMessageEntry::init_from_memory` at components\patina_adv_logger\src\memory_log.rs:294:9: 297:10
note: inside `memory_log::AdvLoggerInfo::add_log_entry`
   --> components\patina_adv_logger\src\memory_log.rs:182:18
    |
182 |         unsafe { AdvLoggerMessageEntry::init_from_memory(address as *mut c_void, message_size, log_entry) }       
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `memory_log::tests::create_fill_check_test`
   --> components\patina_adv_logger\src\memory_log.rs:407:29
    |
407 |             let log_entry = log.unwrap().add_log_entry(entry);
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
   --> components\patina_adv_logger\src\memory_log.rs:391:32
    |
390 |     #[test]
    |     ------- in this procedural macro expansion
391 |     fn create_fill_check_test() {
    |                                ^
    = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error; 2 warnings emitted

test memory_log::tests::create_fill_check_test ... error: test failed, to rerun pass `-p patina_adv_logger --lib`

You'll probably also discover that some of your tests have UB (at least this one did #545) so I think this would be a great driver to improve quality!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.