4
# Copyright (C) 2013 Canonical Ltd
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License version 3 as
8
# published by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
# This is a very quick and dirty attempt to figure some metrics for our tests
20
# It monitors all qml files with inotifywatch and generates a cobertura
21
# compatible coverage.xml file containing the statistics. This is far from
22
# perfect but its a start and indeed gives somewhat meaningful numbers
24
# If this proves to be useful, it probably could/should be rewritten
25
# in a more robust and flexible way, preferably in a language where
26
# floating point operations and xml writing is natively supported.
29
if test -e SettingsComponents.qml; then
30
echo In-source build detected.
32
elif test -e ../SettingsComponents.qml; then
33
echo Out-of-source build detected. Found source dir at ..
36
echo Out-of-source build detected. Source dir not found at ..
37
echo Only in-source builds or out-of-source builds with source dir at .. are supported.
45
for i in `find . -name "*.qml" -or -name "*.js" | grep -v tests | grep -v debian | grep -v doc/`; do
46
file_list="$file_list $i"
49
(inotifywatch -v -e access $file_list > statistics.txt) &
69
for i in $file_list; do
70
countedfiles=$((countedfiles+1))
71
thislines=`cat $i | grep -v '^$' | wc -l`
72
headerlines=`grep -n -m 1 "{" $i | cut -d ":" -f 1`
73
thislines=$((thislines-headerlines))
74
countedlines=$((countedlines+thislines))
75
grep $i statistics.txt > /dev/null
78
testedfiles=$((testedfiles+1))
79
testedlines=$((testedlines+$thislines))
80
testedfilelist="$testedfilelist $i"
87
filespercentage=$((testedfiles*100/countedfiles))
88
echo "Total files: $testedfiles/$countedfiles ($filespercentage%)"
91
linespercentage=$((testedlines*100/countedlines))
92
linespercentagef=`echo "$testedlines/$countedlines" | bc -l`
93
echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)"
97
coveragefile=coverage-qml.xml
99
echo "<?xml version=\"1.0\" ?>" > $coveragefile
100
echo "<!DOCTYPE coverage" >> $coveragefile
101
echo " SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile
103
echo "<coverage branch-rate=\"0.0\" line-rate=\"$linespercentagef\" timestamp=\"`date +%s`\" version=\"gcovr 2.5-prerelease\">" >> $coveragefile
104
echo " <sources>" >> $coveragefile
105
echo " <source>`pwd`</source>" >> $coveragefile
106
echo " </sources>" >> $coveragefile
107
echo " <packages>" >> $coveragefile
108
echo " <package branch-rate=\"0.0\" complexity=\"0.0\" line-rate=\"$linespercentagef\" name=\"unity8\">" >> $coveragefile
109
echo " <classes>" >> $coveragefile
111
for i in $file_list; do
113
for j in $testedfilelist; do
114
if [ $i == $j ]; then
119
thislines=`cat $SRCDIR/$i | grep -v '^$' | wc -l`
120
headerlines=`grep -n -m 1 "{" $SRCDIR/$i | cut -d ":" -f 1`
121
thislines=$((thislines-headerlines))
123
if [ $found -eq 1 ]; then
124
echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"1.0\" name=\"$i\">" >> $coveragefile
126
echo " <lines>" >> $coveragefile
127
for linenr in $(seq 1 $thislines); do
128
echo " <line branch=\"false\" hits=\"1\" number=\"$linenr\"/>" >> $coveragefile
130
echo " </lines>" >> $coveragefile
133
echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"0.0\" name=\"$i\">" >> $coveragefile
135
echo " <lines>" >> $coveragefile
136
for linenr in $(seq 1 $thislines); do
137
echo " <line branch=\"false\" hits=\"0\" number=\"$linenr\"/>" >> $coveragefile
139
echo " </lines>" >> $coveragefile
142
echo " </class>" >> $coveragefile
145
echo " </classes>" >> $coveragefile
146
echo " </package>" >> $coveragefile
147
echo " </packages>" >> $coveragefile
148
echo "</coverage>" >> $coveragefile