-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-code-coverage.sh
More file actions
50 lines (38 loc) · 1.29 KB
/
check-code-coverage.sh
File metadata and controls
50 lines (38 loc) · 1.29 KB
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
#!/bin/bash
# Compile the program with code coverage flags and generate report
# Basedon information from
# https://github.com/mapbox/cpp/blob/master/docs/coverage.md
PROG=$0
EXE="./a.out-code-coverage"
# How we want to call our executable,
# possibly with some command line parameters
EXEC_PROGRAM="$EXE maze0.txt maze1.txt maze2.txt maze3.txt badfile.txt"
PROFDATA=$EXE.profdata
CC=clang++
rm $EXE $PROFDATA default.profraw 2>/dev/null
programs=($CC "llvm-profdata" "llvm-cov")
for p in "${programs[@]}"; do
if ! hash $CC 2>/dev/null; then
echo "ERROR: $PROG: cannot find $CC executable"
exit 1
fi
done
$CC -g -std=c++11 -fprofile-instr-generate -fcoverage-mapping *.cpp -o $EXE
if [ ! -f $EXE ]; then
echo "ERROR: $PROG: Failed to create executable"
exit 1
fi
# Execute the program
$EXEC_PROGRAM > /dev/null
if [ ! -f "default.profraw" ]; then
echo "ERROR: $PROG: Failed to create default.profraw data"
exit 1
fi
llvm-profdata merge default.profraw -output=$PROFDATA
if [ ! -f $PROFDATA ]; then
echo "ERROR: $PROG: Failed to create $PROFDATA"
else
llvm-cov report -show-functions=1 -Xdemangler=llvm-cxxfilt $EXE -instr-profile=$PROFDATA *.cpp
llvm-cov show $EXE -instr-profile=$PROFDATA
fi
rm -rf a.out* $EXE $PROFDATA default.profraw 2>/dev/null