aboutsummaryrefslogtreecommitdiff
path: root/pan/cgi/results.cgi
blob: f84a92c7d1de5cb49a6d0c70c6467e6176093ea7 (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
#!/usr/bin/perl

use CGI qw(:standard escapeHTML);

# When something goes wrong before we start output, use this function
# so there is still output
sub failure {
	print header("text/html"),start_html;
	print "$_[0]\n";
	print end_html;
	exit;
}

# Most of the work is done in this directory
unless (chdir("/usr/tests/ltp/results")) {
	failure("Could not get to the results directory\n");
}


# grab the parameters that determine what's going on then branch
$get_df = param("get_df");
if ($get_df) {
	# copy a driver file and output it.
	$get_df = (<$get_df*>)[0];
	($host, $datestr, $suite, $type, $gz) = split(/\./, $get_df);
	#print start_html, "<pre>\n";
	if ($gz) {
		open (DF, "gunzip -c $get_df|") || print "$get_df not found\n";
	} else {
		open (DF, "$get_df") || print "$get_df not found";
	}
	if ($type eq "driver" || $type eq "summary") {
		print header("text/plain");
		$zoom_tag = param("zoom_tag");
		if ($zoom_tag) {
			while (<DF>) {
				# find the start of a test
				while (<DF>) {
					if (/\<\<\<test_start\>\>\>/) {
						$line = <DF>;
						if ($line =~ /^tag=$zoom_tag /) {
							print "<<<test_start>>>\n";
							print $line;

							do {
								$line = <DF>;
								print $line;
							} until ($line =~ /\<\<\<test_end\>\>\>/);
							exit;
						}
					}
				}
			}
			print "Did not find tag $zoom_tag\n";
		} else {
			while (<DF>) {
				print $_;
			}
		}
	} elsif ($type eq "scanner") {
		print header("text/html");
		print start_html, "<pre>\n";
		while (<DF>) {
			print;
			if (/^-+/) { last;}
		}
		@rest = <DF>;
		# this is just to put the * at the end of the test case list
		unless (param("raw")) {
			foreach (@rest) { s/\*/{/; }
			foreach (@rest) { s/(\s)-(\s)/\1}\2/; }
			@rest = sort @rest;
			foreach (@rest) { s/{/*/; }
			foreach (@rest) { s/}/-/; }
		}

		foreach (@rest) {
			s/(\S+)/<a href="results.cgi?get_df=$host.$datestr.$suite.driver&zoom_tag=\1">\1<\/a>/;
			# colorize the status column
			s/\bPASS\b/\<font color\=green\>PASS\<\/font\>/i;
			s/\bFAIL\b/\<font color\=\"red\"\>FAIL\<\/font\>/i;
			s/\bCONF\b/\<font color\=\"yellow\"\>CONF\<\/font\>/i;
			s/\bBROK\b/\<font color\=\"blue\"\>BROK\<\/font\>/i;
			print;
		}
		print "\n</pre>",end_html;
	}
	close(DF);
	#print "\n</pre>\n",end_html;
} else {
	%results = ();

	# run through the files in the results directory
	@driver_files = <*driver*>;
	foreach $df (sort(@driver_files)) {

		($host, $datestr, $suite, $type, $gz) = split(/\./, $df);

		$a_rec = ();
		$a_rec->{HOST} = $host;
		$a_rec->{DATE} = $datestr;
		$a_rec->{SUITE} = $suite;
		$a_rec->{DRIVER_FILE} = $df;

		$results{ $a_rec->{DRIVER_FILE} } = $a_rec;
	}

	# write the HTML file
	print header("text/html"),start_html;

	@ri = values %results;
	@ri = sort { $a->{HOST} cmp $b->{HOST}
			||$b->{DATE} <=> $a->{DATE}
			||$a->{SUITE} cmp $b->{SUITE} } @ri;
	$lasthost = "";
	$lastdate = "";
	$lastsuite = "";
	$indent = 0;
	print "<table>\n";
	print "<tr><th>Hostname<th>Date<th>Suite</tr>\n";
	foreach $rp ( @ri ) {
		$thishost = $rp->{HOST};
		$thisdate = $rp->{DATE};
		$thissuite = $rp->{SUITE};

		# figure out where is the table we need to start
		if ($lasthost ne $thishost) {
			$indent = 0;
		} elsif ($lastdate ne $thisdate) {
			$indent = 1;
		} elsif ($lastsuite ne $thissuite) {
			$indent = 2;
		}

		# write the rows we need depending on the starting point
		# host level
		if ($indent <= 0) {
			print "<tr><td>$thishost\n";
		}
		# date level
		if ($indent <= 1) {
			($year, $month, $day, $hour, $min) = ($thisdate =~ /(\d+)(\d{2})(\d{2})(\d{2})(\d{2})/);
			print "<tr><td><td>$year-$month-$day $hour:$min\n";
		}
		# suite level
		if ($indent <= 2) {
			print "<tr><td><td><td>";
			print "$thissuite";
			print " [<a href=\"results.cgi?get_df=$rp->{DRIVER_FILE}\">driver output</a>]";
			print " [<a href=\"results.cgi?get_df=$thishost.$thisdate.$thissuite.scanner\">results</a>]";
			print " [<a href=\"results.cgi?get_df=$thishost.$thisdate.$thissuite.summary\">summary</a>]";

			print "\n";
		}

		# make sure we update the $last... variables
		$lasthost = $thishost;
		$lastdate = $thisdate;
		$lastsuite = $thissuite;
	}
	print "</table>\n";
	print end_html;
}