1
by Michał Sawicz
Inital unity8 commit. |
1 |
#!/bin/bash
|
2 |
||
3 |
#
|
|
4 |
# Copyright (C) 2013 Canonical Ltd
|
|
5 |
#
|
|
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.
|
|
9 |
#
|
|
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.
|
|
14 |
#
|
|
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/>.
|
|
17 |
#
|
|
18 |
||
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
|
|
23 |
#
|
|
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.
|
|
27 |
||
28 |
||
597.1.4
by Michał Sawicz
Simplify getting SRCDIR in runtests.sh, we're not supporting in-source builds anyway. |
29 |
SRCDIR=`dirname "$(readlink -f "$0")"` |
1
by Michał Sawicz
Inital unity8 commit. |
30 |
|
31 |
file_list="" |
|
32 |
||
33 |
for i in `find . -name "*.qml" -or -name "*.js" | grep -v tests | grep -v debian | grep -v doc/`; do |
|
34 |
file_list="$file_list $i" |
|
35 |
done
|
|
36 |
||
37 |
(inotifywatch -v -e access $file_list > statistics.txt) & |
|
38 |
INOTIFYPID=`echo $!` |
|
39 |
||
40 |
sleep 1
|
|
41 |
||
1595.5.15
by handsome_feng
update |
42 |
cd -
|
1
by Michał Sawicz
Inital unity8 commit. |
43 |
|
1752.7.6
by Michał Sawicz
Transition runtests.sh to new target |
44 |
make -k xvfballtests |
1752.2.2
by Albert Astals Cid
Instead of failing the .sh create a fake "fail" .xml |
45 |
if [ $? -ne 0 ]; then |
46 |
echo '<?xml version="1.0" encoding="UTF-8" ?><testsuite errors="0" failures="1" tests="1" name="makeExitStatusTest"><properties/><testcase result="fail" name="makeExitStatus"><failure message="Make test did not suceed" result="fail"/></testcase><system-err/></testsuite>' > testMakeExitStatus.xml |
|
47 |
fi
|
|
1
by Michał Sawicz
Inital unity8 commit. |
48 |
|
49 |
cd -
|
|
50 |
||
51 |
kill $INOTIFYPID |
|
52 |
sleep 1
|
|
53 |
||
54 |
countedfiles=0 |
|
55 |
testedfiles=0 |
|
56 |
countedlines=0 |
|
57 |
testedlines=0 |
|
58 |
testedfilelist="" |
|
59 |
||
60 |
for i in $file_list; do |
|
61 |
countedfiles=$((countedfiles+1)) |
|
62 |
thislines=`cat $i | grep -v '^$' | wc -l` |
|
63 |
headerlines=`grep -n -m 1 "{" $i | cut -d ":" -f 1` |
|
64 |
thislines=$((thislines-headerlines)) |
|
65 |
countedlines=$((countedlines+thislines)) |
|
66 |
grep $i statistics.txt > /dev/null
|
|
67 |
if [ $? -eq 0 ]; then |
|
68 |
echo "[Y] $i" |
|
69 |
testedfiles=$((testedfiles+1)) |
|
70 |
testedlines=$((testedlines+$thislines)) |
|
71 |
testedfilelist="$testedfilelist $i" |
|
72 |
else
|
|
73 |
echo "[N] $i" |
|
74 |
fi
|
|
75 |
done
|
|
76 |
||
77 |
||
78 |
filespercentage=$((testedfiles*100/countedfiles)) |
|
79 |
echo "Total files: $testedfiles/$countedfiles ($filespercentage%)" |
|
80 |
||
81 |
||
82 |
linespercentage=$((testedlines*100/countedlines)) |
|
83 |
linespercentagef=`echo "$testedlines/$countedlines" | bc -l` |
|
84 |
echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)" |
|
85 |
||
86 |
cd -
|
|
87 |
||
88 |
coveragefile=coverage-qml.xml |
|
89 |
||
90 |
echo "<?xml version=\"1.0\" ?>" > $coveragefile |
|
91 |
echo "<!DOCTYPE coverage" >> $coveragefile |
|
92 |
echo " SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile |
|
93 |
||
94 |
echo "<coverage branch-rate=\"0.0\" line-rate=\"$linespercentagef\" timestamp=\"`date +%s`\" version=\"gcovr 2.5-prerelease\">" >> $coveragefile |
|
95 |
echo " <sources>" >> $coveragefile |
|
96 |
echo " <source>`pwd`</source>" >> $coveragefile |
|
97 |
echo " </sources>" >> $coveragefile |
|
98 |
echo " <packages>" >> $coveragefile |
|
99 |
echo " <package branch-rate=\"0.0\" complexity=\"0.0\" line-rate=\"$linespercentagef\" name=\"unity8\">" >> $coveragefile |
|
100 |
echo " <classes>" >> $coveragefile |
|
101 |
||
102 |
for i in $file_list; do |
|
103 |
found=0 |
|
104 |
for j in $testedfilelist; do |
|
105 |
if [ $i == $j ]; then |
|
106 |
found=1 |
|
107 |
fi
|
|
108 |
done
|
|
109 |
||
110 |
thislines=`cat $SRCDIR/$i | grep -v '^$' | wc -l` |
|
111 |
headerlines=`grep -n -m 1 "{" $SRCDIR/$i | cut -d ":" -f 1` |
|
112 |
thislines=$((thislines-headerlines)) |
|
113 |
||
114 |
if [ $found -eq 1 ]; then |
|
115 |
echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"1.0\" name=\"$i\">" >> $coveragefile |
|
116 |
||
117 |
echo " <lines>" >> $coveragefile |
|
118 |
for linenr in $(seq 1 $thislines); do |
|
119 |
echo " <line branch=\"false\" hits=\"1\" number=\"$linenr\"/>" >> $coveragefile |
|
120 |
done
|
|
121 |
echo " </lines>" >> $coveragefile |
|
122 |
||
123 |
else
|
|
124 |
echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"0.0\" name=\"$i\">" >> $coveragefile |
|
125 |
||
126 |
echo " <lines>" >> $coveragefile |
|
127 |
for linenr in $(seq 1 $thislines); do |
|
128 |
echo " <line branch=\"false\" hits=\"0\" number=\"$linenr\"/>" >> $coveragefile |
|
129 |
done
|
|
130 |
echo " </lines>" >> $coveragefile |
|
131 |
||
132 |
fi
|
|
133 |
echo " </class>" >> $coveragefile |
|
134 |
done
|
|
135 |
||
136 |
echo " </classes>" >> $coveragefile |
|
137 |
echo " </package>" >> $coveragefile |
|
138 |
echo " </packages>" >> $coveragefile |
|
139 |
echo "</coverage>" >> $coveragefile |