Skip to content

Commit

Permalink
fix: update source coverage script
Browse files Browse the repository at this point in the history
The source coverage script and workflow are slightly stale. This updates
them to get 'em going again.
  • Loading branch information
CjS77 committed Mar 5, 2024
1 parent 4890885 commit 821d5fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/source-cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ on:
push:
branches:
- main
env:
RUSTUP_TOOLCHAIN: "stable"
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y jq lcov
- name: Download Rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
override: true
toolchain: ${{ env.RUSTUP_TOOLCHAIN }}
components: llvm-tools-preview
- name: Install llvm-tools
- name: Install requirements for code coverage
run: |
rustup component add llvm-tools-preview
cargo install cargo-binutils
cargo install rustfilt
- name: Run test coverage
Expand Down
39 changes: 23 additions & 16 deletions test_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
# 5. genhtml
# $ sudo apt install lcov

RUSTFLAGS="-Z instrument-coverage"
LLVM_PROFILE_FILE="./cov_raw/tari_utilities-%m.profraw"
RUSTFLAGS="-C instrument-coverage"
RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN:-stable}
DEST=tari_utilities
echo "Using ${RUSTUP_TOOLCHAIN} toolchain"
LLVM_PROFILE_FILE="./cov_raw/${DEST}-%m.profraw"

get_binaries() {
files=$( RUSTFLAGS=$RUSTFLAGS cargo test --tests --no-run --message-format=json \
files=$( RUSTFLAGS=$RUSTFLAGS cargo +${RUSTUP_TOOLCHAIN} test --tests --no-run --message-format=json \
| jq -r "select(.profile.test == true) | .filenames[]" \
| grep -v dSYM - \
);
Expand All @@ -23,13 +26,15 @@ get_binaries() {

get_binaries

echo "** Generating ..."
echo ${files}
# Remove old coverage files
rm cov_raw/*profraw cov_raw/tari_utilities.profdata cov_raw/tari_utilities.lcov cov_raw/tari_utilities.txt
rm -fr cov_raw coverage_report default*.profraw

RUSTFLAGS=$RUSTFLAGS LLVM_PROFILE_FILE=$LLVM_PROFILE_FILE cargo test --tests
RUSTFLAGS=$RUSTFLAGS LLVM_PROFILE_FILE=${LLVM_PROFILE_FILE} cargo +${RUSTUP_TOOLCHAIN} test --tests

cargo profdata -- \
merge -sparse ./cov_raw/tari_utilities-*.profraw -o ./cov_raw/tari_utilities.profdata
merge -sparse ./cov_raw/${DEST}-*.profraw -o ./cov_raw/${DEST}.profdata

cargo cov -- \
export \
Expand All @@ -38,27 +43,29 @@ cargo cov -- \
--show-branch-summary \
--show-instantiation-summary \
--show-region-summary \
--ignore-filename-regex='/.cargo/registry' \
--ignore-filename-regex="^/rustc" \
--instr-profile=cov_raw/tari_utilities.profdata \
--ignore-filename-regex='\.cargo' \
--ignore-filename-regex="rustc" \
--ignore-filename-regex="\.git" \
--instr-profile=cov_raw/${DEST}.profdata \
$files \
> cov_raw/tari_utilities.lcov
> cov_raw/${DEST}.lcov

cargo cov -- \
show \
--Xdemangler=rustfilt \
--show-branch-summary \
--show-instantiation-summary \
--show-region-summary \
--ignore-filename-regex='/.cargo/registry' \
--ignore-filename-regex="^/rustc" \
--instr-profile=cov_raw/tari_utilities.profdata \
--ignore-filename-regex='\.cargo' \
--ignore-filename-regex="rustc" \
--ignore-filename-regex="\.git" \
--instr-profile=cov_raw/${DEST}.profdata \
$files \
> cov_raw/tari_utilities.txt
> cov_raw/${DEST}.txt

if [ -z ${SKIP_HTML+x} ]; then
genhtml -o coverage_report cov_raw/tari_utilities.lcov
genhtml -o coverage_report cov_raw/${DEST}.lcov
else
echo "Skipping html generation"
fi
# open coverage_report/src/index.html
# open coverage_report/src/index.html

0 comments on commit 821d5fa

Please sign in to comment.