~macslow/unity8/fix-1475678

« back to all changes in this revision

Viewing changes to runtests.sh

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
29
if test -e Shell.qml; then
 
30
  echo In-source build detected.
 
31
  SRCDIR=`pwd`
 
32
elif test -e ../Shell.qml; then
 
33
  echo Out-of-source build detected. Found source dir at ..
 
34
  SRCDIR=`pwd`/..
 
35
else
 
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
 
39
fi
 
40
 
 
41
cd $SRCDIR
 
42
 
 
43
file_list=""
 
44
 
 
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"
 
47
done
 
48
 
 
49
(inotifywatch -v -e access $file_list > statistics.txt) &
 
50
INOTIFYPID=`echo $!`
 
51
 
 
52
sleep 1
 
53
 
 
54
cd -
 
55
 
 
56
make -k qmltests
 
57
 
 
58
cd -
 
59
 
 
60
kill $INOTIFYPID
 
61
sleep 1
 
62
 
 
63
countedfiles=0
 
64
testedfiles=0
 
65
countedlines=0
 
66
testedlines=0
 
67
testedfilelist=""
 
68
 
 
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
 
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
 
84
done
 
85
 
 
86
 
 
87
filespercentage=$((testedfiles*100/countedfiles))
 
88
echo "Total files: $testedfiles/$countedfiles ($filespercentage%)"
 
89
 
 
90
 
 
91
linespercentage=$((testedlines*100/countedlines))
 
92
linespercentagef=`echo "$testedlines/$countedlines" | bc -l`
 
93
echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)"
 
94
 
 
95
cd -
 
96
 
 
97
coveragefile=coverage-qml.xml
 
98
 
 
99
echo "<?xml version=\"1.0\" ?>" > $coveragefile
 
100
echo "<!DOCTYPE coverage" >> $coveragefile
 
101
echo "  SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile
 
102
 
 
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
 
110
 
 
111
for 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
 
118
 
 
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))
 
122
 
 
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
 
125
 
 
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
 
131
 
 
132
  else
 
133
    echo "        <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"0.0\" name=\"$i\">" >> $coveragefile
 
134
 
 
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
 
140
 
 
141
  fi
 
142
    echo "        </class>" >> $coveragefile
 
143
done
 
144
 
 
145
echo "      </classes>" >> $coveragefile
 
146
echo "    </package>"  >> $coveragefile
 
147
echo "  </packages>" >> $coveragefile
 
148
echo "</coverage>" >> $coveragefile