forked from mcallegari/qlcplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.sh
executable file
·133 lines (108 loc) · 3.63 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
#!/bin/bash
#
# To measure unit test coverage, perform these steps:
# 0. export CCACHE_DISABLE=1 # (only if you use compiler cache)
# 1. qmake
# 2. make distclean
# 3. qmake CONFIG+=coverage
# 4. ./coverage.sh
#
# 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
#############################################################################
COUNT=0
test[$COUNT]="engine/src"
COUNT=$((COUNT+1))
if [ "$TARGET" == "ui" ]; then
test[$COUNT]="ui/src"
COUNT=$((COUNT+1))
fi
test[$COUNT]="plugins/artnet/test"
COUNT=$((COUNT+1))
test[$COUNT]="plugins/enttecwing/src"
COUNT=$((COUNT+1))
#test[$COUNT]="plugins/midiinput/common/src"
#COUNT=$((COUNT+1))
if [ ${ARCH} != "Darwin" ]; then
test[$COUNT]="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.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 *Library* -o coverage/coverage.info # OSX
# Generate HTML report
genhtml -o coverage/html coverage/coverage.info