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