Skip to content

Commit

Permalink
Add code coverage measurements to test script (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
brucek authored Oct 26, 2022
1 parent f98fe9a commit 1f32c01
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .github/actions-rs/grcov.yml
Original file line number Diff line number Diff line change
@@ -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: .
29 changes: 26 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
5 changes: 4 additions & 1 deletion Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ brew 'cmake'
brew 'go'
brew 'llvm'
brew 'protobuf'
brew 'openssl'
brew 'openssl'

# Test dependencies
brew 'lcov'
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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.

Expand Down Expand Up @@ -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
```

Expand Down
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -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/"
2 changes: 1 addition & 1 deletion mirror/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions tools/test-with-coverage.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit 1f32c01

Please sign in to comment.