#!/usr/bin/perl #****************************************************************************# # Copyright (c) International Business Machines Corp., 2001 # # # # This program is free software; you can redistribute it an#or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # # the GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # # #****************************************************************************# #****************************************************************************# # # # File: genhtml.pl # # # # Description: This is a Parser which can parse the text output generated by # # pan and convert the same to am HTML format, with proper high- # # lighting of test result backgorund for easy identification of # # pass/fail of testcases # # # # Author: Subrata Modak: subrata@linux.vnet.ibm.com # # # # # #****************************************************************************# my $process_line = 0; my $row_line = ""; my $flag = 0; my $flag2 = 0; my $flag3 = 0; my $flag4 = 0; my $test_counter = 1; my $failed_test_counter = 0; my $failed_test_counter_flag = 0; my $brok_test_counter = 0; my $brok_test_counter_flag = 0; my $warn_test_counter = 0; my $warn_test_counter_flag = 0; my $retr_test_counter = 0; my $retr_test_counter_flag = 0; my $conf_test_counter = 0; my $conf_test_counter_flag = 0; my $test_passed = 0; my $detected_fail = 0; my $detected_pass = 0; my $detected_warn = 0; my $detected_brok = 0; my $detected_retr = 0; my $detected_conf = 0; my $background_colour =0; my $header_file = shift (@ARGV) || syntax(); my $start_tag = shift (@ARGV) || syntax(); my $end_tag = shift (@ARGV) || syntax(); my $output_tag = shift (@ARGV) || syntax(); my $execution_tag = shift (@ARGV) || syntax(); sub syntax() { print "syntax: prtag2tag start_tag end_tag output_tag execution_tag file(s)\n"; exit (1); } sub get_background_colour_column() { if ( $detected_fail == 1 ) { return "#ff0000"; } elsif ( $detected_brok == 1 ) { return Yellow; } elsif ( $detected_warn == 1 ) { return Fuchsia; } elsif ( $detected_retr == 1 ) { return "#8dc997"; } elsif ( $detected_conf == 1 ) { return Aqua; } else { return "#66ff66"; } } if ($start_tag eq "" || $end_tag eq "" || $output_tag eq "" || $execution_tag eq "") { syntax(); } open (FILE, "$header_file") || "Cannot open file: $header_file"; while ($line_2 = ) { $row_line = $row_line . $line_2; } $row_line =~ s/LTP\ Output\/Log/LTP\ Output\/Log\ (Report\ Generated\ on\ $ENV{TEST_START_TIME})/; print $row_line; close (FILE); $row_line = ""; foreach my $file (@ARGV) { open (FILE, $file) || die "Cannot open file: $file\n"; LINE: while ($line = ) { chomp $line; if ($line =~ /$start_tag/) { $process_line = 1; $flag = 1; } if ($line =~ /$end_tag/) { print "$row_line"; $process_line = 0; $flag = 0; $flag2 = 0; $flag3 = 0; $flag4 = 0; $flag5 = 0; $detected_fail = 0; $detected_pass = 0; $detected_warn = 0; $detected_brok = 0; $detected_retr = 0; $detected_conf = 0; $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= ""; } if ($process_line) { if ( $flag == 2) { #Assuming we will find "tag" and "stime" values here @variable_value_pair = split(/\ /, $line); @tag_value = split(/=/,$variable_value_pair[0]); @stime_value = split(/=/,$variable_value_pair[1]); $row_line = $row_line . "

$test_counter

\n" . "

$tag_value[1]

\n" . "

";
                             $get_proper_time = localtime ($stime_value[1]);
                             $row_line = $row_line . "$get_proper_time" . "

\n"; $test_counter++; } if ( $flag == 3) { #Assuming we will find "cmdling" value here @variable_value_pair = split(/=/, $line); $row_line = $row_line . "

$variable_value_pair[1]

\n"; } if ( $flag == 4) { #Assuming we will find "contact" value here @variable_value_pair = split(/=/, $line); $row_line = $row_line . "

$variable_value_pair[1]

\n"; } if ( $flag == 5) { #Assuming we will find "analysis" value here @variable_value_pair = split(/=/, $line); $row_line = $row_line . "

$variable_value_pair[1]

\n"; } if ( $flag3 == 1 ) { if ( $flag4 == 1 ) { @variable_value_pair = split(/=/, $line); $row_line = $row_line . "

$variable_value_pair[1]

\n"; } if ( $flag4 == 2 ) { @variable_value_pair = split(/\ /, $line); @duration_value = split(/=/, $variable_value_pair[0]); @termination_type_value = split(/=/, $variable_value_pair[1]); @termination_id_value = split(/=/, $variable_value_pair[2]); @corefile_value = split(/=/, $variable_value_pair[3]); $background_colour = get_background_colour_column(); $row_line = $row_line . "

$duration_value[1]

\n" . "

$termination_type_value[1]

\n" . "

$termination_id_value[1]

\n" . "

$corefile_value[1]

\n"; $row_line =~ s///; } if ( $flag4 == 3 ) { @variable_value_pair = split(/\ /, $line); @cutime_value = split(/=/, $variable_value_pair[0]); @cstime_value = split(/=/, $variable_value_pair[1]); $row_line = $row_line . "

$cutime_value[1]

\n" . "

$cstime_value[1]

\n"; } $flag4++; } if ( $line =~ /$execution_tag/ ) { $flag2 = 0; $flag3 = 1; $flag4 = 1; $flag5 = 1; $row_line = $row_line . "
"; } if ( $flag2 == 1 ) { $row_line = $row_line . "$line \n"; } if ( $flag5 == 1 ) { if ($line =~ "termination_id=1" ) { $detected_fail = 1; $failed_test_counter++; } elsif ($line =~ "termination_id=2" ) { $detected_brok = 1; $brok_test_counter++; } elsif ($line =~ "termination_id=4" ) { $detected_warn = 1; $warn_test_counter++; } elsif ($line =~ "termination_id=32" ) { $detected_conf = 1; $conf_test_counter++; } elsif ($line =~ "termination_id=0" ) { $detected_pass = 1; $test_passed++; } } if ( $line =~ /$output_tag/ ) { $flag2 = 1; $row_line = $row_line . "
";
                        }
                        $flag++;
		}
	}
	close (FILE);
}

print " \n\n

Summary Report

\n\n
\n\n\n\n\n"; } else { print "bgcolor=\"#66ff66\"> Test Summary

\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $test_passed=$test_counter-$failed_test_counter-$brok_test_counter-$warn_test_counter-$retr_test_counter-$conf_test_counter; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Test Summary

Pan reported some Tests FAIL

Pan reported all Test Pass

LTP Version $ENV{LTP_VERSION}
Start Time $ENV{TEST_START_TIME}
End Time $ENV{TEST_END_TIME}
Log Result $ENV{TEST_LOGS_DIRECTORY}
Output/Failed Result $ENV{TEST_OUTPUT_DIRECTORY}
Total Tests"; $test_counter--; print "$test_counter
Total Test TPASS: $test_passed
Total Test TFAIL: $failed_test_counter
Total Test TBROK $brok_test_counter
Total Test TWARN $warn_test_counter
Total Test TCONF $conf_test_counter
Kernel Version $ENV{KERNEL_VERSION}
Machine Architecture $ENV{MACHINE_ARCH}
Hostname "; $hostname=system("uname -n"); chop($hostname); print " $hostname
\n";