Skip to content

Doubts about Incorrect Source-Based Test Coverage Results #91661

Closed
@heisen-li

Description

@heisen-li

I used grcov to measure the test coverage of the project, but the results didn't seem very good, both source-based and gcov-based.@richkadel

The source-based approach is shown here.

To test the rand project, perform the following steps:

rustup component add llvm-tools-preview
export RUSTFLAGS="-Zinstrument-coverage"
cargo build
export LLVM_PROFILE_FILE="your_name-%p-%m.profraw"
cargo test
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/

In the rand test result, for example, in the /rand/target/debug/coverage/rand_core/src/le.rs file:

Q1: In this file, two similar functions, one is detected and the other is not found. I don't know why.
image

Only one function is shown here, and the other function seems odd that grcov did not find it.
image

Note: In the /rand/target/debug/coverage/rand_core/src/block.rs file, a large number of codes are not covered. Judgment here seems to have failed.
image
image
...

Q2:In addition, the test function does not appear to be detected. In other files, the test function is executed.
Do not execute test code:/rand/target/debug/coverage/rand_core/src/os.rs
image
execute test code:/rand/target/debug/coverage/src/seq/mod.rs
image

Q3:Sometimes structs/enumerations are included in the row coverage, but sometimes they are not. What are the criteria for this?

rustc --version --verbose:

rustc 1.58.0-nightly (29b124802 2021-10-25)
binary: rustc
commit-hash: 29b1248025b19bd132c8047fc710ea9314b9b76b
commit-date: 2021-10-25
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions