From 48eb86effaaa5823c5a6ea4589a3c471784f3c38 Mon Sep 17 00:00:00 2001 From: Philip Robinson Date: Thu, 24 Mar 2022 11:03:06 +0000 Subject: [PATCH] feat: script to produce coverage report for wallet (#3938) Description --- This PR adds a script that will use the LLVM profiler and grcov to produce a coverage report of the wallet crate. --- .gitignore | 4 ++++ scripts/code_coverage_wallet.sh | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 scripts/code_coverage_wallet.sh diff --git a/.gitignore b/.gitignore index 41c569e532..703e8332d3 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/scripts/code_coverage_wallet.sh b/scripts/code_coverage_wallet.sh new file mode 100644 index 0000000000..099bdd61f3 --- /dev/null +++ b/scripts/code_coverage_wallet.sh @@ -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" \ No newline at end of file