File: parse_ctest_output.py

package info (click to toggle)
deal.ii 9.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 236,560 kB
  • sloc: cpp: 334,965; ansic: 72,687; python: 2,374; sh: 841; perl: 761; xml: 437; makefile: 82; javascript: 14
file content (303 lines) | stat: -rw-r--r-- 8,063 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/env python3

## ---------------------------------------------------------------------
##
## Copyright (C) 2016 - 2018 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE.md at
## the top level directory of deal.II.
##
## ---------------------------------------------------------------------

#
# Written by timo.heister@gmail.com
#
# This is an (incomplete) script that parses test output from ctest's xml
# files and generates a static html page from it.
#
# Execute in the directory build/Testing

import xml.etree.ElementTree as ET
import glob

class Group:
    def __init__(self, name):
        self.name = name
        self.n_tests = 0
        self.n_fail = 0
        self.fail = []
        self.fail_text = {}
        self.fail_status = {}
        self.n_status = [0,0,0,0,0]

class Revision:
    def __init__(self):
        self.groups = {}
        self.number = -1
        self.name = ''
        self.n_tests = 0
        self.n_fail = 0

def parse_revision(dirname):
    rev = Revision()

    if len(glob.glob(dirname+'/Update.xml'))>0:
        #new format
        tree = ET.parse(dirname+'/Update.xml')
        rev.name = tree.getroot().find('BuildName').text
        rev.number = tree.getroot().find('Revision').text
    elif len(glob.glob(dirname+'/Notes.xml'))>0:
        #old format
        tree = ET.parse(dirname+'/Notes.xml')
        rev.name = tree.getroot().attrib['BuildName']
        number = rev.name.split('-')[-1]
        rev.number = number[1:]
    else:
        return None

    print dirname, "BUILD: ", rev.name

    #now Test.xml:
    tree = ET.parse(dirname+'/Test.xml')
    root = tree.getroot()
    testing = root.find('Testing')

    for test in testing.findall("Test"):
        fail=False
        if test.attrib['Status']=="failed":
            fail=True
        name = test.find('Name').text
        group = name.split('/')[0]
        status = 4
        if fail:
            text = test.find('Results').find('Measurement').find('Value').text
            if text == None:
                text=""
            failtext = text.encode('utf-8')
            failtextlines = failtext.replace('"','').split('\n')
            failstatustxt = failtextlines[0].split(' ')[-1]
            for i in range(0,len(failtextlines)):
                failtextlines[i] = failtextlines[i][0:80]
                if failtextlines[i].startswith('FAILED: '):
                    failtextlines[i]='FAILED: ...'
            failtext = '\n'.join(failtextlines[4:min(25,len(failtext))])
            statuslist=['CONFIGURE','BUILD','RUN','DIFF']
            if failstatustxt in statuslist:
                status = statuslist.index(failstatustxt)
            else:
                print "unknown status '%s' in test %s "% (failstatustxt,name)
                status=0

        if not group in rev.groups:
            rev.groups[group]= Group(group)

        rev.groups[group].n_tests += 1
        rev.n_tests += 1
        rev.groups[group].n_status[status] += 1
        if fail:
            rev.groups[group].n_fail += 1
            rev.n_fail += 1
            rev.groups[group].fail.append(name)
            rev.groups[group].fail_text[name]=failtext
            rev.groups[group].fail_status[name]=status

    for g in sorted(rev.groups):
        g = rev.groups[g]
        #print g.name, g.n_tests, g.n_fail, g.fail

    return rev




#from xml.dom import minidom


n=glob.glob("*/Build.xml")
n.sort(reverse=True)
numberofrevisions=10
n = n[0:min(10,len(n))]

revs = []

allgroups = set()

for f in n:
    dirname = f.replace('/Build.xml','')
    rev = parse_revision(dirname)
    if rev!=None:
        revs.append(rev)
        for gr in rev.groups:
            allgroups.add(gr)

revs.sort(key=lambda x: x.number, reverse=True)

allgroups = sorted(allgroups)

