From 1f32c0194384d754e10d73034845102cca24e7c7 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Wed, 26 Oct 2022 14:19:54 -0400 Subject: [PATCH] Add code coverage measurements to test script (#535) --- .github/actions-rs/grcov.yml | 12 ++++++++++++ .github/workflows/ci.yml | 29 ++++++++++++++++++++++++++--- Brewfile | 5 ++++- README.md | 10 +++++++++- codecov.yml | 13 +++++++++++++ mirror/test/README.md | 2 +- tools/test-with-coverage.sh | 32 ++++++++++++++++++++++++++++++++ tools/test.sh | 5 ++--- 8 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 .github/actions-rs/grcov.yml create mode 100644 codecov.yml create mode 100755 tools/test-with-coverage.sh diff --git a/.github/actions-rs/grcov.yml b/.github/actions-rs/grcov.yml new file mode 100644 index 000000000..be95504da --- /dev/null +++ b/.github/actions-rs/grcov.yml @@ -0,0 +1,12 @@ +binary-path: ./target/debug/deps/ +branch: true +ignore: + - "../*" + - "/*" + - "mobilecoin/*" + - "target/*" + - "*/e2e_tests/*" +ignore-not-existing: true +output-type: lcov +output-path: ./tests.lcov +source-dir: . \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0aa352e4e..fd68c2cef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,6 +90,29 @@ jobs: INGEST_SIGSTRUCT_URI=$(curl -s https://enclave-distribution.test.mobilecoin.com/production.json | grep ingest-enclave.css | awk '{print $2}' | tr -d \" | tr -d ,) (cd /var/tmp && curl -O https://enclave-distribution.test.mobilecoin.com/${INGEST_SIGSTRUCT_URI}) - - name: Cargo Test - run: | - cargo test \ No newline at end of file + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly-2022-04-29 + override: true + components: llvm-tools-preview + + - uses: actions-rs/cargo@v1 + with: + command: test + env: + CARGO_INCREMENTAL: '0' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + + - id: coverage + uses: actions-rs/grcov@v0.1 + + - name: Codecov + uses: codecov/codecov-action@v3.1.0 + with: + files: ${{ steps.coverage.outputs.report }} + verbose: true + fail_ci_if_error: true + env: + CODECOV_TOKEN: 5be757b6-e923-40f2-80ea-5deac1e02b1e \ No newline at end of file diff --git a/Brewfile b/Brewfile index 0f0706a9f..b5957492a 100644 --- a/Brewfile +++ b/Brewfile @@ -3,4 +3,7 @@ brew 'cmake' brew 'go' brew 'llvm' brew 'protobuf' -brew 'openssl' \ No newline at end of file +brew 'openssl' + +# Test dependencies +brew 'lcov' diff --git a/README.md b/README.md index 8f7dff2b3..28085c62b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![codecov](https://codecov.io/github/mobilecoinofficial/full-service/branch/main/graph/badge.svg?token=KqBsyfOOHW)](https://codecov.io/github/mobilecoinofficial/full-service) # Full Service A MobileCoin service for wallet implementations. @@ -69,7 +70,7 @@ sudo xcode-select -s /Applications/Xcode_12.5.1.app/Contents/Developer On Ubuntu: ```sh - sudo apt install build-essential cmake protobuf-compiler libprotobuf-dev llvm llvm-dev clang libclang-dev libsqlite3-dev libssl-dev + sudo apt install build-essential cmake protobuf-compiler libprotobuf-dev llvm llvm-dev clang libclang-dev libsqlite3-dev libssl-dev lcov ``` On MacOS: @@ -95,6 +96,10 @@ sudo xcode-select -s /Applications/Xcode_12.5.1.app/Contents/Developer export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig" ``` + Finally for both: + ```sh + rustup component add llvm-tools-preview + ``` 4. Pull submodule. @@ -428,6 +433,9 @@ Under the covers, this runs: SGX_MODE=HW \ IAS_MODE=DEV \ CONSENSUS_ENCLAVE_CSS=$(pwd)/consensus-enclave.css \ +CARGO_INCREMENTAL=0 \ +RUSTFLAGS='-Cinstrument-coverage' \ +LLVM_PROFILE_FILE="../target/profraw/json5format-%m.profraw" \ cargo test ``` diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..15615155c --- /dev/null +++ b/codecov.yml @@ -0,0 +1,13 @@ +coverage: + status: + project: + default: false + full-service: + target: auto + paths: "full-service/" + mirror: + target: auto + paths: "mirror/" + validator: + target: auto + paths: "validator/" \ No newline at end of file diff --git a/mirror/test/README.md b/mirror/test/README.md index fca83206b..833461cd2 100644 --- a/mirror/test/README.md +++ b/mirror/test/README.md @@ -2,7 +2,7 @@ This directory contains a shell script + associated files for testing a full service mirror release. -This can be run with varying degress of automation. Either with docker, or by running run.sh with a binary you downloaded yourself +This can be run with varying degrees of automation. Either with docker, or by running run.sh with a binary you downloaded yourself ## Test with Docker diff --git a/tools/test-with-coverage.sh b/tools/test-with-coverage.sh new file mode 100755 index 000000000..a7e89940f --- /dev/null +++ b/tools/test-with-coverage.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (c) 2018-2020 MobileCoin Inc. + +# RUSTFLAGS="-C instrument-coverage" \ + +set -e + +if [[ ! -z "$1" ]]; then + cd "$1" +fi + +echo "Testing in $PWD" +CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE="../target/profraw/json5format-%m.profraw" \ +SGX_MODE=SW IAS_MODE=DEV CONSENSUS_ENCLAVE_CSS=$(pwd)/consensus-enclave.css \ +cargo test +echo "Testing in $PWD complete." + +echo "Building coverage report (lcov) html to target/coverage/results" +mkdir -p ./target/coverage +grcov . --binary-path ./target/debug/deps/ --source-dir . -t lcov --branch --ignore-not-existing \ +--ignore "../*" --ignore "/*" --ignore "mobilecoin/*" --ignore "target/*" --ignore "*/e2e_tests/*" \ +-o ./target/coverage/tests.lcov +genhtml ./target/coverage/tests.lcov --show-details --prefix "$PWD" --output-directory ./target/coverage/results + +if [[ "$OSTYPE" == "darwin"* ]]; then + open ./target/coverage/results/index.html +#elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # ... +else + echo "test output written to target/coverage/results/index.html" +fi \ No newline at end of file diff --git a/tools/test.sh b/tools/test.sh index 3b145e95c..1dd603c8f 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -11,7 +11,6 @@ if [[ ! -z "$1" ]]; then fi echo "Testing in $PWD" -LLVM_PROFILE_FILE="json5format-%m.profraw" \ SGX_MODE=SW IAS_MODE=DEV CONSENSUS_ENCLAVE_CSS=$(pwd)/consensus-enclave.css \ -cargo test -p mc-full-service -echo "Testing in $PWD complete." +cargo test +echo "Testing in $PWD complete." \ No newline at end of file