|
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 # tjavahelperserver test expects 4 kern-exec 0 panics |
|
40 push(@{$expectedPanicsHash{"tjavahelperserver_epocwind.txt"}}, (0, |
|
41 ("Thread tjavahelperserver.exe::Worker.*Panic KERN-EXEC 0", 5))); |
|
42 |
|
43 # Authserver test should be uncommented when it is released. |
|
44 # authserver related tests expect panics |
|
45 push(@{$expectedPanicsHash{"tauthexpr_epocwind.txt"}}, (0, |
|
46 ("Thread tauthcliserv.exe::Worker.*Panic AuthServer 3", 1))); |
|
47 push(@{$expectedPanicsHash{"tauthcliserv_debug_epocwind.txt"}}, (0, |
|
48 ("Thread tauthcliserv.exe::Worker.*Panic AUTHEXPR 64", 3))); |
|
49 push(@{$expectedPanicsHash{"tauthsvr2_epocwind.txt"}}, (0, |
|
50 ("Thread AuthServer.EXE::!AuthServer Panic AuthServer 5", 2))); |
|
51 |
|
52 # crypto - padding related tests expect panics |
|
53 push(@{$expectedPanicsHash{"tpaddingudeb_epocwind.txt"}}, (0, |
|
54 ("Thread tpaddingServer.exe::Worker.*Panic CRYPTO-LIB 1", 1))); |
|
55 |
|
56 die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT}); |
|
57 |
|
58 # Searches for the most recently created Log directory |
|
59 my @logDirectories = glob("$ENV{EPOCROOT}logs_*\\winscw"); |
|
60 @logDirectories = sort(@logDirectories); |
|
61 |
|
62 my $emulatorLogDirectory = "$logDirectories[$#logDirectories]"; |
|
63 |
|
64 if ( ! -d $emulatorLogDirectory ) |
|
65 { |
|
66 die "$emulatorLogDirectory is not a directory"; |
|
67 } |
|
68 |
|
69 my $outputFile; |
|
70 if (@ARGV[0]) |
|
71 { |
|
72 $outputFile = $ARGV[0]; |
|
73 } |
|
74 else |
|
75 { |
|
76 $outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\panicscanlog.txt"; |
|
77 } |
|
78 |
|
79 unlink $outputFile; |
|
80 die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) ); |
|
81 |
|
82 |
|
83 print SCANLOG "\nScanning epocwind.txt files in $emulatorLogDirectory for panics.\n\n"; |
|
84 |
|
85 my $failureCount = 0; |
|
86 my $skipCount = 0; |
|
87 my @fileList = getFiles($emulatorLogDirectory, "_epocwind\.txt\$"); |
|
88 my $fileCount = @fileList; |
|
89 |
|
90 foreach my $file (@fileList) |
|
91 { |
|
92 print (SCANLOG "$file: \n"); |
|
93 my @matchPatterns=(); |
|
94 if (exists $expectedPanicsHash{$file}) |
|
95 { |
|
96 (my $skipFile, @matchPatterns) = @{$expectedPanicsHash{$file}}; |
|
97 if ($skipFile) |
|
98 { |
|
99 print (SCANLOG "\tSkipping check.\n\n"); |
|
100 $skipCount++; |
|
101 next; |
|
102 } |
|
103 } |
|
104 |
|
105 my @panicLines = grep(/panic/i, ReadListFromFile("$emulatorLogDirectory/$file")); |
|
106 my $failed = 0; |
|
107 |
|
108 if (@panicLines) |
|
109 { |
|
110 if (@matchPatterns > 0) |
|
111 { |
|
112 print(SCANLOG "\tPanics found, checking against expected panics.\n"); |
|
113 my $j; |
|
114 my @remainingCounts=(); |
|
115 for ($j=1; $j < @matchPatterns; $j=$j+2) |
|
116 { |
|
117 push @remainingCounts,$matchPatterns[$j]; |
|
118 } |
|
119 |
|
120 PANICLOOP: foreach my $panic (@panicLines) |
|
121 { |
|
122 chomp $panic; |
|
123 for ($j=0; $j < @matchPatterns; $j=$j+2) |
|
124 { |
|
125 if (grep(/$matchPatterns[$j]/, $panic)) |
|
126 { |
|
127 print (SCANLOG "\t\"$panic\" matches expected pattern.\n"); |
|
128 $remainingCounts[$j/2]--; |
|
129 next PANICLOOP; |
|
130 } |
|
131 } |
|
132 print (SCANLOG "\t\"$panic\" does not match expected patterns\n"); |
|
133 $failed = 1; |
|
134 } |
|
135 |
|
136 for ($j=0; $j < @remainingCounts; $j++) |
|
137 { |
|
138 if ($remainingCounts[$j] != 0) |
|
139 { |
|
140 $failed = 1; |
|
141 my $expectedCount = $matchPatterns[$j*2+1]; |
|
142 my $actualCount = $expectedCount - $remainingCounts[$j]; |
|
143 print (SCANLOG "\tExpected $expectedCount occurrences of pattern \"$matchPatterns[$j*2]\", got $actualCount\n"); |
|
144 } |
|
145 } |
|
146 } |
|
147 else |
|
148 { |
|
149 print (SCANLOG "\tPanics found and none expected.\n"); |
|
150 $failed = 1; |
|
151 foreach my $panic (@panicLines) |
|
152 { |
|
153 print (SCANLOG "\t$panic"); |
|
154 } |
|
155 } |
|
156 } |
|
157 else |
|
158 { |
|
159 if (exists $expectedPanicsHash{$file}) |
|
160 { |
|
161 print(SCANLOG "\tPanics expected but none found.\n"); |
|
162 $failed = 1; |
|
163 } |
|
164 else |
|
165 { |
|
166 print(SCANLOG "\tNo panics expected and none found.\n"); |
|
167 } |
|
168 } |
|
169 |
|
170 if ($failed) |
|
171 { |
|
172 print (SCANLOG "\tTest for $file FAILED.\n\n"); |
|
173 $failureCount++; |
|
174 } |
|
175 else |
|
176 { |
|
177 print (SCANLOG "\tTest for $file PASSED.\n\n"); |
|
178 } |
|
179 } |
|
180 |
|
181 if ($skipCount) |
|
182 { |
|
183 print (SCANLOG "\nSkipped $skipCount files ($fileCount total.)"); |
|
184 } |
|
185 my $testedCount = $fileCount - $skipCount; |
|
186 print (SCANLOG "\nTested $testedCount files.\n"); |
|
187 print (SCANLOG "$failureCount tests failed out of $testedCount \n"); |
|
188 |
|
189 close SCANLOG; |
|
190 |
|
191 # -------------------------------------------------------------------------- |
|
192 |
|
193 # Return an array of files matching a regexp in a directory |
|
194 sub getFiles($$) { |
|
195 my $dir = shift; |
|
196 my $regfiles = shift; |
|
197 my @files; |
|
198 |
|
199 if ( opendir DIR, $dir ) { |
|
200 @files = grep (/$regfiles/, readdir(DIR)); |
|
201 closedir DIR; |
|
202 } |
|
203 return @files; |
|
204 } |
|
205 |
|
206 # -------------------------------------------------------------------------- |
|
207 |
|
208 # Read the contents of a file into an array and return it |
|
209 sub ReadListFromFile ($) { |
|
210 my ($file) = @_; |
|
211 open FILE, "<$file" or die "Can't read from $file: $!"; |
|
212 my @data = <FILE>; |
|
213 close FILE; |
|
214 return @data; |
|
215 } |
|
216 |
|
217 # -------------------------------------------------------------------------- |