forked from mcallegari/qlcplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage_cmake.sh
executable file
·136 lines (110 loc) · 4.08 KB
/
coverage_cmake.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
134
135
136
#!/bin/bash
#
# To measure unit test coverage, perform these steps:
# 0. export CCACHE_DISABLE=1 # (only if you use compiler cache)
# 1. rm -rf build && mkdir build # Remove original build directory and recreate it. You can skip this step if you want to preserve the build directory.
# 2. cd ./build && cmake -DCMAKE_PREFIX_PATH="/home/<user>/Qt/5.15.2/gcc_64/lib/cmake|/usr/lib/x86_64-linux-gnu/cmake/Qt5" [-Dqmlui=ON] -Dcoverage=ON ..
# 3. make -j8
# 4. make lcov
#
# Human-readable HTML results are written under coverage/html.
#
set -e
ARCH=$(uname)
THISCMD=`basename "$0"`
TARGET=${1:-}
if [ "$TARGET" != "ui" ] && [ "$TARGET" != "qmlui" ]; then
echo >&2 "Usage: $THISCMD ui|qmlui"
exit 1
fi
#############################################################################
# Test directories to find coverage measurements from
#############################################################################
DEST_DIR="build" # Do NOT change to "./build" or "build/"
COUNT=0
test[$COUNT]="$DEST_DIR/engine/src"
COUNT=$((COUNT+1))
if [ "$TARGET" == "ui" ]; then
test[$COUNT]="$DEST_DIR/ui/src"
COUNT=$((COUNT+1))
fi
test[$COUNT]="$DEST_DIR/plugins/artnet/test"
COUNT=$((COUNT+1))
test[$COUNT]="$DEST_DIR/plugins/enttecwing/src"
COUNT=$((COUNT+1))
#test[$COUNT]="$DEST_DIR/plugins/midiinput/common/src"
#COUNT=$((COUNT+1))
if [ ${ARCH} != "Darwin" ]; then
test[$COUNT]="$DEST_DIR/plugins/velleman/src"
COUNT=$((COUNT+1))
fi
# Number of tests
tlen=${#test[@]}
#############################################################################
# Functions
#############################################################################
# arg1:srcdir arg2:testname
function prepare {
lcov -d ${1} -z || exit $?
lcov -d ${1} -c -i -o coverage/${2}-base.info
}
# arg1:srcdir arg2:testname
function gather_data {
lcov -d ${1} -c -o coverage/${2}-test.info
lcov -a coverage/${2}-base.info -a coverage/${2}-test.info \
-o coverage/${2}-merge.info
}
#############################################################################
# Initialization
#############################################################################
# Check if lcov is installed
if [ -z "$(which lcov)" ]; then
echo "Unable to produce coverage results; can't find lcov."
fi
# Remove previous data
if [ -d coverage ]; then
rm -rf coverage
fi
# Create directories for new coverage data
mkdir -p coverage/html
#############################################################################
# Preparation
#############################################################################
for ((i = 0; i < tlen; i++))
do
prepare ${test[i]} $i || exit $?
done
#############################################################################
# Run unit tests
#############################################################################
./unittest_cmake.sh $TARGET
FAILED=$?
if [ ${FAILED} != 0 ]; then
echo "Will not measure coverage because ${FAILED} unit tests failed."
exit ${FAILED}
fi
#############################################################################
# Gather results
#############################################################################
for ((i = 0; i < tlen; i++))
do
gather_data ${test[i]} $i
done
#############################################################################
# All combined and HTMLized
#############################################################################
for ((i = 0; i < tlen; i++))
do
mergeargs="${mergeargs} -a coverage/${i}-merge.info"
done
lcov ${mergeargs} -o coverage/coverage.info
# Remove stuff that isn't part of QLC sources
lcov -r coverage/coverage.info *.h -o coverage/coverage.info # Q_OBJECT etc.
lcov -r coverage/coverage.info *moc_* -o coverage/coverage.info
lcov -r coverage/coverage.info *usr* -o coverage/coverage.info
lcov -r coverage/coverage.info *_test* -o coverage/coverage.info
lcov -r coverage/coverage.info */ui_* -o coverage/coverage.info
lcov -r coverage/coverage.info */$DEST_DIR/* -o coverage/coverage.info
lcov -r coverage/coverage.info *Library* -o coverage/coverage.info # OSX
# Generate HTML report
genhtml -o coverage/html coverage/coverage.info