sl@0: # sl@0: # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # This script scans epocwind.out log files resulting from an automated emulator test run sl@0: # and checks for panics. Files to skip or those with expected panics can be identified sl@0: # in the hash table "expectedPanicsHash". sl@0: # If looks for logs in %EPOCROOT%\logs\winscw - rhe DABS scripts will rename epocwind.out sl@0: # files for all tests to end in "_epocwind.txt" so this script scans only files matching sl@0: # this pattern. sl@0: # If run without arguments the output logfile will be sl@0: # %EPOCROOT%\epoc32\winscw\c\panicscanlog.txt but a log path/name can be specified as the sl@0: # only command line argument. sl@0: # sl@0: sl@0: sl@0: use Cwd; sl@0: use strict; sl@0: use Getopt::Std; sl@0: use File::Basename; sl@0: use File::Copy; # for future portability sl@0: sl@0: # Hash entries are in the form , ([pattern1, expectedCount1], [pattern2, expectedCount2],...) sl@0: # where anything non-zero for the first entry will skip the check for the file. sl@0: # The match patterns are regular expressions. sl@0: sl@0: my %expectedPanicsHash = (); sl@0: sl@0: # TCAF test expects CafUtils 0 panics sl@0: push(@{$expectedPanicsHash{"TCAF_epocwind.txt"}}, (0, sl@0: ("Thread tcaf.exe::Worker.*Panic CafUtils 0",6))); sl@0: sl@0: # tjavahelperserver test expects 4 kern-exec 0 panics sl@0: push(@{$expectedPanicsHash{"tjavahelperserver_epocwind.txt"}}, (0, sl@0: ("Thread tjavahelperserver.exe::Worker.*Panic KERN-EXEC 0", 5))); sl@0: sl@0: # Authserver test should be uncommented when it is released. sl@0: # authserver related tests expect panics sl@0: push(@{$expectedPanicsHash{"tauthexpr_epocwind.txt"}}, (0, sl@0: ("Thread tauthcliserv.exe::Worker.*Panic AuthServer 3", 1))); sl@0: push(@{$expectedPanicsHash{"tauthcliserv_debug_epocwind.txt"}}, (0, sl@0: ("Thread tauthcliserv.exe::Worker.*Panic AUTHEXPR 64", 3))); sl@0: push(@{$expectedPanicsHash{"tauthsvr2_epocwind.txt"}}, (0, sl@0: ("Thread AuthServer.EXE::Main Panic AuthServer 5", 3))); sl@0: sl@0: # crypto - padding related tests expect panics sl@0: push(@{$expectedPanicsHash{"tpaddingudeb_epocwind.txt"}}, (0, sl@0: ("Thread tpaddingserver.exe::Worker.*Panic CRYPTO-LIB 1", 1))); sl@0: sl@0: # Expected UPS panics sl@0: push(@{$expectedPanicsHash{"tpolicycache_epocwind.txt"}}, (0, sl@0: ("Thread tupspolicies.exe::Worker.*Panic UPS-Policies 0", 2))); sl@0: push(@{$expectedPanicsHash{"tserviceconfig_epocwind.txt"}}, (0, sl@0: ("Thread tupspolicies.exe::Worker.*Panic UPS-Policies 0", 1))); sl@0: push(@{$expectedPanicsHash{"scstest_epocwind.txt"}}, sl@0: (0, sl@0: ("Thread scstestserver.exe::Main Panic SCS-Server 0", 1), sl@0: ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 0", 1), sl@0: ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 1", 1), sl@0: ("Thread scstest.exe::ScsTestPanic Panic SCS-Client 2", 1) sl@0: )); sl@0: sl@0: die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT}); sl@0: sl@0: # Searches for the most recently created Log directory sl@0: my @logDirectories = glob("$ENV{EPOCROOT}logs_*\\winscw"); sl@0: @logDirectories = sort(@logDirectories); sl@0: sl@0: my $emulatorLogDirectory = "$logDirectories[$#logDirectories]"; sl@0: sl@0: if ( ! -d $emulatorLogDirectory ) sl@0: { sl@0: die "$emulatorLogDirectory is not a directory"; sl@0: } sl@0: sl@0: my $outputFile; sl@0: if (@ARGV[0]) sl@0: { sl@0: $outputFile = $ARGV[0]; sl@0: } sl@0: else sl@0: { sl@0: $outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\panicscanlog.txt"; sl@0: } sl@0: sl@0: unlink $outputFile; sl@0: die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) ); sl@0: sl@0: sl@0: print SCANLOG "\nScanning epocwind.txt files in $emulatorLogDirectory for panics.\n\n"; sl@0: sl@0: my $failureCount = 0; sl@0: my $skipCount = 0; sl@0: my @fileList = getFiles($emulatorLogDirectory, "_epocwind\.txt\$"); sl@0: my $fileCount = @fileList; sl@0: sl@0: foreach my $file (@fileList) sl@0: { sl@0: print (SCANLOG "$file: \n"); sl@0: my @matchPatterns=(); sl@0: if (exists $expectedPanicsHash{$file}) sl@0: { sl@0: (my $skipFile, @matchPatterns) = @{$expectedPanicsHash{$file}}; sl@0: if ($skipFile) sl@0: { sl@0: print (SCANLOG "\tSkipping check.\n\n"); sl@0: $skipCount++; sl@0: next; sl@0: } sl@0: } sl@0: sl@0: my @panicLines = grep(/Thread\s+.+\s+panic/i, ReadListFromFile("$emulatorLogDirectory/$file")); sl@0: my $failed = 0; sl@0: sl@0: if (@panicLines) sl@0: { sl@0: if (@matchPatterns > 0) sl@0: { sl@0: print(SCANLOG "\tPanics found, checking against expected panics.\n"); sl@0: my $j; sl@0: my @remainingCounts=(); sl@0: for ($j=1; $j < @matchPatterns; $j=$j+2) sl@0: { sl@0: push @remainingCounts,$matchPatterns[$j]; sl@0: } sl@0: sl@0: PANICLOOP: foreach my $panic (@panicLines) sl@0: { sl@0: chomp $panic; sl@0: for ($j=0; $j < @matchPatterns; $j=$j+2) sl@0: { sl@0: if (grep(/$matchPatterns[$j]/, $panic)) sl@0: { sl@0: print (SCANLOG "\t\"$panic\" matches expected pattern.\n"); sl@0: $remainingCounts[$j/2]--; sl@0: next PANICLOOP; sl@0: } sl@0: } sl@0: print (SCANLOG "\t\"$panic\" does not match expected patterns\n"); sl@0: $failed = 1; sl@0: } sl@0: sl@0: for ($j=0; $j < @remainingCounts; $j++) sl@0: { sl@0: if ($remainingCounts[$j] != 0) sl@0: { sl@0: $failed = 1; sl@0: my $expectedCount = $matchPatterns[$j*2+1]; sl@0: my $actualCount = $expectedCount - $remainingCounts[$j]; sl@0: print (SCANLOG "\tExpected $expectedCount occurrences of pattern \"$matchPatterns[$j*2]\", got $actualCount\n"); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: print (SCANLOG "\tPanics found and none expected.\n"); sl@0: $failed = 1; sl@0: foreach my $panic (@panicLines) sl@0: { sl@0: print (SCANLOG "\t$panic"); sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (exists $expectedPanicsHash{$file}) sl@0: { sl@0: print(SCANLOG "\tPanics expected but none found.\n"); sl@0: $failed = 1; sl@0: } sl@0: else sl@0: { sl@0: print(SCANLOG "\tNo panics expected and none found.\n"); sl@0: } sl@0: } sl@0: sl@0: if ($failed) sl@0: { sl@0: print (SCANLOG "\tTest for $file FAILED.\n\n"); sl@0: $failureCount++; sl@0: } sl@0: else sl@0: { sl@0: print (SCANLOG "\tTest for $file PASSED.\n\n"); sl@0: } sl@0: } sl@0: sl@0: if ($skipCount) sl@0: { sl@0: print (SCANLOG "\nSkipped $skipCount files ($fileCount total.)"); sl@0: } sl@0: my $testedCount = $fileCount - $skipCount; sl@0: print (SCANLOG "\nTested $testedCount files.\n"); sl@0: print (SCANLOG "$failureCount tests failed out of $testedCount \n"); sl@0: sl@0: close SCANLOG; sl@0: sl@0: # -------------------------------------------------------------------------- sl@0: sl@0: # Return an array of files matching a regexp in a directory sl@0: sub getFiles($$) { sl@0: my $dir = shift; sl@0: my $regfiles = shift; sl@0: my @files; sl@0: sl@0: if ( opendir DIR, $dir ) { sl@0: @files = grep (/$regfiles/, readdir(DIR)); sl@0: closedir DIR; sl@0: } sl@0: return @files; sl@0: } sl@0: sl@0: # -------------------------------------------------------------------------- sl@0: sl@0: # Read the contents of a file into an array and return it sl@0: sub ReadListFromFile ($) { sl@0: my ($file) = @_; sl@0: open FILE, "<$file" or die "Can't read from $file: $!"; sl@0: my @data = ; sl@0: close FILE; sl@0: return @data; sl@0: } sl@0: sl@0: # --------------------------------------------------------------------------