-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-kcov-test-all
executable file
·89 lines (75 loc) · 2.69 KB
/
run-kcov-test-all
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
#!/bin/bash
die() { echo "ABORT: $*"; exit 1; }
TARGET=${CARGO_TARGET_DIR:-./target}
# Check macro.rs COVERAGE tags
perl -e '
die unless open IN, "<src/macros.rs";
my %tags = ();
while (<IN>) {
if (/COVERAGE\!\((.*?)\)/) {
die "Duplicate COVERAGE tag: $1" if exists $tags{$1};
$tags{$1} = 1;
}
}
die unless close IN;
print((0 + keys %tags) . " macro.rs COVERAGE tags\n");
die unless open IN, "<src/test/macro_coverage.rs";
while (<IN>) {
if (/pub\s+fn\s+(\S*?)\(\)/) {
delete $tags{$1};
}
}
exit 0 if 0 == keys %tags;
print "Coverage tag without entry in macro_coverage.rs: $_" for keys %tags;
exit 1;
' || die COVERAGE tag problem
# Run test with all feature combinations
rm -r kcov >/dev/null 2>&1
mkdir kcov || die "Can't creat kcov/"
COUNT=1000
./run-feature-combinations | while read FEATURES
do
ID=${COUNT#1}
let COUNT=COUNT+1
echo === $ID $FEATURES
# Depending on the Rust version, test executables may be
# dumped in $TARGET/debug or $TARGET/debug/deps
rm -r $(find $TARGET/debug -name "stakker-*") >/dev/null 2>&1
# Can't use --no-run because it excludes some of the tests.
# Need "link-dead-code" to get all the source (including
# source without coverage) to show up. Need "opt-level=0" or
# otherwise "link-dead-code" fails with linking problems.
RUSTFLAGS="-C link-dead-code -C codegen-units=1 -C opt-level=0" \
cargo test $FEATURES >kcov/test-$ID 2>&1 ||
die "cargo test failed; see kcov/test-$ID"
rm kcov/test-$ID
set ""
set $(find $TARGET/debug -name "stakker-*" -type f -executable)
#was: ls $TARGET/debug/stakker-* | egrep 'stakker-[A-Fa-f0-9]+$'
[ -z "$1" ] && die "Can't find test binary in $TARGET/debug"
[ ! -z "$2" ] && die "Found more than one test binary in $TARGET/debug"
EXE="$1"
TESTS=$(echo $(find src -name "*.rs" | fgrep /test | fgrep -v macro_coverage) | perl -pe 's/ /,/g')
mkdir kcov/out-$ID
kcov --verify \
--include-pattern=stakker/src \
--exclude-pattern=$TESTS \
kcov/out-$ID $EXE ||
die "kcov failed"
done
echo "=== MERGING reports to kcov/out/ ..."
mkdir kcov/out
kcov --merge kcov/out kcov/out-*
# Check that no files have been excluded. Skip src/lib.rs, because
# there is no executable code in it.
( find src -name "*.rs" |
fgrep -v test |
perl -pe 's|.*/||';
echo macro_coverage.rs; # Always include this
) | sort >kcov/list-source
ls kcov/out/kcov-merged/*.rs.*.html |
perl -pe 's/\.rs.*/.rs/; s|.*/||;' |
sort >kcov/list-covered
cmp kcov/list-source kcov/list-covered >/dev/null 2>&1 || {
echo "WARNING: Some files not included in report:" $(comm -23 kcov/list-source kcov/list-covered)
}