10 use FindBin qw($RealBin);
13 my ($class, $dirname, $statistics) = @_;
16 statistics => $statistics,
18 local_statistics => {},
22 expected_success => [],
23 unexpected_success => [],
24 expected_failure => [],
25 unexpected_failure => [],
26 skip_testsuites => [],
31 link("$RealBin/output/testresults.css", "$dirname/testresults.css");
33 open(INDEX, ">$dirname/index.html");
37 $self->print_html_header("Samba Testsuite Run", *INDEX);
39 print INDEX " <center>";
40 print INDEX " <table>\n";
41 print INDEX " <tr>\n";
42 print INDEX " <td class=\"tableHead\">Test</td>\n";
43 print INDEX " <td class=\"tableHead\">Result</td>\n";
44 print INDEX " </tr>\n";
49 sub print_html_header($$$)
51 my ($self, $title, $fh) = @_;
53 print $fh "<html lang=\"en\">\n";
55 print $fh " <title>$title</title>\n";
56 print $fh " <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
57 print $fh "</head>\n";
59 print $fh "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
60 print $fh " <tr><td class=\"title\">$title</td></tr>\n";
61 print $fh " <tr><td>\n";
64 sub print_html_footer($$)
68 print $fh "</td></tr>\n";
69 print $fh "</table>\n";
70 print $fh "</body>\n";
71 print $fh "</html>\n";
76 sub start_testsuite($$$)
78 my ($self, $name, $state) = @_;
80 $self->{local_statistics} = {
87 $state->{HTMLFILE} = "$name.html";
88 $state->{HTMLFILE} =~ s/[:\t\n \/]/_/g;
90 open(TEST, ">$self->{dirname}/$state->{HTMLFILE}") or die("Unable to open $state->{HTMLFILE} for writing");
92 $self->print_html_header("Test Results for $name", *TEST);
94 if ($state->{ENVNAME} ne "none") {
95 print TEST "<h2>Environment settings</h2>\n";
97 print TEST " <table>\n";
98 print TEST " <tr><td><b>Variable name</b></td><td><b>Variable value</b></td></tr>\n";
99 foreach (keys %{$state->{ENVVARS}}) {
100 print TEST " <tr><td>$_</td><td>";
101 my $val = $state->{ENVVARS}->{$_};
102 if ($val =~ /^\.\// and -r $val) {
103 print TEST "<a href=\"../$val\">$val</a>";
105 print TEST "<a href=\"$val\">$val</a>";
109 print TEST "</td></tr>\n";
111 print TEST " </table>\n";
114 print TEST "<h2>Tests</h2>\n";
116 print TEST " <table>\n";
121 my ($self, $state, $output) = @_;
123 $self->{msg} .= "<span class=\"control\">$output<br/></span>\n";
128 my ($self, $state, $output) = @_;
130 unless (defined($self->{active_test})) {
131 print TEST "$output<br/>";
133 $self->{msg} .= "$output<br/>";
137 sub end_testsuite($$$$$)
139 my ($self, $name, $state, $expected_ret, $ret, $envlog) = @_;
141 print TEST "</table>\n";
143 print TEST "<div class=\"command\">$state->{CMD}</div>\n";
144 print TEST "<div class=\"duration\">Duration: " . (time() - $state->{START_TIME}) . "s</div>\n";
146 $self->print_html_footer(*TEST);
150 print INDEX "<tr>\n";
151 print INDEX " <td class=\"testSuite\"><a href=\"$state->{HTMLFILE}\">$name</a></td>\n";
152 my $st = $self->{local_statistics};
154 if ($ret == $expected_ret) {
156 print INDEX " <td class=\"resultExpectedFailure\">";
158 print INDEX " <td class=\"resultOk\">";
161 print INDEX " <td class=\"resultFailure\">";
165 if ($st->{success} > 0) {
166 print INDEX "$st->{success} ok";
169 if ($st->{skip} > 0) {
170 print INDEX ", " if ($l);
171 print INDEX "$st->{skip} skipped";
174 if ($st->{failure} > 0) {
175 print INDEX ", " if ($l);
176 print INDEX "$st->{failure} failures";
179 if ($st->{error} > 0) {
180 print INDEX ", " if ($l);
181 print INDEX "$st->{error} errors";
186 if ($ret == $expected_ret) {
195 print INDEX "</tr>\n";
200 my ($self, $state, $testname) = @_;
202 $self->{active_test} = $testname;
208 my ($self, $state, $testname, $result, $unexpected, $reason) = @_;
212 $self->{local_statistics}->{$result}++;
216 if ($result eq "skip") {
217 print TEST "<td class=\"outputSkipped\">\n";
218 $track_class = "skip";
219 } elsif ($unexpected) {
220 print TEST "<td class=\"outputFailure\">\n";
221 if ($result eq "error") {
222 $track_class = "error";
224 $track_class = "unexpected_$result";
227 if ($result eq "failure") {
228 print TEST "<td class=\"outputExpectedFailure\">\n";
230 print TEST "<td class=\"outputOk\">\n";
232 $track_class = "expected_$result";
235 push(@{$self->{error_summary}->{$track_class}}, ,
236 [$state->{HTMLFILE}, $testname, $state->{NAME},
239 print TEST "<a name=\"$testname\"><h3>$testname</h3></a>\n";
241 print TEST $self->{msg};
243 if (defined($reason)) {
244 print TEST "<div class=\"reason\">$reason</div>\n";
247 print TEST "</td></tr>\n";
249 $self->{active_test} = undef;
256 my $st = $self->{statistics};
257 print INDEX "<tr>\n";
258 print INDEX " <td class=\"testSuiteTotal\">Total</td>\n";
259 print INDEX " <td></td>\n";
261 if ($st->{SUITES_FAIL} == 0) {
262 print INDEX " <td class=\"resultOk\">";
264 print INDEX " <td class=\"resultFailure\">";
266 print INDEX ($st->{TESTS_EXPECTED_OK} + $st->{TESTS_UNEXPECTED_OK}) . " ok";
267 if ($st->{TESTS_UNEXPECTED_OK} > 0) {
268 print INDEX " ($st->{TESTS_UNEXPECTED_OK} unexpected)";
270 if ($st->{TESTS_SKIP} > 0) {
271 print INDEX ", $st->{TESTS_SKIP} skipped";
273 if (($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) > 0) {
274 print INDEX ", " . ($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) . " failures";
275 if ($st->{TESTS_UNEXPECTED_FAIL} > 0) {
276 print INDEX " ($st->{TESTS_EXPECTED_FAIL} expected)";
279 if ($st->{TESTS_ERROR} > 0) {
280 print INDEX ", $st->{TESTS_ERROR} errors";
285 print INDEX "</tr>\n";
287 print INDEX "</table>\n";
288 print INDEX "<a href=\"summary.html\">Summary</a>\n";
289 print INDEX "</center>\n";
290 $self->print_html_footer(*INDEX);
293 my $summ = $self->{error_summary};
294 open(SUMMARY, ">$self->{dirname}/summary.html");
295 $self->print_html_header("Summary", *SUMMARY);
296 sub print_table($$) {
297 my ($title, $list) = @_;
298 return if ($#$list == -1);
299 print SUMMARY "<h3>$title</h3>\n";
300 print SUMMARY "<table>\n";
301 print SUMMARY "<tr>\n";
302 print SUMMARY " <td class=\"tableHead\">Testsuite</td>\n";
303 print SUMMARY " <td class=\"tableHead\">Test</td>\n";
304 print SUMMARY " <td class=\"tableHead\">Reason</td>\n";
305 print SUMMARY "</tr>\n";
308 print SUMMARY "<tr>\n";
309 print SUMMARY " <td><a href=\"" . $$_[0] . "\">$$_[2]</a></td>\n";
310 print SUMMARY " <td><a href=\"" . $$_[0] . "#$$_[1]\">$$_[1]</a></td>\n";
311 if (defined($$_[3])) {
312 print SUMMARY " <td>$$_[3]</td>\n";
314 print SUMMARY " <td></td>\n";
316 print SUMMARY "</tr>\n";
319 print SUMMARY "</table>";
321 print_table("Errors", $summ->{error});
322 print_table("Unexpected successes", $summ->{unexpected_success});
323 print_table("Unexpected failures", $summ->{unexpected_failure});
324 print_table("Skipped tests", $summ->{skip});
325 print_table("Expected failures", $summ->{expected_failure});
327 print SUMMARY "<h3>Skipped testsuites</h3>\n";
328 print SUMMARY "<table>\n";
329 print SUMMARY "<tr>\n";
330 print SUMMARY " <td class=\"tableHead\">Testsuite</td>\n";
331 print SUMMARY " <td class=\"tableHead\">Reason</td>\n";
332 print SUMMARY "</tr>\n";
334 foreach (@{$summ->{skip_testsuites}}) {
335 print SUMMARY "<tr>\n";
336 print SUMMARY " <td>$$_[1]</td>\n";
337 if (defined($$_[2])) {
338 print SUMMARY " <td>$$_[2]</td>\n";
340 print SUMMARY " <td></td>\n";
342 print SUMMARY "</tr>\n";
345 print SUMMARY "</table>";
347 $self->print_html_footer(*SUMMARY);
351 sub skip_testsuite($$$$)
353 my ($self, $name, $reason) = @_;
355 push (@{$self->{error_summary}->{skip_testsuites}},