os/security/cryptomgmtlibs/securitytestfw/test/autotesting/panicscan.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/autotesting/panicscan.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,234 @@
     1.4 +#
     1.5 +# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +# All rights reserved.
     1.7 +# This component and the accompanying materials are made available
     1.8 +# under the terms of the License "Eclipse Public License v1.0"
     1.9 +# which accompanies this distribution, and is available
    1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +#
    1.12 +# Initial Contributors:
    1.13 +# Nokia Corporation - initial contribution.
    1.14 +#
    1.15 +# Contributors:
    1.16 +#
    1.17 +# Description: 
    1.18 +# This script scans epocwind.out log files resulting from an automated emulator test run
    1.19 +# and checks for panics.  Files to skip or those with expected panics can be identified
    1.20 +# in the hash table "expectedPanicsHash".
    1.21 +# If looks for logs in %EPOCROOT%\logs\winscw - rhe DABS scripts will rename epocwind.out
    1.22 +# files for all tests to end in "_epocwind.txt" so this script scans only files matching
    1.23 +# this pattern.
    1.24 +# If run without arguments the output logfile will be
    1.25 +# %EPOCROOT%\epoc32\winscw\c\panicscanlog.txt but a log path/name can be specified as the
    1.26 +# only command line argument.
    1.27 +#
    1.28 +
    1.29 +
    1.30 +use Cwd;
    1.31 +use strict;
    1.32 +use Getopt::Std;
    1.33 +use File::Basename;
    1.34 +use File::Copy;     # for future portability
    1.35 +
    1.36 +# Hash entries are in the form <skip check>, ([pattern1, expectedCount1], [pattern2, expectedCount2],...)
    1.37 +# where anything non-zero for the first entry will skip the check for the file.
    1.38 +# The match patterns are regular expressions.
    1.39 +
    1.40 +my %expectedPanicsHash = ();
    1.41 +
    1.42 +# TCAF test expects CafUtils 0 panics
    1.43 +push(@{$expectedPanicsHash{"TCAF_epocwind.txt"}}, (0,
    1.44 +	("Thread tcaf.exe::Worker.*Panic CafUtils 0",6)));
    1.45 +
    1.46 +# tjavahelperserver test expects 4 kern-exec 0 panics
    1.47 +push(@{$expectedPanicsHash{"tjavahelperserver_epocwind.txt"}}, (0,
    1.48 +	("Thread tjavahelperserver.exe::Worker.*Panic KERN-EXEC 0", 5)));
    1.49 +
    1.50 +# Authserver test should be uncommented when it is released.
    1.51 +# authserver related tests expect panics
    1.52 +#push(@{$expectedPanicsHash{"tauthexpr_epocwind.txt"}}, (0,
    1.53 +#	("Thread tauthcliserv.exe::Worker.*Panic AuthServer 3", 1)));
    1.54 +#push(@{$expectedPanicsHash{"tauthcliserv_debug_epocwind.txt"}}, (0,
    1.55 +#	("Thread tauthcliserv.exe::Worker.*Panic AUTHEXPR 64", 3)));
    1.56 +#push(@{$expectedPanicsHash{"tauthsvr2_epocwind.txt"}}, (0,
    1.57 +#	("Thread AuthServer.EXE::Main Panic AuthServer 5", 2)));
    1.58 +
    1.59 +# crypto - padding related tests expect panics
    1.60 +push(@{$expectedPanicsHash{"tpaddingudeb_epocwind.txt"}}, (0,
    1.61 +	("Thread tpaddingserver.exe::Worker.*Panic CRYPTO-LIB 1", 1)));
    1.62 +
    1.63 +# Expected UPS panics
    1.64 +push(@{$expectedPanicsHash{"tpolicycache_epocwind.txt"}}, (0,
    1.65 +	("Thread tupspolicies.exe::Worker.*Panic UPS-Policies 0", 2)));
    1.66 +push(@{$expectedPanicsHash{"tserviceconfig_epocwind.txt"}}, (0,
    1.67 +	("Thread tupspolicies.exe::Worker.*Panic UPS-Policies 0", 1)));
    1.68 +push(@{$expectedPanicsHash{"scstest_epocwind.txt"}}, 
    1.69 +    (0,
    1.70 +	   ("Thread scstestserver.exe::Main Panic SCS-Server 0", 1),
    1.71 +       ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 0", 1),
    1.72 +       ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 1", 1),
    1.73 +       ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 2", 1)
    1.74 +    ));
    1.75 +
    1.76 +die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT});
    1.77 +
    1.78 +# Searches for the most recently created Log directory
    1.79 +my @logDirectories = glob("$ENV{EPOCROOT}logs_*\\winscw");
    1.80 +@logDirectories = sort(@logDirectories);
    1.81 +
    1.82 +my $emulatorLogDirectory = "$logDirectories[$#logDirectories]";
    1.83 +
    1.84 +if ( ! -d $emulatorLogDirectory )
    1.85 +	{
    1.86 +	die "$emulatorLogDirectory is not a directory";
    1.87 +	}
    1.88 +
    1.89 +my $outputFile;
    1.90 +if (@ARGV[0])
    1.91 +	{
    1.92 +	$outputFile = $ARGV[0];
    1.93 +	}
    1.94 +else
    1.95 +	{
    1.96 +	$outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\panicscanlog.txt";
    1.97 +	}
    1.98 +
    1.99 +unlink $outputFile;
   1.100 +die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) );
   1.101 +
   1.102 +
   1.103 +print SCANLOG "\nScanning epocwind.txt files in $emulatorLogDirectory for panics.\n\n";
   1.104 +
   1.105 +my $failureCount = 0;
   1.106 +my $skipCount = 0;
   1.107 +my @fileList = getFiles($emulatorLogDirectory, "_epocwind\.txt\$");
   1.108 +my $fileCount = @fileList;
   1.109 +
   1.110 +foreach my $file (@fileList)
   1.111 +	{
   1.112 +	print (SCANLOG "$file: \n");
   1.113 +	my @matchPatterns=();
   1.114 +	if (exists $expectedPanicsHash{$file})
   1.115 +		{
   1.116 +		(my $skipFile, @matchPatterns) = @{$expectedPanicsHash{$file}};
   1.117 +		if ($skipFile)
   1.118 +			{
   1.119 +			print (SCANLOG "\tSkipping check.\n\n");
   1.120 +			$skipCount++;
   1.121 +			next;
   1.122 +			}
   1.123 +		}
   1.124 +
   1.125 +	my @panicLines = grep(/Thread\s+.+\s+panic/i, ReadListFromFile("$emulatorLogDirectory/$file"));
   1.126 +	my $failed = 0;
   1.127 +
   1.128 +	if (@panicLines)
   1.129 +		{
   1.130 +		if (@matchPatterns > 0)
   1.131 +			{
   1.132 +			print(SCANLOG "\tPanics found, checking against expected panics.\n");
   1.133 +			my $j;
   1.134 +			my @remainingCounts=();
   1.135 +			for ($j=1; $j < @matchPatterns; $j=$j+2)
   1.136 +				{
   1.137 +				push @remainingCounts,$matchPatterns[$j];
   1.138 +				}
   1.139 +
   1.140 +PANICLOOP:		foreach my $panic (@panicLines)
   1.141 +				{
   1.142 +				chomp $panic;
   1.143 +				for ($j=0; $j < @matchPatterns; $j=$j+2)
   1.144 +					{
   1.145 +					if (grep(/$matchPatterns[$j]/, $panic))
   1.146 +						{
   1.147 +						print (SCANLOG "\t\"$panic\" matches expected pattern.\n");
   1.148 +						$remainingCounts[$j/2]--;
   1.149 +						next PANICLOOP;
   1.150 +						}
   1.151 +					}
   1.152 +				print (SCANLOG "\t\"$panic\" does not match expected patterns\n");
   1.153 +				$failed = 1;
   1.154 +				}
   1.155 +
   1.156 +			for ($j=0; $j < @remainingCounts; $j++)
   1.157 +				{
   1.158 +				if ($remainingCounts[$j] != 0)
   1.159 +					{
   1.160 +					$failed = 1;
   1.161 +					my $expectedCount = $matchPatterns[$j*2+1];
   1.162 +					my $actualCount = $expectedCount - $remainingCounts[$j];
   1.163 +					print (SCANLOG "\tExpected $expectedCount occurrences of pattern \"$matchPatterns[$j*2]\", got $actualCount\n");
   1.164 +					}
   1.165 +				}
   1.166 +			}
   1.167 +		else
   1.168 +			{
   1.169 +			print (SCANLOG "\tPanics found and none expected.\n");
   1.170 +			$failed = 1;
   1.171 +			foreach my $panic (@panicLines)
   1.172 +				{
   1.173 +				print (SCANLOG "\t$panic");		
   1.174 +				}
   1.175 +			}
   1.176 +		}
   1.177 +	else
   1.178 +		{
   1.179 +		if (exists $expectedPanicsHash{$file})
   1.180 +			{
   1.181 +			print(SCANLOG "\tPanics expected but none found.\n");
   1.182 +			$failed = 1;
   1.183 +			}
   1.184 +		else
   1.185 +			{
   1.186 +			print(SCANLOG "\tNo panics expected and none found.\n");
   1.187 +			}
   1.188 +		}
   1.189 +
   1.190 +	if ($failed)
   1.191 +		{
   1.192 +		print (SCANLOG "\tTest for $file FAILED.\n\n");
   1.193 +		$failureCount++;
   1.194 +		}
   1.195 +	else
   1.196 +		{
   1.197 +		print (SCANLOG "\tTest for $file PASSED.\n\n");
   1.198 +		}
   1.199 +	}
   1.200 +
   1.201 +if ($skipCount)
   1.202 +	{
   1.203 +	print (SCANLOG "\nSkipped $skipCount files ($fileCount total.)");
   1.204 +	}
   1.205 +my $testedCount = $fileCount - $skipCount;
   1.206 +print (SCANLOG "\nTested $testedCount files.\n");
   1.207 +print (SCANLOG "$failureCount tests failed out of $testedCount \n");
   1.208 +
   1.209 +close SCANLOG;
   1.210 +
   1.211 +# --------------------------------------------------------------------------
   1.212 +
   1.213 +# Return an array of files matching a regexp in a directory
   1.214 +sub getFiles($$) {
   1.215 +    my $dir = shift;
   1.216 +    my $regfiles = shift;
   1.217 +    my @files;
   1.218 +
   1.219 +    if ( opendir DIR, $dir ) {
   1.220 +       @files = grep (/$regfiles/, readdir(DIR));
   1.221 +       closedir DIR;
   1.222 +    }
   1.223 +    return @files;
   1.224 +}
   1.225 +
   1.226 +# --------------------------------------------------------------------------
   1.227 +
   1.228 +# Read the contents of a file into an array and return it
   1.229 +sub ReadListFromFile ($) {
   1.230 +	my ($file) = @_;
   1.231 +	open FILE, "<$file" or die "Can't read from $file: $!";
   1.232 +	my @data = <FILE>;
   1.233 +	close FILE;
   1.234 +	return @data;
   1.235 +}
   1.236 +
   1.237 +# --------------------------------------------------------------------------