f = open('tests.html', 'w')
f.write('<html><head></head>')
f.write("""<style type="text/css">
table {
border-collapse:collapse;
}
.fail {background-color:red;}
.togglebody tr {background-color:#CCC}
.test4 {
    background-color: #90ff80;
text-align: right;
}

.test3 {
    background-color: #FFFF00;
text-align: right;
}

.test2 {
    background-color: #FFA000;
text-align: right;
}

.test1 {
    background-color: #FF2020;
text-align: right;
}

.test0 {
    background-color: #C030D0;
text-align: right;
}

thead{
border: 2px solid;
}

.groupALL {
text-align: center;
}

.colgroup {
border: 2px solid;
}

.onerow {background: #FFE}
.otherrow {background: #EEE}

</style>""")
f.write("""<script>
function toggle_id(obj)
{
var e = document.getElementById(obj);
if(e.style.display != 'none')
 e.style.display = 'none';
else
 e.style.display = '';
}
</script>
<body>""")
f.write('<table>')

f.write('<colgroup span="1" class="colgroup""/>')
for rev in revs:
    f.write('<colgroup span="5" class="colgroup"/>')
f.write('\n')


f.write('<thead><tr>')
f.write('<th style="width:250px">&nbsp;</th>')

for rev in revs:
    f.write('<th colspan="5"><a href="http://www.dealii.org/websvn/revision.php?repname=deal.II+Repository&rev=%s">r%s</th>'%(rev.number,rev.number))
f.write('</tr></thead>\n')

f.write('<tbody><tr>')
f.write('<td>ALL</td>')
for rev in revs:
    if (rev.n_fail>0):
        f.write('<td colspan="5" class="groupALL"><span class="fail">' + str(rev.n_fail) + '</span> / ' + str(rev.n_tests) + '</td>')
    else:
        f.write('<td colspan="5" class="groupALL">' + str(rev.n_fail) + ' / ' + str(rev.n_tests) + '</td>')
f.write('</tr></tbody>\n')

#second header
f.write('<tbody><tr style="border-bottom: 2px solid">')
f.write('<td></td>')
for rev in revs:
    for c in range(0,5):

        titles=['Configure','Build','Run','Diff','Pass']
        caption=['C','B','R','D','P']
        f.write('<td title="%s" class="test%d">%s</td>'%(titles[c],c,caption[c]))
f.write('</tr></tbody>\n')

counter=0
for group in allgroups:
    counter+=1
    if counter % 2==0:
        f.write('<tbody class="onerow"><tr>')
    else:
        f.write('<tbody class="otherrow"><tr>')

    failing = set()
    for rev in revs:
        if group in rev.groups:
            failing |= set(rev.groups[group].fail)
    failing = sorted(failing)

    if (len(failing)>0):
        f.write('<td><a href="#" onclick="toggle_id(\'group:%s\');return false">%s</a></td>'%(group,group))
    else:
        f.write('<td>' + group + '</td>')

    for rev in revs:
        if group not in rev.groups:
            for c in range(0,5):
                f.write('<td></td>')
        else:
            gr = rev.groups[group]
            for c in range(0,5):
                if gr.n_status[c]==0:
                    f.write('<td></td>')
                else:
                    f.write('<td class="test%d">%d</td>'%(c,gr.n_status[c]))

    f.write('</tr></tbody>\n')


    #failing tests in group:
    if len(failing)>0:
        f.write('<tbody class="togglebody" style="display:none" id="group:%s">'%group)
        for fail in failing:
            f.write('<tr>')
            name = fail[len(group):] # cut off group name
            f.write('<td>&nbsp;' + name + '</td>')
            for rev in revs:
                if group in rev.groups and fail in rev.groups[group].fail:
                    status=rev.groups[group].fail_status[fail]
                    text=rev.groups[group].fail_text[fail]
                    for c in range(0,5):
                        if c==status:
                            f.write('<td class="test%d" title="%s">X</td>'%(c,text))
                        else:
                            f.write('<td></td>')

                else:
                    f.write('<td colspan="5"></td>')

            f.write('</tr>\n')
        f.write('</tbody>\n')

    f.write('\n\n')


f.write('</table>')


f.write('</body></html>')