os/security/cryptomgmtlibs/securitytestfw/test/autotesting/panicscan_authserver.pl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 #
     2 # Copyright (c) 2007-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 # This script scans epocwind.out log files resulting from an automated emulator test run
    16 # and checks for panics.  Files to skip or those with expected panics can be identified
    17 # in the hash table "expectedPanicsHash".
    18 # If looks for logs in %EPOCROOT%\logs\winscw - rhe DABS scripts will rename epocwind.out
    19 # files for all tests to end in "_epocwind.txt" so this script scans only files matching
    20 # this pattern.
    21 # If run without arguments the output logfile will be
    22 # %EPOCROOT%\epoc32\winscw\c\panicscanlog.txt but a log path/name can be specified as the
    23 # only command line argument.
    24 #
    25 
    26 
    27 use Cwd;
    28 use strict;
    29 use Getopt::Std;
    30 use File::Basename;
    31 use File::Copy;     # for future portability
    32 
    33 # Hash entries are in the form <skip check>, ([pattern1, expectedCount1], [pattern2, expectedCount2],...)
    34 # where anything non-zero for the first entry will skip the check for the file.
    35 # The match patterns are regular expressions.
    36 
    37 my %expectedPanicsHash = ();
    38 
    39 # TCAF test expects CafUtils 0 panics
    40 push(@{$expectedPanicsHash{"TCAF_epocwind.txt"}}, (0,
    41 	("Thread tcaf.exe::Worker.*Panic CafUtils 0",6)));
    42 
    43 # tjavahelperserver test expects 4 kern-exec 0 panics
    44 push(@{$expectedPanicsHash{"tjavahelperserver_epocwind.txt"}}, (0,
    45 	("Thread tjavahelperserver.exe::Worker.*Panic KERN-EXEC 0", 5)));
    46 
    47 # Authserver test should be uncommented when it is released.
    48 # authserver related tests expect panics
    49 push(@{$expectedPanicsHash{"tauthexpr_epocwind.txt"}}, (0,
    50 	("Thread tauthcliserv.exe::Worker.*Panic AuthServer 3", 1)));
    51 push(@{$expectedPanicsHash{"tauthcliserv_debug_epocwind.txt"}}, (0,
    52 	("Thread tauthcliserv.exe::Worker.*Panic AUTHEXPR 64", 3)));
    53 push(@{$expectedPanicsHash{"tauthsvr2_epocwind.txt"}}, (0,
    54 	("Thread AuthServer.EXE::Main Panic AuthServer 5", 3)));
    55 	
    56 # crypto - padding related tests expect panics
    57 push(@{$expectedPanicsHash{"tpaddingudeb_epocwind.txt"}}, (0,
    58 	("Thread tpaddingserver.exe::Worker.*Panic CRYPTO-LIB 1", 1)));
    59 
    60 # Expected UPS panics
    61 push(@{$expectedPanicsHash{"tpolicycache_epocwind.txt"}}, (0,
    62 	("Thread tupspolicies.exe::Worker.*Panic UPS-Policies 0", 2)));
    63 push(@{$expectedPanicsHash{"tserviceconfig_epocwind.txt"}}, (0,
    64 	("Thread tupspolicies.exe::Worker.*Panic UPS-Policies 0", 1)));
    65 push(@{$expectedPanicsHash{"scstest_epocwind.txt"}}, 
    66     (0,
    67 	   ("Thread scstestserver.exe::Main Panic SCS-Server 0", 1),
    68        ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 0", 1),
    69        ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 1", 1),
    70        ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 2", 1)
    71     ));
    72 
    73 die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT});
    74 
    75 # Searches for the most recently created Log directory
    76 my @logDirectories = glob("$ENV{EPOCROOT}logs_*\\winscw");
    77 @logDirectories = sort(@logDirectories);
    78 
    79 my $emulatorLogDirectory = "$logDirectories[$#logDirectories]";
    80 
    81 if ( ! -d $emulatorLogDirectory )
    82 	{
    83 	die "$emulatorLogDirectory is not a directory";
    84 	}
    85 
    86 my $outputFile;
    87 if (@ARGV[0])
    88 	{
    89 	$outputFile = $ARGV[0];
    90 	}
    91 else
    92 	{
    93 	$outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\panicscanlog.txt";
    94 	}
    95 
    96 unlink $outputFile;
    97 die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) );
    98 
    99 
   100 print SCANLOG "\nScanning epocwind.txt files in $emulatorLogDirectory for panics.\n\n";
   101 
   102 my $failureCount = 0;
   103 my $skipCount = 0;
   104 my @fileList = getFiles($emulatorLogDirectory, "_epocwind\.txt\$");
   105 my $fileCount = @fileList;
   106 
   107 foreach my $file (@fileList)
   108 	{
   109 	print (SCANLOG "$file: \n");
   110 	my @matchPatterns=();
   111 	if (exists $expectedPanicsHash{$file})
   112 		{
   113 		(my $skipFile, @matchPatterns) = @{$expectedPanicsHash{$file}};
   114 		if ($skipFile)
   115 			{
   116 			print (SCANLOG "\tSkipping check.\n\n");
   117 			$skipCount++;
   118 			next;
   119 			}
   120 		}
   121 
   122 	my @panicLines = grep(/Thread\s+.+\s+panic/i, ReadListFromFile("$emulatorLogDirectory/$file"));
   123 	my $failed = 0;
   124 
   125 	if (@panicLines)
   126 		{
   127 		if (@matchPatterns > 0)
   128 			{
   129 			print(SCANLOG "\tPanics found, checking against expected panics.\n");
   130 			my $j;
   131 			my @remainingCounts=();
   132 			for ($j=1; $j < @matchPatterns; $j=$j+2)
   133 				{
   134 				push @remainingCounts,$matchPatterns[$j];
   135 				}
   136 
   137 PANICLOOP:		foreach my $panic (@panicLines)
   138 				{
   139 				chomp $panic;
   140 				for ($j=0; $j < @matchPatterns; $j=$j+2)
   141 					{
   142 					if (grep(/$matchPatterns[$j]/, $panic))
   143 						{
   144 						print (SCANLOG "\t\"$panic\" matches expected pattern.\n");
   145 						$remainingCounts[$j/2]--;
   146 						next PANICLOOP;
   147 						}
   148 					}
   149 				print (SCANLOG "\t\"$panic\" does not match expected patterns\n");
   150 				$failed = 1;
   151 				}
   152 
   153 			for ($j=0; $j < @remainingCounts; $j++)
   154 				{
   155 				if ($remainingCounts[$j] != 0)
   156 					{
   157 					$failed = 1;
   158 					my $expectedCount = $matchPatterns[$j*2+1];
   159 					my $actualCount = $expectedCount - $remainingCounts[$j];
   160 					print (SCANLOG "\tExpected $expectedCount occurrences of pattern \"$matchPatterns[$j*2]\", got $actualCount\n");
   161 					}
   162 				}
   163 			}
   164 		else
   165 			{
   166 			print (SCANLOG "\tPanics found and none expected.\n");
   167 			$failed = 1;
   168 			foreach my $panic (@panicLines)
   169 				{
   170 				print (SCANLOG "\t$panic");		
   171 				}
   172 			}
   173 		}
   174 	else
   175 		{
   176 		if (exists $expectedPanicsHash{$file})
   177 			{
   178 			print(SCANLOG "\tPanics expected but none found.\n");
   179 			$failed = 1;
   180 			}
   181 		else
   182 			{
   183 			print(SCANLOG "\tNo panics expected and none found.\n");
   184 			}
   185 		}
   186 
   187 	if ($failed)
   188 		{
   189 		print (SCANLOG "\tTest for $file FAILED.\n\n");
   190 		$failureCount++;
   191 		}
   192 	else
   193 		{
   194 		print (SCANLOG "\tTest for $file PASSED.\n\n");
   195 		}
   196 	}
   197 
   198 if ($skipCount)
   199 	{
   200 	print (SCANLOG "\nSkipped $skipCount files ($fileCount total.)");
   201 	}
   202 my $testedCount = $fileCount - $skipCount;
   203 print (SCANLOG "\nTested $testedCount files.\n");
   204 print (SCANLOG "$failureCount tests failed out of $testedCount \n");
   205 
   206 close SCANLOG;
   207 
   208 # --------------------------------------------------------------------------
   209 
   210 # Return an array of files matching a regexp in a directory
   211 sub getFiles($$) {
   212     my $dir = shift;
   213     my $regfiles = shift;
   214     my @files;
   215 
   216     if ( opendir DIR, $dir ) {
   217        @files = grep (/$regfiles/, readdir(DIR));
   218        closedir DIR;
   219     }
   220     return @files;
   221 }
   222 
   223 # --------------------------------------------------------------------------
   224 
   225 # Read the contents of a file into an array and return it
   226 sub ReadListFromFile ($) {
   227 	my ($file) = @_;
   228 	open FILE, "<$file" or die "Can't read from $file: $!";
   229 	my @data = <FILE>;
   230 	close FILE;
   231 	return @data;
   232 }
   233 
   234 # --------------------------------------------------------------------------