Skip to content
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

Please test and defend use of insert-gcov-profiling for coverage measurement #4868

Closed
ctz opened this issue Dec 27, 2017 · 5 comments
Closed
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@ctz
Copy link

ctz commented Dec 27, 2017

This is a feature request (tangentially related to #4865) for cargo to include an integration test that ensures that this method of building code with coverage measurement enabled continues to work in future versions.

Here's documentation of how I currently do this for the sct and rustls projects:

Prerequisites: a compatible llvm installation, lcov, nightly rustc

  1. Clean up: cargo clean and delete all .gcda and .gcno intermediate files
  2. Build: run cargo rustc --all-features --profile test --lib, with RUSTC_WRAPPER set to a shell script that adds COVERAGE_OPTIONS to the rustc invocation for a specific crate build (see below).
  3. Execute the library unit tests program that now exists, eg ./target/debug/sct-43d2a05ec780a9bc
  4. Use lcov to extract coverage data from resulting gcno files: run lcov --gcov-tool ./admin/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --capture --directory . --base-directory . -o sct.info
  5. Merge all .info files into one coverage.info: run lcov --gcov-tool ./admin/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --add sct.info -o coverage.info
  6. Trim coverage.info to remove uninteresting sources: run lcov --gcov-tool ./admin/llvm-gcov --rc lcov_branch_coverage=1 --rc lcov_excl_line=assert --extract coverage.info /home/full/path/to/sct/src/\* -o final.info

My RUSTC_WRAPPER program is:

#!/bin/bash -e

get_crate_name()
{
  while [[ $# -gt 1 ]] ; do
    v=$1
    case $v in
      --crate-name)
        echo $2
        return
        ;;
    esac
    shift
  done
}

case $(get_crate_name "$@") in
  sct)
    EXTRA=$COVERAGE_OPTIONS
    ;;
  *)
    ;;
esac

exec "$@" $EXTRA

admin/llvm-gcov is:

#!/bin/sh -e
llvm-cov gcov $*

This method works in cargo 0.23.0 (61fa02415 2017-11-22) but is broken in cargo 0.25.0-nightly (e08f31018 2017-12-24) (and not just due to #4865).

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Dec 27, 2017
@ctz
Copy link
Author

ctz commented Feb 21, 2018

Hello, is there anybody I can lobby for this to be prioritized? Afaict this regression was now released in stable(!!!) and now all my builds are broken.

@alexcrichton
Copy link
Member

@ctz I believe code coverage and such are unstable features in rustc so they don't have upstream support or stability guarantees, this is a feature which likely needs its own champion upstream in rustc before stability can be achieved.

@ctz
Copy link
Author

ctz commented Mar 12, 2018

How does one go about finding such a champion?

I kinda feel like this bug was me shouting "Hey! I'm walking here!" as soon as I saw breakage in nightly, but I got run over anyway. I presumed that this was the point of regularly testing with nightlies -- to prevent regressions making it to release :(

@alexcrichton
Copy link
Member

Ah that'd either probably be championing it yourself or posting on internals to see if others are interested. You never know who might bite nowadays!

epage added a commit to epage/cargo that referenced this issue Oct 17, 2023
- That a version is accepted
- That you are selecting from the source a package which led to part of
  the confusion in rust-lang#4868

I wonder if we should rename our `CRATE` value names to `PKG`/`PACKAGE`
@epage
Copy link
Contributor

epage commented Oct 17, 2023

FYU there is rust-lang/rfcs#3287 for finding a way to get built-in support for cargo.

The coverage landscape has changed a lot since this was opened. I'm going to close as this approach doesn't sound as relevant from what I've seen of coverage. If there is something I've missed, let us know and we can re-evaluate!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

3 participants