summaryrefslogtreecommitdiff
path: root/source4/selftest/output/html.pm
blob: 22488576b41fd4434bdc2768a0ea5ba1827edc26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/usr/bin/perl

package output::html;
use Exporter;
@ISA = qw(Exporter);

use strict;
use warnings;

use FindBin qw($RealBin);

sub new($$$$) {
	my ($class, $dirname, $statistics) = @_;
	my $self = { 
		dirname => $dirname,
		statistics => $statistics,
		active_test => undef,
		local_statistics => {},
		msg => "",
		error_summary => { 
			skip => [],
			expected_success => [],
			unexpected_success => [],
			expected_failure => [],
			unexpected_failure => [],
			skip_testsuites => [],
			error => []
		}
	};

	link("$RealBin/output/testresults.css", "$dirname/testresults.css");

	open(INDEX, ">$dirname/index.html");

	bless($self, $class);

	$self->print_html_header("Samba Testsuite Run", *INDEX);

	print INDEX "  <center>";
	print INDEX "  <table>\n";
	print INDEX "  <tr>\n";
	print INDEX "    <td class=\"tableHead\">Test</td>\n";
	print INDEX "    <td class=\"tableHead\">Environment</td>\n";
	print INDEX "    <td class=\"tableHead\">Result</td>\n";
	print INDEX "  </tr>\n";

	return $self;
}

sub print_html_header($$$)
{
	my ($self, $title, $fh) = @_;

	print $fh "<html lang=\"en\">\n";
	print $fh "<head>\n";
	print $fh "  <title>$title</title>\n";
	print $fh "  <link rel=\"stylesheet\" type=\"text/css\" href=\"testresults.css\"/>\n";
	print $fh "</head>\n";
	print $fh "<body>\n";
	print $fh "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
	print $fh "  <tr><td class=\"title\">$title</td></tr>\n";
	print $fh "  <tr><td>\n";
}

sub print_html_footer($$)
{
	my ($self, $fh) = @_;

	print $fh "</td></tr>\n";
	print $fh "</table>\n";
	print $fh "</body>\n";
	print $fh "</html>\n";
}

sub output_msg($$$);

sub start_testsuite($$)
{
	my ($self, $state) = @_;

	$self->{local_statistics} = {
		success => 0,
		skip => 0,
		error => 0,
		failure => 0
	};

	$state->{HTMLFILE} = "$state->{NAME}.html";
	$state->{HTMLFILE} =~ s/[:\t\n \/]/_/g;

	open(TEST, ">$self->{dirname}/$state->{HTMLFILE}") or die("Unable to open $state->{HTMLFILE} for writing");

	$self->print_html_header("Test Results for $state->{NAME}",
		                     *TEST);

	if ($state->{ENVNAME} ne "none") {
		print TEST "<h2>Environment settings</h2>\n";

		print TEST "  <table>\n";
		print TEST "    <tr><td><b>Variable name</b></td><td><b>Variable value</b></td></tr>\n";
		foreach (keys %{$state->{ENVVARS}}) {
			print TEST "    <tr><td>$_</td><td>";
			my $val = $state->{ENVVARS}->{$_};
			if ($val =~ /^\.\// and -r $val) { 
				print TEST "<a href=\"../$val\">$val</a>"; 
			} elsif (-r $val) {
				print TEST "<a href=\"$val\">$val</a>"; 
			} else { 
				print TEST $val; 
			}
			print TEST "</td></tr>\n";
		}
		print TEST "  </table>\n";
	}

	print TEST "<h2>Tests</h2>\n";

	print TEST "  <table>\n";
}

sub control_msg($$$)
{
	my ($self, $state, $output) = @_;

	$self->{msg} .=  "<span class=\"control\">$output<br/></span>\n";
}

sub output_msg($$$)
{
	my ($self, $state, $output) = @_;

	unless (defined($self->{active_test})) {
		print TEST "$output<br/>";
	} else {
		$self->{msg} .= "$output<br/>";
	}
}

