Skip to content

Investigate code coverage #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thibault-martinez opened this issue Feb 26, 2021 · 1 comment · Fixed by #451
Closed

Investigate code coverage #438

thibault-martinez opened this issue Feb 26, 2021 · 1 comment · Fixed by #451
Assignees

Comments

@thibault-martinez
Copy link
Member

No description provided.

@Adam-Gleave
Copy link
Contributor

Adam-Gleave commented Mar 4, 2021

I have written a quick bash script to make use of Cargo's source-based-coverage functionality. Currently this runs all unit tests, but not doctests, since there is currently an open issue regarding the accuracy of their results: rust-lang/rust#79417.

The commands will output an HTML report in a coverage directory in the root of the repository:

#! /bin/bash

# Ensure past coverage files are deleted
find . -name "*.profraw" -type f -delete
find . -name "*.profdata" -type f -delete
rm -r coverage
mkdir coverage

# Run tests with profiling instrumentation
RUSTFLAGS="-Zinstrument-coverage" LLVM_PROFILE_FILE="bee-%m.profraw" cargo test --tests

# Merge all .profraw files into "bee.profdata"
cargo profdata -- merge */bee-*.profraw -o bee.profdata

# Generate and export the coverage report to lcov format
cargo cov -- export \
    $( \
      for file in \
        $( \
          RUSTFLAGS="-Zinstrument-coverage" \
            cargo test --tests --no-run --message-format=json \
              | jq -r "select(.profile.test == true) | .filenames[]" \
              | grep -v dSYM - \
        ); \
      do \
        printf "%s %s " -object $file; \
      done \
    ) \
  --instr-profile=bee.profdata \
  --ignore-filename-regex="/.cargo|rustc|/.rustup" \
  --format=lcov --Xdemangler=rustfilt \
  >> coverage/coverage.info

# Generate report html
genhtml coverage/coverage.info --legend --title="Bee Coverage" --output-directory=coverage

This will ignore any code for external dependencies or the Rust codebase, with the option --ignore-filename-regex="/.cargo|rustc|/.rustup", so the only code that gets checked is Bee source code, with no dependencies. On the chrysalis-pt-2 branch, this means some Bee crates do not get covered (since they are pulled from the dev branch and placed in ~/.cargo/git – this will not happen on the dev branch).

Results

Running these commands against commit 117ab6a gives these summary results:

  • Line coverage: 46.0%
  • Function coverage: 62.8%

@Adam-Gleave Adam-Gleave linked a pull request Mar 5, 2021 that will close this issue
3 tasks
Alex6323 pushed a commit to Alex6323/bee that referenced this issue Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants