1f08c3bdfSopenharmony_ci#!/usr/bin/perl
2f08c3bdfSopenharmony_ci
3f08c3bdfSopenharmony_ci#
4f08c3bdfSopenharmony_ci# reconsile.cgi - reconsile two or more scanner files
5f08c3bdfSopenharmony_ci#
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ciuse CGI qw(:standard);
8f08c3bdfSopenharmony_ci
9f08c3bdfSopenharmony_cichdir("/usr/tests/ltp/results/");
10f08c3bdfSopenharmony_ci
11f08c3bdfSopenharmony_ci# Get the list of results to compare.
12f08c3bdfSopenharmony_ci@results = param("results");
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ciprint header("text/html");
15f08c3bdfSopenharmony_ciprint start_html, "<pre>\n";
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ci# Give a warning if the suites do not match
18f08c3bdfSopenharmony_ci($a, $b, $lastsuite) = split(/\./, $results[0]);
19f08c3bdfSopenharmony_cifor ($i = 1; $i <= $#results; $i++) {
20f08c3bdfSopenharmony_ci	($a, $b, $thissuite) = split(/\./, $results[$i]);
21f08c3bdfSopenharmony_ci	if ($lastsuite ne $thissuite) {
22f08c3bdfSopenharmony_ci		print "Warning: Suites do not match!\n";
23f08c3bdfSopenharmony_ci		last;
24f08c3bdfSopenharmony_ci	}
25f08c3bdfSopenharmony_ci}
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_ci# check that each requested result exists.  If one does not exist,
28f08c3bdfSopenharmony_ci# print a warning and continue.  If the number of available results
29f08c3bdfSopenharmony_ci# is less than two, halt with an error
30f08c3bdfSopenharmony_ci@result_filenames = ();
31f08c3bdfSopenharmony_ciforeach $a_result (@results) {
32f08c3bdfSopenharmony_ci	if (-f "$a_result.scanner") {
33f08c3bdfSopenharmony_ci		push(@result_filenames, "$a_result.scanner");
34f08c3bdfSopenharmony_ci	} else {
35f08c3bdfSopenharmony_ci		print "Could not find a scanner file for $a_result\n";
36f08c3bdfSopenharmony_ci	}
37f08c3bdfSopenharmony_ci}
38f08c3bdfSopenharmony_ciif ($#result_filenames < 1) {
39f08c3bdfSopenharmony_ci	print "Not enough result files to compare\n";
40f08c3bdfSopenharmony_ci	die;
41f08c3bdfSopenharmony_ci}
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_ci# for each result file read in and store the header information in
44f08c3bdfSopenharmony_ci# an associative array.  Take the rest of the input file and store
45f08c3bdfSopenharmony_ci# it as a list.
46f08c3bdfSopenharmony_ci@result_details = ();
47f08c3bdfSopenharmony_ci@result_testcases = ();
48f08c3bdfSopenharmony_ci$i = 0;
49f08c3bdfSopenharmony_ciforeach $result_filename (@result_filenames) {
50f08c3bdfSopenharmony_ci	unless (open(F, $result_filename)) {
51f08c3bdfSopenharmony_ci		print "failed openning $result_filename\n";
52f08c3bdfSopenharmony_ci		next;
53f08c3bdfSopenharmony_ci	}
54f08c3bdfSopenharmony_ci	# advance past the header then read in the rest
55f08c3bdfSopenharmony_ci	$result_testcases->[$i] = ();
56f08c3bdfSopenharmony_ci	$result_details->[$i] = {};
57f08c3bdfSopenharmony_ci	($host, $datestr, $suite, $ext) = split(/\./, $result_filename);
58f08c3bdfSopenharmony_ci	$result_details->[$i]->{HOST} = $host;
59f08c3bdfSopenharmony_ci	$result_details->[$i]->{DATESTR} = $datestr;
60f08c3bdfSopenharmony_ci	$result_details->[$i]->{SUITE} = $suite;
61f08c3bdfSopenharmony_ci	while ($line = <F>) {
62f08c3bdfSopenharmony_ci		# check for the end of the header
63f08c3bdfSopenharmony_ci		if ($line =~ /^-+/) {
64f08c3bdfSopenharmony_ci			# we've reached the top of the scanner output
65f08c3bdfSopenharmony_ci			# grab the rest and stop the while loop;
66f08c3bdfSopenharmony_ci			@rest = <F>;
67f08c3bdfSopenharmony_ci			close(F);
68f08c3bdfSopenharmony_ci			last;
69f08c3bdfSopenharmony_ci		}
70f08c3bdfSopenharmony_ci		# grab information from the header
71f08c3bdfSopenharmony_ci		if ($line =~ /^UNAME/) {
72f08c3bdfSopenharmony_ci			$line =~ s/UNAME *//;
73f08c3bdfSopenharmony_ci			$result_details->[$i]->{UNAME} = $line;
74f08c3bdfSopenharmony_ci			next;
75f08c3bdfSopenharmony_ci		}
76f08c3bdfSopenharmony_ci	}
77f08c3bdfSopenharmony_ci	# convert the results to records and add them to the list
78f08c3bdfSopenharmony_ci	foreach $line (@rest) {
79f08c3bdfSopenharmony_ci		($tag, $tcid, $tc, $status, $contact) = split(/\s+/, $line);
80f08c3bdfSopenharmony_ci		# fix some of the fields so they sort properly
81f08c3bdfSopenharmony_ci		$tcid = '{' if ($tcid eq '*');
82f08c3bdfSopenharmony_ci		$tcid = '}' if ($tcid eq '-');
83f08c3bdfSopenharmony_ci		$tc = '{' if ($tc eq '*');
84f08c3bdfSopenharmony_ci		$tc = '}' if ($tc eq '-');
85f08c3bdfSopenharmony_ci		$rec = ();
86f08c3bdfSopenharmony_ci		$rec->{TAG} = $tag;
87f08c3bdfSopenharmony_ci		$rec->{TCID} = $tcid;
88f08c3bdfSopenharmony_ci		$rec->{TC} = $tc;
89f08c3bdfSopenharmony_ci		$rec->{STATUS} = $status;
90f08c3bdfSopenharmony_ci		$rec->{CONTACT} = $contact;
91f08c3bdfSopenharmony_ci		push(@{$result_testcases[$i]}, $rec);
92f08c3bdfSopenharmony_ci	}
93f08c3bdfSopenharmony_ci	$i++;
94f08c3bdfSopenharmony_ci}
95f08c3bdfSopenharmony_ci
96f08c3bdfSopenharmony_ci# sort each set of results.
97f08c3bdfSopenharmony_ci# This is the most important step since walking the data depends on
98f08c3bdfSopenharmony_ci# correctly sorting the data.  Some substitutions are made to keep
99f08c3bdfSopenharmony_ci# the test cases in each test tag in the proper order.  i.e.
100f08c3bdfSopenharmony_ci# s/\*/{/
101f08c3bdfSopenharmony_ci#$i = 0;
102f08c3bdfSopenharmony_ciforeach $rtcs (@result_testcases) {
103f08c3bdfSopenharmony_ci	@$rtcs = sort { $a->{TAG} cmp $b->{TAG}
104f08c3bdfSopenharmony_ci					|| $a->{TCID} cmp $b->{TCID}
105f08c3bdfSopenharmony_ci					|| $a->{TC} <=> $b->{TC}
106f08c3bdfSopenharmony_ci					|| $a->{TC} cmp $b->{TC}
107f08c3bdfSopenharmony_ci					|| $a->{STATUS} cmp $b->{STATUS}} @$rtcs;
108f08c3bdfSopenharmony_ci	#print "sorted file $i\n";
109f08c3bdfSopenharmony_ci	#print "=" x 50 . "\n";
110f08c3bdfSopenharmony_ci	#foreach (@$rtcs) {
111f08c3bdfSopenharmony_ci	#	print "$_->{TAG}:$_->{TCID}:$_->{TC}:$_->{STATUS}\n";
112f08c3bdfSopenharmony_ci	#}
113f08c3bdfSopenharmony_ci	#print "=" x 50 . "\n";
114f08c3bdfSopenharmony_ci	#$i++;
115f08c3bdfSopenharmony_ci}
116f08c3bdfSopenharmony_ci
117f08c3bdfSopenharmony_ci# here is the loop that prints the data into a multi-column table with the test
118f08c3bdfSopenharmony_ci# tags grouped together.
119f08c3bdfSopenharmony_ci
120f08c3bdfSopenharmony_ciprint "</pre>";
121f08c3bdfSopenharmony_ciprint "<table border=1>\n";
122f08c3bdfSopenharmony_ci
123f08c3bdfSopenharmony_ciprint "<tr><td>";
124f08c3bdfSopenharmony_cifor($i=0; $i <= $#result_testcases; $i++) {
125f08c3bdfSopenharmony_ci	print "<th colspan=3>$result_details->[$i]->{HOST}.$result_details->[$i]->{DATESTR}.$result_details->[$i]->{SUITE}";
126f08c3bdfSopenharmony_ci}
127f08c3bdfSopenharmony_ciprint "</tr>\n";
128f08c3bdfSopenharmony_ci
129f08c3bdfSopenharmony_ciprint "<tr><th>Test Tag";
130f08c3bdfSopenharmony_cifor($i=0; $i <= $#result_testcases; $i++) {
131f08c3bdfSopenharmony_ci	print "<th>TCID<th>Test Case<th>Status";
132f08c3bdfSopenharmony_ci}
133f08c3bdfSopenharmony_ciprint "<th>Contact</tr>\n";
134f08c3bdfSopenharmony_ci
135f08c3bdfSopenharmony_ci# while the result lists still have test cases
136f08c3bdfSopenharmony_ci# 	Find the smallest record from the top of the lists
137f08c3bdfSopenharmony_ci#   remove matching records from the lists and output them
138f08c3bdfSopenharmony_ci$last_tag = "";
139f08c3bdfSopenharmony_ciwhile (1) {
140f08c3bdfSopenharmony_ci
141f08c3bdfSopenharmony_ci	# if there wasn't anything left, leave
142f08c3bdfSopenharmony_ci	$somethingleft = 0;
143f08c3bdfSopenharmony_ci	foreach $rtcs (@result_testcases) {
144f08c3bdfSopenharmony_ci		if ($#$rtcs > -1) {
145f08c3bdfSopenharmony_ci			$somethingleft = 1;
146f08c3bdfSopenharmony_ci			last;
147f08c3bdfSopenharmony_ci		}
148f08c3bdfSopenharmony_ci	}
149f08c3bdfSopenharmony_ci	unless ($somethingleft) { last; }
150f08c3bdfSopenharmony_ci
151f08c3bdfSopenharmony_ci	# find the Lowest Common Record
152f08c3bdfSopenharmony_ci	@tops = ();
153f08c3bdfSopenharmony_ci	foreach $rtcs (@result_testcases) {
154f08c3bdfSopenharmony_ci		if (@$rtcs[0]) {
155f08c3bdfSopenharmony_ci			push(@tops, copy_record(@$rtcs[0]));
156f08c3bdfSopenharmony_ci		}
157f08c3bdfSopenharmony_ci	}
158f08c3bdfSopenharmony_ci	@tops = sort { $a->{TAG} cmp $b->{TAG}
159f08c3bdfSopenharmony_ci				|| $a->{TCID} cmp $b->{TCID}
160f08c3bdfSopenharmony_ci				|| $a->{TC} <=> $b->{TC}
161f08c3bdfSopenharmony_ci				|| $a->{TC} cmp $b->{TC}
162f08c3bdfSopenharmony_ci				|| $a->{STATUS} cmp $b->{STATUS}} @tops;
163f08c3bdfSopenharmony_ci
164f08c3bdfSopenharmony_ci	$LCR = $tops[0];
165f08c3bdfSopenharmony_ci
166f08c3bdfSopenharmony_ci	# check to see if everyone matches
167f08c3bdfSopenharmony_ci	$matches = 0;
168f08c3bdfSopenharmony_ci	foreach $rtcs (@result_testcases) {
169f08c3bdfSopenharmony_ci		if (! @$rtcs[0]) { next; }
170f08c3bdfSopenharmony_ci		if (@$rtcs[0]->{TAG} eq $LCR->{TAG}
171f08c3bdfSopenharmony_ci			&& @$rtcs[0]->{TCID} eq $LCR->{TCID}
172f08c3bdfSopenharmony_ci			&& @$rtcs[0]->{TC} eq $LCR->{TC}
173f08c3bdfSopenharmony_ci			&& @$rtcs[0]->{STATUS} eq $LCR->{STATUS}) {
174f08c3bdfSopenharmony_ci
175f08c3bdfSopenharmony_ci			$matches++;
176f08c3bdfSopenharmony_ci		}
177f08c3bdfSopenharmony_ci	}
178f08c3bdfSopenharmony_ci	# if everyone does match (status included) shift them
179f08c3bdfSopenharmony_ci	# and move on.
180f08c3bdfSopenharmony_ci	if ($matches == ($#result_testcases+1)) {
181f08c3bdfSopenharmony_ci		foreach $rtcs (@result_testcases) { shift(@$rtcs); }
182f08c3bdfSopenharmony_ci		next;
183f08c3bdfSopenharmony_ci	}
184f08c3bdfSopenharmony_ci
185f08c3bdfSopenharmony_ci	# if we've already output stuff related to this test tag,
186f08c3bdfSopenharmony_ci	# skip that column, otherwise print the tag
187f08c3bdfSopenharmony_ci	if ($LCR->{TAG} eq $lasttag) {
188f08c3bdfSopenharmony_ci		print "<tr><td>";
189f08c3bdfSopenharmony_ci	} else {
190f08c3bdfSopenharmony_ci		print "<tr><td>$LCR->{TAG}";
191f08c3bdfSopenharmony_ci		$lasttag = $LCR->{TAG};
192f08c3bdfSopenharmony_ci	}
193f08c3bdfSopenharmony_ci
194f08c3bdfSopenharmony_ci	# walk through the lists again outputting as we match
195f08c3bdfSopenharmony_ci	$column = 0;
196f08c3bdfSopenharmony_ci	foreach $rtcs (@result_testcases) {
197f08c3bdfSopenharmony_ci		if (! @$rtcs[0]) {
198f08c3bdfSopenharmony_ci			print "<td><td><td>";
199f08c3bdfSopenharmony_ci			$column++;
200f08c3bdfSopenharmony_ci			next;
201f08c3bdfSopenharmony_ci		} elsif (@$rtcs[0]->{TAG} eq $LCR->{TAG}
202f08c3bdfSopenharmony_ci			&& @$rtcs[0]->{TCID} eq $LCR->{TCID}
203f08c3bdfSopenharmony_ci			&& @$rtcs[0]->{TC} eq $LCR->{TC}) {
204f08c3bdfSopenharmony_ci
205f08c3bdfSopenharmony_ci			$match = shift(@$rtcs);
206f08c3bdfSopenharmony_ci			$match->{TCID} = '*' if ($match->{TCID} eq '{');
207f08c3bdfSopenharmony_ci			$match->{TCID} = '-' if ($match->{TCID} eq '}');
208f08c3bdfSopenharmony_ci			$match->{TC} = '*' if ($match->{TC} eq '{');
209f08c3bdfSopenharmony_ci			$match->{TC} = '-' if ($match->{TC} eq '}');
210f08c3bdfSopenharmony_ci			print "<td>";
211f08c3bdfSopenharmony_ci			$rd = $result_details->[$column];
212f08c3bdfSopenharmony_ci			print "<a href=\"results.cgi?get_df=$rd->{HOST}.$rd->{DATESTR}.$rd->{SUITE}.driver&zoom_tag=$match->{TAG}\">";
213f08c3bdfSopenharmony_ci			print "$match->{TCID}</a>";
214f08c3bdfSopenharmony_ci			print "<td>$match->{TC}";
215f08c3bdfSopenharmony_ci			print "<td>";
216f08c3bdfSopenharmony_ci			if ($match->{STATUS} =~ /PASS/) {
217f08c3bdfSopenharmony_ci				print "<font color=green>";
218f08c3bdfSopenharmony_ci			} elsif ($match->{STATUS} =~ /FAIL/) {
219f08c3bdfSopenharmony_ci				print "<font color=red>";
220f08c3bdfSopenharmony_ci			} elsif ($match->{STATUS} =~ /CONF/) {
221f08c3bdfSopenharmony_ci				print "<font color=yello>";
222f08c3bdfSopenharmony_ci			} elsif ($match->{STATUS} =~ /BROK/) {
223f08c3bdfSopenharmony_ci				print "<font color=blue>";
224f08c3bdfSopenharmony_ci			} else {
225f08c3bdfSopenharmony_ci				print "<font color=black>";
226f08c3bdfSopenharmony_ci			}
227f08c3bdfSopenharmony_ci			print "$match->{STATUS}</font>";
228f08c3bdfSopenharmony_ci		} else {
229f08c3bdfSopenharmony_ci			print "<td><td><td>";
230f08c3bdfSopenharmony_ci		}
231f08c3bdfSopenharmony_ci		$column++;
232f08c3bdfSopenharmony_ci	}
233f08c3bdfSopenharmony_ci	print "<td>$LCR->{CONTACT}</tr>\n";
234f08c3bdfSopenharmony_ci}
235f08c3bdfSopenharmony_ciprint "</table>";
236f08c3bdfSopenharmony_ci
237f08c3bdfSopenharmony_ciprint end_html;
238f08c3bdfSopenharmony_ci
239f08c3bdfSopenharmony_ci
240f08c3bdfSopenharmony_cisub copy_record {
241f08c3bdfSopenharmony_ci	my $copy, $rec = shift;
242f08c3bdfSopenharmony_ci
243f08c3bdfSopenharmony_ci	$copy->{TAG} = $rec->{TAG};
244f08c3bdfSopenharmony_ci	$copy->{TCID} = $rec->{TCID};
245f08c3bdfSopenharmony_ci	$copy->{TC} = $rec->{TC};
246f08c3bdfSopenharmony_ci	$copy->{STATUS} = $rec->{STATUS};
247f08c3bdfSopenharmony_ci	$copy->{CONTACT} = $rec->{CONTACT};
248f08c3bdfSopenharmony_ci	return $copy;
249f08c3bdfSopenharmony_ci
250f08c3bdfSopenharmony_ci}
251