sub end_testsuite($$$$$)
{
	my ($self, $state, $expected_ret, $ret, $envlog) = @_;

	print TEST "</table>\n";

	print TEST "<div class=\"command\">$state->{CMD}</div>\n";
	print TEST "<div class=\"duration\">Duration: " . (time() - $state->{START_TIME}) . "s</div>\n";

	$self->print_html_footer(*TEST);

	close(TEST);

	print INDEX "<tr>\n";
	print INDEX "  <td class=\"testSuite\"><a href=\"$state->{HTMLFILE}\">$state->{NAME}</a></td>\n";
	print INDEX "  <td class=\"environment\">$state->{ENVNAME}</td>\n";
	my $st = $self->{local_statistics};

	if ($ret == $expected_ret) {
		if ($ret == 0) {
			print INDEX "  <td class=\"resultExpectedFailure\">";
		} else {
			print INDEX "  <td class=\"resultOk\">";
		}
	} else {
		print INDEX "  <td class=\"resultFailure\">";
	}

	my $l = 0;
	if ($st->{success} > 0) {
		print INDEX "$st->{success} ok";
		$l++;
	}
	if ($st->{skip} > 0) {
		print INDEX ", " if ($l);
		print INDEX "$st->{skip} skipped";
		$l++;
	}
	if ($st->{failure} > 0) {
		print INDEX ", " if ($l);
		print INDEX "$st->{failure} failures";
		$l++;
	}
	if ($st->{error} > 0) {
		print INDEX ", " if ($l);
		print INDEX "$st->{error} errors";
		$l++;
	}

	if ($l == 0) {
		if ($ret == $expected_ret) {
			print INDEX "OK";
		} else {
			print INDEX "FAIL";
		}
	}

	print INDEX "</td>";
		
	print INDEX "</tr>\n";
}

sub start_test($$$)
{
	my ($self, $state, $testname) = @_;

	$self->{active_test} = $testname;
	$self->{msg} = "";
}

sub end_test($$$$$$)
{
	my ($self, $state, $testname, $result, $unexpected, $reason) = @_;

	print TEST "<tr>";

	$self->{local_statistics}->{$result}++;

	my $track_class;

	if ($result eq "skip") {
		print TEST "<td class=\"outputSkipped\">\n";
		$track_class = "skip";
	} elsif ($unexpected) {
		print TEST "<td class=\"outputFailure\">\n";
		if ($result eq "error") {
			$track_class = "error";
		} else {
			$track_class = "unexpected_$result";
		}
	} else {
		if ($result eq "failure") {
			print TEST "<td class=\"outputExpectedFailure\">\n";
		} else {
			print TEST "<td class=\"outputOk\">\n";
		}
		$track_class = "expected_$result";
	}

	push(@{$self->{error_summary}->{$track_class}}, ,
		 [$state->{HTMLFILE}, $testname, $state->{NAME}, 
		  $reason]);

	print TEST "<a name=\"$testname\"><h3>$testname</h3></a>\n";

	print TEST $self->{msg};

	if (defined($reason)) {
		print TEST "<div class=\"reason\">$reason</div>\n";
	}

	print TEST "</td></tr>\n";

	$self->{active_test} = undef;
}

