Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage measurements to test script #535

Merged
merged 7 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 +95,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 +432,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
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
19 changes: 17 additions & 2 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@ if [[ ! -z "$1" ]]; then
fi

echo "Testing in $PWD"
LLVM_PROFILE_FILE="json5format-%m.profraw" \
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 -p mc-full-service
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