|
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 "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 require Algorithm::Diff; |
|
18 #ppm install Algorithm-Diff |
|
19 |
|
20 # Globle variables |
|
21 # compare result counter |
|
22 { |
|
23 $PASSCounter = 0; |
|
24 $DIFFCounter = 0; |
|
25 $MISSCounter = 0; #only existed in BaseLine directory |
|
26 $NEWADDCounter = 0; #only existed in DABS directory |
|
27 $IGNCounter = 0; # this is some case cann't using this tool to comapre |
|
28 } |
|
29 |
|
30 $GlobleisLowCases = 0; |
|
31 $CmpDetail = 0; # this is detailed compare information switch |
|
32 $ShowPassCmp = 0; # only output negtive compare result. |
|
33 $cmpResultF = "dailyregresultfile.txt"; |
|
34 my $CurrentDir = "."; |
|
35 |
|
36 sub compareBase2DABS_ReturnEmailBody |
|
37 { |
|
38 my ( $baseLineDir, $DABSResultDir,$currentpath) = @_; |
|
39 $CurrentDir = $currentpath; #save to inner pm current variable |
|
40 compareBase2DABS( $baseLineDir, $DABSResultDir); |
|
41 my $mydir = "$currentpath\\$cmpResultF"; |
|
42 print $mydir; |
|
43 my @fileArr = read_file($mydir); |
|
44 my $buf; |
|
45 foreach $item (@fileArr){ |
|
46 $buf = $buf . $item . "<br>\n";# for lotus not mail. |
|
47 } |
|
48 return $buf; |
|
49 } |
|
50 #main |
|
51 sub compareBase2DABS |
|
52 { |
|
53 my ( $baseLineDir, $DABSResultDir, $argv3, $argv4 ) = @_; |
|
54 $CurrentDir = getcwd; |
|
55 # print $argv1." VS ".$argv2."\n"; |
|
56 # my($GlobleisLowCases); |
|
57 |
|
58 |
|
59 |
|
60 if (!open( DailyRegResultOutPut, ">$cmpResultF" )) |
|
61 { |
|
62 print "open $DailyRegResultOutPut failed."; |
|
63 } |
|
64 print DailyRegResultOutPut "Start of Result compare\n"; |
|
65 |
|
66 |
|
67 compare_BaseLineFiles_with_DABSResult( $baseLineDir, $DABSResultDir ); |
|
68 checking_TestCase_no_BaseLine( $baseLineDir, $DABSResultDir ); |
|
69 |
|
70 print DailyRegResultOutPut "End of Result compare\n"; |
|
71 SummaryCounter2File(); |
|
72 close(DailyRegResultOutPut); |
|
73 } |
|
74 #main |
|
75 # gerarate the baseline dir of tef code |
|
76 # this is utility function for DABS |
|
77 sub makeBaseLineDir |
|
78 { |
|
79 my ( $device, $build ) = @_; |
|
80 my ( $device1, $build1 ); |
|
81 my ($dirResult); |
|
82 $dirResult = "\\testexecute\\Test\\baseline"; |
|
83 if ( $device =~ /arm/i ) { |
|
84 $device1 = "\\h4"; |
|
85 } |
|
86 elsif ( $device =~ /winscw/i ) { |
|
87 $device1 = "\\emulator"; |
|
88 } |
|
89 else { |
|
90 return "error_path"; |
|
91 } |
|
92 |
|
93 if ( $build =~ /urel/i ) { |
|
94 $build1 = "\\urel"; |
|
95 } |
|
96 elsif ( $build =~ /udeb/i ) { |
|
97 $build1 = "\\udeb"; |
|
98 } |
|
99 else { |
|
100 return "error_path"; |
|
101 } |
|
102 return $dirResult = |
|
103 $dirResult . $device1 . $build1; #\testexecute\Test\baseline\h4\udeb |
|
104 } |
|
105 |
|
106 sub SummaryCounter2File |
|
107 { |
|
108 my($seperator,$eol); |
|
109 $seperator = " = "; |
|
110 $eol = "\n"; |
|
111 |
|
112 print DailyRegResultOutPut $eol,"*******************" ,$eol,"Compare Summary: ",$eol; |
|
113 |
|
114 |
|
115 print DailyRegResultOutPut "Pass", $seperator, $PASSCounter,$eol; |
|
116 print DailyRegResultOutPut "Diff", $seperator, $DIFFCounter,$eol; |
|
117 print DailyRegResultOutPut "Existing only on Base Line" , $seperator, $MISSCounter,$eol; |
|
118 print DailyRegResultOutPut "Existing only on DABS", $seperator, $NEWADDCounter,$eol; |
|
119 print DailyRegResultOutPut "Needs to manual check", $seperator, $IGNCounter,$eol; |
|
120 } |
|
121 |
|
122 sub checking_TestCase_no_BaseLine { |
|
123 my ( $baseLineDir, $DABSResultDir ) = @_; |
|
124 |
|
125 # read DABS file list |
|
126 my $thisdir; |
|
127 opendir( $thisdir, $DABSResultDir ); |
|
128 my @DABSFiles = readdir($thisdir); |
|
129 closedir($thisdir); |
|
130 |
|
131 # read base file list |
|
132 opendir( $thisdir, $baseLineDir ); |
|
133 my @baseFiles = readdir($thisdir); |
|
134 closedir($thisdir); |
|
135 |
|
136 # New test case without base line |
|
137 my ( $DABSfile, $basefile ); |
|
138 |
|
139 # compare all the file name |
|
140 foreach $DABSfile (@DABSFiles) { |
|
141 if ( $DABSfile =~ /\.htm/ ) { |
|
142 my ( $i, $match ); |
|
143 for ( $i = 0, $match = 0 ; $i < @baseFiles ; $i++ ) { |
|
144 $basefile = @baseFiles[$i]; |
|
145 if ( $DABSfile eq $basefile ) { |
|
146 $match = 1; |
|
147 last; |
|
148 } |
|
149 } |
|
150 |
|
151 # the new test case file name found! |
|
152 if ( $match != 1 ) { |
|
153 print DailyRegResultOutPut |
|
154 "$DABSfile is a new test case without baseline.\n"; |
|
155 $NEWADDCounter++; |
|
156 } |
|
157 } |
|
158 |
|
159 } |
|
160 return; |
|
161 } |
|
162 |
|
163 sub compare_BaseLineFiles_with_DABSResult { |
|
164 my ( $baseLineDir, $DABSResultDir ) = @_; |
|
165 #chdir($baseLineDir) ; |
|
166 if ( !-e $baseLineDir) |
|
167 { |
|
168 print DailyRegResultOutPut |
|
169 "[Fatal Error]: Can not open $baseLineDir.\n"; |
|
170 return; |
|
171 } |
|
172 my $thisdir; |
|
173 opendir( $thisdir, $baseLineDir ); |
|
174 my @baseLineFiles = readdir($thisdir); |
|
175 closedir($thisdir); |
|
176 my $i = 0; |
|
177 my @BaseFileSet; |
|
178 my @DABSFileSet; |
|
179 |
|
180 # generate the file path |
|
181 my $count2 = 0; |
|
182 while ( $i < @baseLineFiles ) { |
|
183 if ( ( !-d @baseLineFiles[$i] ) |
|
184 && ( @baseLineFiles[$i] =~ /\.htm/ ) |
|
185 ) # (@files[$count] =~/\.htm/) to select all *.htm files |
|
186 { |
|
187 @BaseFileSet[$count2] = $baseLineDir . "\\" . "@baseLineFiles[$i]"; |
|
188 |
|
189 # print "@srcfiles[$i] \n"; |
|
190 @DABSFileSet[$count2] = |
|
191 $DABSResultDir . "\\" . "@baseLineFiles[$i]"; |
|
192 |
|
193 # print "@dstfiles[$i] \n"; |
|
194 $count2++; |
|
195 } |
|
196 $i++; |
|
197 } |
|
198 |
|
199 # file context compare |
|
200 $i = 2; #ignore .. and . files |
|
201 while ( $i < @BaseFileSet ) { |
|
202 if ( @DABSFileSet[$i] =~ /dt-tef-concurrent/ |
|
203 || @DABSFileSet[$i] =~ /dt-tef-performance-0001/ |
|
204 || @DABSFileSet[$i] =~ /dt-tef-command-line/ |
|
205 ) { |
|
206 #skip concurrent compare |
|
207 print DailyRegResultOutPut @DABSFileSet[$i], |
|
208 " compare has being ignored. Plese checke your self.\n"; |
|
209 $IGNCounter++; |
|
210 } |
|
211 elsif ( !-e @BaseFileSet[$i] ) { |
|
212 # this case will not TRUE because only baseline's file name will be compared. |
|
213 # see the upper while {....} |
|
214 print DailyRegResultOutPut |
|
215 "@BaseFileSet[$i] does not exist in baseline.\n";# is a new test case without baseline |
|
216 #baseLineFiles[$i] only contain file name. |
|
217 $NEWADDCounter++; |
|
218 } |
|
219 elsif ( !-e @DABSFileSet[$i] ) { |
|
220 print DailyRegResultOutPut |
|
221 "$DABSFileSet[$i] does not exist in DABS.\n"; |
|
222 #baseLineFiles[$i] only contain file name. |
|
223 $MISSCounter++; |
|
224 } |
|
225 else { |
|
226 FileCompare( @BaseFileSet[$i], @DABSFileSet[$i] ); |
|
227 } |
|
228 $i++; |
|
229 } |
|
230 #chang back to the orginal dir. |
|
231 chdir($CurrentDir); # don't die this fail not change |
|
232 } |
|
233 |
|
234 sub FileCompare { |
|
235 my ( $argv1, $argv2 ) = @_; |
|
236 @array1 = file_array( $argv1, $GlobleisLowCases ); |
|
237 @array2 = file_array( $argv2, $GlobleisLowCases ); |
|
238 |
|
239 # This example produces traditional 'diff' output: |
|
240 my $diff = |
|
241 Algorithm::Diff->new( \@array1, \@array2 ); # this must done in main |
|
242 my ($result); |
|
243 $result = TEF_Compare_Diff($diff); |
|
244 if ( $result == 0 ) #file diff |
|
245 { |
|
246 print DailyRegResultOutPut $argv2, " different with baseline.\n"; |
|
247 $DIFFCounter++; |
|
248 } |
|
249 else { |
|
250 if ( $ShowPassCmp == 1 ) |
|
251 { |
|
252 print DailyRegResultOutPut $argv2, " PASS\n"; |
|
253 } |
|
254 $PASSCounter++; |
|
255 } |
|
256 |
|
257 # if ( $argv4 == "-D" ) { |
|
258 # Save_Tailored_to_file( "PR1", @array1 ); |
|
259 # Save_Tailored_to_file( "PR2", @array2 ); |
|
260 # } |
|
261 |
|
262 # print @file1[0].@file2[0]; |
|
263 return; |
|
264 } |
|
265 |
|
266 sub file_array { |
|
267 my ( $filename, $isLowCase ) = @_; |
|
268 # if ($isLowCase == 1) |
|
269 # { |
|
270 # print "file_arrayisLowCases = 1"; |
|
271 # print "\n"; |
|
272 # } |
|
273 # else |
|
274 # { |
|
275 # print "file_arrayisLowCases = 0"; |
|
276 # print "\n"; |
|
277 # } |
|
278 my @readarray; |
|
279 @readarray = read_file($filename); |
|
280 return @readarray = remove_prefix_from_arrary( @readarray, $isLowCase ); |
|
281 } |
|
282 |
|
283 sub read_file { |
|
284 my ($read_file1) = @_; |
|
285 if(!open( IN1, $read_file1 ) ) |
|
286 { |
|
287 print DailyRegResultOutPut "[Fatal Error]: Can not open the $read_file1 file !\n" ; |
|
288 } |
|
289 my @content = <IN1>; |
|
290 close(IN1); |
|
291 return @content; |
|
292 } |
|
293 sub TEF_Compare_Diff { |
|
294 |
|
295 # This example produces traditional 'diff' output: |
|
296 # my $diff = Algorithm::Diff->new( \@arr1, \@arr2 ); |
|
297 |
|
298 my ($diff) = @_; |
|
299 my ($BoolSame); |
|
300 $BoolSame = 1; #file same |
|
301 $diff->Base(1); # Return line numbers, not indices |
|
302 while ( $diff->Next() ) { |
|
303 next if $diff->Same(); |
|
304 if ( $CmpDetail == 1 ) { |
|
305 my $sep = ''; |
|
306 if ( !$diff->Items(2) ) { |
|
307 printf DailyRegResultOutPut "%d,%dd%d\n", |
|
308 $diff->Get(qw( Min1 Max1 Max2 )); |
|
309 } |
|
310 elsif ( !$diff->Items(1) ) { |
|
311 printf DailyRegResultOutPut "%da%d,%d\n", |
|
312 $diff->Get(qw( Max1 Min2 Max2 )); |
|
313 } |
|
314 else { |
|
315 $sep = "---\n"; |
|
316 printf DailyRegResultOutPut "%d,%dc%d,%d\n", |
|
317 $diff->Get(qw( Min1 Max1 Min2 Max2 )); |
|
318 } |
|
319 print DailyRegResultOutPut "< $_" for $diff->Items(1); |
|
320 print DailyRegResultOutPut $sep; |
|
321 print DailyRegResultOutPut "> $_" for $diff->Items(2); |
|
322 } |
|
323 $BoolSame = 0; #file diff |
|
324 } |
|
325 return $BoolSame; |
|
326 } |
|
327 |
|
328 sub Save_Tailored_to_file { |
|
329 my ( $write_file1, @array ) = @_; |
|
330 |
|
331 if (!open( OUT, "| cat >$write_file1" ) ) |
|
332 { |
|
333 print DailyRegResultOutPut "[Fatal Error]: Can NOT open the $write_file1 file !\n" ; |
|
334 return ; |
|
335 } |
|
336 my $i = 0; |
|
337 my $item; |
|
338 while ( $i < @array ) { |
|
339 $item = @array[ $i++ ]; |
|
340 print OUT $item; |
|
341 } |
|
342 close(OUT); |
|
343 return; |
|
344 } |
|
345 |
|
346 sub output_arrary { |
|
347 my (@array) = @_; |
|
348 my $i = 0; |
|
349 while ( $i < @array ) { |
|
350 $item = @array[ $i++ ]; |
|
351 print $item ; |
|
352 } |
|
353 } |
|
354 |
|
355 sub remove_prefix_from_arrary { |
|
356 my ( @_array, $LowCase ) = @_; |
|
357 my $i = 0; |
|
358 |
|
359 my $item; |
|
360 while ( $i < @_array ) { |
|
361 $item = @_array[$i]; |
|
362 $item = remove_time_stamp($item); |
|
363 $item = remove_INFOPRINT($item); |
|
364 $item = remove_remote_panic($item); |
|
365 $item = remove_time_infomation($item); |
|
366 @_array[$i] = remove_script_linenum($item); |
|
367 |
|
368 if ( $GlobleisLowCases == 1 ) { |
|
369 @_array[$i] = lc( @_array[$i] ); |
|
370 } |
|
371 $i++; |
|
372 } |
|
373 return @_array; |
|
374 } |
|
375 |
|
376 sub remove_script_linenum { |
|
377 my ($srcstring) = @_; |
|
378 |
|
379 # search for |
|
380 # ....\dt-tef-testclient-0009.script Line = 22 Command = END_TESTCASE... |
|
381 $_ = $srcstring; |
|
382 if (/[.]*.script [Ll]ine = [\d]+ [Cc]ommand =[.]*/) { |
|
383 |
|
384 # print ":)\n"; |
|
385 $srcstring =~ |
|
386 s/[.]*.script [Ll]ine = [\d]+ [Cc]ommand =[.]*/\.script line = command =/; |
|
387 } |
|
388 return $srcstring; |
|
389 } |
|
390 |
|
391 sub remove_remote_panic { |
|
392 my ($srcstring) = @_; |
|
393 $_ = $srcstring; |
|
394 if (/[Rr]emote [Pp]anic \d/) { |
|
395 |
|
396 # print ":)\n"; |
|
397 return $srcstring = ""; # remove panic string |
|
398 } |
|
399 else { |
|
400 |
|
401 # print ":(\n"; |
|
402 return $srcstring; |
|
403 } |
|
404 } |
|
405 |
|
406 sub remove_INFOPRINT { |
|
407 my ($srcstring) = @_; |
|
408 $_ = $srcstring; |
|
409 |
|
410 # if (/(INFO|ERROR|WARN|HIGH|MEDIUM|LOW)[ ]- [0-9]+[ ][a-zA-Z0-9_-]+[.][a-zA-Z]* [0-9]+/) { |
|
411 # the file name to strict for "03:39:57:980 INFO - 2607 DIR\DIR\ 221 GetCPPModuleName" |
|
412 # "DIR\DIR\" not a legeal file name, |
|
413 # so I change the regx |
|
414 if ( |
|
415 /(INFO|ERROR|WARN|HIGH|MEDIUM|LOW)[ ]- [0-9]+[ ][a-zA-Z0-9_.-\\]* [0-9]+/ |
|
416 ) |
|
417 { |
|
418 |
|
419 # print ":)\n"; |
|
420 $srcstring =~ s/[ ]- [0-9]+[ ][a-zA-Z0-9_.-\\]* [0-9]+//; |
|
421 } |
|
422 ## now else no use. |
|
423 # else |
|
424 # { |
|
425 # print ":(\n"; |
|
426 # } |
|
427 return $srcstring; |
|
428 } |
|
429 sub remove_time_stamp { |
|
430 my ($srcstring) = @_; |
|
431 $_ = substr( $srcstring, 0, 12 ); |
|
432 |
|
433 if (/[0-9]+:[0-9]+:[0-9]+:[0-9]+/) { |
|
434 return substr( $srcstring, 12 ); |
|
435 } |
|
436 } |
|
437 sub remove_time_infomation { |
|
438 my ($srcstring) = @_; |
|
439 if ($srcstring =~ /[.]*[0-9]+\/[0-9]+\/[0-9]+ [0-9]+\:[0-9]+\:[0-9]+ [apAP][.]*/) { |
|
440 #print ":)\n"; |
|
441 $srcstring =~ s/[.]*[0-9]+\/[0-9]+\/[0-9]+ [0-9]+\:[0-9]+\:[0-9]+ [apAP][.]*/$1/; |
|
442 } |
|
443 # else |
|
444 # { |
|
445 # print ":(\n"; |
|
446 # } |
|
447 return $srcstring; |
|
448 } |
|
449 |
|
450 |
|
451 1; |