liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/perl
 
use CGI qw(:standard);
 
# keep a copy of each 'uname -a' string so we don't have to search for it every time.
%uname_cache = {};
 
# 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;
}
# get the UNAME line for a host, date, suite
sub get_result_uname {
   my($inhost, $indate, $insuite, $filename);
   my(@possible_files, $pf, $line);
   my($host, $datestr, $suite, $type, $gz);
   # build a filename
   $inhost = $_[0];
   $indate = $_[1];
   if ($#_ >= 2) {
       $insuite = $_[2];
   } else {
       $insuite = "*";
   }
   # check to see if we've done this already
   if (exists($uname_cache{"$inhost.$indate"})) {
       return $uname_cache{"$inhost.$indate"};
   }
   $filename = "$inhost.$indate.$insuite.*";
   @possible_files = <${filename}>;
   if ($#possible_files < 1) {
       return "";
   }
   foreach $pf (@possible_files) {
       ($host, $datestr, $suite, $type, $gz) = split(/\./, $pf);
       if ($type eq "summary") {
           next;
       } elsif ($type eq "scanner") {
           open (UF, $pf) || next;
           while ($line = <UF>) {
               if ($line =~ /^UNAME/) {
                   close(UF);
                   $line =~ s/UNAME *//;
                   $line =~ s/$inhost//;
                   $uname_cache{"$inhost.$indate"} = $line;
                   return $line;
               }
           }
       } elsif ($type eq "driver") {
           if ($gz) {
               open (UF, "gunzip -c $pf|") || next;
           } else {
               open (UF, "$pf") || next;
           }
           while ($line = <UF>) {
               if ($line =~ /^UNAME/) {
                   close(UF);
                   $line =~ s/UNAME="(.*)"/\1/;
                   $line =~ s/$inhost//;
                   $uname_cache{"$inhost.$indate"} = $line;
                   return $line;
               }
           }
       } else {
           next;
       }
   }
   return "";
}
 
# Create the headers row, adding links for sorting options
sub print_headers {
 
   print "\n<tr>";
 
   for($i = 0; $i <= $#rso; $i++) {
       print "<th><a href=\"browse.cgi?sort=";
       for ($j = 0; $j <= $#rso; $j++) {
           if ($j == $i) { $rsd[$j] = $rsd[$j] * -1; }
           if ($rsd[$j] == -1) { print "-"; }
           if ($j == $i) { $rsd[$j] = $rsd[$j] * -1; }
           print $rso[$j];
           if ($j < $#rso) { print ","; }
       }
       print "\">$rso[$i]</a>\n";
   }
 
   print "</tr>\n";
}
 
############
# main()   #
############
 
# Most of the work is done in this directory
unless (chdir("/usr/tests/ltp/results")) {
   failure("Could not get to the results directory\n");
}
 
@extra_path = split(/\//, $ENV{PATH_INFO});
 
# rso = Result Sort Order
# rsd = Result Sort Direction
#@rso = (HOST,SUITE, DATE, UNAME);
@rso = (SUITE, HOST, DATE, UNAME);
@rsd = (1, 1, -1, 1);
 
# allow the user to specify the sort order
if ($sort_order = param("sort")) {
   @so = split(/,/, $sort_order);
   print $so;
   @rso = ();
   for($i = 0; $i <= $#so; $i++) {
       # parse the field
       if ($so[$i] =~ /host/i) { push(@rso, HOST); }
       elsif ($so[$i] =~ /date/i) { push(@rso, DATE); }
       elsif ($so[$i] =~ /suite/i) { push(@rso, SUITE); }
       elsif ($so[$i] =~ /uname/i) { push(@rso, UNAME); }
       # parse the direction
       if ($so[$i] =~ /-/) { $rsd[$i] = -1; }
       else { $rsd[$i] = 1; }
   }
}
 
if ($#extra_path > 0) {
 
} else {
 
   %results = ();
 
   # run through the files in the results directory
   @driver_files = <*driver*>;
   foreach $df (@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;
       $a_rec->{UNAME} = get_result_uname($host, $datestr);
 
       $results{ $a_rec->{DRIVER_FILE} } = $a_rec;
   }
 
   # write the HTML file
   print header("text/html"),start_html;
   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;
   @ri = values %results;
   @ri = sort { ($a->{$rso[0]} cmp $b->{$rso[0]})*$rsd[0]
           || ($a->{$rso[1]} cmp $b->{$rso[1]})*$rsd[1]
           || ($a->{$rso[2]} cmp $b->{$rso[2]})*$rsd[2]
           || ($a->{$rso[3]} cmp $b->{$rso[3]})*$rsd[3] } @ri;
 
   $last = ();
   $last->{$rso[0]} = "";
   $last->{$rso[1]} = "";
   $last->{$rso[2]} = "";
   $lasthost = "";
   $lastdate = "";
   $lastsuite = "";
   #$lastindent = 0;
   $thisindent = 0;
   print "<form method=get action=\"reconsile.cgi\">";
   print "<table border=1>\n";
   #print "<tr><th>Hostname<th>Date<th>Suite</tr>\n";
   print_headers();
   foreach $rp ( @ri ) {
 
       $this = ();
       $this->{$rso[0]} = $rp->{$rso[0]};
       $this->{$rso[1]} = $rp->{$rso[1]};
       $this->{$rso[2]} = $rp->{$rso[2]};
       $this->{$rso[3]} = $rp->{$rso[3]};
 
       # figure out the first column that is different
       for ($i = 0; $i <= $#rso; $i++) {
           if ($last->{$rso[$i]} ne $this->{$rso[$i]}) {
               $thisindent = $i;
               last;
           }
       }
 
       print "<tr>\n";
       for ($i = 0; $i < $thisindent; $i++) {
           print "<td>";
 
       }
       for ($i = $thisindent; $i <= $#rso; $i++) {
           print "<td>";
           if ($i == $#rso) {
               print "<a href=\"results.cgi?get_df=$this->{HOST}.$this->{DATE}.$this->{SUITE}.scanner\">";
           }
           print "$this->{$rso[$i]}";
           if ($i == $#rso) {
               print "</a>";
           }
           if ($i == $#rso) {
               # last column
               print " <input type=checkbox name=results value=\"$this->{HOST}.$this->{DATE}.$this->{SUITE}\">";
 
           }
 
 
       }
       print "</tr>\n";
 
       # make sure we update the $last... variables
       $last->{$rso[0]} = $this->{$rso[0]};
       $last->{$rso[1]} = $this->{$rso[1]};
       $last->{$rso[2]} = $this->{$rso[2]};
   }
   print "</table>\n";
   print "<input type=submit name=compare value=\"Compare\">\n";
   print "<input type=reset>\n";
   print "</form>";
   print end_html;
 
}