There is very annoying issue 91092 in rustc, that force to use cargo test
in single thread mode in case you want coverage information without random noise caused by data race.
Which in turn make coverage info gathering unusable if you have as many tests as I, especially in debug mode.
I did some digging into this issue, and find out that rustc
only insert llvm instricts (like llvm.instrprof.increment
) into IR code, and then all other stuff handled by compiler-rt library which part of llvm project. So data race happens on llvm side as I understand (and confirmed by reading assembler and compiler-rt code).
So why 91092 not marked as llvm bug, and reported to llvm upstream? Is compiler-rt in rustc source tree patched, and this bug may be introduced by Rust developers?
To save time in 91092 the bug reporter runs such two tests in parallel:
impl State {
pub fn parse(src: &str) -> Self {
Self(String::from(src))
}
}
#[test]
fn state_has_true() {
let s = State::parse("value");
assert!(s.has("value"))
}
#[test]
fn state_has_false() {
let s = State::parse("value");
assert!(!s.has("missing"))
}
and if run cargo test
thousands of times then one time you got line coverage results different from all other run of cargo test
, but if force cargo test
to use one test threads all works fine, and thousands of test execution returns the same result.