Skip to content

Commit

Permalink
feat: script to produce coverage report for wallet (#3938)
Browse files Browse the repository at this point in the history
Description
---
This PR adds a script that will use the LLVM profiler and grcov to produce a coverage report of the wallet crate.
  • Loading branch information
philipr-za authored Mar 24, 2022
1 parent 869abd3 commit 48eb86e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ buildtools/Output/
# any specific "assets" folders should be gitignored
# closer to where they live
#assets/

# Ignore coverage profiling artifacts
*.profraw
/report/
42 changes: 42 additions & 0 deletions scripts/code_coverage_wallet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
set -e

REPORT_DIR="report/"
CRATE_DIR="../base_layer/wallet"
RELATIVE_TARGET_DIR="../../target/debug"

echo "Check if latest llvm-tools are installed:"
rustup component add llvm-tools-preview

echo "Check if grcov installed:"
if [ "$(command -v grcov)" ]
then
echo " + Already installed"
else
echo " + Installing.."
cargo install grcov
fi

export LLVM_PROFILE_FILE="coverage_data-%p-%m.profraw"
export RUSTFLAGS="-Zinstrument-coverage"

echo "Running Wallet tests to produce coverage profiling data:"
cd $CRATE_DIR
# We force the tests to use a single thread. Something about the profiling breaks the Sqlite connection pool even though every test
# with a db uses its own unique pool connection to its own unique file ¯\_(ツ)_/¯
cargo test -- --test-threads=1

echo "Clear Report directories:"
if [ -d "$report_dir" ]; then
rm -rf $report_dir
echo " + Report directory removed"
else
echo " + Report directory already cleared"
fi


echo "Generating coverage report:"
grcov . -s . --binary-path $RELATIVE_TARGET_DIR -t html --branch --ignore-not-existing -o $REPORT_DIR

CUR_DIR=$(pwd)
echo "Coverage report can be found in $CUR_DIR/$REPORT_DIR"

0 comments on commit 48eb86e

Please sign in to comment.