Crates.io | cargo-minicov |
lib.rs | cargo-minicov |
version | 0.1.2 |
source | src |
created_at | 2020-04-20 11:16:22.022841 |
updated_at | 2020-11-13 22:51:31.673016 |
description | Code coverage support for no_std and embedded programs |
homepage | |
repository | https://github.com/Amanieu/minicov |
max_upload_size | |
id | 232161 |
size | 25,575 |
This crate provides code coverage support for no_std
and embedded programs.
Note: This crate requires a recent nightly compiler (2020-04-20 or later).
cargo-minicov
tool:cargo install cargo-minicov
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Zno-profiler-runtime -Copt-level=0 -Clink-dead-code -Coverflow-checks=off"
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
cargo build
# Works
cargo build --target x86_64-unknown-linux-gnu
minicov
crate as a dependency to your program:[dependencies]
minicov = "0.1"
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.
minicov::capture_coverage
which returns
a Vec<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.
cargo minicov
command to
generate GCOV .gcda files from the captured coverage:cargo minicov output.minicov
You can pass multiple input files to cargo minicov
, or even concatenate
multiple input files into a single file:
cargo minicov a.minicov b.minicov
# Or
cat a.minicov b.minicov > combined.minicov
cargo minicov combined.minicov
grcov ./target/x86_64-unknown-linux-gnu/debug/ -s . -t html --llvm --branch --ignore-not-existing -o ./target/debug/coverage/
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.