installationservices/switestfw/test/autotesting/newdigest.pl
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 #
       
     2 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 
       
    18 use strict;
       
    19 use Getopt::Long;
       
    20 use IO::Handle;
       
    21 use IO::Seekable;
       
    22 use File::Basename;
       
    23 
       
    24 main();
       
    25 exit(0);
       
    26 
       
    27 sub main {
       
    28 	if ($#ARGV != 0)
       
    29 	{
       
    30 		print "usage: newdigest.pl <logfile>\n";
       
    31 		exit;
       
    32 	}
       
    33 	
       
    34 	my ($log_file) = $ARGV[0];
       
    35 	
       
    36 	if (-f $log_file)
       
    37 	{
       
    38 		system ("del $log_file");
       
    39 	}
       
    40 	
       
    41 	opendir( DIR, "." ) or die("Unable to open directory");
       
    42 	my @dirs = readdir DIR;
       
    43 	my $entry;
       
    44 	
       
    45 	my $nTotalTestCase = 0;
       
    46 	my $nTotalPassedCase = 0;
       
    47 	my $nTotalFailedCase = 0;
       
    48 	my $nTotalPassedStep = 0;
       
    49 	my $nTotalFailedStep = 0;
       
    50 	my $scriptsRun = 0;
       
    51 	open (SUMMARY, ">$log_file") || die "couldn't open digest file: $!";
       
    52 	
       
    53 	foreach $entry ( sort @dirs )
       
    54 	{
       
    55 		next if ( $entry eq ".." or $entry eq "." );
       
    56 		next if ( -d $entry );
       
    57 
       
    58 		my $failed = 0;
       
    59 		my $passed = 0;
       
    60 		my $ntestcasepassed = 0;
       
    61 		my $ntestcasefailed = 0;
       
    62 
       
    63 		if ( $entry =~ /\.log/ || $entry =~ /\.txt/)
       
    64 		{
       
    65 			parseLog($entry, \$failed, \$passed);
       
    66 			#printf SUMMARY (" %45s: %d tests failed out of %d\r\n", $entry, $failed, $failed+$passed);			
       
    67 		}
       
    68 		elsif ($entry =~ /\.htm/) 
       
    69 		{
       
    70 			parseHtm($entry, \$failed, \$passed, \$ntestcasefailed, \$ntestcasepassed);
       
    71 			#printf SUMMARY (" %45s: %d tests failed out of %d\r\n", $entry, $ntestcasefailed, $ntestcasepassed+$ntestcasefailed);
       
    72 		}
       
    73 		if ( $passed > 0 or $failed > 0)
       
    74 		{
       
    75 			$scriptsRun++;
       
    76 			$nTotalPassedStep += $passed;
       
    77 			$nTotalFailedStep += $failed;
       
    78 
       
    79 			if ( $ntestcasepassed > 0 || $ntestcasefailed > 0 )
       
    80 			{
       
    81 			$nTotalPassedCase += $ntestcasepassed;
       
    82 			$nTotalFailedCase += $ntestcasefailed;
       
    83 			}
       
    84 			else
       
    85 			{
       
    86 			if ( $failed > 0 )
       
    87 			{
       
    88 			$nTotalFailedCase++;
       
    89 			}
       
    90 			else
       
    91 			{
       
    92 			$nTotalPassedCase++;
       
    93 			}
       
    94 			}
       
    95 		}
       
    96 	}
       
    97 	my $ntestScripts = " Test Scripts Run \t";
       
    98 	print SUMMARY "\n";	
       
    99 	print SUMMARY ($scriptsRun, $ntestScripts);
       
   100 	
       
   101 	my $nTotalTestCases = $nTotalFailedCase+$nTotalPassedCase;	
       
   102 	print SUMMARY "\n";	
       
   103 	print SUMMARY "\r\nTest Cases\tPassed\tFailed\tTotal\r\n";
       
   104 	printf SUMMARY ("\t\t%d\t%d\t%d\n", $nTotalPassedCase, $nTotalFailedCase, $nTotalTestCases);
       
   105 	if ($nTotalTestCases > 0)
       
   106 	{
       
   107 	print SUMMARY "\r\n\t\t%Passed\t\t%Failed\r\n";	
       
   108 	printf SUMMARY ("\t\t%.2f\t\t%.2f\r\n", $nTotalPassedCase/$nTotalTestCases*100, $nTotalFailedCase/$nTotalTestCases*100);	
       
   109 	}
       
   110 	my $nTotalTestSteps = $nTotalPassedStep+$nTotalFailedStep;
       
   111 	print SUMMARY "\n";
       
   112 	print SUMMARY "\r\nTest Steps\tPassed\tFailed\tTotal\r\n";
       
   113 	printf SUMMARY ("\t\t%d\t%d\t%d\n", $nTotalPassedStep, $nTotalFailedStep, $nTotalTestSteps);
       
   114 	if ($nTotalTestSteps > 0)
       
   115 	{
       
   116 	print SUMMARY "\r\n\t\t%Passed\t\t%Failed\r\n";
       
   117 	printf SUMMARY ("\t\t%.2f\t\t%.2f\r\n", $nTotalPassedStep/$nTotalTestSteps*100, $nTotalFailedStep/$nTotalTestSteps*100);
       
   118 	}
       
   119 }
       
   120 
       
   121 
       
   122 sub parseLog($$$) {
       
   123 	my ($entry, $failed, $passed) = @_;
       
   124 
       
   125     open (LOG, "$entry" ) or die("open failed");
       
   126     my $found = "false";
       
   127 	my $notests = 0;
       
   128     while(<LOG>)
       
   129     {
       
   130 	chomp;
       
   131 	
       
   132 	my $line  = $_;
       
   133 	$line =~ s/\x0//g;
       
   134 	if ($line =~ /tests failed/)
       
   135 	{
       
   136 	    $line =~ /(\d+) tests failed out of (\d+)/;
       
   137 	    printf SUMMARY (" %45s: %s\r\n", $entry, $&);
       
   138 	    $found = "true";
       
   139 	    $$failed = $1;
       
   140 	    $notests = $2;
       
   141 	}
       
   142     }
       
   143     close LOG;
       
   144 
       
   145     if ( $found eq "false" && $entry ne "buildid.txt")
       
   146     {
       
   147 	printf SUMMARY ("WARNING: Could not parse file %s\r\n", $entry);
       
   148     }
       
   149 	$$passed = $notests - $$failed;
       
   150 }
       
   151 
       
   152 sub parseHtm($$$$$) {
       
   153 	my ($entry, $nfailed, $npassed, $nCasesFailed, $nCasesPassed) = @_;
       
   154     my ($textfile);
       
   155     $textfile = $entry;
       
   156     $textfile =~ s/\.htm/\.log/;
       
   157     next if ( -f $textfile);
       
   158 	
       
   159     my $ncasestotal = 0;
       
   160 	my $nstepstotal = 0;
       
   161 	my $passed = 0;
       
   162 	my $failed = 0;
       
   163 	my $casepassed = 0;
       
   164 	my $casefailed = 0;
       
   165 	my $TEST_STEP_SECTION = 0;
       
   166 	my $TEST_CASE_SECTION = 0;
       
   167 	my $noTestCase = 0;
       
   168 	
       
   169 	
       
   170     open (LOG, $entry) || die "couldn't open $entry: $!";
       
   171     while (<LOG>)
       
   172     {
       
   173 		my ($sLine) = $_;
       
   174 	
       
   175 		if ( $sLine =~ /TEST STEP SUMMARY:<\/font>/i) 
       
   176 		{
       
   177 			$TEST_STEP_SECTION = 1;
       
   178 			$TEST_CASE_SECTION = 0;
       
   179 		}
       
   180 		elsif ( $sLine =~ /RUN PROGRAM SUMMARY:<\/font>/i) 
       
   181 		{
       
   182 			$TEST_STEP_SECTION = 0;
       
   183 		}
       
   184 	        elsif( $sLine =~ /TEST CASE SUMMARY:<\/font>/i)
       
   185 		{
       
   186 			$TEST_CASE_SECTION = 1;
       
   187 			$TEST_STEP_SECTION = 0;
       
   188 		}		
       
   189 		elsif ( $sLine =~ /SUMMARY:<\/font>/i ) # To Keep Last
       
   190 		{
       
   191 			$TEST_STEP_SECTION = 1;
       
   192 			$noTestCase = 1;
       
   193 		}
       
   194 	
       
   195 		if ( $TEST_STEP_SECTION )
       
   196 		{
       
   197 			$passed += $1 if( $sLine =~ /<font.*color=00AF00> PASS = (\d+)<\/font>/i);
       
   198 			$passed += $1 if( $sLine =~ /<font.*color=00AF00>PASS = (\d+)<\/font>/i);
       
   199 			$failed += $1 if( $sLine =~ /<font.*color=FF0000>FAIL = (\d+)<\/font>/i);
       
   200 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>ABORT = (\d+)<\/font>/i);
       
   201 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>PANIC = (\d+)<\/font>/i);
       
   202 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>INCONCLUSIVE = (\d+)<\/font>/i);
       
   203 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>UNKNOWN = (\d+)<\/font>/i);
       
   204 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>UNEXECUTED = (\d+)<\/font>/i);
       
   205 		}
       
   206 		if ( $TEST_CASE_SECTION )
       
   207 		{
       
   208 			$casepassed += $1 if( $sLine =~ /<font.*color=00AF00> PASS = (\d+)<\/font>/i);
       
   209 			$casepassed += $1 if( $sLine =~ /<font.*color=00AF00>PASS = (\d+)<\/font>/i);
       
   210 			$casefailed += $1 if( $sLine =~ /<font.*color=FF0000>FAIL = (\d+)<\/font>/i);
       
   211 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>ABORT = (\d+)<\/font>/i);
       
   212 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>PANIC = (\d+)<\/font>/i);
       
   213 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>INCONCLUSIVE = (\d+)<\/font>/i);
       
   214 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>UNKNOWN = (\d+)<\/font>/i);
       
   215 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>UNEXECUTED = (\d+)<\/font>/i);
       
   216 		}
       
   217     }
       
   218 	$ncasestotal = $casefailed + $casepassed;
       
   219 	$nstepstotal = $passed + $failed;
       
   220 	
       
   221     close LOG;
       
   222 	if($ncasestotal != 0 or $noTestCase == 1) 
       
   223 	{
       
   224 	  printf SUMMARY (" %45s: %d tests failed out of %d\r\n", $entry, $failed, $nstepstotal);
       
   225 	}
       
   226 	else
       
   227 	{
       
   228 	  printf SUMMARY ("WARNING: %45s: %d tests failed out of %d\r\n", $entry, $failed, $nstepstotal);
       
   229 	}
       
   230 	$$npassed = $passed;
       
   231 	$$nfailed = $failed;
       
   232 	$$nCasesPassed = $casepassed;
       
   233 	$$nCasesFailed = $casefailed;
       
   234 }
       
   235 
       
   236 
       
   237 
       
   238 
       
   239 
       
   240