2 # HTML output for selftest
3 # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
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.
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/>.
24 use FindBin qw($RealBin);
25 use lib "$RealBin/..";
27 use Subunit qw(parse_results);
30 my ($class, $dirname, $statistics) = @_;
34 local_statistics => {},
35 statistics => $statistics,
39 expected_success => [],
40 unexpected_success => [],
41 expected_failure => [],
42 unexpected_failure => [],
43 skip_testsuites => [],
48 link("$RealBin/output/testresults.css", "$dirname/testresults.css");
50 open(INDEX, ">$dirname/index.html");
54 $self->print_html_header("Samba Testsuite Run", *INDEX);
56 print INDEX " <center>";
57 print INDEX " <table>\n";
58 print INDEX " <tr>\n";
59 print INDEX " <td class=\"tableHead\">Test</td>\n";
60 print INDEX " <td class=\"tableHead\">Result</td>\n";
61 print INDEX " </tr>\n";
66 sub print_html_header($$$)
68 my ($self, $title, $fh) = @_;
70 print $fh "<html lang=\"en\">\n";
72 print $fh " <title>$title</title>\n";
73 print $fh " <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
74 print $fh "</head>\n";
76 print $fh "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
77 print $fh " <tr><td class=\"title\">$title</td></tr>\n";
78 print $fh " <tr><td>\n";
81 sub print_html_footer($$)
85 print $fh "</td></tr>\n";
86 print $fh "</table>\n";
87 print $fh "</body>\n";
88 print $fh "</html>\n";
93 sub start_testsuite($$)
95 my ($self, $name) = @_;
97 $self->{local_statistics} = {
104 $self->{NAME} = $name;
105 $self->{HTMLFILE} = "$name.html";
106 $self->{HTMLFILE} =~ s/[:\t\n \/]/_/g;
108 open(TEST, ">$self->{dirname}/$self->{HTMLFILE}") or die("Unable to open $self->{HTMLFILE} for writing");
110 $self->print_html_header("Test Results for $name", *TEST);
112 print TEST "<h2>Tests</h2>\n";
114 print TEST " <table>\n";
119 my ($self, $output) = @_;
121 $self->{msg} .= "<span class=\"control\">$output<br/></span>\n";
126 my ($self, $output) = @_;
128 unless (defined($self->{active_test})) {
129 print TEST "$output<br/>";
131 $self->{msg} .= "$output<br/>";
135 sub end_testsuite($$$$)
137 my ($self, $name, $result, $unexpected, $reason) = @_;
139 print TEST "</table>\n";
141 print TEST "<div class=\"duration\">Duration: " . (time() - $self->{START_TIME}) . "s</div>\n";
143 $self->print_html_footer(*TEST);
147 print INDEX "<tr>\n";
148 print INDEX " <td class=\"testSuite\"><a href=\"$self->{HTMLFILE}\">$name</a></td>\n";
149 my $st = $self->{local_statistics};
151 if (not $unexpected) {
152 if ($result eq "failure") {
153 print INDEX " <td class=\"resultExpectedFailure\">";
155 print INDEX " <td class=\"resultOk\">";
158 print INDEX " <td class=\"resultFailure\">";
162 if ($st->{success} > 0) {
163 print INDEX "$st->{success} ok";
166 if ($st->{skip} > 0) {
167 print INDEX ", " if ($l);
168 print INDEX "$st->{skip} skipped";
171 if ($st->{failure} > 0) {
172 print INDEX ", " if ($l);
173 print INDEX "$st->{failure} failures";
176 if ($st->{error} > 0) {
177 print INDEX ", " if ($l);
178 print INDEX "$st->{error} errors";
183 if (not $unexpected) {
192 print INDEX "</tr>\n";
197 my ($self, $parents, $testname) = @_;
199 if ($#$parents == -1) {
200 $self->{START_TIME} = time();
201 $self->start_testsuite($testname);
205 $self->{active_test} = $testname;
211 my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
213 if ($#$parents == -1) {
214 $self->end_testsuite($testname, $result, $unexpected, $reason);
220 $self->{local_statistics}->{$result}++;
224 if ($result eq "skip") {
225 print TEST "<td class=\"outputSkipped\">\n";
226 $track_class = "skip";
227 } elsif ($unexpected) {
228 print TEST "<td class=\"outputFailure\">\n";
229 if ($result eq "error") {
230 $track_class = "error";
232 $track_class = "unexpected_$result";
235 if ($result eq "failure") {
236 print TEST "<td class=\"outputExpectedFailure\">\n";
238 print TEST "<td class=\"outputOk\">\n";
240 $track_class = "expected_$result";
243 push(@{$self->{error_summary}->{$track_class}}, ,
244 [$self->{HTMLFILE}, $testname, $self->{NAME},
247 print TEST "<a name=\"$testname\"><h3>$testname</h3></a>\n";
249 print TEST $self->{msg};
251 if (defined($reason)) {
252 print TEST "<div class=\"reason\">$reason</div>\n";
255 print TEST "</td></tr>\n";
257 $self->{active_test} = undef;
264 my $st = $self->{statistics};
265 print INDEX "<tr>\n";
266 print INDEX " <td class=\"testSuiteTotal\">Total</td>\n";
268 if ($st->{TESTS_UNEXPECTED_OK} == 0 and
269 $st->{TESTS_UNEXPECTED_FAIL} == 0 and
270 $st->{TESTS_ERROR} == 0) {
271 print INDEX " <td class=\"resultOk\">";
273 print INDEX " <td class=\"resultFailure\">";
275 print INDEX ($st->{TESTS_EXPECTED_OK} + $st->{TESTS_UNEXPECTED_OK}) . " ok";
276 if ($st->{TESTS_UNEXPECTED_OK} > 0) {
277 print INDEX " ($st->{TESTS_UNEXPECTED_OK} unexpected)";
279 if ($st->{TESTS_SKIP} > 0) {
280 print INDEX ", $st->{TESTS_SKIP} skipped";
282 if (($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) > 0) {
283 print INDEX ", " . ($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) . " failures";
284 if ($st->{TESTS_UNEXPECTED_FAIL} > 0) {
285 print INDEX " ($st->{TESTS_EXPECTED_FAIL} expected)";
288 if ($st->{TESTS_ERROR} > 0) {
289 print INDEX ", $st->{TESTS_ERROR} errors";
294 print INDEX "</tr>\n";
296 print INDEX "</table>\n";
297 print INDEX "<a href=\"summary.html\">Summary</a>\n";
298 print INDEX "</center>\n";
299 $self->print_html_footer(*INDEX);
302 my $summ = $self->{error_summary};
303 open(SUMMARY, ">$self->{dirname}/summary.html");
304 $self->print_html_header("Summary", *SUMMARY);
305 sub print_table($$) {
306 my ($title, $list) = @_;
307 return if ($#$list == -1);
308 print SUMMARY "<h3>$title</h3>\n";
309 print SUMMARY "<table>\n";
310 print SUMMARY "<tr>\n";
311 print SUMMARY " <td class=\"tableHead\">Testsuite</td>\n";
312 print SUMMARY " <td class=\"tableHead\">Test</td>\n";
313 print SUMMARY " <td class=\"tableHead\">Reason</td>\n";
314 print SUMMARY "</tr>\n";
317 print SUMMARY "<tr>\n";
318 print SUMMARY " <td><a href=\"" . $$_[0] . "\">$$_[2]</a></td>\n";
319 print SUMMARY " <td><a href=\"" . $$_[0] . "#$$_[1]\">$$_[1]</a></td>\n";
320 if (defined($$_[3])) {
321 print SUMMARY " <td>$$_[3]</td>\n";
323 print SUMMARY " <td></td>\n";
325 print SUMMARY "</tr>\n";
328 print SUMMARY "</table>";
330 print_table("Errors", $summ->{error});
331 print_table("Unexpected successes", $summ->{unexpected_success});
332 print_table("Unexpected failures", $summ->{unexpected_failure});
333 print_table("Skipped tests", $summ->{skip});
334 print_table("Expected failures", $summ->{expected_failure});
336 print SUMMARY "<h3>Skipped testsuites</h3>\n";
337 print SUMMARY "<table>\n";
338 print SUMMARY "<tr>\n";
339 print SUMMARY " <td class=\"tableHead\">Testsuite</td>\n";
340 print SUMMARY " <td class=\"tableHead\">Reason</td>\n";
341 print SUMMARY "</tr>\n";
343 foreach (@{$summ->{skip_testsuites}}) {
344 print SUMMARY "<tr>\n";
345 print SUMMARY " <td>$$_[0]</td>\n";
346 if (defined($$_[1])) {
347 print SUMMARY " <td>$$_[1]</td>\n";
349 print SUMMARY " <td></td>\n";
351 print SUMMARY "</tr>\n";
354 print SUMMARY "</table>";
356 $self->print_html_footer(*SUMMARY);
360 sub skip_testsuite($$$$)
362 my ($self, $name, $reason) = @_;
364 push (@{$self->{error_summary}->{skip_testsuites}},