Skip to content

Commit fa20692

Browse files
authored
Source coverage (#48)
* Support stable rust Updated dependencies such that Rust stable 1.53 is now supported. The optimised avx_2 option will NOT rust on stable because there's still an unstable feature on subtle-ng. BUT this feature is actually for doc generation and has been removed from Rust. As soon as subtle-ng merges dalek-cryptography/subtle#85, avx2 will probably be supported on stable as well. The rand dep update breaks the benchmarks, but these will be fixed in the next commit. * Update benchmarks and fmt * Update benchmark code to use new dependency APIs * Run rust-fmt * Use source coverage in tests Replace the grcov action with the more accurate source coverage approach as detailed in https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/instrument-coverage.html This PR also provides the `test_coverage.sh` script that generates a test coverage report lcoally (see the comments for setting up pre-requisites) * Exclude std lib from coverage
1 parent dd05268 commit fa20692

File tree

5 files changed

+85
-44
lines changed

5 files changed

+85
-44
lines changed

.github/actions-rs/grcov.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/grcov.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/source-cov.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Source Coverage
2+
push:
3+
branches:
4+
- main
5+
jobs:
6+
coverage:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v1
11+
- name: Install dependencies
12+
run: |
13+
sudo apt update
14+
sudo apt install -y jq lcov
15+
- name: Download Rust
16+
uses: actions-rs/toolchain@v1
17+
- name: Install llvm-tools
18+
run: |
19+
rustup component add llvm-tools-preview
20+
cargo install cargo-binutils
21+
cargo install rustfilt
22+
- name: Run test coverage
23+
id: coverage
24+
env:
25+
SKIP_HTML: '1'
26+
run: |
27+
/bin/bash -c ./test_coverage.sh
28+
- name: Coveralls upload
29+
uses: coverallsapp/github-action@master
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
path-to-lcov: ./cov_raw/tari_crypto.lcov

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ tags
2121
.clippy.toml
2222

2323
# Ignore Code Coverage Report files
24-
report
24+
cov_raw/
25+
coverage_report/
2526

2627
Cargo.lock
2728
*.log
@@ -30,4 +31,4 @@ Cargo.lock
3031
/libtari/tari_crypto.h
3132

3233
# C-demo output
33-
bin/
34+
bin/

test_coverage.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# Prerequisites
3+
# 1. You need LLVM-COV tools:
4+
# $ rustup component add llvm-tools-preview
5+
# 2. and Rust wrappers for llvm-cov:
6+
# $ cargo install cargo-binutils
7+
# 3. The rust name demangler
8+
# $ cargo install rustfilt
9+
# 4. jq
10+
# 5. genhtml
11+
# $ sudo apt install lcov
12+
13+
RUSTFLAGS="-Z instrument-coverage"
14+
LLVM_PROFILE_FILE="./cov_raw/tari_crypto-%m.profraw"
15+
16+
get_binaries() {
17+
files=$( RUSTFLAGS=$RUSTFLAGS cargo test --tests --no-run --message-format=json \
18+
| jq -r "select(.profile.test == true) | .filenames[]" \
19+
| grep -v dSYM - \
20+
);
21+
files=("${files[@]/#/-object }")
22+
}
23+
24+
get_binaries
25+
echo $files
26+
27+
RUSTFLAGS=$RUSTFLAGS LLVM_PROFILE_FILE=$LLVM_PROFILE_FILE cargo test --tests
28+
29+
cargo profdata -- \
30+
merge -sparse ./cov_raw/tari_crypto-*.profraw -o ./cov_raw/tari_crypto.profdata
31+
32+
cargo cov -- \
33+
export \
34+
--Xdemangler=rustfilt \
35+
--format=lcov \
36+
--show-branch-summary \
37+
--show-instantiation-summary \
38+
--show-region-summary \
39+
--ignore-filename-regex='/.cargo/registry' \
40+
--ignore-filename-regex="^/rustc" \
41+
--instr-profile=cov_raw/tari_crypto.profdata \
42+
$files \
43+
> cov_raw/tari_crypto.lcov
44+
45+
if [ -z ${SKIP_HTML+x} ]; then
46+
genhtml -o coverage_report cov_raw/tari_crypto.lcov
47+
else
48+
echo "Skipping html generation"
49+
fi
50+
# open coverage_report/src/index.html

0 commit comments

Comments
 (0)