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.
8 # This script converts wvtest protocol output to HTML pages.
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="([^"]+)"')
28 date = time.localtime(time.time())
31 def __init__(self, what, where):
40 def add_line(self, line):
41 self.output.append(line)
42 match = re_assertion.match(line)
45 result = match.group(3)
50 if self.what == "all":
53 title = '%s (%s)' % (self.what, self.where)
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)))
63 def printDetailHtml(self, file):
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" />
74 <h1>NUL Test Report</h1>
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)
82 result = match.group(3)
86 status_class = "failed"
87 linestatus = " status-%s" % status_class
88 resultstatus = " class='status-%s'" % status_class
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>")
101 for line in sys.stdin.readlines():
104 match = re_date.match(line)
106 date = time.strptime(match.group(1), "%a, %d %b %Y %H:%M:%S +0200")
109 match = re_testing.match(line)
111 what = match.group(2)
112 where = match.group(3)
114 test = Test(what, where)
117 match = re_commit.match(what)
119 date = time.strptime(match.group(1), "%Y-%m-%d %H:%M:%S")
120 commit = match.group(2)
121 match = re_commithash.search(commit);
123 commithash = match.group(1)
128 if test: test.add_line(line)
130 tests_nonempty = [t for t in tests if t.check_count > 0]
132 for t in tests_nonempty:
137 date_and_commit = (time.strftime("%a, %d %b %Y %H:%M:%S +0000", date) + " " + commit)
139 date_and_commit = time.strftime("%a, %d %b %Y %H:%M:%S %Z")
142 targetDir = sys.argv[1]
143 if not os.path.isdir(targetDir):
146 wvtest_css = open(os.path.join(targetDir, "wvtest.css"), 'w')
147 wvtest_css.write("""\
149 border: solid 1px black;
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; }
162 index_html = open(os.path.join(targetDir, "index.html"), 'w')
164 index_html.write("""\
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" />
174 <h1>NUL Test Report</h1>
177 """ % date_and_commit)
178 for test in tests_nonempty:
179 test.printSummaryHtml(index_html)
180 index_html.write("""\
186 for test in tests_nonempty:
187 f = open(os.path.join(targetDir, "test%d.html" % test.num), 'w')
188 test.printDetailHtml(f)
193 # compile-command: "make report"