forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoverage.sh
executable file
·133 lines (110 loc) · 3.95 KB
/
coverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
#
# Runs all tests and collects code coverage
#
# Warning: this process is a little slow
#
if ! command -v grcov; then
echo "Error: grcov not found. Try |cargo install grcov|"
exit 1
fi
if [[ ! "$(grcov --version)" =~ 0.8.[0-9] ]]; then
echo Error: Required grcov version not installed
echo "Installed version: $(grcov --version)"
exit 1
fi
set -e
cd "$(dirname "$0")/.."
source ci/_
cargo="$(readlink -f "./cargo")"
: "${CI_COMMIT:=local}"
reportName="lcov-${CI_COMMIT:0:9}"
if [[ -z $1 ]]; then
packages=(--lib --all --exclude solana-local-cluster)
else
packages=("$@")
fi
coverageFlags=()
coverageFlags+=(-Zprofile) # Enable coverage
coverageFlags+=("-Aincomplete_features") # Supress warnings due to frozen abi, which is harmless for it
if [[ $(uname) != Darwin ]]; then # macOS skipped due to https://github.com/rust-lang/rust/issues/63047
coverageFlags+=("-Clink-dead-code") # Dead code should appear red in the report
fi
coverageFlags+=("-Ccodegen-units=1") # Disable code generation parallelism which is unsupported under -Zprofile (see [rustc issue #51705]).
coverageFlags+=("-Cinline-threshold=0") # Disable inlining, which complicates control flow.
coverageFlags+=("-Copt-level=0")
coverageFlags+=("-Coverflow-checks=off") # Disable overflow checks, which create unnecessary branches.
export RUSTFLAGS="${coverageFlags[*]} $RUSTFLAGS"
export CARGO_INCREMENTAL=0
export RUST_BACKTRACE=1
export RUST_MIN_STACK=8388608
echo "--- remove old coverage results"
if [[ -d target/cov ]]; then
find target/cov -type f -name '*.gcda' -delete
fi
rm -rf target/cov/$reportName
mkdir -p target/cov
# Mark the base time for a clean room dir
touch target/cov/before-test
# Force rebuild of possibly-cached proc macro crates and build.rs because
# we always want stable coverage for them
# Don't support odd file names in our repo ever
if [[ -n $CI || -z $1 ]]; then
# shellcheck disable=SC2046
touch \
$(git ls-files :**/build.rs) \
$(git grep -l "proc-macro.*true" :**/Cargo.toml | sed 's|Cargo.toml|src/lib.rs|')
fi
# limit jobs to 4gb/thread
if [[ -f "/proc/meminfo" ]]; then
JOBS=$(grep MemTotal /proc/meminfo | awk '{printf "%.0f", ($2 / (4 * 1024 * 1024))}')
else
JOBS=$(sysctl hw.memsize | awk '{printf "%.0f", ($2 / (4 * 1024**3))}')
fi
NPROC=$(nproc)
JOBS=$((JOBS>NPROC ? NPROC : JOBS))
RUST_LOG=solana=trace _ "$cargo" nightly test --jobs "$JOBS" --target-dir target/cov --no-run "${packages[@]}"
if RUST_LOG=solana=trace _ "$cargo" nightly test --jobs "$JOBS" --target-dir target/cov "${packages[@]}" -- --nocapture 2> >(tee target/cov/coverage-stderr.log >&2); then
test_status=0
else
test_status=$?
echo "Failed: $test_status"
echo "^^^ +++"
if [[ -n $CI ]]; then
exit $test_status
fi
fi
touch target/cov/after-test
echo "--- grcov"
# Create a clean room dir only with updated gcda/gcno files for this run,
# because our cached target dir is full of other builds' coverage files
rm -rf target/cov/tmp
mkdir -p target/cov/tmp
# Can't use a simpler construct under the condition of SC2044 and bash 3
# (macOS's default). See: https://github.com/koalaman/shellcheck/wiki/SC2044
find target/cov -type f -name '*.gcda' -newer target/cov/before-test ! -newer target/cov/after-test -print0 |
(while IFS= read -r -d '' gcda_file; do
gcno_file="${gcda_file%.gcda}.gcno"
ln -sf "../../../$gcda_file" "target/cov/tmp/$(basename "$gcda_file")"
ln -sf "../../../$gcno_file" "target/cov/tmp/$(basename "$gcno_file")"
done)
(
grcov_args=(
target/cov/tmp
--llvm
--ignore \*.cargo\*
--ignore \*build.rs
--ignore bench-tps\*
--ignore upload-perf\*
--ignore bench-streamer\*
--ignore local-cluster\*
)
set -x
grcov "${grcov_args[@]}" -t html -o target/cov/$reportName
grcov "${grcov_args[@]}" -t lcov -o target/cov/lcov.info
cd target/cov
tar zcf report.tar.gz $reportName
)
ls -l target/cov/$reportName/index.html
ln -sfT $reportName target/cov/LATEST
exit $test_status