blob: 7e9bdd471b17105aad85edf57cd12b263fdaf642 [file] [log] [blame]
subrata_modake47fb352007-11-25 17:03:49 +00001#!/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 #
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #
subrata_modake47fb352007-11-25 17:03:49 +000018# #
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;
subrata_modak48cd9cf2009-04-02 06:37:28 +000045my $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;
subrata_modake47fb352007-11-25 17:03:49 +000053
54my $detected_fail = 0;
55my $detected_pass = 0;
56my $detected_warn = 0;
57my $detected_brok = 0;
58my $detected_retr = 0;
59my $detected_conf = 0;
60my $background_colour =0;
61
62my $header_file = shift (@ARGV) || syntax();
63my $start_tag = shift (@ARGV) || syntax();
64my $end_tag = shift (@ARGV) || syntax();
65my $output_tag = shift (@ARGV) || syntax();
66my $execution_tag = shift (@ARGV) || syntax();
67
68sub syntax() {
69 print "syntax: prtag2tag start_tag end_tag output_tag execution_tag file(s)\n";
70 exit (1);
71}
72
73sub get_background_colour_column() {
74 if ( $detected_fail == 1 ) {
75 return "#ff0000";
76 } elsif ( $detected_brok == 1 ) {
77 return Yellow;
78 } elsif ( $detected_warn == 1 ) {
79 return Fuchsia;
80 } elsif ( $detected_retr == 1 ) {
81 return "#8dc997";
82 } elsif ( $detected_conf == 1 ) {
83 return Aqua;
84 } else {
85 return "#66ff66";
86 }
87}
88
89
90if ($start_tag eq "" || $end_tag eq "" || $output_tag eq "" || $execution_tag eq "") {
91 syntax();
92}
93
94open (FILE, "$header_file") || "Cannot open file: $header_file";
95while ($line_2 = <FILE>) {
96 $row_line = $row_line . $line_2;
97}
98$row_line =~ s/LTP\ Output\/Log/LTP\ Output\/Log\ (Report\ Generated\ on\ $ENV{TEST_START_TIME})/;
99print $row_line;
100close (FILE);
101$row_line = "";
102
103
104foreach my $file (@ARGV) {
105
106 open (FILE, $file) || die "Cannot open file: $file\n";
107
108 LINE: while ($line = <FILE>) {
109 chomp $line;
110
111 if ($line =~ /$start_tag/) {
112 $process_line = 1;
113 $flag = 1;
114 }
115 if ($line =~ /$end_tag/) {
116 print "$row_line";
117 $process_line = 0;
118 $flag = 0; $flag2 = 0; $flag3 = 0; $flag4 = 0;
119 $detected_fail = 0; $detected_pass = 0; $detected_warn = 0; $detected_brok = 0; $detected_retr = 0; $detected_conf = 0;
subrata_modak48cd9cf2009-04-02 06:37:28 +0000120 $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= "";
subrata_modake47fb352007-11-25 17:03:49 +0000121 }
122
123 if ($process_line) {
124 if ( $flag == 2) { #Assuming we will find "tag" and "stime" values here
125 @variable_value_pair = split(/\ /, $line);
126 @tag_value = split(/=/,$variable_value_pair[0]);
127 @stime_value = split(/=/,$variable_value_pair[1]);
Chris Dearman37550cf2012-10-17 19:54:01 -0700128 $row_line = $row_line . "<tr><td><p><strong>$test_counter</strong></p></td>\n" .
subrata_modake47fb352007-11-25 17:03:49 +0000129 "<td><p><strong>$tag_value[1]</strong></p></td>\n" .
130 "<td><p><pre><strong>";
131 $get_proper_time = localtime ($stime_value[1]);
Chris Dearman37550cf2012-10-17 19:54:01 -0700132 $row_line = $row_line . "$get_proper_time" . "</strong></pre></p></td>\n";
subrata_modake47fb352007-11-25 17:03:49 +0000133 $test_counter++;
134 }
135 if ( $flag == 3) { #Assuming we will find "cmdling" value here
136 @variable_value_pair = split(/=/, $line);
137 $row_line = $row_line . "<td><p><strong> $variable_value_pair[1] </strong></p></td>\n";
138 }
139 if ( $flag == 4) { #Assuming we will find "contact" value here
140 @variable_value_pair = split(/=/, $line);
141 $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
142 }
143 if ( $flag == 5) { #Assuming we will find "analysis" value here
144 @variable_value_pair = split(/=/, $line);
145 $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
146 }
subrata_modake47fb352007-11-25 17:03:49 +0000147 if ( $flag3 == 1 ) {
148 if ( $flag4 == 1 ) {
subrata_modakf6b28b52009-06-09 16:14:40 +0000149 @variable_value_pair = split(/=/, $line);
150 $row_line = $row_line . "<td><p><strong>$variable_value_pair[1]</strong></p></td>\n";
151 }
152 if ( $flag4 == 2 ) {
subrata_modake47fb352007-11-25 17:03:49 +0000153 @variable_value_pair = split(/\ /, $line);
154 @duration_value = split(/=/, $variable_value_pair[0]);
155 @termination_type_value = split(/=/, $variable_value_pair[1]);
156 @termination_id_value = split(/=/, $variable_value_pair[2]);
157 @corefile_value = split(/=/, $variable_value_pair[3]);
158 $background_colour = get_background_colour_column();
159 $row_line = $row_line . "<td><p><strong>$duration_value[1]</strong></p></td>\n" .
160 "<td><p><strong>$termination_type_value[1]<strong></p></td>\n" .
161 "<td><p><strong>$termination_id_value[1]</strong></p></td>\n" .
162 "<td><p><strong>$corefile_value[1]</strong></p></td>\n";
163 $row_line =~ s/<tr>/<tr\ bgcolor=$background_colour>/;
164 }
subrata_modakf6b28b52009-06-09 16:14:40 +0000165 if ( $flag4 == 3 ) {
subrata_modake47fb352007-11-25 17:03:49 +0000166 @variable_value_pair = split(/\ /, $line);
167 @cutime_value = split(/=/, $variable_value_pair[0]);
168 @cstime_value = split(/=/, $variable_value_pair[1]);
169 $row_line = $row_line . "<td><p><strong>$cutime_value[1]</strong></p></td>\n" .
170 "<td><p><strong>$cstime_value[1]</strong></p></td></tr>\n";
171 }
172 $flag4++;
173 }
174 if ( $line =~ /$execution_tag/ ) {
175 $flag2 = 0;
176 $flag3 = 1;
177 $flag4 = 1;
178 $row_line = $row_line . "</strong></pre></td>";
179 }
180 if ( $flag2 == 1 ) {
subrata_modak48cd9cf2009-04-02 06:37:28 +0000181 $row_line = $row_line . "$line \n";
yaberauneya7ef2c622009-10-13 17:26:27 +0000182 if ($line =~ /\ TFAIL\ / ) {
subrata_modak48cd9cf2009-04-02 06:37:28 +0000183 $detected_fail = 1;
184 if ( $failed_test_counter_flag == 0 ) {
185 $failed_test_counter++;
186 $failed_test_counter_flag=1;
187 }
yaberauneya7ef2c622009-10-13 17:26:27 +0000188 } elsif ($line =~ /\ TBROK\ / ) {
subrata_modak48cd9cf2009-04-02 06:37:28 +0000189 $detected_brok = 1;
190 if ( $brok_test_counter_flag == 0 ) {
191 $brok_test_counter++;
192 $brok_test_counter_flag=1;
193 }
yaberauneya7ef2c622009-10-13 17:26:27 +0000194 } elsif ($line =~ /\ TWARN\ / ) {
subrata_modak48cd9cf2009-04-02 06:37:28 +0000195 $detected_warn = 1;
196 if ( $warn_test_counter_flag == 0 ) {
197 $warn_test_counter++;
198 $warn_test_counter_flag=1;
199 }
yaberauneya7ef2c622009-10-13 17:26:27 +0000200 } elsif ($line =~ /\ TCONF\ / ) {
subrata_modak48cd9cf2009-04-02 06:37:28 +0000201 $detected_conf = 1;
202 if ( $conf_test_counter_flag == 0 ) {
203 $conf_test_counter++;
204 $conf_test_counter_flag=1;
205 }
subrata_modake47fb352007-11-25 17:03:49 +0000206 } else {
207 $detected_pass = 1;
208 }
209 }
210 if ( $line =~ /$output_tag/ ) {
211 $flag2 = 1;
212 $row_line = $row_line . "<td><pre><strong>";
213 }
214 $flag++;
215 }
216 }
217 close (FILE);
218}
219
220print "</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 ";
221if ($ENV{LTP_EXIT_VALUE} == 1 ) {
subrata_modakd48c4d02008-01-23 12:59:40 +0000222 print "bgcolor=\"#ff0000\"> <strong>Test Summary</strong></p></td><td bgcolor=\"#ff0000\"><strong>Pan reported some Tests FAIL</strong></p></td></tr>\n";
subrata_modake47fb352007-11-25 17:03:49 +0000223}
224else {
subrata_modakd48c4d02008-01-23 12:59:40 +0000225 print "bgcolor=\"#66ff66\"> <strong>Test Summary</strong></p></td><td bgcolor=\"#66ff66\"><strong>Pan reported all Test Pass</strong></p></td></tr>\n";
subrata_modake47fb352007-11-25 17:03:49 +0000226}
227
228print "<tr><td><strong>LTP Version</strong> </td><td><strong> $ENV{LTP_VERSION} </strong></td></tr>\n";
229print "<tr><td><strong>Start Time</strong> </td><td><strong> $ENV{TEST_START_TIME} </strong></td></tr>\n";
230print "<tr><td><strong>End Time</strong> </td><td><strong> $ENV{TEST_END_TIME} </strong></td></tr>\n";
231print "<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";
232print "<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";
233print "<tr><td><strong>Total Tests</strong></td><td><strong>";
234$test_counter--;
235print "$test_counter </strong></td></tr>\n";
subrata_modak48cd9cf2009-04-02 06:37:28 +0000236$test_passed=$test_counter-$failed_test_counter-$brok_test_counter-$warn_test_counter-$retr_test_counter-$conf_test_counter;
237print "<tr><td><strong>Total Test TPASS:</strong></td><td><strong> $test_passed </strong></td></tr>\n";
238print "<tr><td><strong>Total Test TFAIL:</strong></td><td><strong> $failed_test_counter </strong></td></tr>\n";
239print "<tr><td><strong>Total Test TBROK</strong></td><td><strong> $brok_test_counter </strong></td></tr>\n";
240print "<tr><td><strong>Total Test TWARN</strong></td><td><strong> $warn_test_counter </strong></td></tr>\n";
subrata_modak48cd9cf2009-04-02 06:37:28 +0000241print "<tr><td><strong>Total Test TCONF</strong></td><td><strong> $conf_test_counter </strong></td></tr>\n";
242print "<tr><td><strong>Kernel Version</strong></td><td><strong> $ENV{KERNEL_VERSION} </strong></td></tr>\n";
243print "<tr><td><strong>Machine Architecture</strong></td><td><strong> $ENV{MACHINE_ARCH} </strong></td></tr>\n";
subrata_modake47fb352007-11-25 17:03:49 +0000244print "<tr><td><strong>Hostname</strong> </td> <td><strong>";
Chris Dearman37550cf2012-10-17 19:54:01 -0700245$hostname=system("uname -n"); chop($hostname);
subrata_modake47fb352007-11-25 17:03:49 +0000246print " $hostname </strong></td></tr></tbody></table></div></body></html>\n";