xref: /aosp_15_r20/external/ltp/pan/cgi/browse.cgi (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker#!/usr/bin/perl
2*49cdfc7eSAndroid Build Coastguard Worker
3*49cdfc7eSAndroid Build Coastguard Workeruse CGI qw(:standard);
4*49cdfc7eSAndroid Build Coastguard Worker
5*49cdfc7eSAndroid Build Coastguard Worker# keep a copy of each 'uname -a' string so we don't have to search for it every time.
6*49cdfc7eSAndroid Build Coastguard Worker%uname_cache = {};
7*49cdfc7eSAndroid Build Coastguard Worker
8*49cdfc7eSAndroid Build Coastguard Worker# When something goes wrong before we start output, use this
9*49cdfc7eSAndroid Build Coastguard Worker# function so there is still output
10*49cdfc7eSAndroid Build Coastguard Workersub failure {
11*49cdfc7eSAndroid Build Coastguard Worker	print header("text/html"),start_html;
12*49cdfc7eSAndroid Build Coastguard Worker	print "$_[0]\n";
13*49cdfc7eSAndroid Build Coastguard Worker	print end_html;
14*49cdfc7eSAndroid Build Coastguard Worker	exit;
15*49cdfc7eSAndroid Build Coastguard Worker}
16*49cdfc7eSAndroid Build Coastguard Worker# get the UNAME line for a host, date, suite
17*49cdfc7eSAndroid Build Coastguard Workersub get_result_uname {
18*49cdfc7eSAndroid Build Coastguard Worker	my($inhost, $indate, $insuite, $filename);
19*49cdfc7eSAndroid Build Coastguard Worker	my(@possible_files, $pf, $line);
20*49cdfc7eSAndroid Build Coastguard Worker	my($host, $datestr, $suite, $type, $gz);
21*49cdfc7eSAndroid Build Coastguard Worker	# build a filename
22*49cdfc7eSAndroid Build Coastguard Worker	$inhost = $_[0];
23*49cdfc7eSAndroid Build Coastguard Worker	$indate = $_[1];
24*49cdfc7eSAndroid Build Coastguard Worker	if ($#_ >= 2) {
25*49cdfc7eSAndroid Build Coastguard Worker		$insuite = $_[2];
26*49cdfc7eSAndroid Build Coastguard Worker	} else {
27*49cdfc7eSAndroid Build Coastguard Worker		$insuite = "*";
28*49cdfc7eSAndroid Build Coastguard Worker	}
29*49cdfc7eSAndroid Build Coastguard Worker	# check to see if we've done this already
30*49cdfc7eSAndroid Build Coastguard Worker	if (exists($uname_cache{"$inhost.$indate"})) {
31*49cdfc7eSAndroid Build Coastguard Worker		return $uname_cache{"$inhost.$indate"};
32*49cdfc7eSAndroid Build Coastguard Worker	}
33*49cdfc7eSAndroid Build Coastguard Worker	$filename = "$inhost.$indate.$insuite.*";
34*49cdfc7eSAndroid Build Coastguard Worker	@possible_files = <${filename}>;
35*49cdfc7eSAndroid Build Coastguard Worker	if ($#possible_files < 1) {
36*49cdfc7eSAndroid Build Coastguard Worker		return "";
37*49cdfc7eSAndroid Build Coastguard Worker	}
38*49cdfc7eSAndroid Build Coastguard Worker	foreach $pf (@possible_files) {
39*49cdfc7eSAndroid Build Coastguard Worker		($host, $datestr, $suite, $type, $gz) = split(/\./, $pf);
40*49cdfc7eSAndroid Build Coastguard Worker		if ($type eq "summary") {
41*49cdfc7eSAndroid Build Coastguard Worker			next;
42*49cdfc7eSAndroid Build Coastguard Worker		} elsif ($type eq "scanner") {
43*49cdfc7eSAndroid Build Coastguard Worker			open (UF, $pf) || next;
44*49cdfc7eSAndroid Build Coastguard Worker			while ($line = <UF>) {
45*49cdfc7eSAndroid Build Coastguard Worker				if ($line =~ /^UNAME/) {
46*49cdfc7eSAndroid Build Coastguard Worker					close(UF);
47*49cdfc7eSAndroid Build Coastguard Worker					$line =~ s/UNAME *//;
48*49cdfc7eSAndroid Build Coastguard Worker					$line =~ s/$inhost//;
49*49cdfc7eSAndroid Build Coastguard Worker					$uname_cache{"$inhost.$indate"} = $line;
50*49cdfc7eSAndroid Build Coastguard Worker					return $line;
51*49cdfc7eSAndroid Build Coastguard Worker				}
52*49cdfc7eSAndroid Build Coastguard Worker			}
53*49cdfc7eSAndroid Build Coastguard Worker		} elsif ($type eq "driver") {
54*49cdfc7eSAndroid Build Coastguard Worker			if ($gz) {
55*49cdfc7eSAndroid Build Coastguard Worker				open (UF, "gunzip -c $pf|") || next;
56*49cdfc7eSAndroid Build Coastguard Worker			} else {
57*49cdfc7eSAndroid Build Coastguard Worker				open (UF, "$pf") || next;
58*49cdfc7eSAndroid Build Coastguard Worker			}
59*49cdfc7eSAndroid Build Coastguard Worker			while ($line = <UF>) {
60*49cdfc7eSAndroid Build Coastguard Worker				if ($line =~ /^UNAME/) {
61*49cdfc7eSAndroid Build Coastguard Worker					close(UF);
62*49cdfc7eSAndroid Build Coastguard Worker					$line =~ s/UNAME="(.*)"/\1/;
63*49cdfc7eSAndroid Build Coastguard Worker					$line =~ s/$inhost//;
64*49cdfc7eSAndroid Build Coastguard Worker					$uname_cache{"$inhost.$indate"} = $line;
65*49cdfc7eSAndroid Build Coastguard Worker					return $line;
66*49cdfc7eSAndroid Build Coastguard Worker				}
67*49cdfc7eSAndroid Build Coastguard Worker			}
68*49cdfc7eSAndroid Build Coastguard Worker		} else {
69*49cdfc7eSAndroid Build Coastguard Worker			next;
70*49cdfc7eSAndroid Build Coastguard Worker		}
71*49cdfc7eSAndroid Build Coastguard Worker	}
72*49cdfc7eSAndroid Build Coastguard Worker	return "";
73*49cdfc7eSAndroid Build Coastguard Worker}
74*49cdfc7eSAndroid Build Coastguard Worker
75*49cdfc7eSAndroid Build Coastguard Worker# Create the headers row, adding links for sorting options
76*49cdfc7eSAndroid Build Coastguard Workersub print_headers {
77*49cdfc7eSAndroid Build Coastguard Worker
78*49cdfc7eSAndroid Build Coastguard Worker	print "\n<tr>";
79*49cdfc7eSAndroid Build Coastguard Worker
80*49cdfc7eSAndroid Build Coastguard Worker	for($i = 0; $i <= $#rso; $i++) {
81*49cdfc7eSAndroid Build Coastguard Worker		print "<th><a href=\"browse.cgi?sort=";
82*49cdfc7eSAndroid Build Coastguard Worker		for ($j = 0; $j <= $#rso; $j++) {
83*49cdfc7eSAndroid Build Coastguard Worker			if ($j == $i) { $rsd[$j] = $rsd[$j] * -1; }
84*49cdfc7eSAndroid Build Coastguard Worker			if ($rsd[$j] == -1) { print "-"; }
85*49cdfc7eSAndroid Build Coastguard Worker			if ($j == $i) { $rsd[$j] = $rsd[$j] * -1; }
86*49cdfc7eSAndroid Build Coastguard Worker			print $rso[$j];
87*49cdfc7eSAndroid Build Coastguard Worker			if ($j < $#rso) { print ","; }
88*49cdfc7eSAndroid Build Coastguard Worker		}
89*49cdfc7eSAndroid Build Coastguard Worker		print "\">$rso[$i]</a>\n";
90*49cdfc7eSAndroid Build Coastguard Worker	}
91*49cdfc7eSAndroid Build Coastguard Worker
92*49cdfc7eSAndroid Build Coastguard Worker	print "</tr>\n";
93*49cdfc7eSAndroid Build Coastguard Worker}
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker############
96*49cdfc7eSAndroid Build Coastguard Worker# main()   #
97*49cdfc7eSAndroid Build Coastguard Worker############
98*49cdfc7eSAndroid Build Coastguard Worker
99*49cdfc7eSAndroid Build Coastguard Worker# Most of the work is done in this directory
100*49cdfc7eSAndroid Build Coastguard Workerunless (chdir("/usr/tests/ltp/results")) {
101*49cdfc7eSAndroid Build Coastguard Worker	failure("Could not get to the results directory\n");
102*49cdfc7eSAndroid Build Coastguard Worker}
103*49cdfc7eSAndroid Build Coastguard Worker
104*49cdfc7eSAndroid Build Coastguard Worker@extra_path = split(/\//, $ENV{PATH_INFO});
105*49cdfc7eSAndroid Build Coastguard Worker
106*49cdfc7eSAndroid Build Coastguard Worker# rso = Result Sort Order
107*49cdfc7eSAndroid Build Coastguard Worker# rsd = Result Sort Direction
108*49cdfc7eSAndroid Build Coastguard Worker#@rso = (HOST,SUITE, DATE, UNAME);
109*49cdfc7eSAndroid Build Coastguard Worker@rso = (SUITE, HOST, DATE, UNAME);
110*49cdfc7eSAndroid Build Coastguard Worker@rsd = (1, 1, -1, 1);
111*49cdfc7eSAndroid Build Coastguard Worker
112*49cdfc7eSAndroid Build Coastguard Worker# allow the user to specify the sort order
113*49cdfc7eSAndroid Build Coastguard Workerif ($sort_order = param("sort")) {
114*49cdfc7eSAndroid Build Coastguard Worker	@so = split(/,/, $sort_order);
115*49cdfc7eSAndroid Build Coastguard Worker	print $so;
116*49cdfc7eSAndroid Build Coastguard Worker	@rso = ();
117*49cdfc7eSAndroid Build Coastguard Worker	for($i = 0; $i <= $#so; $i++) {
118*49cdfc7eSAndroid Build Coastguard Worker		# parse the field
119*49cdfc7eSAndroid Build Coastguard Worker		if ($so[$i] =~ /host/i) { push(@rso, HOST); }
120*49cdfc7eSAndroid Build Coastguard Worker		elsif ($so[$i] =~ /date/i) { push(@rso, DATE); }
121*49cdfc7eSAndroid Build Coastguard Worker		elsif ($so[$i] =~ /suite/i) { push(@rso, SUITE); }
122*49cdfc7eSAndroid Build Coastguard Worker		elsif ($so[$i] =~ /uname/i) { push(@rso, UNAME); }
123*49cdfc7eSAndroid Build Coastguard Worker		# parse the direction
124*49cdfc7eSAndroid Build Coastguard Worker		if ($so[$i] =~ /-/) { $rsd[$i] = -1; }
125*49cdfc7eSAndroid Build Coastguard Worker		else { $rsd[$i] = 1; }
126*49cdfc7eSAndroid Build Coastguard Worker	}
127*49cdfc7eSAndroid Build Coastguard Worker}
128*49cdfc7eSAndroid Build Coastguard Worker
129*49cdfc7eSAndroid Build Coastguard Workerif ($#extra_path > 0) {
130*49cdfc7eSAndroid Build Coastguard Worker
131*49cdfc7eSAndroid Build Coastguard Worker} else {
132*49cdfc7eSAndroid Build Coastguard Worker
133*49cdfc7eSAndroid Build Coastguard Worker	%results = ();
134*49cdfc7eSAndroid Build Coastguard Worker
135*49cdfc7eSAndroid Build Coastguard Worker	# run through the files in the results directory
136*49cdfc7eSAndroid Build Coastguard Worker	@driver_files = <*driver*>;
137*49cdfc7eSAndroid Build Coastguard Worker	foreach $df (@driver_files) {
138*49cdfc7eSAndroid Build Coastguard Worker
139*49cdfc7eSAndroid Build Coastguard Worker		($host, $datestr, $suite, $type, $gz) = split(/\./, $df);
140*49cdfc7eSAndroid Build Coastguard Worker
141*49cdfc7eSAndroid Build Coastguard Worker		$a_rec = ();
142*49cdfc7eSAndroid Build Coastguard Worker		$a_rec->{HOST} = $host;
143*49cdfc7eSAndroid Build Coastguard Worker		$a_rec->{DATE} = $datestr;
144*49cdfc7eSAndroid Build Coastguard Worker		$a_rec->{SUITE} = $suite;
145*49cdfc7eSAndroid Build Coastguard Worker		$a_rec->{DRIVER_FILE} = $df;
146*49cdfc7eSAndroid Build Coastguard Worker		$a_rec->{UNAME} = get_result_uname($host, $datestr);
147*49cdfc7eSAndroid Build Coastguard Worker
148*49cdfc7eSAndroid Build Coastguard Worker		$results{ $a_rec->{DRIVER_FILE} } = $a_rec;
149*49cdfc7eSAndroid Build Coastguard Worker	}
150*49cdfc7eSAndroid Build Coastguard Worker
151*49cdfc7eSAndroid Build Coastguard Worker	# write the HTML file
152*49cdfc7eSAndroid Build Coastguard Worker	print header("text/html"),start_html;
153*49cdfc7eSAndroid Build Coastguard Worker	print "This is a demo page for browsing the Linux LTP results.  Select the results you want to compare and click the \"Compare\" button.", p, h2("Warning"), "The results are placed in a large table which may take a long time to render on some browsers", p;
154*49cdfc7eSAndroid Build Coastguard Worker	@ri = values %results;
155*49cdfc7eSAndroid Build Coastguard Worker	@ri = sort { ($a->{$rso[0]} cmp $b->{$rso[0]})*$rsd[0]
156*49cdfc7eSAndroid Build Coastguard Worker			|| ($a->{$rso[1]} cmp $b->{$rso[1]})*$rsd[1]
157*49cdfc7eSAndroid Build Coastguard Worker			|| ($a->{$rso[2]} cmp $b->{$rso[2]})*$rsd[2]
158*49cdfc7eSAndroid Build Coastguard Worker			|| ($a->{$rso[3]} cmp $b->{$rso[3]})*$rsd[3] } @ri;
159*49cdfc7eSAndroid Build Coastguard Worker
160*49cdfc7eSAndroid Build Coastguard Worker	$last = ();
161*49cdfc7eSAndroid Build Coastguard Worker	$last->{$rso[0]} = "";
162*49cdfc7eSAndroid Build Coastguard Worker	$last->{$rso[1]} = "";
163*49cdfc7eSAndroid Build Coastguard Worker	$last->{$rso[2]} = "";
164*49cdfc7eSAndroid Build Coastguard Worker	$lasthost = "";
165*49cdfc7eSAndroid Build Coastguard Worker	$lastdate = "";
166*49cdfc7eSAndroid Build Coastguard Worker	$lastsuite = "";
167*49cdfc7eSAndroid Build Coastguard Worker	#$lastindent = 0;
168*49cdfc7eSAndroid Build Coastguard Worker	$thisindent = 0;
169*49cdfc7eSAndroid Build Coastguard Worker	print "<form method=get action=\"reconsile.cgi\">";
170*49cdfc7eSAndroid Build Coastguard Worker	print "<table border=1>\n";
171*49cdfc7eSAndroid Build Coastguard Worker	#print "<tr><th>Hostname<th>Date<th>Suite</tr>\n";
172*49cdfc7eSAndroid Build Coastguard Worker	print_headers();
173*49cdfc7eSAndroid Build Coastguard Worker	foreach $rp ( @ri ) {
174*49cdfc7eSAndroid Build Coastguard Worker
175*49cdfc7eSAndroid Build Coastguard Worker		$this = ();
176*49cdfc7eSAndroid Build Coastguard Worker		$this->{$rso[0]} = $rp->{$rso[0]};
177*49cdfc7eSAndroid Build Coastguard Worker		$this->{$rso[1]} = $rp->{$rso[1]};
178*49cdfc7eSAndroid Build Coastguard Worker		$this->{$rso[2]} = $rp->{$rso[2]};
179*49cdfc7eSAndroid Build Coastguard Worker		$this->{$rso[3]} = $rp->{$rso[3]};
180*49cdfc7eSAndroid Build Coastguard Worker
181*49cdfc7eSAndroid Build Coastguard Worker		# figure out the first column that is different
182*49cdfc7eSAndroid Build Coastguard Worker		for ($i = 0; $i <= $#rso; $i++) {
183*49cdfc7eSAndroid Build Coastguard Worker			if ($last->{$rso[$i]} ne $this->{$rso[$i]}) {
184*49cdfc7eSAndroid Build Coastguard Worker				$thisindent = $i;
185*49cdfc7eSAndroid Build Coastguard Worker				last;
186*49cdfc7eSAndroid Build Coastguard Worker			}
187*49cdfc7eSAndroid Build Coastguard Worker		}
188*49cdfc7eSAndroid Build Coastguard Worker
189*49cdfc7eSAndroid Build Coastguard Worker		print "<tr>\n";
190*49cdfc7eSAndroid Build Coastguard Worker		for ($i = 0; $i < $thisindent; $i++) {
191*49cdfc7eSAndroid Build Coastguard Worker			print "<td>";
192*49cdfc7eSAndroid Build Coastguard Worker
193*49cdfc7eSAndroid Build Coastguard Worker		}
194*49cdfc7eSAndroid Build Coastguard Worker		for ($i = $thisindent; $i <= $#rso; $i++) {
195*49cdfc7eSAndroid Build Coastguard Worker			print "<td>";
196*49cdfc7eSAndroid Build Coastguard Worker			if ($i == $#rso) {
197*49cdfc7eSAndroid Build Coastguard Worker				print "<a href=\"results.cgi?get_df=$this->{HOST}.$this->{DATE}.$this->{SUITE}.scanner\">";
198*49cdfc7eSAndroid Build Coastguard Worker			}
199*49cdfc7eSAndroid Build Coastguard Worker			print "$this->{$rso[$i]}";
200*49cdfc7eSAndroid Build Coastguard Worker			if ($i == $#rso) {
201*49cdfc7eSAndroid Build Coastguard Worker				print "</a>";
202*49cdfc7eSAndroid Build Coastguard Worker			}
203*49cdfc7eSAndroid Build Coastguard Worker			if ($i == $#rso) {
204*49cdfc7eSAndroid Build Coastguard Worker				# last column
205*49cdfc7eSAndroid Build Coastguard Worker				print " <input type=checkbox name=results value=\"$this->{HOST}.$this->{DATE}.$this->{SUITE}\">";
206*49cdfc7eSAndroid Build Coastguard Worker
207*49cdfc7eSAndroid Build Coastguard Worker			}
208*49cdfc7eSAndroid Build Coastguard Worker
209*49cdfc7eSAndroid Build Coastguard Worker
210*49cdfc7eSAndroid Build Coastguard Worker		}
211*49cdfc7eSAndroid Build Coastguard Worker		print "</tr>\n";
212*49cdfc7eSAndroid Build Coastguard Worker
213*49cdfc7eSAndroid Build Coastguard Worker		# make sure we update the $last... variables
214*49cdfc7eSAndroid Build Coastguard Worker		$last->{$rso[0]} = $this->{$rso[0]};
215*49cdfc7eSAndroid Build Coastguard Worker		$last->{$rso[1]} = $this->{$rso[1]};
216*49cdfc7eSAndroid Build Coastguard Worker		$last->{$rso[2]} = $this->{$rso[2]};
217*49cdfc7eSAndroid Build Coastguard Worker	}
218*49cdfc7eSAndroid Build Coastguard Worker	print "</table>\n";
219*49cdfc7eSAndroid Build Coastguard Worker	print "<input type=submit name=compare value=\"Compare\">\n";
220*49cdfc7eSAndroid Build Coastguard Worker	print "<input type=reset>\n";
221*49cdfc7eSAndroid Build Coastguard Worker	print "</form>";
222*49cdfc7eSAndroid Build Coastguard Worker	print end_html;
223*49cdfc7eSAndroid Build Coastguard Worker
224*49cdfc7eSAndroid Build Coastguard Worker}
225*49cdfc7eSAndroid Build Coastguard Worker
226