]> rtime.felk.cvut.cz Git - nul-nightly.git/blob - wvtest2html.py
New nightly build log
[nul-nightly.git] / wvtest2html.py
1 #!/usr/bin/env python
2 #
3 # WvTest:
4 #   Copyright (C) 2012, 2014 Michal Sojka <sojka@os.inf.tu-dresden.de>
5 #       Licensed under the GNU Library General Public License, version 2.
6 #       See the included file named LICENSE for license information.
7 #
8 # This script converts wvtest protocol output to HTML pages.
9
10 import sys
11 import re
12 import os
13 import os.path
14 import string
15 import time
16 import numpy as np
17 import cgi
18
19 re_prefix = "\([0-9]+\) (?:#   )?"
20 re_date = re.compile('^Date: (.*)')
21 re_testing = re.compile('^('+re_prefix+')?\s*Testing "(.*)" in (.*):\s*$')
22 re_commit = re.compile('.*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*, commit: (.*)')
23 re_commithash = re.compile('([0-9a-f]{7})(-dirty)? \(')
24 re_assertion = re.compile('^('+re_prefix+')?!\s*(.*?)\s+(\S+)\s*$')
25 re_perf =  re.compile('^('+re_prefix+')?!\s*(.*?)\s+PERF:\s*(.*?)\s+(\S+)\s*$')
26 re_perfaxis = re.compile('axis="([^"]+)"')
27
28 date = time.localtime(time.time())
29
30 class Test:
31     def __init__(self, what, where):
32         self.what = what
33         self.where = where
34         self.output = []
35         self.status = 'ok'
36         self.check_count = 0
37         self.failures = 0
38         self.num = None
39
40     def add_line(self, line):
41         self.output.append(line)
42         match = re_assertion.match(line)
43         if match:
44             self.check_count += 1
45             result = match.group(3)
46             if result != "ok":
47                 self.status = result
48                 self.failures += 1
49     def title(self):
50         if self.what == "all":
51             title = self.where
52         else:
53             title = '%s (%s)' % (self.what, self.where)
54         return title
55
56     def printSummaryHtml(self, file):
57         if self.status == "ok": status_class="ok"
58         else: status_class = "failed"
59         file.write("<tr class='testheader status-%s'><td class='testnum'>%d.</td><td class='testname'><a href='test%d.html'>%s</a></td>"
60                    % (status_class, self.num, self.num, cgi.escape(self.title())))
61         file.write("<td>%s</td></tr>\n" % (cgi.escape(self.status)))
62
63     def printDetailHtml(self, file):
64         file.write("""\
65 <!DOCTYPE HTML>
66 <html>
67 <head>
68 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
69 <title>NUL Test Report</title>
70 <link rel="stylesheet" href="wvtest.css" type="text/css" />
71 </head>
72
73 <body>
74 <h1>NUL Test Report</h1>
75 %s
76 <h2>%d. %s</h2>
77 <table class='output'>
78 """ % (date_and_commit, self.num, cgi.escape(self.title())))
79         for line in self.output:
80             match = re_assertion.match(line)
81             if match:
82                 result = match.group(3)
83                 if result == "ok":
84                     status_class = "ok"
85                 else:
86                     status_class = "failed"
87                 linestatus = " status-%s" % status_class
88                 resultstatus = " class='status-%s'" % status_class
89             else:
90                 linestatus = ''
91                 resultstatus = ''
92                 result = ''
93
94             file.write("<tr><td class='outputline%s'>%s</td><td%s>%s</td></tr>\n" % \
95                 (linestatus, cgi.escape(line), resultstatus, cgi.escape(result)))
96         file.write("</table></body></html>")
97
98 tests = []
99 test = None
100
101 for line in sys.stdin.readlines():
102     line = line.rstrip()
103
104     match = re_date.match(line)
105     if (match):
106         date = time.strptime(match.group(1), "%a, %d %b %Y %H:%M:%S +0200")
107         continue
108
109     match = re_testing.match(line)
110     if match:
111         what = match.group(2)
112         where = match.group(3)
113
114         test = Test(what, where)
115         tests.append(test)
116
117         match = re_commit.match(what)
118         if match:
119             date = time.strptime(match.group(1), "%Y-%m-%d %H:%M:%S")
120             commit = match.group(2)
121             match = re_commithash.search(commit);
122             if match:
123                 commithash = match.group(1)
124             else:
125                 commithash = None
126         continue
127
128     if test: test.add_line(line)
129
130 tests_nonempty = [t for t in tests if t.check_count > 0]
131 num = 1
132 for t in tests_nonempty:
133     t.num = num
134     num += 1
135
136 try:
137     date_and_commit = (time.strftime("%a, %d %b %Y %H:%M:%S +0000", date) + " " + commit)
138 except:
139     date_and_commit = time.strftime("%a, %d %b %Y %H:%M:%S %Z")
140     pass
141
142 targetDir = sys.argv[1]
143 if not os.path.isdir(targetDir):
144     os.mkdir(targetDir)
145
146 wvtest_css = open(os.path.join(targetDir, "wvtest.css"), 'w')
147 wvtest_css.write("""\
148 table {
149   border: solid 1px black;
150   max-width: 100%%;
151 }
152 .status-ok { background: lightgreen; }
153 .status-failed { background: red; }
154 .testnum { text-align: right; }
155 .outputrow { display: none; }
156 .output { width: 100%%; }
157 .outputline { white-space: pre-wrap; font-family: monospace; }
158 .testheader { font-weight: bold; }
159 """)
160 wvtest_css.close()
161
162 index_html = open(os.path.join(targetDir, "index.html"), 'w')
163
164 index_html.write("""\
165 <!DOCTYPE HTML>
166 <html>
167 <head>
168 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
169 <title>NUL Test Report</title>
170 <link rel="stylesheet" href="wvtest.css" type="text/css" />
171 </head>
172
173 <body>
174 <h1>NUL Test Report</h1>
175 %s
176 <table>
177 """ % date_and_commit)
178 for test in tests_nonempty:
179     test.printSummaryHtml(index_html)
180 index_html.write("""\
181 </table>
182 </body>
183 </html>
184 """)
185
186 for test in tests_nonempty:
187     f = open(os.path.join(targetDir, "test%d.html" % test.num), 'w')
188     test.printDetailHtml(f)
189     f.close()
190
191
192 # Local Variables:
193 # compile-command: "make report"
194 # End: