on 8.00+14.10.20140822-0ubuntu1 help sign in
unity8/runtests.sh
136 lines 4.3 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 qmltests
46cd -
48kill $INOTIFYPID
49sleep 1
51countedfiles=0
52testedfiles=0
53countedlines=0
54testedlines=0
55testedfilelist=""
57for i in $file_list; do
58 countedfiles=$((countedfiles+1))
59 thislines=`cat $i | grep -v '^$' | wc -l`
60 headerlines=`grep -n -m 1 "{" $i | cut -d ":" -f 1`
61 thislines=$((thislines-headerlines))
62 countedlines=$((countedlines+thislines))
63 grep $i statistics.txt > /dev/null
64 if [ $? -eq 0 ]; then
65 echo "[Y] $i"
66 testedfiles=$((testedfiles+1))
67 testedlines=$((testedlines+$thislines))
68 testedfilelist="$testedfilelist $i"
69 else
70 echo "[N] $i"
71 fi
72done
75filespercentage=$((testedfiles*100/countedfiles))
76echo "Total files: $testedfiles/$countedfiles ($filespercentage%)"
79linespercentage=$((testedlines*100/countedlines))
80linespercentagef=`echo "$testedlines/$countedlines" | bc -l`
81echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)"
83cd -
85coveragefile=coverage-qml.xml
87echo "<?xml version=\"1.0\" ?>" > $coveragefile
88echo "<!DOCTYPE coverage" >> $coveragefile
89echo " SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile
91echo "<coverage branch-rate=\"0.0\" line-rate=\"$linespercentagef\" timestamp=\"`date +%s`\" version=\"gcovr 2.5-prerelease\">" >> $coveragefile
92echo " <sources>" >> $coveragefile
93echo " <source>`pwd`</source>" >> $coveragefile
94echo " </sources>" >> $coveragefile
95echo " <packages>" >> $coveragefile
96echo " <package branch-rate=\"0.0\" complexity=\"0.0\" line-rate=\"$linespercentagef\" name=\"unity8\">" >> $coveragefile
97echo " <classes>" >> $coveragefile
99for i in $file_list; do
100 found=0
101 for j in $testedfilelist; do
102 if [ $i == $j ]; then
103 found=1
104 fi
105 done
107 thislines=`cat $SRCDIR/$i | grep -v '^$' | wc -l`
108 headerlines=`grep -n -m 1 "{" $SRCDIR/$i | cut -d ":" -f 1`
109 thislines=$((thislines-headerlines))
111 if [ $found -eq 1 ]; then
112 echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"1.0\" name=\"$i\">" >> $coveragefile
114 echo " <lines>" >> $coveragefile
115 for linenr in $(seq 1 $thislines); do
116 echo " <line branch=\"false\" hits=\"1\" number=\"$linenr\"/>" >> $coveragefile
117 done
118 echo " </lines>" >> $coveragefile
120 else
121 echo " <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"0.0\" name=\"$i\">" >> $coveragefile
123 echo " <lines>" >> $coveragefile
124 for linenr in $(seq 1 $thislines); do
125 echo " <line branch=\"false\" hits=\"0\" number=\"$linenr\"/>" >> $coveragefile
126 done
127 echo " </lines>" >> $coveragefile
129 fi
130 echo " </class>" >> $coveragefile
131done
133echo " </classes>" >> $coveragefile
134echo " </package>" >> $coveragefile
135echo " </packages>" >> $coveragefile
136echo "</coverage>" >> $coveragefile