This crate provides code coverage support for no_std and embedded programs.
Usage
Note: This crate requires a recent nightly compiler (2020-04-20 or later).
- Install the
cargo-minicovtool:
- Ensure that the following environment variables are set up:
Note that the use of these flags may cause build-dependencies and proc macros to fail to compile. This can be worked around by explicitly specifying a target when invoking cargo:
# Fails to compile
# Works
- Add the
minicovcrate as a dependency to your program:
[]
= "0.1"
- (optional) The profiling instrumentation generated by LLVM relies on global constructors to work. This will generally work out of the box on most systems. However if your program runs on bare metal then you may need to do this yourself. minicov provides a helper function for this:
unsafe {
minicov::run_static_constructors();
}
WARNING: Make sure you don't call static constructors again if your runtime has already done this for you. Doing so is undefined behavior and may result in crashes and/or data corruption.
- Before your program exits, call
minicov::capture_coveragewhich returns aVec<u8>and dump its contents to a file:
fn main() {
// ...
let coverage = minicov::capture_coverage().unwrap();
std::fs::write("output.minicov", coverage).unwrap();
}
If your program is running on a different system than your build system then you will need to transfer this file back to your build system.
- After your program finishes running, use the
cargo minicovcommand to generate GCOV .gcda files from the captured coverage:
- Use your favorite GCOV-compatible coverage tool (e.g. grcov) to process the .gcda files.