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

[code-coverage] use cargo llvm-cov to generate coverage info #3693

Merged
merged 32 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
48 changes: 39 additions & 9 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: self-hosted
steps:
- name: checkout
uses: actions/checkout@v1
uses: actions/checkout@v3
with:
submodules: recursive
- name: setup rust toolchain
Expand All @@ -20,18 +20,48 @@ jobs:
components: rustfmt,clippy
- name: setup environment
run: bash ./scripts/dev_setup.sh -b -t -y
- name: Install grcov and lcov
run: |
sudo apt-get update
sudo apt-get install lcov -y
cargo install --force grcov
- run: rustup component add llvm-tools-preview
- uses: taiki-e/install-action@v1.5.6
with:
tool: cargo-llvm-cov
- name: Run code coverage
env:
RUST_LOG: error
run: ./scripts/coverage_report.sh . target/codecov --batch
- name: Upload coverage to Codecov
# CARGO_LLVM_COV_TARGET_DIR: ./target
# CARGO_TARGET_DIR: ./target
# CARGO_INCREMENTAL: 1
run: ./scripts/coverage_report.sh . target --batch
- name: Upload coverage to Codecov, attempt 1
uses: codecov/codecov-action@v1
id: upload_code_coverage_report_1
continue-on-error: true
with:
file: ./target/codecov/lcov.info
# file: ./target/codecov/lcov.info
file: ./target/lcov.info
flags: unittests
fail_ci_if_error: false
# retry upload to resolve random upload failure caused by github and codecov
# https://github.com/starcoinorg/starcoin/pull/3693#issuecomment-1230963051
- name: Wait on failure 1
if: steps.upload_code_coverage_report_1.outcome == 'failure'
run: |
sleep 120s
- name: Upload coverage to Codecov, attempt 2
id: upload_code_coverage_report_2
if: steps.upload_code_coverage_report_1.outcome == 'failure'
uses: codecov/codecov-action@v3
continue-on-error: true
with:
fail_ci_if_error: false
verbose: true
- name: Wait on failure 2
if: steps.upload_code_coverage_report_2.outcome == 'failure'
run: |
sleep 360s
- name: Upload coverage to Codecov, attempt 3
id: upload_code_coverage_report_3
if: steps.upload_code_coverage_report_2.outcome == 'failure'
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
verbose: true
52 changes: 28 additions & 24 deletions scripts/coverage_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@ fi

#set -e

# Check that grcov is installed
if ! [ -x "$(command -v grcov)" ]; then
echo "Error: grcov is not installed." >&2
if [ $SKIP_PROMPTS -eq 0 ]; then
read -p "Install grcov? [yY/*] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
[[ "$0" == "$BASH_SOURCE" ]] && exit 1 || return 1
fi
cargo install grcov
else
exit 1
fi
fi
# # Check that grcov is installed
# if ! [ -x "$(command -v grcov)" ]; then
# echo "Error: grcov is not installed." >&2
# if [ $SKIP_PROMPTS -eq 0 ]; then
# read -p "Install grcov? [yY/*] " -n 1 -r
# echo ""
# if [[ ! $REPLY =~ ^[Yy]$ ]]; then
# [[ "$0" == "$BASH_SOURCE" ]] && exit 1 || return 1
# fi
# cargo install grcov
# else
# exit 1
# fi
# fi

# Check that lcov is installed
if ! [ -x "$(command -v lcov)" ]; then
echo "Error: lcov is not installed." >&2
echo "Documentation for lcov can be found at http://ltp.sourceforge.net/coverage/lcov.php"
echo "If on macOS and using homebrew, run 'brew install lcov'"
exit 1
fi
# # Check that lcov is installed
# if ! [ -x "$(command -v lcov)" ]; then
# echo "Error: lcov is not installed." >&2
# echo "Documentation for lcov can be found at http://ltp.sourceforge.net/coverage/lcov.php"
# echo "If on macOS and using homebrew, run 'brew install lcov'"
# exit 1
# fi

# Warn that cargo clean will happen
if [ $SKIP_PROMPTS -eq 0 ]; then
Expand Down Expand Up @@ -81,7 +81,11 @@ echo "Cleaning project..."
)

# Run tests
echo "Running tests..."
cargo xtest --html-lcov-dir="${COVERAGE_DIR}" --no-fail-fast --lib -j 5 || true
echo "Running tests and collecting coverage data ..."
# cargo llvm-cov -v --lib --ignore-run-fail --workspace --test unit_tests::transaction_test::transaction_payload_bcs_roundtrip --no-run --lcov --jobs 5 --output-path "${COVERAGE_DIR}"/lcov.info || true
# cargo llvm-cov -v --lib --ignore-run-fail --package starcoin-transactional-test-harness --lcov --jobs 5 --output-path "${COVERAGE_DIR}"/lcov.info || true
# cargo llvm-cov -v --lib --package starcoin-rpc-api --ignore-run-fail --lcov --jobs 8 --output-path "${COVERAGE_DIR}"/lcov.info || true
# cargo llvm-cov -v --package starcoin-storage --lib --ignore-run-fail --lcov --jobs 8 --output-path "${COVERAGE_DIR}"/lcov.info || true
cargo llvm-cov --lib --ignore-run-fail --lcov --jobs 8 --output-path "${COVERAGE_DIR}"/lcov.info || true

echo "Done. Please view report at ${COVERAGE_DIR}/index.html"
echo "Done. Please view report at ${COVERAGE_DIR}/lcov.info"
2 changes: 1 addition & 1 deletion x.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[grcov.installer]
version = "0.8.0"
version = "0.8.11"


[system-tests]
Expand Down