on 2139c25 help sign in
unity8/runtests.sh
148 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.
29if test -e Shell.qml; then
30 echo In-source build detected.
31 SRCDIR=`pwd`
32elif test -e ../Shell.qml; then
33 echo Out-of-source build detected. Found source dir at ..
34 SRCDIR=`pwd`/..
35else
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.
38 exit 1
39fi
41cd $SRCDIR
43file_list=""
45for i in `find . -name "*.qml" -or -name "*.js" | grep -v tests | grep -v debian | grep -v doc/`; do
46 file_list="$file_list $i"
47done
49(inotifywatch -v -e access $file_list > statistics.txt) &
50INOTIFYPID=`echo $!`
52sleep 1
54cd -
56make -k qmltests
58cd -
60kill $INOTIFYPID
61sleep 1
63countedfiles=0
64testedfiles=0
65countedlines=0
66testedlines=0
67testedfilelist=""
69for 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
76 if [ $? -eq 0 ]; then
77 echo "[Y] $i"
78 testedfiles=$((testedfiles+1))
79 testedlines=$((testedlines+$thislines))
80 testedfilelist="$testedfilelist $i"
81 else
82 echo "[N] $i"
83 fi
84done
87filespercentage=$((testedfiles*100/countedfiles))
88echo "Total files: $testedfiles/$countedfiles ($filespercentage%)"
91linespercentage=$((testedlines*100/countedlines))
92linespercentagef=`echo "$testedlines/$countedlines" | bc -l`
93echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)"
95cd -
97coveragefile=coverage-qml.xml
99echo "<?xml version=\"1.0\" ?>" > $coveragefile
100echo "<!DOCTYPE coverage" >> $coveragefile
101echo " SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile
103echo "<coverage branch-rate=\"0.0\" line-rate=\"$linespercentagef\" timestamp=\"`date +%s`\" version=\"gcovr 2.5-prerelease\">" >> $coveragefile
104echo " <sources>" >> $coveragefile
105echo " <source>`pwd`</source>" >> $coveragefile
106echo " </sources>" >> $coveragefile
107echo " <packages>" >> $coveragefile
108echo " <package branch-rate=\"0.0\" complexity=\"0.0\" line-rate=\"$linespercentagef\" name=\"unity8\">" >> $coveragefile
109echo " <classes>" >> $coveragefile
111for i in $file_list; do
112 found=0
113 for j in $testedfilelist; do
114 if [ $i == $j ]; then
115 found=1
116 fi
117 done
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
129 done
130 echo " </lines>" >> $coveragefile
132 else
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
138 done
139 echo " </lines>" >> $coveragefile
141 fi
142 echo " </class>" >> $coveragefile
143done
145echo " </classes>" >> $coveragefile
146echo " </package>" >> $coveragefile
147echo " </packages>" >> $coveragefile
148echo "</coverage>" >> $coveragefile