Skip to content

Code Coverage (llvm-cov) #51

Code Coverage (llvm-cov)

Code Coverage (llvm-cov) #51

Workflow file for this run

name: Code Coverage (llvm-cov)
on:
schedule:
- cron: "0 1 * * *" # every day at 1am (UTC)
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
# Find a good balance between performance and coverage metadata
CARGO_PROFILE_TEST_OPT_LEVEL: 2
CARGO_PROFILE_TEST_DEBUG: true
CARGO_PROFILE_TEST_DEBUG_ASSERTIONS: true
CARGO_PROFILE_TEST_OVERFLOW_CHECKS: false
CARGO_PROFILE_TEST_LTO: off
CARGO_PROFILE_TEST_CODEGEN_UNITS: 1
CARGO_PROFILE_TEST_PANIC: abort
# Allow more retries for network requests in cargo (downloading crates) and
# rustup (installing toolchains). This should help to reduce flaky CI failures
# from transient network timeouts or other issues.
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
# RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
jobs:
llvm-cov:
name: Generate code coverage
runs-on: self-hosted
timeout-minutes: 180
env:
CARGO_TERM_COLOR: always
steps:
# can be removed when actions are available on the image already
- name: Update Rust toolchain
run: rustup update stable
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # pin@v4
- uses: bmwill/rust-cache@fb63fcd7a959767755b88b5af2f5cbf65fb8a127 # pin@v1
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@125e82eef6e60d2b0c20d4d1f4cf81db37f68bf3 # pin@cargo-llvm-cov
- name: Install nextest
uses: taiki-e/install-action@7e58f89e24a544d88f7a74c6eed8a3df3fd4c658 # pin@nextest
- name: Set Swap Space
uses: actionhippie/swap-space@v1
with:
size: 256G
- name: Compute code coverage and create report (nextest.info)
run: |
cargo llvm-cov clean --profraw-only
TOOLCHAIN=$(rustup show active-toolchain | awk '{print $1}')
rustup component add llvm-tools --toolchain "$TOOLCHAIN"
LLVM_PROFDATA="$HOME/.rustup/toolchains/$TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata"
if [ -x "$LLVM_PROFDATA" ]; then
$LLVM_PROFDATA --version
else
echo "Error: llvm-profdata not found or not executable at $LLVM_PROFDATA"
exit 1
fi
set +e
echo "Computing code coverage."
IOTA_SKIP_SIMTESTS=1 cargo llvm-cov --ignore-run-fail --no-report nextest -vv
echo "Checking validity of generated .profraw files."
find target/llvm-cov-target -name '*.profraw' | while read file; do
if ! "$LLVM_PROFDATA" show "$file" > /dev/null 2>&1; then
echo "Removing corrupted file: $file"
rm "$file"
fi
done
echo "Creating nextest report."
cargo llvm-cov report --lcov --output-path target/nextest.info
[ -f "target/nextest.info" ] || exit 1
# - name: Compute code coverage and create report (simtest.info)
# run: |
# cargo llvm-cov clean --profraw-only
# git clean -fd
# set +e
# echo "Computing code coverage."
# ./scripts/simtest/simtest-cov.sh
# [ -f "target/simtest.info" ] || exit 1
- name: Create html report (report.tgz)
run: |
if ! command -v lcov &> /dev/null; then
sudo apt-get install -y lcov
fi
cd target || exit 1
if [ -d "report" ]; then
rm -rf report
fi
echo "Creating html report."
# genhtml -o report nextest.info simtest.info
genhtml -o report nextest.info
[ -d "report" ] || exit 1
echo "Packaging html report."
tar -czf report.tgz report
[ -f "report.tgz" ] || exit 1
- name: Publish html report and trigger update
run: |
cd target || exit 1
rsync -av report.tgz ${{ secrets.CODEGOV_REPORT_HOST }}:transfer/cargo-llvm-cov/
ssh ${{ secrets.CODEGOV_REPORT_HOST }}
- name: Backup html report
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # pin@v4
if: always()
with:
name: report
path: target/report.tgz
if-no-files-found: error
retention-days: 30