Skip to content

Commit

Permalink
[CI] add code coverage by grcov
Browse files Browse the repository at this point in the history
We need to track the code coverage to make sure the basic testing is
in place to exercise all the code.

We are adding grcov to the CI pipeline to collect and aggregate code
coverage. The coverage result is uploaded to codecov.io. The dashboard
can help visualize the breakdown of test coverage.

Closes: #1420
Approved by: bob-wilson
  • Loading branch information
sausagee authored and bors-libra committed Nov 15, 2019
1 parent 907dc9a commit ad93795
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ commands:
sudo apt-get clean
sudo rm -r /var/lib/apt/lists/*
rustup component add clippy rustfmt
install_code_coverage_deps:
steps:
- run:
name: Install grcov and lcov
command: |
sudo apt-get update
sudo apt-get install lcov
cargo install --force grcov
install_rust_nightly_toolchain:
steps:
- run:
name: Install nightly toolchain for features not in beta/stable
command: rustup install nightly
build_setup:
steps:
- checkout
Expand Down Expand Up @@ -138,6 +151,22 @@ jobs:
cargo install --force cargo-audit
cargo audit
- build_teardown
code-coverage:
description: Run code coverage
executor: build-executor
steps:
- build_setup
- install_code_coverage_deps
- install_rust_nightly_toolchain
- run:
name: Setup code coverage output
command: echo "export CODECOV_OUTPUT=codecov" >> $BASH_ENV
- run:
name: Run code coverage
command: ./scripts/coverage_report.sh . $CODECOV_OUTPUT --batch
- run:
name: Upload result to codecov.io
command: bash <(curl -s https://codecov.io/bash) -f $CODECOV_OUTPUT/lcov.info;
terraform:
executor: terraform-executor
steps:
Expand Down Expand Up @@ -203,3 +232,4 @@ workflows:
only: master
jobs:
- audit
- code-coverage
18 changes: 18 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
codecov:
require_ci_to_pass: true

ignore:
- testsuite/*
- x/*

coverage:
# range for color spectrum display, red=50%, green=80%
range: "50...80"
round: down
precision: 1

status:
project: true
patch: true
changes: false
4 changes: 3 additions & 1 deletion scripts/coverage_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ echo "Cleaning project..."
echo "Running tests..."
while read -r line; do
dirline=$(realpath $(dirname "$line"));
(cd "$dirline" && pwd && cargo xtest)
# Don't fail out of the loop here. We just want to run the test binary
# to collect its profile data.
(cd "$dirline" && pwd && cargo xtest || true)
done < <(find "$TEST_DIR" -name 'Cargo.toml')

# Make the coverage directory if it doesn't exist
Expand Down

0 comments on commit ad93795

Please sign in to comment.