4 # Script to convert testsuite JSON log into html page
10 # Test result to html color dict
15 'Untested': '#0000bb',
16 'Internal Error': '#800000',
17 'Segmentation Fault': '#e00000',
20 'FP Exception': '#e00000',
21 'Memory Leak': '#a0a000',
26 # Convert bytes to human-readable string
32 if (size
< 1024 * 512):
33 return "%.2fkB" % (float(size
) / 1024)
35 if (size
< 1024 * 1024 * 512):
36 return "%.2fMB" % (float(size
) / 1024 / 1024)
38 return "%.2fGB" % (float(size
) / 1024 / 1024 / 1024)
41 # Malloc statistics Class created from JSON dict
44 def __init__(self
, malloc_stats
):
45 self
.total_size
= malloc_stats
["Total Size"]
46 self
.total_chunks
= malloc_stats
["Total Chunks"]
47 self
.max_size
= malloc_stats
["Max Size"]
48 self
.max_chunks
= malloc_stats
["Max Chunks"]
49 self
.lost_size
= malloc_stats
["Lost Size"]
50 self
.lost_chunks
= malloc_stats
["Lost Chunks"]
54 print(' <td bgcolor="#ffffcc" colspan="3">')
61 print(' <td bgcolor="#ffffaa">')
62 print(' <small>Total size</small>')
65 print(' <td bgcolor="#ffffaa">')
66 print(' <small>Total chunks</small>')
69 print(' <td bgcolor="#ffffaa">')
70 print(' <small>Max size</small>')
73 print(' <td bgcolor="#ffffaa">')
74 print(' <small>Max chunks</small>')
77 print(' <td bgcolor="#ffffaa">')
78 print(' <small>Lost size</small>')
81 print(' <td bgcolor="#ffffaa">')
82 print(' <small>Lost chunks</small>')
90 print(' <td bgcolor="#ffffaa">')
91 print(' <center><small>%s</small></center>' %
92 bytes_conv(self
.total_size
))
95 print(' <td bgcolor="#ffffaa">')
96 print(' <center><small>%s</small></center>' %
97 bytes_conv(self
.total_chunks
))
100 print(' <td bgcolor="#ffffaa">')
101 print(' <center><small>%s</small></center>' %
102 bytes_conv(self
.max_size
))
105 print(' <td bgcolor="#ffffaa">')
106 print(' <center><small>%s</small></center>' %
107 bytes_conv(self
.max_chunks
))
110 print(' <td bgcolor="#ffffaa">')
111 print(' <center><small>%s</small></center>' %
112 bytes_conv(self
.lost_size
))
115 print(' <td bgcolor="#ffffaa">')
116 print(' <center><small>%s</small></center>' %
117 bytes_conv(self
.lost_chunks
))
128 # Benchmark statistics Class created from JSON dict
131 def __init__(self
, bench_data
):
132 self
.time_mean
= bench_data
["Time Mean"]
133 self
.time_variance
= bench_data
["Time Variance"]
134 self
.iterations
= bench_data
["Iterations"]
138 print(' <td bgcolor="#fd8" colspan="3">')
145 print(' <td colspan="2" bgcolor="#fb2">')
146 print(' <center><small>Benchmark data</small></center>')
153 print(' <td bgcolor="#fc4">')
154 print(' <center><small>Iterations</small></center>')
157 print(' <td bgcolor="#fc4">')
158 print(' <center><small>Mean ∓ Variance</small></center>')
166 print(' <td bgcolor=\"#fc4\">')
167 print(' <small>%i</small>' % (self
.iterations
))
170 print(' <td bgcolor=\"#fc4\">')
171 print(' <small>%.6fs ∓ %.6fs</small>' %
172 (self
.time_mean
, self
.time_variance
))
183 # Test Result Class created from JSON dict
186 def __init__(self
, test_result
):
187 self
.name
= test_result
["Test Name"]
188 self
.result
= test_result
["Test Result"]
189 self
.reports
= test_result
["Test Reports"]
190 self
.cpu_time
= test_result
["CPU Time"]
191 self
.run_time
= test_result
["Run Time"]
192 self
.test_reports
= test_result
["Test Reports"]
194 if ("Malloc Stats" in test_result
):
195 self
.malloc_stats
= MallocStats(test_result
["Malloc Stats"])
197 if ("Benchmark" in test_result
):
198 self
.bench_data
= BenchmarkData(test_result
["Benchmark"])
200 def html(self
, bg_color
):
204 print(' <td bgcolor="%s">%s </td>' % (bg_color
, self
.name
))
206 print(' <td bgcolor="%s">' % (bg_color
))
207 print(' <center><small><font color=\"#222\">')
208 print(' %.3fs %.3fs' % (self
.run_time
, self
.cpu_time
))
209 print(' </font></small></center>')
212 print(' <td bgcolor="%s">' % (html_colors
[self
.result
]))
213 print(' <center><font color="white"> %s </center>' %
219 # Add malloc statistics, if present
220 if (hasattr(self
, 'malloc_stats')):
221 self
.malloc_stats
.html()
224 if (hasattr(self
, 'bench_data')):
225 self
.bench_data
.html()
228 if (self
.test_reports
):
230 print(' <td colspan=\"3\" bgcolor=\"#eeeeee\">')
232 for msg
in self
.test_reports
:
233 print(' <small>%s</small><br>' % (msg
))
235 if (self
.test_reports
):
240 def __init__(self
, testsuite_result
):
241 self
.suite_name
= testsuite_result
["Suite Name"]
242 self
.test_results
= []
244 for test_result
in testsuite_result
["Test Results"]:
245 self
.test_results
.append(TestResult(test_result
))
253 print(' <table bgcolor="#99a">')
255 print(' <td colspan="3" bgcolor="#bbbbff">');
256 print(' <center><b>%s</b></center>' % (self
.suite_name
))
262 for tst
in self
.test_results
:
280 for i
in html_colors
:
283 for tst
in self
.test_results
:
284 res_dict
[tst
.result
] = res_dict
[tst
.result
] + 1;
288 # Creates table row with a link to results page
289 def html_summary(self
, link
):
292 res_dict
= self
.results()
294 test_ok
= res_dict
['Success']
295 test_ok
+= res_dict
['Skipped']
296 test_ok
+= res_dict
['Untested']
298 test_all
= len(self
.test_results
)
300 if (test_ok
< test_all
):
301 bg_color
= html_colors
['Failed']
307 print(' <td bgcolor="#ccccee">%s</td>' % (self
.suite_name
))
308 print(' <td bgcolor="%s">%i</td>' % (bg_color
, test_all
- test_ok
))
310 test_skipped
= res_dict
['Skipped']
312 if (test_skipped
> 0):
313 bg_color
= html_colors
['Skipped']
317 print(' <td bgcolor="%s">%i</td>' % (bg_color
, test_skipped
))
318 print(' <td bgcolor="#ccccee">%i</td>' % (test_all
))
319 print(' <td bgcolor="#ccccee"><small><a href="%s">Details</a></small></td>' % (link
))
323 filename
= 'log.json'
328 if (len(argv
) > 1 and argv
[1] == '-s'):
333 if (len(argv
) > pars
):
334 filename
= argv
[pars
]
341 # convert to python objects
342 test_suite
= TestSuite(data
)
345 test_suite
.html_summary(link
)
349 if __name__
== '__main__':