~ci-train-bot/unity8/ubuntu-rtm-14.09-proposed

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
42
cd -
43
44
make -k qmltests
45
46
cd -
47
48
kill $INOTIFYPID
49
sleep 1
50
51
countedfiles=0
52
testedfiles=0
53
countedlines=0
54
testedlines=0
55
testedfilelist=""
56
57
for 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
72
done
73
74
75
filespercentage=$((testedfiles*100/countedfiles))
76
echo "Total files: $testedfiles/$countedfiles ($filespercentage%)"
77
78
79
linespercentage=$((testedlines*100/countedlines))
80
linespercentagef=`echo "$testedlines/$countedlines" | bc -l`
81
echo "Total lines: $testedlines/$countedlines ($((linespercentage))%)"
82
83
cd -
84
85
coveragefile=coverage-qml.xml
86
87
echo "<?xml version=\"1.0\" ?>" > $coveragefile
88
echo "<!DOCTYPE coverage" >> $coveragefile
89
echo "  SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>" >> $coveragefile
90
91
echo "<coverage branch-rate=\"0.0\" line-rate=\"$linespercentagef\" timestamp=\"`date +%s`\" version=\"gcovr 2.5-prerelease\">" >> $coveragefile
92
echo "  <sources>" >> $coveragefile
93
echo "    <source>`pwd`</source>" >> $coveragefile
94
echo "  </sources>" >> $coveragefile
95
echo "  <packages>" >> $coveragefile
96
echo "    <package branch-rate=\"0.0\" complexity=\"0.0\" line-rate=\"$linespercentagef\" name=\"unity8\">"  >> $coveragefile
97
echo "      <classes>" >> $coveragefile
98
99
for 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
106
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))
110
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
113
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
119
120
  else
121
    echo "        <class branch-rate=\"0.0\" complexity=\"0.0\" filename=\"$i\" line-rate=\"0.0\" name=\"$i\">" >> $coveragefile
122
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
128
129
  fi
130
    echo "        </class>" >> $coveragefile
131
done
132
133
echo "      </classes>" >> $coveragefile
134
echo "    </package>"  >> $coveragefile
135
echo "  </packages>" >> $coveragefile
136
echo "</coverage>" >> $coveragefile