sub summary($)
{
	my ($self) = @_;

	my $st = $self->{statistics};
	print INDEX "<tr>\n";
	print INDEX "  <td class=\"testSuiteTotal\">Total</td>\n";
	print INDEX "  <td></td>\n";

	if ($st->{SUITES_FAIL} == 0) {
		print INDEX "  <td class=\"resultOk\">";
	} else {
		print INDEX "  <td class=\"resultFailure\">";
	}
	print INDEX ($st->{TESTS_EXPECTED_OK} + $st->{TESTS_UNEXPECTED_OK}) . " ok";
	if ($st->{TESTS_UNEXPECTED_OK} > 0) {
		print INDEX " ($st->{TESTS_UNEXPECTED_OK} unexpected)";
	}
	if ($st->{TESTS_SKIP} > 0) {
		print INDEX ", $st->{TESTS_SKIP} skipped";
	}
	if (($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) > 0) {
		print INDEX ", " . ($st->{TESTS_UNEXPECTED_FAIL} + $st->{TESTS_EXPECTED_FAIL}) . " failures";
		if ($st->{TESTS_UNEXPECTED_FAIL} > 0) {
			print INDEX " ($st->{TESTS_EXPECTED_FAIL} expected)";
		}
	}
	if ($st->{TESTS_ERROR} > 0) {
		print INDEX ", $st->{TESTS_ERROR} errors";
	}

	print INDEX "</td>";

	print INDEX "</tr>\n";

	print INDEX "</table>\n";
	print INDEX "<a href=\"summary.html\">Summary</a>\n";
	print INDEX "</center>\n";
	$self->print_html_footer(*INDEX);
	close(INDEX);

	my $summ = $self->{error_summary};
	open(SUMMARY, ">$self->{dirname}/summary.html");
	$self->print_html_header("Summary", *SUMMARY);
	sub print_table($$) {
		my ($title, $list) = @_;
		return if ($#$list == -1);
		print SUMMARY "<h3>$title</h3>\n";
		print SUMMARY "<table>\n";
		print SUMMARY "<tr>\n";
		print SUMMARY "  <td class=\"tableHead\">Testsuite</td>\n";
		print SUMMARY "  <td class=\"tableHead\">Test</td>\n";
		print SUMMARY "  <td class=\"tableHead\">Reason</td>\n";
		print SUMMARY "</tr>\n";

		foreach (@$list) {
			print SUMMARY "<tr>\n";
			print SUMMARY "  <td><a href=\"" . $$_[0] . "\">$$_[2]</a></td>\n";
			print SUMMARY "  <td><a href=\"" . $$_[0] . "#$$_[1]\">$$_[1]</a></td>\n";
			if (defined($$_[3])) {
				print SUMMARY "  <td>$$_[3]</td>\n";
			} else {
				print SUMMARY "  <td></td>\n";
			}
			print SUMMARY "</tr>\n";
		}

		print SUMMARY "</table>";
	}
	print_table("Errors", $summ->{error});
	print_table("Unexpected successes", $summ->{unexpected_success});
	print_table("Unexpected failures", $summ->{unexpected_failure});
	print_table("Skipped tests", $summ->{skip});
	print_table("Expected failures", $summ->{expected_failure});

	print SUMMARY "<h3>Skipped testsuites</h3>\n";
	print SUMMARY "<table>\n";
	print SUMMARY "<tr>\n";
	print SUMMARY "  <td class=\"tableHead\">Testsuite</td>\n";
	print SUMMARY "  <td class=\"tableHead\">Reason</td>\n";
	print SUMMARY "</tr>\n";

	foreach (@{$summ->{skip_testsuites}}) {
		print SUMMARY "<tr>\n";
		print SUMMARY "  <td>$$_[1]</td>\n";
		if (defined($$_[2])) {
			print SUMMARY "  <td>$$_[2]</td>\n";
		} else {
			print SUMMARY "  <td></td>\n";
		}
		print SUMMARY "</tr>\n";
	}

	print SUMMARY "</table>";

	$self->print_html_footer(*SUMMARY);
	close(SUMMARY);
}

sub missing_env($$$)
{
	my ($self, $name, $envname) = @_;

	$self->skip_testsuite($envname, $name, "environment `$envname` not available!");
}

sub skip_testsuite($$$$)
{
	my ($self, $envname, $name, $reason) = @_;

	push (@{$self->{error_summary}->{skip_testsuites}}, 
		  [$envname, $name, $reason]);
}

1;