Fix bug 6774 - smbd crashes if "aio write behind" is set.
[Samba.git] / selftest / output / html.pm
blob1049527129c50f3296f9daa2be4bc5c3f218d574
1 #!/usr/bin/perl
3 package output::html;
4 use Exporter;
5 @ISA = qw(Exporter);
7 use strict;
8 use warnings;
10 use FindBin qw($RealBin);
11 use lib "$RealBin/..";
13 use Subunit qw(parse_results);
15 sub new($$$) {
16 my ($class, $dirname, $statistics) = @_;
17 my $self = {
18 dirname => $dirname,
19 active_test => undef,
20 local_statistics => {},
21 statistics => $statistics,
22 msg => "",
23 error_summary => {
24 skip => [],
25 expected_success => [],
26 unexpected_success => [],
27 expected_failure => [],
28 unexpected_failure => [],
29 skip_testsuites => [],
30 error => []
34 link("$RealBin/output/testresults.css", "$dirname/testresults.css");
36 open(INDEX, ">$dirname/index.html");
38 bless($self, $class);
40 $self->print_html_header("Samba Testsuite Run", *INDEX);
42 print INDEX " <center>";
43 print INDEX " <table>\n";
44 print INDEX " <tr>\n";
45 print INDEX " <td class=\"tableHead\">Test</td>\n";
46 print INDEX " <td class=\"tableHead\">Result</td>\n";
47 print INDEX " </tr>\n";
49 return $self;
52 sub print_html_header($$$)
54 my ($self, $title, $fh) = @_;
56 print $fh "<html lang=\"en\">\n";
57 print $fh "<head>\n";
58 print $fh " <title>$title</title>\n";
59 print $fh " <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
60 print $fh "</head>\n";
61 print $fh "<body>\n";
62 print $fh "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
63 print $fh " <tr><td class=\"title\">$title</td></tr>\n";
64 print $fh " <tr><td>\n";
67 sub print_html_footer($$)
69 my ($self, $fh) = @_;
71 print $fh "</td></tr>\n";
72 print $fh "</table>\n";
73 print $fh "</body>\n";
74 print $fh "</html>\n";
77 sub output_msg($$);
79 sub start_testsuite($$)
81 my ($self, $name) = @_;
83 $self->{local_statistics} = {
84 success => 0,
85 skip => 0,
86 error => 0,
87 failure => 0
90 $self->{NAME} = $name;
91 $self->{HTMLFILE} = "$name.html";
92 $self->{HTMLFILE} =~ s/[:\t\n \/]/_/g;
94 open(TEST, ">$self->{dirname}/$self->{HTMLFILE}") or die("Unable to open $self->{HTMLFILE} for writing");
96 $self->print_html_header("Test Results for $name", *TEST);
98 print TEST "<h2>Tests</h2>\n";
100 print TEST " <table>\n";
103 sub control_msg($$)
105 my ($self, $output) = @_;
107 $self->{msg} .= "<span class=\"control\">$output<br/></span>\n";
110 sub output_msg($$)
112 my ($self, $output) = @_;
114 unless (defined($self->{active_test})) {
115 print TEST "$output<br/>";
116 } else {
117 $self->{msg} .= "$output<br/>";
121 sub end_testsuite($$$$)
123 my ($self, $name, $result, $unexpected, $reason) = @_;
125 print TEST "</table>\n";
127 print TEST "<div class=\"duration\">Duration: " . (time() - $self->{START_TIME}) . "s</div>\n";
129 $self->print_html_footer(*TEST);
131 close(TEST);
133 print INDEX "<tr>\n";
134 print INDEX " <td class=\"testSuite\"><a href=\"$self->{HTMLFILE}\">$name</a></td>\n";
135 my $st = $self->{local_statistics};
137 if (not $unexpected) {
138 if ($result eq "failure") {
139 print INDEX " <td class=\"resultExpectedFailure\">";
140 } else {
141 print INDEX " <td class=\"resultOk\">";
143 } else {
144 print INDEX " <td class=\"resultFailure\">";
147 my $l = 0;
148 if ($st->{success} > 0) {
149 print INDEX "$st->{success} ok";
150 $l++;
152 if ($st->{skip} > 0) {
153 print INDEX ", " if ($l);
154 print INDEX "$st->{skip} skipped";
155 $l++;
157 if ($st->{failure} > 0) {
158 print INDEX ", " if ($l);
159 print INDEX "$st->{failure} failures";
160 $l++;
162 if ($st->{error} > 0) {
163 print INDEX ", " if ($l);
164 print INDEX "$st->{error} errors";
165 $l++;
168 if ($l == 0) {
169 if (not $unexpected) {
170 print INDEX "OK";
171 } else {
172 print INDEX "FAIL";
176 print INDEX "</td>";
178 print INDEX "</tr>\n";
181 sub start_test($$)
183 my ($self, $parents, $testname) = @_;
185 if ($#$parents == -1) {
186 $self->{START_TIME} = time();
187 $self->start_testsuite($testname);
188 return;
191 $self->{active_test} = $testname;
192 $self->{msg} = "";
195 sub end_test($$$$$$)
197 my ($self, $parents, $testname, $result, $unexpected, $reason) = @_;
199 if ($#$parents == -1) {
200 $self->end_testsuite($testname, $result, $unexpected, $reason);
201 return;
204 print TEST "<tr>";
206 $self->{local_statistics}->{$result}++;
208 my $track_class;
210 if ($result eq "skip") {
211 print TEST "<td class=\"outputSkipped\">\n";
212 $track_class = "skip";
213 } elsif ($unexpected) {
214 print TEST "<td class=\"outputFailure\">\n";
215 if ($result eq "error") {
216 $track_class = "error";
217 } else {
218 $track_class = "unexpected_$result";
220 } else {
221 if ($result eq "failure") {
222 print TEST "<td class=\"outputExpectedFailure\">\n";
223 } else {
224 print TEST "<td class=\"outputOk\">\n";
226 $track_class = "expected_$result";
229 push(@{$self->{error_summary}->{$track_class}}, ,
230 [$self->{HTMLFILE}, $testname, $self->{NAME},
231 $reason]);
233 print TEST "<a name=\"$testname\"><h3>$testname</h3></a>\n";
235 print TEST $self->{msg};
237 if (defined($reason)) {
238 print TEST "<div class=\"reason\">$reason</div>\n";
241 print TEST "</td></tr>\n";
243 $self->{active_test} = undef;
246 sub summary($)
248 my ($self) = @_;
250 my $st = $self->{statistics};
251 print INDEX "<tr>\n";
252 print INDEX " <td class=\"testSuiteTotal\">Total</td>\n";
254 if ($st->{TESTS_UNEXPECTED_OK} == 0 and
255 $st->{TESTS_UNEXPECTED_FAIL} == 0 and
256 $st->{TESTS_ERROR} == 0) {
257 print INDEX " <td class=\"resultOk\">";
258 } else {
259 print INDEX " <td class=\"resultFailure\">";
261 print INDEX ($st->{TESTS_EXPECTED_OK} + $st->{TESTS_UNEXPECTED_OK}) . " ok";
262 if ($st->{TESTS_UNEXPECTED_OK} > 0) {
263 print INDEX " ($st->{TESTS_UNEXPECTED_OK} unexpected)";
265 if ($st->{TESTS_SKIP} > 0) {
266 print INDEX ", $st->{TESTS_SKIP} skipped";
268 if (($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) > 0) {
269 print INDEX ", " . ($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) . " failures";
270 if ($st->{TESTS_UNEXPECTED_FAIL} > 0) {
271 print INDEX " ($st->{TESTS_EXPECTED_FAIL} expected)";
274 if ($st->{TESTS_ERROR} > 0) {
275 print INDEX ", $st->{TESTS_ERROR} errors";
278 print INDEX "</td>";
280 print INDEX "</tr>\n";
282 print INDEX "</table>\n";
283 print INDEX "<a href=\"summary.html\">Summary</a>\n";
284 print INDEX "</center>\n";
285 $self->print_html_footer(*INDEX);
286 close(INDEX);
288 my $summ = $self->{error_summary};
289 open(SUMMARY, ">$self->{dirname}/summary.html");
290 $self->print_html_header("Summary", *SUMMARY);
291 sub print_table($$) {
292 my ($title, $list) = @_;
293 return if ($#$list == -1);
294 print SUMMARY "<h3>$title</h3>\n";
295 print SUMMARY "<table>\n";
296 print SUMMARY "<tr>\n";
297 print SUMMARY " <td class=\"tableHead\">Testsuite</td>\n";
298 print SUMMARY " <td class=\"tableHead\">Test</td>\n";
299 print SUMMARY " <td class=\"tableHead\">Reason</td>\n";
300 print SUMMARY "</tr>\n";
302 foreach (@$list) {
303 print SUMMARY "<tr>\n";
304 print SUMMARY " <td><a href=\"" . $$_[0] . "\">$$_[2]</a></td>\n";
305 print SUMMARY " <td><a href=\"" . $$_[0] . "#$$_[1]\">$$_[1]</a></td>\n";
306 if (defined($$_[3])) {
307 print SUMMARY " <td>$$_[3]</td>\n";
308 } else {
309 print SUMMARY " <td></td>\n";
311 print SUMMARY "</tr>\n";
314 print SUMMARY "</table>";
316 print_table("Errors", $summ->{error});
317 print_table("Unexpected successes", $summ->{unexpected_success});
318 print_table("Unexpected failures", $summ->{unexpected_failure});
319 print_table("Skipped tests", $summ->{skip});
320 print_table("Expected failures", $summ->{expected_failure});
322 print SUMMARY "<h3>Skipped testsuites</h3>\n";
323 print SUMMARY "<table>\n";
324 print SUMMARY "<tr>\n";
325 print SUMMARY " <td class=\"tableHead\">Testsuite</td>\n";
326 print SUMMARY " <td class=\"tableHead\">Reason</td>\n";
327 print SUMMARY "</tr>\n";
329 foreach (@{$summ->{skip_testsuites}}) {
330 print SUMMARY "<tr>\n";
331 print SUMMARY " <td>$$_[0]</td>\n";
332 if (defined($$_[1])) {
333 print SUMMARY " <td>$$_[1]</td>\n";
334 } else {
335 print SUMMARY " <td></td>\n";
337 print SUMMARY "</tr>\n";
340 print SUMMARY "</table>";
342 $self->print_html_footer(*SUMMARY);
343 close(SUMMARY);
346 sub skip_testsuite($$$$)
348 my ($self, $name, $reason) = @_;
350 push (@{$self->{error_summary}->{skip_testsuites}},
351 [$name, $reason]);