os/security/cryptomgmtlibs/securitytestfw/test/autotesting/newdigest.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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                 
    69  		elsif ($entry =~ /\.htm/) 
    70  		{
    71 		    open (HTML_LOG, "$entry" ) or die("open failed");
    72             my $Is_Tef_Htm = 1; 
    73 
    74             while(<HTML_LOG>)
    75 		    {
    76 			chomp;
    77 	
    78 			my $line  = $_;
    79 			$line =~ s/\x0//g;
    80 
    81 			if ($line =~ /tests failed/)
    82 			{
    83               parseLog($entry, \$failed, \$passed);
    84  			  #printf SUMMARY (" %45s: %d tests failed out of %d\r\n", $entry, $failed, $failed+$passed);			
    85               $Is_Tef_Htm = 0;
    86             }
    87 
    88             }
    89 
    90 	 	    close HTML_LOG;                    
    91 	        if( $Is_Tef_Htm )
    92             {
    93 	 	      parseHtm($entry, \$failed, \$passed, \$ntestcasefailed, \$ntestcasepassed);
    94             }        
    95 		}
    96 		if ( $passed > 0 or $failed > 0)
    97 		{
    98 			$scriptsRun++;
    99 			$nTotalPassedStep += $passed;
   100 			$nTotalFailedStep += $failed;
   101 
   102 			if ( $ntestcasepassed > 0 || $ntestcasefailed > 0 )
   103 			{
   104 			$nTotalPassedCase += $ntestcasepassed;
   105 			$nTotalFailedCase += $ntestcasefailed;
   106 			}
   107 			else
   108 			{
   109 			if ( $failed > 0 )
   110 			{
   111 			$nTotalFailedCase++;
   112 			}
   113 			else
   114 			{
   115 			$nTotalPassedCase++;
   116 			}
   117 			}
   118 		}
   119 	}
   120 	my $ntestScripts = " Test Scripts Run \t";
   121 	print SUMMARY "\n";	
   122 	print SUMMARY ($scriptsRun, $ntestScripts);
   123 	
   124 	my $nTotalTestCases = $nTotalFailedCase+$nTotalPassedCase;	
   125 	print SUMMARY "\n";	
   126 	print SUMMARY "\r\nTest Cases\tPassed\tFailed\tTotal\r\n";
   127 	printf SUMMARY ("\t\t%d\t%d\t%d\n", $nTotalPassedCase, $nTotalFailedCase, $nTotalTestCases);
   128 	if ($nTotalTestCases > 0)
   129 	{
   130 	print SUMMARY "\r\n\t\t%Passed\t\t%Failed\r\n";	
   131 	printf SUMMARY ("\t\t%.2f\t\t%.2f\r\n", $nTotalPassedCase/$nTotalTestCases*100, $nTotalFailedCase/$nTotalTestCases*100);	
   132 	}
   133 	my $nTotalTestSteps = $nTotalPassedStep+$nTotalFailedStep;
   134 	print SUMMARY "\n";
   135 	print SUMMARY "\r\nTest Steps\tPassed\tFailed\tTotal\r\n";
   136 	printf SUMMARY ("\t\t%d\t%d\t%d\n", $nTotalPassedStep, $nTotalFailedStep, $nTotalTestSteps);
   137 	if ($nTotalTestSteps > 0)
   138 	{
   139 	print SUMMARY "\r\n\t\t%Passed\t\t%Failed\r\n";
   140 	printf SUMMARY ("\t\t%.2f\t\t%.2f\r\n", $nTotalPassedStep/$nTotalTestSteps*100, $nTotalFailedStep/$nTotalTestSteps*100);
   141 	}
   142 }
   143 
   144 
   145 sub parseLog($$$) {
   146 	my ($entry, $failed, $passed) = @_;
   147 
   148     open (LOG, "$entry" ) or die("open failed");
   149     my $found = "false";
   150 	my $notests = 0;
   151     while(<LOG>)
   152     {
   153 	chomp;
   154 	
   155 	my $line  = $_;
   156 	$line =~ s/\x0//g;
   157 	if ($line =~ /tests failed/)
   158 	{
   159 	    $line =~ /(\d+) tests failed out of (\d+)/;
   160 	    printf SUMMARY (" %45s: %s\r\n", $entry, $&);
   161 	    $found = "true";
   162 	    $$failed = $1;
   163 	    $notests = $2;
   164 	}
   165     }
   166     close LOG;
   167 
   168     if ( $found eq "false" && $entry ne "buildid.txt")
   169     {
   170 	printf SUMMARY ("WARNING: Could not parse file %s\r\n", $entry);
   171     }
   172 	$$passed = $notests - $$failed;
   173 }
   174 
   175 sub parseHtm($$$$$) {
   176 	my ($entry, $nfailed, $npassed, $nCasesFailed, $nCasesPassed) = @_;
   177     my ($textfile);
   178     $textfile = $entry;
   179     $textfile =~ s/\.htm/\.log/;
   180     next if ( -f $textfile);
   181 	
   182     my $ncasestotal = 0;
   183 	my $nstepstotal = 0;
   184 	my $passed = 0;
   185 	my $failed = 0;
   186 	my $casepassed = 0;
   187 	my $casefailed = 0;
   188 	my $TEST_STEP_SECTION = 0;
   189 	my $TEST_CASE_SECTION = 0;
   190 	my $noTestCase = 0;
   191 	
   192 	
   193     open (LOG, $entry) || die "couldn't open $entry: $!";
   194     while (<LOG>)
   195     {
   196 		my ($sLine) = $_;
   197 	
   198 		if ( $sLine =~ /TEST STEP SUMMARY:<\/font>/i) 
   199 		{
   200 			$TEST_STEP_SECTION = 1;
   201 			$TEST_CASE_SECTION = 0;
   202 		}
   203 		elsif ( $sLine =~ /RUN PROGRAM SUMMARY:<\/font>/i) 
   204 		{
   205 			$TEST_STEP_SECTION = 0;
   206 		}
   207 	        elsif( $sLine =~ /TEST CASE SUMMARY:<\/font>/i)
   208 		{
   209 			$TEST_CASE_SECTION = 1;
   210 			$TEST_STEP_SECTION = 0;
   211 		}		
   212 		elsif ( $sLine =~ /SUMMARY:<\/font>/i ) # To Keep Last
   213 		{
   214 			$TEST_STEP_SECTION = 1;
   215 			$noTestCase = 1;
   216 		}
   217 	
   218 		if ( $TEST_STEP_SECTION )
   219 		{
   220 			$passed += $1 if( $sLine =~ /<font.*color=00AF00> PASS = (\d+)<\/font>/i);
   221 			$passed += $1 if( $sLine =~ /<font.*color=00AF00>PASS = (\d+)<\/font>/i);
   222 			$failed += $1 if( $sLine =~ /<font.*color=FF0000>FAIL = (\d+)<\/font>/i);
   223 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>ABORT = (\d+)<\/font>/i);
   224 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>PANIC = (\d+)<\/font>/i);
   225 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>INCONCLUSIVE = (\d+)<\/font>/i);
   226 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>UNKNOWN = (\d+)<\/font>/i);
   227 			$failed += $1 if( $sLine =~ /<font.*color=0000FF>UNEXECUTED = (\d+)<\/font>/i);
   228 		}
   229 		if ( $TEST_CASE_SECTION )
   230 		{
   231 			$casepassed += $1 if( $sLine =~ /<font.*color=00AF00> PASS = (\d+)<\/font>/i);
   232 			$casepassed += $1 if( $sLine =~ /<font.*color=00AF00>PASS = (\d+)<\/font>/i);
   233 			$casefailed += $1 if( $sLine =~ /<font.*color=FF0000>FAIL = (\d+)<\/font>/i);
   234 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>ABORT = (\d+)<\/font>/i);
   235 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>PANIC = (\d+)<\/font>/i);
   236 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>INCONCLUSIVE = (\d+)<\/font>/i);
   237 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>UNKNOWN = (\d+)<\/font>/i);
   238 			$casefailed += $1 if( $sLine =~ /<font.*color=0000FF>UNEXECUTED = (\d+)<\/font>/i);
   239 		}
   240     }
   241 	$ncasestotal = $casefailed + $casepassed;
   242 	$nstepstotal = $passed + $failed;
   243 	
   244     close LOG;
   245 	if($ncasestotal != 0 or $noTestCase == 1) 
   246 	{
   247 	  printf SUMMARY (" %45s: %d tests failed out of %d\r\n", $entry, $failed, $nstepstotal);
   248 	}
   249 	else
   250 	{
   251 	  printf SUMMARY ("WARNING: %45s: %d tests failed out of %d\r\n", $entry, $failed, $nstepstotal);
   252 	}
   253 	$$npassed = $passed;
   254 	$$nfailed = $failed;
   255 	$$nCasesPassed = $casepassed;
   256 	$$nCasesFailed = $casefailed;
   257 }
   258 
   259 
   260 
   261 
   262 
   263