on bionic help sign in
unity8/runtests.sh
139 lines 4.6 kB history raw
1#!/bin/bash
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.
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.
29SRCDIR=`dirname "$(readlink -f "$0")"`
31file_list=""
33for i in `find . -name "*.qml" -or -name "*.js" | grep -v tests | grep -v debian | grep -v doc/`; do
34 file_list="$file_list $i"
35done
37(inotifywatch -v -e access $file_list > statistics.txt) &
38INOTIFYPID=`echo $!`
40sleep 1
42cd -
44make -k xvfballtests
45if [ $? -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
47fi
49cd -
51kill $INOTIFYPID
52sleep 1
54countedfiles=0
55testedfiles=0
56countedlines=0
57testedlines=0
58testedfilelist=""
60for 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
75done
78filespercentage=$((testedfiles*100/countedfiles))
79echo "Total files: $testedfiles/$countedfiles ($filespercentage%)"
82linespercentage=$((testedlines*100/countedlines))
83linespercentagef=`echo "$testedlines/$countedlines" | bc -l`
84echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)"
86cd -
88coveragefile=coverage-qml.xml
90echo "<?xml version=\"1.0\" ?>" > $coveragefile
91echo "<!DOCTYPE coverage" >> $coveragefile
92echo " SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile
94echo "<coverage branch-rate=\"0.0\" line-rate=\"$linespercentagef\" timestamp=\"`date +%s`\" version=\"gcovr 2.5-prerelease\">" >> $coveragefile
95echo " <sources>" >> $coveragefile
96echo " <source>`pwd`</source>" >> $coveragefile
97echo " </sources>" >> $coveragefile
98echo " <packages>" >> $coveragefile
99echo " <package branch-rate=\"0.0\" complexity=\"0.0\" line-rate=\"$linespercentagef\" name=\"unity8\">" >> $coveragefile
100echo " <classes>" >> $coveragefile
102for 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
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))
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
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
123 else
124 echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"0.0\" name=\"$i\">" >> $coveragefile
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
132 fi
133 echo " </class>" >> $coveragefile
134done
136echo " </classes>" >> $coveragefile
137echo " </package>" >> $coveragefile
138echo " </packages>" >> $coveragefile
139echo "</coverage>" >> $coveragefile