• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl
2#****************************************************************************#
3# Copyright (c) International Business Machines  Corp., 2001                 #
4#                                                                            #
5# This program is free software;  you can redistribute it an#or modify       #
6# it under the terms of the GNU General Public License as published by       #
7# the Free Software Foundation; either version 2 of the License, or          #
8# (at your option) any later version.                                        #
9#                                                                            #
10# This program is distributed in the hope that it will be useful,            #
11# but WITHOUT ANY WARRANTY;  without even the implied warranty of            #
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  #
13# the GNU General Public License for more details.                           #
14#                                                                            #
15# You should have received a copy of the GNU General Public License          #
16# along with this program;  if not, write to the Free Software               #
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    #
18#                                                                            #
19#****************************************************************************#
20
21#****************************************************************************#
22#                                                                            #
23# File:        genhtml.pl                                                    #
24#                                                                            #
25# Description: This is a Parser which can parse the text output generated by #
26#              pan and convert the same to am HTML format, with proper high- #
27#              lighting of test result backgorund for easy identification of #
28#              pass/fail of testcases                                        #
29#                                                                            #
30# Author:      Subrata Modak: subrata@linux.vnet.ibm.com                     #
31#                                                                            #
32#                                                                            #
33#****************************************************************************#
34
35
36my $process_line  = 0;
37my $row_line      = "";
38my $flag          = 0;
39my $flag2         = 0;
40my $flag3         = 0;
41my $flag4         = 0;
42my $test_counter  = 1;
43my $failed_test_counter       = 0;
44my $failed_test_counter_flag  = 0;
45my $brok_test_counter       = 0;
46my $brok_test_counter_flag  = 0;
47my $warn_test_counter       = 0;
48my $warn_test_counter_flag  = 0;
49my $retr_test_counter       = 0;
50my $retr_test_counter_flag  = 0;
51my $conf_test_counter       = 0;
52my $conf_test_counter_flag  = 0;
53my $test_passed             = 0;
54
55my $detected_fail = 0;
56my $detected_pass = 0;
57my $detected_warn = 0;
58my $detected_brok = 0;
59my $detected_retr = 0;
60my $detected_conf = 0;
61my $background_colour =0;
62
63my $header_file   = shift (@ARGV) || syntax();
64my $start_tag     = shift (@ARGV) || syntax();
65my $end_tag       = shift (@ARGV) || syntax();
66my $output_tag    = shift (@ARGV) || syntax();
67my $execution_tag = shift (@ARGV) || syntax();
68
69sub syntax() {
70	print "syntax: prtag2tag start_tag end_tag output_tag execution_tag file(s)\n";
71	exit (1);
72}
73
74sub get_background_colour_column() {
75    if ( $detected_fail == 1 ) {
76      return "#ff0000";
77    } elsif ( $detected_brok == 1 ) {
78      return Yellow;
79    } elsif ( $detected_warn == 1 ) {
80      return Fuchsia;
81    } elsif ( $detected_retr == 1 ) {
82      return "#8dc997";
83    } elsif ( $detected_conf == 1 ) {
84      return Aqua;
85    } else {
86      return "#66ff66";
87    }
88}
89
90print STDERR "-------------------------------------------------\n";
91print STDERR "INFO: genhtml.pl script is deprecated, try kirk\n";
92print STDERR "(new LTP runner which also generates JSON output)\n";
93print STDERR "https://github.com/linux-test-project/kirk\n";
94print STDERR "-------------------------------------------------\n";
95
96if ($start_tag eq "" || $end_tag eq "" || $output_tag eq "" || $execution_tag eq "") {
97	syntax();
98}
99
100open (FILE, "$header_file") || "Cannot open file: $header_file";
101while ($line_2 = <FILE>) {
102       $row_line = $row_line . $line_2;
103}
104$row_line =~ s/LTP\ Output\/Log/LTP\ Output\/Log\ (Report\ Generated\ on\ $ENV{TEST_START_TIME})/;
105print $row_line;
106close (FILE);
107$row_line = "";
108
109
110foreach my $file (@ARGV) {
111
112	open (FILE, $file) || die "Cannot open file: $file\n";
113
114	LINE: while ($line = <FILE>) {
115		chomp $line;
116
117		if ($line =~ /$start_tag/) {
118			$process_line = 1;
119                        $flag = 1;
120		}
121		if ($line =~ /$end_tag/) {
122                        print "$row_line";
123			$process_line  = 0;
124                        $flag  = 0;             $flag2 = 0;            $flag3 = 0;            $flag4 = 0;            $flag5 = 0;
125                        $detected_fail = 0;     $detected_pass = 0;    $detected_warn = 0;    $detected_brok = 0;    $detected_retr = 0;    $detected_conf = 0;
126                        $background_colour = 0; $failed_test_counter_flag = 0; $brok_test_counter_flag = 0; $warn_test_counter_flag = 0; $retr_test_counter_flag = 0; $conf_test_counter_flag = 0;  $row_line= "";
127		}
128
129		if ($process_line) {
130                        if ( $flag == 2) { #Assuming we will find "tag" and "stime" values here
131                             @variable_value_pair = split(/\ /, $line);
132                             @tag_value   = split(/=/,$variable_value_pair[0]);
133                             @stime_value = split(/=/,$variable_value_pair[1]);
134                             $row_line = $row_line . "<tr><td><p><strong>$test_counter</strong></p></td>\n" .
135                                                     "<td><p><strong>$tag_value[1]</strong></p></td>\n"     .
136                                                     "<td><p><pre><strong>";
137                             $get_proper_time = localtime ($stime_value[1]);
138                             $row_line = $row_line . "$get_proper_time" . "</strong></pre></p></td>\n";
139                             $test_counter++;
140                        }
141                        if ( $flag == 3) { #Assuming we will find "cmdling" value here
142                             @variable_value_pair = split(/=/, $line);
143                             $row_line = $row_line . "<td><p><strong> $variable_value_pair[1] </strong></p></td>\n";
144                        }
145                        if ( $flag == 4) { #Assuming we will find "contact" value here
146                             @variable_value_pair = split(/=/, $line);
147                             $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
148                        }
149                        if ( $flag == 5) { #Assuming we will find "analysis" value here
150                             @variable_value_pair = split(/=/, $line);
151                             $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
152                        }
153                        if ( $flag3 == 1 ) {
154                             if ( $flag4 == 1 ) {
155				  @variable_value_pair = split(/=/, $line);
156				  $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
157			     }
158                             if ( $flag4 == 2 ) {
159                                  @variable_value_pair    = split(/\ /, $line);
160                                  @duration_value         = split(/=/, $variable_value_pair[0]);
161                                  @termination_type_value = split(/=/, $variable_value_pair[1]);
162                                  @termination_id_value   = split(/=/, $variable_value_pair[2]);
163                                  @corefile_value         = split(/=/, $variable_value_pair[3]);
164                                  $background_colour = get_background_colour_column();
165                                  $row_line = $row_line . "<td><p><strong>$duration_value[1]</strong></p></td>\n"     .
166                                              "<td><p><strong>$termination_type_value[1]<strong></p></td>\n" .
167                                              "<td><p><strong>$termination_id_value[1]</strong></p></td>\n"  .
168                                              "<td><p><strong>$corefile_value[1]</strong></p></td>\n";
169                                  $row_line =~ s/<tr>/<tr\ bgcolor=$background_colour>/;
170                                  $flag4++;
171                             }
172                             if ( $flag4 == 3 ) {
173                                  @variable_value_pair    = split(/\ /, $line);
174                                  @cutime_value           = split(/=/, $variable_value_pair[0]);
175                                  @cstime_value           = split(/=/, $variable_value_pair[1]);
176                                  $row_line = $row_line . "<td><p><strong>$cutime_value[1]</strong></p></td>\n" .
177                                              "<td><p><strong>$cstime_value[1]</strong></p></td></tr>\n";
178                             }
179                        }
180                        if ( $line =~ /$execution_tag/ ) {
181                             $flag2 = 0;
182                             $flag3 = 1;
183                             $flag4 = 1;
184                             $flag5 = 1;
185                             $row_line = $row_line . "</strong></pre></td>";
186                        }
187                        if ( $flag2 == 1 ) {
188			    $row_line = $row_line . "$line \n";
189                        }
190			 if ( $flag5 == 1 ) {
191			 	 if ($line =~ "termination_id=1" ) {
192					 $detected_fail = 1;
193					 $failed_test_counter++;
194					 $flag4 = 2;
195				 } elsif ($line =~ "termination_id=2" ) {
196					 $detected_brok = 1;
197					 $brok_test_counter++;
198					 $flag4 = 2;
199				 } elsif ($line =~ "termination_id=4" ) {
200					 $detected_warn = 1;
201					 $warn_test_counter++;
202					 $flag4 = 2;
203				 } elsif ($line =~ "termination_id=32" ) {
204					 $detected_conf = 1;
205					 $conf_test_counter++;
206					 $flag4 = 2;
207				 } elsif ($line =~ "termination_id=0" ) {
208					 $detected_pass = 1;
209					 $test_passed++;
210					 $flag4 = 2;
211				 }
212			 }
213                        if ( $line =~ /$output_tag/ ) {
214                             $flag2 = 1;
215                             $row_line = $row_line . "<td><pre><strong>";
216                        }
217                        $flag++;
218		}
219	}
220	close (FILE);
221}
222
223print "</tbody></table></div> \n\n<h2 id=\"_2\">Summary Report</h2>\n\n<div>\n\n<table border=\"1\" cellspacing=\"3\"><tbody>\n<tr>\n<td ";
224if ($ENV{LTP_EXIT_VALUE} == 1 ) {
225    print "bgcolor=\"#ff0000\"> <strong>Test Summary</strong></p></td><td bgcolor=\"#ff0000\"><strong>Pan reported some Tests FAIL</strong></p></td></tr>\n";
226}
227else {
228    print "bgcolor=\"#66ff66\"> <strong>Test Summary</strong></p></td><td bgcolor=\"#66ff66\"><strong>Pan reported all Test Pass</strong></p></td></tr>\n";
229}
230
231print "<tr><td><strong>LTP Version</strong> </td><td><strong> $ENV{LTP_VERSION}     </strong></td></tr>\n";
232print "<tr><td><strong>Start Time</strong>  </td><td><strong> $ENV{TEST_START_TIME} </strong></td></tr>\n";
233print "<tr><td><strong>End Time</strong>    </td><td><strong> $ENV{TEST_END_TIME}   </strong></td></tr>\n";
234print "<tr><td><strong>Log Result</strong>  </td><td><a href=\"file://$ENV{TEST_LOGS_DIRECTORY}/\">      <strong>$ENV{TEST_LOGS_DIRECTORY}</strong></a></td></tr>\n";
235print "<tr><td><strong>Output/Failed Result</strong></td><td><a href=\"file://$ENV{TEST_OUTPUT_DIRECTORY}/\"> <strong>$ENV{TEST_OUTPUT_DIRECTORY}</strong></a></td></tr>\n";
236print "<tr><td><strong>Total Tests</strong></td><td><strong>";
237$test_counter--;
238print "$test_counter                         </strong></td></tr>\n";
239$test_passed=$test_counter-$failed_test_counter-$brok_test_counter-$warn_test_counter-$retr_test_counter-$conf_test_counter;
240print "<tr><td><strong>Total Test TPASS:</strong></td><td><strong> $test_passed </strong></td></tr>\n";
241print "<tr><td><strong>Total Test TFAIL:</strong></td><td><strong> $failed_test_counter </strong></td></tr>\n";
242print "<tr><td><strong>Total Test TBROK</strong></td><td><strong> $brok_test_counter </strong></td></tr>\n";
243print "<tr><td><strong>Total Test TWARN</strong></td><td><strong> $warn_test_counter </strong></td></tr>\n";
244print "<tr><td><strong>Total Test TCONF</strong></td><td><strong> $conf_test_counter </strong></td></tr>\n";
245print "<tr><td><strong>Kernel Version</strong></td><td><strong> $ENV{KERNEL_VERSION}  </strong></td></tr>\n";
246print "<tr><td><strong>Machine Architecture</strong></td><td><strong> $ENV{MACHINE_ARCH} </strong></td></tr>\n";
247print "<tr><td><strong>Hostname</strong>  </td> <td><strong>";
248$hostname=system("uname -n");             chop($hostname);
249print " $hostname </strong></td></tr></tbody></table></div></body></html>\n";
250