• 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
90
91if ($start_tag eq "" || $end_tag eq "" || $output_tag eq "" || $execution_tag eq "") {
92	syntax();
93}
94
95open (FILE, "$header_file") || "Cannot open file: $header_file";
96while ($line_2 = <FILE>) {
97       $row_line = $row_line . $line_2;
98}
99$row_line =~ s/LTP\ Output\/Log/LTP\ Output\/Log\ (Report\ Generated\ on\ $ENV{TEST_START_TIME})/;
100print $row_line;
101close (FILE);
102$row_line = "";
103
104
105foreach my $file (@ARGV) {
106
107	open (FILE, $file) || die "Cannot open file: $file\n";
108
109	LINE: while ($line = <FILE>) {
110		chomp $line;
111
112		if ($line =~ /$start_tag/) {
113			$process_line = 1;
114                        $flag = 1;
115		}
116		if ($line =~ /$end_tag/) {
117                        print "$row_line";
118			$process_line  = 0;
119                        $flag  = 0;             $flag2 = 0;            $flag3 = 0;            $flag4 = 0;            $flag5 = 0;
120                        $detected_fail = 0;     $detected_pass = 0;    $detected_warn = 0;    $detected_brok = 0;    $detected_retr = 0;    $detected_conf = 0;
121                        $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= "";
122		}
123
124		if ($process_line) {
125                        if ( $flag == 2) { #Assuming we will find "tag" and "stime" values here
126                             @variable_value_pair = split(/\ /, $line);
127                             @tag_value   = split(/=/,$variable_value_pair[0]);
128                             @stime_value = split(/=/,$variable_value_pair[1]);
129                             $row_line = $row_line . "<tr><td><p><strong>$test_counter</strong></p></td>\n" .
130                                                     "<td><p><strong>$tag_value[1]</strong></p></td>\n"     .
131                                                     "<td><p><pre><strong>";
132                             $get_proper_time = localtime ($stime_value[1]);
133                             $row_line = $row_line . "$get_proper_time" . "</strong></pre></p></td>\n";
134                             $test_counter++;
135                        }
136                        if ( $flag == 3) { #Assuming we will find "cmdling" value here
137                             @variable_value_pair = split(/=/, $line);
138                             $row_line = $row_line . "<td><p><strong> $variable_value_pair[1] </strong></p></td>\n";
139                        }
140                        if ( $flag == 4) { #Assuming we will find "contact" value here
141                             @variable_value_pair = split(/=/, $line);
142                             $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
143                        }
144                        if ( $flag == 5) { #Assuming we will find "analysis" value here
145                             @variable_value_pair = split(/=/, $line);
146                             $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
147                        }
148                        if ( $flag3 == 1 ) {
149                             if ( $flag4 == 1 ) {
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 ( $flag4 == 2 ) {
154                                  @variable_value_pair    = split(/\ /, $line);
155                                  @duration_value         = split(/=/, $variable_value_pair[0]);
156                                  @termination_type_value = split(/=/, $variable_value_pair[1]);
157                                  @termination_id_value   = split(/=/, $variable_value_pair[2]);
158                                  @corefile_value         = split(/=/, $variable_value_pair[3]);
159                                  $background_colour = get_background_colour_column();
160                                  $row_line = $row_line . "<td><p><strong>$duration_value[1]</strong></p></td>\n"     .
161                                              "<td><p><strong>$termination_type_value[1]<strong></p></td>\n" .
162                                              "<td><p><strong>$termination_id_value[1]</strong></p></td>\n"  .
163                                              "<td><p><strong>$corefile_value[1]</strong></p></td>\n";
164                                  $row_line =~ s/<tr>/<tr\ bgcolor=$background_colour>/;
165                             }
166                             if ( $flag4 == 3 ) {
167                                  @variable_value_pair    = split(/\ /, $line);
168                                  @cutime_value           = split(/=/, $variable_value_pair[0]);
169                                  @cstime_value           = split(/=/, $variable_value_pair[1]);
170                                  $row_line = $row_line . "<td><p><strong>$cutime_value[1]</strong></p></td>\n" .
171                                              "<td><p><strong>$cstime_value[1]</strong></p></td></tr>\n";
172                             }
173                             $flag4++;
174                        }
175                        if ( $line =~ /$execution_tag/ ) {
176                             $flag2 = 0;
177                             $flag3 = 1;
178                             $flag4 = 1;
179                             $flag5 = 1;
180                             $row_line = $row_line . "</strong></pre></td>";
181                        }
182                        if ( $flag2 == 1 ) {
183			    $row_line = $row_line . "$line \n";
184                        }
185			 if ( $flag5 == 1 ) {
186			 	 if ($line =~ "termination_id=1" ) {
187					 $detected_fail = 1;
188					 $failed_test_counter++;
189				 } elsif ($line =~ "termination_id=2" ) {
190					 $detected_brok = 1;
191					 $brok_test_counter++;
192				 } elsif ($line =~ "termination_id=4" ) {
193					 $detected_warn = 1;
194					 $warn_test_counter++;
195				 } elsif ($line =~ "termination_id=32" ) {
196					 $detected_conf = 1;
197					 $conf_test_counter++;
198				 } elsif ($line =~ "termination_id=0" ) {
199					 $detected_pass = 1;
200					 $test_passed++;
201				 }
202			 }
203                        if ( $line =~ /$output_tag/ ) {
204                             $flag2 = 1;
205                             $row_line = $row_line . "<td><pre><strong>";
206                        }
207                        $flag++;
208		}
209	}
210	close (FILE);
211}
212
213print "</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 ";
214if ($ENV{LTP_EXIT_VALUE} == 1 ) {
215    print "bgcolor=\"#ff0000\"> <strong>Test Summary</strong></p></td><td bgcolor=\"#ff0000\"><strong>Pan reported some Tests FAIL</strong></p></td></tr>\n";
216}
217else {
218    print "bgcolor=\"#66ff66\"> <strong>Test Summary</strong></p></td><td bgcolor=\"#66ff66\"><strong>Pan reported all Test Pass</strong></p></td></tr>\n";
219}
220
221print "<tr><td><strong>LTP Version</strong> </td><td><strong> $ENV{LTP_VERSION}     </strong></td></tr>\n";
222print "<tr><td><strong>Start Time</strong>  </td><td><strong> $ENV{TEST_START_TIME} </strong></td></tr>\n";
223print "<tr><td><strong>End Time</strong>    </td><td><strong> $ENV{TEST_END_TIME}   </strong></td></tr>\n";
224print "<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";
225print "<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";
226print "<tr><td><strong>Total Tests</strong></td><td><strong>";
227$test_counter--;
228print "$test_counter                         </strong></td></tr>\n";
229$test_passed=$test_counter-$failed_test_counter-$brok_test_counter-$warn_test_counter-$retr_test_counter-$conf_test_counter;
230print "<tr><td><strong>Total Test TPASS:</strong></td><td><strong> $test_passed </strong></td></tr>\n";
231print "<tr><td><strong>Total Test TFAIL:</strong></td><td><strong> $failed_test_counter </strong></td></tr>\n";
232print "<tr><td><strong>Total Test TBROK</strong></td><td><strong> $brok_test_counter </strong></td></tr>\n";
233print "<tr><td><strong>Total Test TWARN</strong></td><td><strong> $warn_test_counter </strong></td></tr>\n";
234print "<tr><td><strong>Total Test TCONF</strong></td><td><strong> $conf_test_counter </strong></td></tr>\n";
235print "<tr><td><strong>Kernel Version</strong></td><td><strong> $ENV{KERNEL_VERSION}  </strong></td></tr>\n";
236print "<tr><td><strong>Machine Architecture</strong></td><td><strong> $ENV{MACHINE_ARCH} </strong></td></tr>\n";
237print "<tr><td><strong>Hostname</strong>  </td> <td><strong>";
238$hostname=system("uname -n");             chop($hostname);
239print " $hostname </strong></td></tr></tbody></table></div></body></html>\n";
240