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