From d63382c36dac12ad5bcfa23b56efcfa6b0a0c04f Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Thu, 22 Feb 2024 15:23:51 +0100 Subject: [PATCH 1/9] switch coverage from tarpaulin to grcov --- tests/coverage.sh | 53 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/tests/coverage.sh b/tests/coverage.sh index 2d79e66..5c2427b 100755 --- a/tests/coverage.sh +++ b/tests/coverage.sh @@ -2,28 +2,39 @@ # # script to run projects tests and report code coverage # -# uses tarpaulin (https://crates.io/crates/cargo-tarpaulin) -# -# other coverage solutions exist but all require rust nightly and the project -# does not build with nightly at the moment +# uses grcov (https://github.com/mozilla/grcov) + +COVERAGE_DIR="target/coverage" -# install tarpaulin if missing -cargo tarpaulin --help >/dev/null 2>&1 || cargo install cargo-tarpaulin +_tit() { + echo + echo "========================================" + echo "$@" + echo "========================================" +} +_tit "installing requirements" +rustup component add llvm-tools-preview +cargo install grcov + +_tit "gathering coverage info" +# enable code coverage instrumentation and set per-test profile file name +export RUSTFLAGS="-Cinstrument-coverage" +export RUSTDOCFLAGS="-Cinstrument-coverage" +export LLVM_PROFILE_FILE="$COVERAGE_DIR/%p-%m.profraw" # run tests -# --skip-clean to avoid re-building everything each time -cargo tarpaulin \ - --count \ - --line \ - --locked \ - --skip-clean \ - --ignore-tests \ - --exclude-files rgb-lib-ffi/ \ - --exclude-files tests/ \ - --exclude-files src/wallet/test/ \ - --out Html \ - -- \ - --test-threads=1 +rm -rf $COVERAGE_DIR && mkdir -p $COVERAGE_DIR +cargo test --no-fail-fast || true + +_tit "generating coverage report" +grcov $COVERAGE_DIR \ + -s . \ + --binary-path target/debug/ \ + --output-types html \ + --branch \ + --ignore 'target/*' \ + --ignore-not-existing \ + -o $COVERAGE_DIR/ -# open the html test report in the default browser -xdg-open tarpaulin-report.html +## show html report location +echo "generated html report: $COVERAGE_DIR/html/index.html" From 362e76c65bdee9a113efe2cb28c9c468796bf78a Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Thu, 22 Feb 2024 23:53:41 +0100 Subject: [PATCH 2/9] add coverage GH actions workflow --- .github/workflows/coverage.yaml | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/coverage.yaml diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 0000000..f2f71db --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,47 @@ +name: Coverage + +on: + push: + branches: + - master + - coverage + pull_request: + branches: + - master + +jobs: + codecov: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + components: llvm-tools-preview + + - name: Run tests + env: + RUSTFLAGS: "-Cinstrument-coverage" + RUSTDOCFLAGS: "-Cinstrument-coverage" + run: cargo test + + - name: Install grcov + run: cargo install grcov + + - name: Generate coverage report + run: > + grcov . -s . --binary-path target/debug/ -t lcov --branch + --ignore-not-existing -o coverage.lcov + + - name: Upload coverage report + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + file: coverage.lcov + flags: rust + token: ${{ secrets.CODECOV_TOKEN }} + From c0a5d59788fd5258246b7a89ff4c135312ffe696 Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 00:25:04 +0100 Subject: [PATCH 3/9] fix grcov run --- .github/workflows/coverage.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index f2f71db..96e77c0 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -27,6 +27,7 @@ jobs: env: RUSTFLAGS: "-Cinstrument-coverage" RUSTDOCFLAGS: "-Cinstrument-coverage" + LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" run: cargo test - name: Install grcov @@ -34,8 +35,8 @@ jobs: - name: Generate coverage report run: > - grcov . -s . --binary-path target/debug/ -t lcov --branch - --ignore-not-existing -o coverage.lcov + grcov target/coverage -s . --binary-path target/debug/ -t lcov --branch + --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov - name: Upload coverage report uses: codecov/codecov-action@v4 From b612e514682c38e692b1d296c81215854aee3b3d Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 09:45:10 +0100 Subject: [PATCH 4/9] another try --- .github/workflows/coverage.yaml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 96e77c0..1171875 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -20,23 +20,28 @@ jobs: - name: Setup rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: + components: rustfmt, llvm-tools-preview + override: true + profile: minimal toolchain: stable - components: llvm-tools-preview - name: Run tests env: - RUSTFLAGS: "-Cinstrument-coverage" + CARGO_INCREMENTAL: "0" + #LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" RUSTDOCFLAGS: "-Cinstrument-coverage" - LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" - run: cargo test + RUSTFLAGS: "-Cinstrument-coverage" + run: cargo test issue - name: Install grcov run: cargo install grcov - name: Generate coverage report - run: > - grcov target/coverage -s . --binary-path target/debug/ -t lcov --branch - --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov + #run: > + # grcov target/coverage -s . --binary-path target/debug/ -t lcov --branch + # --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov + run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov + - name: Upload coverage report uses: codecov/codecov-action@v4 From deff5b4f9836fbb8723b13b88c6869e58681af96 Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 10:01:45 +0100 Subject: [PATCH 5/9] yet another try --- .github/workflows/coverage.yaml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 1171875..9a03aca 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -21,14 +21,12 @@ jobs: uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: rustfmt, llvm-tools-preview - override: true - profile: minimal toolchain: stable - name: Run tests env: CARGO_INCREMENTAL: "0" - #LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" + LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" RUSTDOCFLAGS: "-Cinstrument-coverage" RUSTFLAGS: "-Cinstrument-coverage" run: cargo test issue @@ -36,11 +34,16 @@ jobs: - name: Install grcov run: cargo install grcov + - name: debug + run: | + pwd + ls -hAl + - name: Generate coverage report - #run: > - # grcov target/coverage -s . --binary-path target/debug/ -t lcov --branch - # --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov - run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov + run: > + grcov target/coverage/ -s . --binary-path target/debug/ -t lcov --branch + --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov + #run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov - name: Upload coverage report From ceca808d33b143d547f1cc67f5ad57eb9e00e60f Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 10:20:23 +0100 Subject: [PATCH 6/9] ignore . --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 9a03aca..ed9c370 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -42,7 +42,7 @@ jobs: - name: Generate coverage report run: > grcov target/coverage/ -s . --binary-path target/debug/ -t lcov --branch - --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov + --ignore '.' --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov #run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov From 2bc02e0bc499716e0f30a1b95deca5129d676242 Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 10:27:50 +0100 Subject: [PATCH 7/9] ignore /home/runner/work/rgb-lib/rgb-lib --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index ed9c370..8c0fa54 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -42,7 +42,7 @@ jobs: - name: Generate coverage report run: > grcov target/coverage/ -s . --binary-path target/debug/ -t lcov --branch - --ignore '.' --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov + --ignore '/home/runner/work/rgb-lib/rgb-lib' --ignore '.' --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov #run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov From 2f589cff020ac0ab91b042551c753100492f11c8 Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 10:38:29 +0100 Subject: [PATCH 8/9] try llvm-cov --- .github/workflows/coverage.yaml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 8c0fa54..24da4e7 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -20,29 +20,25 @@ jobs: - name: Setup rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: - components: rustfmt, llvm-tools-preview + components: llvm-tools-preview toolchain: stable - - name: Run tests - env: - CARGO_INCREMENTAL: "0" - LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" - RUSTDOCFLAGS: "-Cinstrument-coverage" - RUSTFLAGS: "-Cinstrument-coverage" - run: cargo test issue + #- name: Run tests + # env: + # CARGO_INCREMENTAL: "0" + # LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" + # RUSTDOCFLAGS: "-Cinstrument-coverage" + # RUSTFLAGS: "-Cinstrument-coverage" + # run: cargo test issue - - name: Install grcov - run: cargo install grcov - - - name: debug - run: | - pwd - ls -hAl + - name: Install llvm-cov + run: cargo install cargo-llvm-cov - name: Generate coverage report run: > - grcov target/coverage/ -s . --binary-path target/debug/ -t lcov --branch - --ignore '/home/runner/work/rgb-lib/rgb-lib' --ignore '.' --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov + cargo llvm-cov --lcov --output-path coverage.lcov -- respect_max_allocations + #grcov target/coverage/ -s . --binary-path target/debug/ -t lcov --branch + #--ignore '/home/runner/work/rgb-lib/rgb-lib' --ignore '.' --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov #run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov From caa92fd03a4412f06546fae4b9581e11f59c1c3e Mon Sep 17 00:00:00 2001 From: Nicola Busanello Date: Fri, 23 Feb 2024 10:48:52 +0100 Subject: [PATCH 9/9] try a full test run --- .github/workflows/coverage.yaml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 24da4e7..3887dca 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -23,24 +23,11 @@ jobs: components: llvm-tools-preview toolchain: stable - #- name: Run tests - # env: - # CARGO_INCREMENTAL: "0" - # LLVM_PROFILE_FILE: "target/coverage/%p-%m.profraw" - # RUSTDOCFLAGS: "-Cinstrument-coverage" - # RUSTFLAGS: "-Cinstrument-coverage" - # run: cargo test issue - - name: Install llvm-cov run: cargo install cargo-llvm-cov - name: Generate coverage report - run: > - cargo llvm-cov --lcov --output-path coverage.lcov -- respect_max_allocations - #grcov target/coverage/ -s . --binary-path target/debug/ -t lcov --branch - #--ignore '/home/runner/work/rgb-lib/rgb-lib' --ignore '.' --ignore '../*' --ignore 'target/*' --ignore 'tests/*' --ignore-not-existing -o coverage.lcov - #run: grcov . --binary-path target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov - + run: cargo llvm-cov --lcov --output-path coverage.lcov - name: Upload coverage report uses: codecov/codecov-action@v4