|
1 #!/usr/bin/perl |
|
2 |
|
3 # Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. |
|
4 # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
|
5 # Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com) |
|
6 # |
|
7 # Redistribution and use in source and binary forms, with or without |
|
8 # modification, are permitted provided that the following conditions |
|
9 # are met: |
|
10 # |
|
11 # 1. Redistributions of source code must retain the above copyright |
|
12 # notice, this list of conditions and the following disclaimer. |
|
13 # 2. Redistributions in binary form must reproduce the above copyright |
|
14 # notice, this list of conditions and the following disclaimer in the |
|
15 # documentation and/or other materials provided with the distribution. |
|
16 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
17 # its contributors may be used to endorse or promote products derived |
|
18 # from this software without specific prior written permission. |
|
19 # |
|
20 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
21 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
23 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
24 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
27 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
|
31 # Script to run the Web Kit Open Source Project layout tests. |
|
32 |
|
33 # Run all the tests passed in on the command line. |
|
34 # If no tests are passed, find all the .html, .shtml, .xml, .xhtml, .pl, .php (and svg) files in the test directory. |
|
35 |
|
36 # Run each text. |
|
37 # Compare against the existing file xxx-expected.txt. |
|
38 # If there is a mismatch, generate xxx-actual.txt and xxx-diffs.txt. |
|
39 |
|
40 # At the end, report: |
|
41 # the number of tests that got the expected results |
|
42 # the number of tests that ran, but did not get the expected results |
|
43 # the number of tests that failed to run |
|
44 # the number of tests that were run but had no expected results to compare against |
|
45 |
|
46 use strict; |
|
47 use warnings; |
|
48 |
|
49 use Cwd; |
|
50 use File::Basename; |
|
51 use File::Copy; |
|
52 use File::Find; |
|
53 use File::Path; |
|
54 use File::Spec; |
|
55 use File::Spec::Functions; |
|
56 use FindBin; |
|
57 use Getopt::Long; |
|
58 use IPC::Open2; |
|
59 use IPC::Open3; |
|
60 use Time::HiRes qw(time); |
|
61 |
|
62 use lib $FindBin::Bin; |
|
63 use webkitdirs; |
|
64 use POSIX; |
|
65 |
|
66 sub openDumpTool(); |
|
67 sub closeDumpTool(); |
|
68 sub dumpToolDidCrash(); |
|
69 sub closeHTTPD(); |
|
70 sub countAndPrintLeaks($$$); |
|
71 sub fileNameWithNumber($$); |
|
72 sub numericcmp($$); |
|
73 sub openHTTPDIfNeeded(); |
|
74 sub pathcmp($$); |
|
75 sub processIgnoreTests($); |
|
76 sub slowestcmp($$); |
|
77 sub splitpath($); |
|
78 sub stripExtension($); |
|
79 sub isTextOnlyTest($); |
|
80 sub expectedDirectoryForTest($;$); |
|
81 sub printFailureMessageForTest($$); |
|
82 sub toURL($); |
|
83 sub toWindowsPath($); |
|
84 sub closeCygpaths(); |
|
85 sub validateSkippedArg($$;$); |
|
86 sub htmlForExpectedAndActualResults($); |
|
87 sub deleteExpectedAndActualResults($); |
|
88 sub recordActualResultsAndDiff($$); |
|
89 sub buildPlatformHierarchy(); |
|
90 |
|
91 # Argument handling |
|
92 my $shouldCheckLeaks = ''; |
|
93 my $configuration = configuration(); |
|
94 my $guardMalloc = ''; |
|
95 my $httpdPort = 8000; |
|
96 my $httpdSSLPort = 8443; |
|
97 my $ignoreTests = ''; |
|
98 my $launchSafari = 1; |
|
99 my $platform; |
|
100 my $pixelTests = ''; |
|
101 my $quiet = ''; |
|
102 my $repaintSweepHorizontally = ''; |
|
103 my $repaintTests = ''; |
|
104 my $report10Slowest = 0; |
|
105 my $resetResults = 0; |
|
106 my $showHelp = 0; |
|
107 my $testsPerDumpTool = 1000; |
|
108 my $testHTTP = 1; |
|
109 my $testOnlySVGs = ''; |
|
110 my $testResultsDirectory = "/tmp/layout-test-results"; |
|
111 my $threaded = 0; |
|
112 my $treatSkipped = "default"; |
|
113 my $verbose = 0; |
|
114 my $useValgrind = 0; |
|
115 my $strictTesting = 0; |
|
116 my $generateNewResults = 1; |
|
117 my $stripEditingCallbacks = isCygwin(); |
|
118 my $root; |
|
119 |
|
120 my $expectedTag = "expected"; |
|
121 my $actualTag = "actual"; |
|
122 my $diffsTag = "diffs"; |
|
123 my $errorTag = "stderr"; |
|
124 |
|
125 if (isTiger()) { |
|
126 $platform = "mac-tiger"; |
|
127 } elsif (isLeopard()) { |
|
128 $platform = "mac-leopard"; |
|
129 } elsif (isOSX()) { |
|
130 $platform = "mac"; |
|
131 } elsif (isQt()) { |
|
132 $platform = "qt"; |
|
133 } elsif (isGtk()) { |
|
134 $platform = "gtk"; |
|
135 } elsif (isCygwin()) { |
|
136 $platform = "win"; |
|
137 } |
|
138 |
|
139 if (!defined($platform)) { |
|
140 print "WARNING: Your platform is not recognized. Any platform-specific results will be generated in platform/undefined.\n"; |
|
141 $platform = "undefined"; |
|
142 } |
|
143 |
|
144 my $programName = basename($0); |
|
145 my $launchSafariDefault = $launchSafari ? "launch" : "do not launch"; |
|
146 my $httpDefault = $testHTTP ? "run" : "do not run"; |
|
147 |
|
148 my $usage = <<EOF; |
|
149 Usage: $programName [options] [testdir|testpath ...] |
|
150 -c|--configuration config Set DumpRenderTree build configuration |
|
151 -g|--guard-malloc Enable malloc guard |
|
152 --help Show this help message |
|
153 -h|--horizontal-sweep Change repaint to sweep horizontally instead of vertically (implies --repaint-tests) |
|
154 --[no-]http Run (or do not run) http tests (default: $httpDefault) |
|
155 -i|--ignore-tests Comma-separated list of directories or tests to ignore |
|
156 --[no-]launch-safari Launch (or do not launch) Safari to display test results (default: $launchSafariDefault) |
|
157 -l|--leaks Enable leaks checking |
|
158 --[no-]new-test-results Generate results for new tests |
|
159 -p|--pixel-tests Enable pixel tests |
|
160 --platform Override the detected platform to use for tests and results (default: $platform) |
|
161 --port Web server port to use with http tests |
|
162 -q|--quiet Less verbose output |
|
163 -r|--repaint-tests Run repaint tests (implies --pixel-tests) |
|
164 --reset-results Reset ALL results (including pixel tests if --pixel-tests is set) |
|
165 -o|--results-directory Output results directory (default: $testResultsDirectory) |
|
166 --root Path to root tools build |
|
167 -1|--singly Isolate each test case run (implies --verbose) |
|
168 --skipped=[default|ignore|only] Specifies how to treat the Skipped file |
|
169 default: Tests/directories listed in the Skipped file are not tested |
|
170 ignore: The Skipped file is ignored |
|
171 only: Only those tests/directories listed in the Skipped file will be run |
|
172 --slowest Report the 10 slowest tests |
|
173 --strict Do a comparison with the output on Mac (Qt only) |
|
174 --[no-]strip-editing-callbacks Remove editing callbacks from expected results |
|
175 --svg Run only SVG tests (implies --pixel-tests) |
|
176 -t|--threaded Run a concurrent JavaScript thead with each test |
|
177 --valgrind Run DumpRenderTree inside valgrind (Qt/Linux only) |
|
178 -v|--verbose More verbose output (overrides --quiet) |
|
179 EOF |
|
180 |
|
181 my $getOptionsResult = GetOptions( |
|
182 'c|configuration=s' => \$configuration, |
|
183 'debug|devel' => sub { $configuration = "Debug" }, |
|
184 'guard-malloc|g' => \$guardMalloc, |
|
185 'help' => \$showHelp, |
|
186 'horizontal-sweep|h' => \$repaintSweepHorizontally, |
|
187 'http!' => \$testHTTP, |
|
188 'ignore-tests|i=s' => \$ignoreTests, |
|
189 'launch-safari!' => \$launchSafari, |
|
190 'leaks|l' => \$shouldCheckLeaks, |
|
191 'pixel-tests|p' => \$pixelTests, |
|
192 'platform=s' => \$platform, |
|
193 'port=i' => \$httpdPort, |
|
194 'quiet|q' => \$quiet, |
|
195 'release|deploy' => sub { $configuration = "Release" }, |
|
196 'repaint-tests|r' => \$repaintTests, |
|
197 'reset-results' => \$resetResults, |
|
198 'new-test-results!' => \$generateNewResults, |
|
199 'results-directory|o=s' => \$testResultsDirectory, |
|
200 'singly|1' => sub { $testsPerDumpTool = 1; }, |
|
201 'nthly=i' => \$testsPerDumpTool, |
|
202 'skipped=s' => \&validateSkippedArg, |
|
203 'slowest' => \$report10Slowest, |
|
204 'svg' => \$testOnlySVGs, |
|
205 'threaded|t' => \$threaded, |
|
206 'verbose|v' => \$verbose, |
|
207 'valgrind' => \$useValgrind, |
|
208 'strict' => \$strictTesting, |
|
209 'strip-editing-callbacks!' => \$stripEditingCallbacks, |
|
210 'root=s' => \$root, |
|
211 ); |
|
212 |
|
213 if (!$getOptionsResult || $showHelp) { |
|
214 print STDERR $usage; |
|
215 exit 1; |
|
216 } |
|
217 |
|
218 my $ignoreSkipped = $treatSkipped eq "ignore"; |
|
219 my $skippedOnly = $treatSkipped eq "only"; |
|
220 |
|
221 !$skippedOnly || @ARGV == 0 or die "--skipped=only cannot be used when tests are specified on the command line."; |
|
222 |
|
223 setConfiguration($configuration); |
|
224 |
|
225 my $configurationOption = "--" . lc($configuration); |
|
226 |
|
227 $repaintTests = 1 if $repaintSweepHorizontally; |
|
228 |
|
229 $pixelTests = 1 if $testOnlySVGs; |
|
230 $pixelTests = 1 if $repaintTests; |
|
231 |
|
232 $verbose = 1 if $testsPerDumpTool == 1; |
|
233 |
|
234 if ($shouldCheckLeaks && $testsPerDumpTool > 1000) { |
|
235 print STDERR "\nWARNING: Running more than 1000 tests at a time with MallocStackLogging enabled may cause a crash.\n\n"; |
|
236 } |
|
237 |
|
238 # Force --no-http for Qt/Linux, for now. |
|
239 $testHTTP = 0 if isQt(); |
|
240 |
|
241 setConfigurationProductDir(Cwd::abs_path($root)) if (defined($root)); |
|
242 my $productDir = productDir(); |
|
243 $productDir .= "/bin" if (isQt()); |
|
244 |
|
245 chdirWebKit(); |
|
246 |
|
247 if(!defined($root)){ |
|
248 my $buildResult; |
|
249 if (isCygwin()) { |
|
250 $buildResult = buildVisualStudioProject("WebKitTools/DumpRenderTree/DumpRenderTree.sln"); |
|
251 } else { |
|
252 # Push the parameters to build-dumprendertree as an array |
|
253 my @args; |
|
254 push(@args, $configuration); |
|
255 |
|
256 if (isQt()) { |
|
257 push(@args, "--qt"); |
|
258 } elsif (isGtk()) { |
|
259 push(@args, "--gtk"); |
|
260 } |
|
261 |
|
262 $buildResult = system "WebKitTools/Scripts/build-dumprendertree", @args; |
|
263 } |
|
264 |
|
265 if ($buildResult) { |
|
266 print STDERR "Compiling DumpRenderTree failed!\n"; |
|
267 exit WEXITSTATUS($buildResult); |
|
268 } |
|
269 } |
|
270 |
|
271 my $dumpToolName = "DumpRenderTree"; |
|
272 $dumpToolName .= "_debug" if isCygwin() && $configuration ne "Release"; |
|
273 my $dumpTool = "$productDir/$dumpToolName"; |
|
274 die "can't find executable $dumpToolName (looked in $productDir)\n" unless -x $dumpTool; |
|
275 |
|
276 my $imageDiffTool = "$productDir/ImageDiff"; |
|
277 die "can't find executable $imageDiffTool (looked in $productDir)\n" if $pixelTests && !-x $imageDiffTool; |
|
278 |
|
279 checkFrameworks() unless isCygwin(); |
|
280 |
|
281 my $layoutTestsName = "LayoutTests"; |
|
282 my $testDirectory = File::Spec->rel2abs($layoutTestsName); |
|
283 my $expectedDirectory = $testDirectory; |
|
284 my $platformBaseDirectory = catdir($testDirectory, "platform"); |
|
285 my $platformTestDirectory = catdir($platformBaseDirectory, $platform); |
|
286 my @platformHierarchy = buildPlatformHierarchy(); |
|
287 |
|
288 $expectedDirectory = $ENV{"WebKitExpectedTestResultsDirectory"} if $ENV{"WebKitExpectedTestResultsDirectory"}; |
|
289 |
|
290 if ($testOnlySVGs) { |
|
291 $testDirectory .= "/svg"; |
|
292 $expectedDirectory .= "/svg"; |
|
293 } |
|
294 |
|
295 my $testResults = catfile($testResultsDirectory, "results.html"); |
|
296 |
|
297 print "Running tests from $testDirectory\n"; |
|
298 |
|
299 my @tests = (); |
|
300 my %testType = (); |
|
301 |
|
302 system "ln", "-s", $testDirectory, "/tmp/LayoutTests" unless -x "/tmp/LayoutTests"; |
|
303 |
|
304 my %ignoredFiles = (); |
|
305 my %ignoredDirectories = map { $_ => 1 } qw(platform); |
|
306 my %ignoredLocalDirectories = map { $_ => 1 } qw(.svn _svn resources); |
|
307 my %supportedFileExtensions = map { $_ => 1 } qw(html shtml xml xhtml pl php); |
|
308 if ($testOnlySVGs) { |
|
309 %supportedFileExtensions = map { $_ => 1 } qw(svg xml); |
|
310 } elsif (checkWebCoreSVGSupport($testOnlySVGs)) { |
|
311 $supportedFileExtensions{'svg'} = 1; |
|
312 } elsif (isCygwin()) { |
|
313 # FIXME: We should fix webkitdirs.pm:hasSVGSupport() to do the correct |
|
314 # check for Windows instead of forcing this here. |
|
315 $supportedFileExtensions{'svg'} = 1; |
|
316 } else { |
|
317 $ignoredLocalDirectories{'svg'} = 1; |
|
318 } |
|
319 if (!$testHTTP) { |
|
320 $ignoredDirectories{'http'} = 1; |
|
321 } |
|
322 |
|
323 if ($ignoreTests) { |
|
324 processIgnoreTests($ignoreTests); |
|
325 } |
|
326 |
|
327 if (!$ignoreSkipped) { |
|
328 foreach my $level (@platformHierarchy) { |
|
329 if (open SKIPPED, "<", "$level/Skipped") { |
|
330 if ($verbose && !$skippedOnly) { |
|
331 my ($dir, $name) = splitpath($level); |
|
332 print "Skipped tests in $name:\n"; |
|
333 } |
|
334 |
|
335 while (<SKIPPED>) { |
|
336 my $skipped = $_; |
|
337 chomp $skipped; |
|
338 $skipped =~ s/^[ \n\r]+//; |
|
339 $skipped =~ s/[ \n\r]+$//; |
|
340 if ($skipped && $skipped !~ /^#/) { |
|
341 if ($skippedOnly) { |
|
342 push(@ARGV, $skipped); |
|
343 } else { |
|
344 if ($verbose) { |
|
345 print " $skipped\n"; |
|
346 } |
|
347 processIgnoreTests($skipped); |
|
348 } |
|
349 } |
|
350 } |
|
351 close SKIPPED; |
|
352 } |
|
353 } |
|
354 } |
|
355 |
|
356 |
|
357 my $directoryFilter = sub { |
|
358 return () if exists $ignoredLocalDirectories{basename($File::Find::dir)}; |
|
359 return () if exists $ignoredDirectories{File::Spec->abs2rel($File::Find::dir, $testDirectory)}; |
|
360 return @_; |
|
361 }; |
|
362 |
|
363 my $fileFilter = sub { |
|
364 my $filename = $_; |
|
365 if ($filename =~ /\.([^.]+)$/) { |
|
366 if (exists $supportedFileExtensions{$1}) { |
|
367 my $path = File::Spec->abs2rel(catfile($File::Find::dir, $filename), $testDirectory); |
|
368 push @tests, $path if !exists $ignoredFiles{$path}; |
|
369 } |
|
370 } |
|
371 }; |
|
372 |
|
373 for my $test (@ARGV) { |
|
374 $test =~ s/^($layoutTestsName|$testDirectory)\///; |
|
375 my $fullPath = catfile($testDirectory, $test); |
|
376 if (file_name_is_absolute($test)) { |
|
377 print "can't run test $test outside $testDirectory\n"; |
|
378 } elsif (-f $fullPath) { |
|
379 my ($filename, $pathname, $fileExtension) = fileparse($test, qr{\.[^.]+$}); |
|
380 if (!exists $supportedFileExtensions{substr($fileExtension, 1)}) { |
|
381 print "test $test does not have a supported extension\n"; |
|
382 } elsif ($testHTTP || $pathname !~ /^http\//) { |
|
383 push @tests, $test; |
|
384 } |
|
385 } elsif (-d $fullPath) { |
|
386 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $fullPath); |
|
387 |
|
388 for my $level (@platformHierarchy) { |
|
389 my $platformPath = catfile($level, $test); |
|
390 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $platformPath) if (-d $platformPath); |
|
391 } |
|
392 } else { |
|
393 print "test $test not found\n"; |
|
394 } |
|
395 } |
|
396 if (!scalar @ARGV) { |
|
397 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $testDirectory); |
|
398 |
|
399 for my $level (@platformHierarchy) { |
|
400 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $level); |
|
401 } |
|
402 } |
|
403 |
|
404 die "no tests to run\n" if !@tests; |
|
405 |
|
406 @tests = sort pathcmp @tests; |
|
407 |
|
408 my %counts; |
|
409 my %tests; |
|
410 my %imagesPresent; |
|
411 my %durations; |
|
412 my $count = 0; |
|
413 my $leaksOutputFileNumber = 1; |
|
414 my $totalLeaks = 0; |
|
415 |
|
416 my @toolArgs = (); |
|
417 push @toolArgs, "--dump-all-pixels" if $pixelTests && $resetResults; |
|
418 push @toolArgs, "--pixel-tests" if $pixelTests; |
|
419 push @toolArgs, "--repaint" if $repaintTests; |
|
420 push @toolArgs, "--horizontal-sweep" if $repaintSweepHorizontally; |
|
421 push @toolArgs, "--threaded" if $threaded; |
|
422 push @toolArgs, "--paint" if $shouldCheckLeaks; # Otherwise, DRT won't exercise painting leaks. |
|
423 push @toolArgs, "-"; |
|
424 |
|
425 $| = 1; |
|
426 |
|
427 my $imageDiffToolPID; |
|
428 if ($pixelTests) { |
|
429 local %ENV; |
|
430 $ENV{MallocStackLogging} = 1 if $shouldCheckLeaks; |
|
431 $imageDiffToolPID = open2(\*DIFFIN, \*DIFFOUT, $imageDiffTool, "") or die "unable to open $imageDiffTool\n"; |
|
432 } |
|
433 |
|
434 my $dumpToolPID; |
|
435 my $isDumpToolOpen = 0; |
|
436 my $dumpToolCrashed = 0; |
|
437 |
|
438 my $atLineStart = 1; |
|
439 my $lastDirectory = ""; |
|
440 |
|
441 my $isHttpdOpen = 0; |
|
442 |
|
443 sub catch_pipe { $dumpToolCrashed = 1; } |
|
444 $SIG{"PIPE"} = "catch_pipe"; |
|
445 |
|
446 print "Testing ", scalar @tests, " test cases.\n"; |
|
447 my $overallStartTime = time; |
|
448 |
|
449 for my $test (@tests) { |
|
450 next if $test eq 'results.html'; |
|
451 |
|
452 openDumpTool(); |
|
453 |
|
454 my $base = stripExtension($test); |
|
455 |
|
456 if ($verbose) { |
|
457 print "running $test -> "; |
|
458 $atLineStart = 0; |
|
459 } elsif (!$quiet) { |
|
460 my $dir = $base; |
|
461 $dir =~ s|/[^/]+$||; |
|
462 if ($dir ne $lastDirectory) { |
|
463 print "\n" unless $atLineStart; |
|
464 print "$dir "; |
|
465 $lastDirectory = $dir; |
|
466 } |
|
467 print "."; |
|
468 $atLineStart = 0; |
|
469 } |
|
470 |
|
471 my $result; |
|
472 |
|
473 my $startTime = time if $report10Slowest; |
|
474 |
|
475 if ($test !~ /^http\//) { |
|
476 my $testPath = "$testDirectory/$test"; |
|
477 if (isCygwin()) { |
|
478 $testPath = toWindowsPath($testPath); |
|
479 } else { |
|
480 $testPath = canonpath($testPath); |
|
481 } |
|
482 print OUT "$testPath\n"; |
|
483 } else { |
|
484 openHTTPDIfNeeded(); |
|
485 if ($test !~ /^http\/tests\/local\// && $test !~ /^http\/tests\/ssl\//) { |
|
486 my $path = canonpath($test); |
|
487 $path =~ s/^http\/tests\///; |
|
488 print OUT "http://127.0.0.1:$httpdPort/$path\n"; |
|
489 } elsif ($test =~ /^http\/tests\/ssl\//) { |
|
490 my $path = canonpath($test); |
|
491 $path =~ s/^http\/tests\///; |
|
492 print OUT "https://127.0.0.1:$httpdSSLPort/$path\n"; |
|
493 } else { |
|
494 my $testPath = "$testDirectory/$test"; |
|
495 if (isCygwin()) { |
|
496 $testPath = toWindowsPath($testPath); |
|
497 } |
|
498 else { |
|
499 $testPath = canonpath($testPath); |
|
500 } |
|
501 print OUT "$testPath\n"; |
|
502 } |
|
503 } |
|
504 |
|
505 my $actual = ""; |
|
506 while (<IN>) { |
|
507 last if /#EOF/; |
|
508 $actual .= $_; |
|
509 } |
|
510 $actual =~ s/\r//g if isCygwin(); |
|
511 |
|
512 my $isText = isTextOnlyTest($actual); |
|
513 |
|
514 $durations{$test} = time - $startTime if $report10Slowest; |
|
515 |
|
516 my $expected; |
|
517 my $expectedDir = expectedDirectoryForTest($base, $isText); |
|
518 |
|
519 if (!$resetResults && open EXPECTED, "<", "$expectedDir/$base-$expectedTag.txt") { |
|
520 $expected = ""; |
|
521 while (<EXPECTED>) { |
|
522 next if $stripEditingCallbacks && $_ =~ /^EDITING DELEGATE:/; |
|
523 $expected .= $_; |
|
524 } |
|
525 close EXPECTED; |
|
526 } |
|
527 my $expectedMac; |
|
528 if (!isOSX() && $strictTesting && !$isText) { |
|
529 if (!$resetResults && open EXPECTED, "<", "$testDirectory/platform/mac/$base-$expectedTag.txt") { |
|
530 $expectedMac = ""; |
|
531 while (<EXPECTED>) { |
|
532 $expectedMac .= $_; |
|
533 } |
|
534 close EXPECTED; |
|
535 } |
|
536 } |
|
537 |
|
538 if ($shouldCheckLeaks && $testsPerDumpTool == 1) { |
|
539 print " $test -> "; |
|
540 } |
|
541 |
|
542 my $actualPNG = ""; |
|
543 my $diffPNG = ""; |
|
544 my $diffPercentage = ""; |
|
545 my $diffResult = "passed"; |
|
546 |
|
547 if ($pixelTests) { |
|
548 my $actualHash = ""; |
|
549 my $expectedHash = ""; |
|
550 my $actualPNGSize = 0; |
|
551 |
|
552 while (<IN>) { |
|
553 last if /#EOF/; |
|
554 if (/ActualHash: ([a-f0-9]{32})/) { |
|
555 $actualHash = $1; |
|
556 } elsif (/BaselineHash: ([a-f0-9]{32})/) { |
|
557 $expectedHash = $1; |
|
558 } elsif (/Content-length: (\d+)\s*/) { |
|
559 $actualPNGSize = $1; |
|
560 read(IN, $actualPNG, $actualPNGSize); |
|
561 } |
|
562 } |
|
563 |
|
564 if ($expectedHash ne $actualHash && -f "$expectedDir/$base-$expectedTag.png") { |
|
565 my $expectedPNGSize = -s "$expectedDir/$base-$expectedTag.png"; |
|
566 my $expectedPNG = ""; |
|
567 open EXPECTEDPNG, "$expectedDir/$base-$expectedTag.png"; |
|
568 read(EXPECTEDPNG, $expectedPNG, $expectedPNGSize); |
|
569 |
|
570 print DIFFOUT "Content-length: $actualPNGSize\n"; |
|
571 print DIFFOUT $actualPNG; |
|
572 |
|
573 print DIFFOUT "Content-length: $expectedPNGSize\n"; |
|
574 print DIFFOUT $expectedPNG; |
|
575 |
|
576 while (<DIFFIN>) { |
|
577 last if /^error/ || /^diff:/; |
|
578 if (/Content-length: (\d+)\s*/) { |
|
579 read(DIFFIN, $diffPNG, $1); |
|
580 } |
|
581 } |
|
582 |
|
583 if (/^diff: (.+)% (passed|failed)/) { |
|
584 $diffPercentage = $1; |
|
585 $diffResult = $2; |
|
586 } |
|
587 } |
|
588 |
|
589 if ($actualPNGSize && ($resetResults || !-f "$expectedDir/$base-$expectedTag.png")) { |
|
590 mkpath(catfile($expectedDir, dirname($base))) if $testDirectory ne $expectedDir; |
|
591 open EXPECTED, ">", "$expectedDir/$base-expected.png" or die "could not create $expectedDir/$base-expected.png\n"; |
|
592 print EXPECTED $actualPNG; |
|
593 close EXPECTED; |
|
594 } |
|
595 |
|
596 # update the expected hash if the image diff said that there was no difference |
|
597 if ($actualHash ne "" && ($resetResults || !-f "$expectedDir/$base-$expectedTag.checksum")) { |
|
598 open EXPECTED, ">", "$expectedDir/$base-$expectedTag.checksum" or die "could not create $expectedDir/$base-$expectedTag.checksum\n"; |
|
599 print EXPECTED $actualHash; |
|
600 close EXPECTED; |
|
601 } |
|
602 } |
|
603 |
|
604 if (!isOSX() && $strictTesting && !$isText) { |
|
605 if (defined $expectedMac) { |
|
606 my $simplified_actual; |
|
607 $simplified_actual = $actual; |
|
608 $simplified_actual =~ s/at \(-?[0-9]+,-?[0-9]+\) *//g; |
|
609 $simplified_actual =~ s/size -?[0-9]+x-?[0-9]+ *//g; |
|
610 $simplified_actual =~ s/text run width -?[0-9]+: //g; |
|
611 $simplified_actual =~ s/text run width -?[0-9]+ [a-zA-Z ]+: //g; |
|
612 $simplified_actual =~ s/RenderButton {BUTTON} .*/RenderButton {BUTTON}/g; |
|
613 $simplified_actual =~ s/RenderImage {INPUT} .*/RenderImage {INPUT}/g; |
|
614 $simplified_actual =~ s/RenderBlock {INPUT} .*/RenderBlock {INPUT}/g; |
|
615 $simplified_actual =~ s/RenderTextControl {INPUT} .*/RenderTextControl {INPUT}/g; |
|
616 $simplified_actual =~ s/\([0-9]+px/px/g; |
|
617 $simplified_actual =~ s/ *" *\n +" */ /g; |
|
618 $simplified_actual =~ s/" +$/"/g; |
|
619 |
|
620 $simplified_actual =~ s/- /-/g; |
|
621 $simplified_actual =~ s/\n( *)"\s+/\n$1"/g; |
|
622 $simplified_actual =~ s/\s+"\n/"\n/g; |
|
623 |
|
624 $expectedMac =~ s/at \(-?[0-9]+,-?[0-9]+\) *//g; |
|
625 $expectedMac =~ s/size -?[0-9]+x-?[0-9]+ *//g; |
|
626 $expectedMac =~ s/text run width -?[0-9]+: //g; |
|
627 $expectedMac =~ s/text run width -?[0-9]+ [a-zA-Z ]+: //g; |
|
628 $expectedMac =~ s/RenderButton {BUTTON} .*/RenderButton {BUTTON}/g; |
|
629 $expectedMac =~ s/RenderImage {INPUT} .*/RenderImage {INPUT}/g; |
|
630 $expectedMac =~ s/RenderBlock {INPUT} .*/RenderBlock {INPUT}/g; |
|
631 $expectedMac =~ s/RenderTextControl {INPUT} .*/RenderTextControl {INPUT}/g; |
|
632 $expectedMac =~ s/\([0-9]+px/px/g; |
|
633 $expectedMac =~ s/ *" *\n +" */ /g; |
|
634 $expectedMac =~ s/" +$/"/g; |
|
635 |
|
636 $expectedMac =~ s/- /-/g; |
|
637 $expectedMac =~ s/\n( *)"\s+/\n$1"/g; |
|
638 $expectedMac =~ s/\s+"\n/"\n/g; |
|
639 |
|
640 if ($simplified_actual ne $expectedMac) { |
|
641 open ACTUAL, ">", "/tmp/actual.txt" or die; |
|
642 print ACTUAL $simplified_actual; |
|
643 close ACTUAL; |
|
644 open ACTUAL, ">", "/tmp/expected.txt" or die; |
|
645 print ACTUAL $expectedMac; |
|
646 close ACTUAL; |
|
647 system "diff -u \"/tmp/expected.txt\" \"/tmp/actual.txt\" > \"/tmp/simplified.diff\""; |
|
648 |
|
649 $diffResult = "failed"; |
|
650 if($verbose) { |
|
651 print "\n"; |
|
652 system "cat /tmp/simplified.diff"; |
|
653 print "failed!!!!!"; |
|
654 } |
|
655 } |
|
656 } |
|
657 } |
|
658 |
|
659 if (dumpToolDidCrash()) { |
|
660 $result = "crash"; |
|
661 |
|
662 printFailureMessageForTest($test, "crashed"); |
|
663 |
|
664 my $dir = "$testResultsDirectory/$base"; |
|
665 $dir =~ s|/([^/]+)$|| or die "Failed to find test name from base\n"; |
|
666 mkpath $dir; |
|
667 |
|
668 deleteExpectedAndActualResults($base); |
|
669 |
|
670 open CRASH, ">", "$testResultsDirectory/$base-$errorTag.txt" or die; |
|
671 print CRASH <ERROR>; |
|
672 close CRASH; |
|
673 |
|
674 recordActualResultsAndDiff($base, $actual); |
|
675 |
|
676 closeDumpTool(); |
|
677 } elsif (!defined $expected) { |
|
678 if ($verbose) { |
|
679 print "new " . ($resetResults ? "result" : "test") ."\n"; |
|
680 $atLineStart = 1; |
|
681 } |
|
682 $result = "new"; |
|
683 |
|
684 if ($generateNewResults || $resetResults) { |
|
685 # Create the path if needed |
|
686 mkpath(catfile($expectedDir, dirname($base))) if $testDirectory ne $expectedDir; |
|
687 |
|
688 open EXPECTED, ">", "$expectedDir/$base-$expectedTag.txt" or die "could not create $expectedDir/$base-$expectedTag.txt\n"; |
|
689 print EXPECTED $actual; |
|
690 close EXPECTED; |
|
691 } |
|
692 deleteExpectedAndActualResults($base); |
|
693 unless ($resetResults) { |
|
694 # Always print the file name for new tests, as they will probably need some manual inspection. |
|
695 # in verbose mode we already printed the test case, so no need to do it again. |
|
696 unless ($verbose) { |
|
697 print "\n" unless $atLineStart; |
|
698 print "$test -> "; |
|
699 } |
|
700 my $resultsDir = catdir($expectedDir, dirname($base)); |
|
701 print "new (results generated in $resultsDir)\n"; |
|
702 $atLineStart = 1; |
|
703 } |
|
704 } elsif ($actual eq $expected && $diffResult eq "passed") { |
|
705 if ($verbose) { |
|
706 print "succeeded\n"; |
|
707 $atLineStart = 1; |
|
708 } |
|
709 $result = "match"; |
|
710 deleteExpectedAndActualResults($base); |
|
711 } else { |
|
712 $result = "mismatch"; |
|
713 |
|
714 printFailureMessageForTest($test, $actual eq $expected ? "pixel test failed" : "failed"); |
|
715 |
|
716 my $dir = "$testResultsDirectory/$base"; |
|
717 $dir =~ s|/([^/]+)$|| or die "Failed to find test name from base\n"; |
|
718 my $testName = $1; |
|
719 mkpath $dir; |
|
720 |
|
721 deleteExpectedAndActualResults($base); |
|
722 recordActualResultsAndDiff($base, $actual); |
|
723 |
|
724 if ($pixelTests && $diffPNG && $diffPNG ne "") { |
|
725 $imagesPresent{$base} = 1; |
|
726 |
|
727 open ACTUAL, ">", "$testResultsDirectory/$base-$actualTag.png" or die; |
|
728 print ACTUAL $actualPNG; |
|
729 close ACTUAL; |
|
730 |
|
731 open DIFF, ">", "$testResultsDirectory/$base-$diffsTag.png" or die; |
|
732 print DIFF $diffPNG; |
|
733 close DIFF; |
|
734 |
|
735 copy("$expectedDir/$base-$expectedTag.png", "$testResultsDirectory/$base-$expectedTag.png"); |
|
736 |
|
737 open DIFFHTML, ">$testResultsDirectory/$base-$diffsTag.html" or die; |
|
738 print DIFFHTML "<html>\n"; |
|
739 print DIFFHTML "<head>\n"; |
|
740 print DIFFHTML "<title>$base Image Compare</title>\n"; |
|
741 print DIFFHTML "<script language=\"Javascript\" type=\"text/javascript\">\n"; |
|
742 print DIFFHTML "var currentImage = 0;\n"; |
|
743 print DIFFHTML "var imageNames = new Array(\"Actual\", \"Expected\");\n"; |
|
744 print DIFFHTML "var imagePaths = new Array(\"$testName-$actualTag.png\", \"$testName-$expectedTag.png\");\n"; |
|
745 if (-f "$testDirectory/$base-w3c.png") { |
|
746 copy("$testDirectory/$base-w3c.png", "$testResultsDirectory/$base-w3c.png"); |
|
747 print DIFFHTML "imageNames.push(\"W3C\");\n"; |
|
748 print DIFFHTML "imagePaths.push(\"$testName-w3c.png\");\n"; |
|
749 } |
|
750 print DIFFHTML "function animateImage() {\n"; |
|
751 print DIFFHTML " var image = document.getElementById(\"animatedImage\");\n"; |
|
752 print DIFFHTML " var imageText = document.getElementById(\"imageText\");\n"; |
|
753 print DIFFHTML " image.src = imagePaths[currentImage];\n"; |
|
754 print DIFFHTML " imageText.innerHTML = imageNames[currentImage] + \" Image\";\n"; |
|
755 print DIFFHTML " currentImage = (currentImage + 1) % imageNames.length;\n"; |
|
756 print DIFFHTML " setTimeout('animateImage()',2000);\n"; |
|
757 print DIFFHTML "}\n"; |
|
758 print DIFFHTML "</script>\n"; |
|
759 print DIFFHTML "</head>\n"; |
|
760 print DIFFHTML "<body onLoad=\"animateImage();\">\n"; |
|
761 print DIFFHTML "<table>\n"; |
|
762 if ($diffPercentage) { |
|
763 print DIFFHTML "<tr>\n"; |
|
764 print DIFFHTML "<td>Difference between images: <a href=\"$testName-$diffsTag.png\">$diffPercentage%</a></td>\n"; |
|
765 print DIFFHTML "</tr>\n"; |
|
766 } |
|
767 print DIFFHTML "<tr>\n"; |
|
768 print DIFFHTML "<td id=\"imageText\" style=\"text-weight: bold;\">Actual Image</td>\n"; |
|
769 print DIFFHTML "</tr>\n"; |
|
770 print DIFFHTML "<tr>\n"; |
|
771 print DIFFHTML "<td><img src=\"$testName-$actualTag.png\" id=\"animatedImage\"></td>\n"; |
|
772 print DIFFHTML "</tr>\n"; |
|
773 print DIFFHTML "</table>\n"; |
|
774 print DIFFHTML "</body>\n"; |
|
775 print DIFFHTML "</html>\n"; |
|
776 } |
|
777 } |
|
778 |
|
779 if (($count + 1) % $testsPerDumpTool == 0 || $count == $#tests) { |
|
780 if ($shouldCheckLeaks) { |
|
781 my $fileName; |
|
782 if ($testsPerDumpTool == 1) { |
|
783 $fileName = "$testResultsDirectory/$base-leaks.txt"; |
|
784 } else { |
|
785 $fileName = "$testResultsDirectory/" . fileNameWithNumber($dumpToolName, $leaksOutputFileNumber) . "-leaks.txt"; |
|
786 } |
|
787 my $leakCount = countAndPrintLeaks($dumpToolName, $dumpToolPID, $fileName); |
|
788 $totalLeaks += $leakCount; |
|
789 $leaksOutputFileNumber++ if ($leakCount); |
|
790 } |
|
791 |
|
792 closeDumpTool(); |
|
793 } |
|
794 |
|
795 $count++; |
|
796 $counts{$result}++; |
|
797 push @{$tests{$result}}, $test; |
|
798 $testType{$test} = $isText; |
|
799 } |
|
800 printf "\n%0.2fs total testing time\n", (time - $overallStartTime) . ""; |
|
801 |
|
802 !$isDumpToolOpen || die "Failed to close $dumpToolName.\n"; |
|
803 |
|
804 closeHTTPD(); |
|
805 |
|
806 # Because multiple instances of this script are running concurrently we cannot |
|
807 # safely delete this symlink. |
|
808 # system "rm /tmp/LayoutTests"; |
|
809 |
|
810 # FIXME: Do we really want to check the image-comparison tool for leaks every time? |
|
811 if ($shouldCheckLeaks && $pixelTests) { |
|
812 $totalLeaks += countAndPrintLeaks("ImageDiff", $imageDiffToolPID, "$testResultsDirectory/ImageDiff-leaks.txt"); |
|
813 } |
|
814 |
|
815 if ($totalLeaks) { |
|
816 print "\nWARNING: $totalLeaks total leaks found!\n"; |
|
817 print "See above for individual leaks results.\n" if ($leaksOutputFileNumber > 2); |
|
818 } |
|
819 |
|
820 close IN; |
|
821 close OUT; |
|
822 close ERROR; |
|
823 |
|
824 if ($report10Slowest) { |
|
825 print "\n\nThe 10 slowest tests:\n\n"; |
|
826 my $count = 0; |
|
827 for my $test (sort slowestcmp keys %durations) { |
|
828 printf "%0.2f secs: %s\n", $durations{$test}, $test; |
|
829 last if ++$count == 10; |
|
830 } |
|
831 } |
|
832 |
|
833 print "\n"; |
|
834 |
|
835 if ($skippedOnly && $counts{"match"}) { |
|
836 print "The following tests are in the Skipped file (" . File::Spec->abs2rel("$platformTestDirectory/Skipped", $testDirectory) . "), but succeeded:\n"; |
|
837 foreach my $test (@{$tests{"match"}}) { |
|
838 print " $test\n"; |
|
839 } |
|
840 } |
|
841 |
|
842 if ($resetResults || ($counts{match} && $counts{match} == $count)) { |
|
843 print "all $count test cases succeeded\n"; |
|
844 unlink $testResults; |
|
845 exit; |
|
846 } |
|
847 |
|
848 |
|
849 my %text = ( |
|
850 match => "succeeded", |
|
851 mismatch => "had incorrect layout", |
|
852 new => "were new", |
|
853 crash => "crashed", |
|
854 ); |
|
855 |
|
856 for my $type ("match", "mismatch", "new", "crash") { |
|
857 my $c = $counts{$type}; |
|
858 if ($c) { |
|
859 my $t = $text{$type}; |
|
860 my $message; |
|
861 if ($c == 1) { |
|
862 $t =~ s/were/was/; |
|
863 $message = sprintf "1 test case (%d%%) %s\n", 1 * 100 / $count, $t; |
|
864 } else { |
|
865 $message = sprintf "%d test cases (%d%%) %s\n", $c, $c * 100 / $count, $t; |
|
866 } |
|
867 $message =~ s-\(0%\)-(<1%)-; |
|
868 print $message; |
|
869 } |
|
870 } |
|
871 |
|
872 mkpath $testResultsDirectory; |
|
873 |
|
874 open HTML, ">", $testResults or die; |
|
875 print HTML "<html>\n"; |
|
876 print HTML "<head>\n"; |
|
877 print HTML "<title>Layout Test Results</title>\n"; |
|
878 print HTML "</head>\n"; |
|
879 print HTML "<body>\n"; |
|
880 |
|
881 if ($counts{mismatch}) { |
|
882 print HTML "<p>Tests where results did not match expected results:</p>\n"; |
|
883 print HTML "<table>\n"; |
|
884 for my $test (@{$tests{mismatch}}) { |
|
885 my $base = stripExtension($test); |
|
886 print HTML "<tr>\n"; |
|
887 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$test</a></td>\n"; |
|
888 print HTML htmlForExpectedAndActualResults($base); |
|
889 if ($pixelTests) { |
|
890 if ($imagesPresent{$base}) { |
|
891 print HTML "<td><a href=\"$base-$expectedTag.png\">expected image</a></td>\n"; |
|
892 print HTML "<td><a href=\"$base-$diffsTag.html\">image diffs</a></td>\n"; |
|
893 } else { |
|
894 print HTML "<td></td><td></td>\n"; |
|
895 } |
|
896 } |
|
897 print HTML "</tr>\n"; |
|
898 } |
|
899 print HTML "</table>\n"; |
|
900 } |
|
901 |
|
902 if ($counts{crash}) { |
|
903 print HTML "<p>Tests that caused the DumpRenderTree tool to crash:</p>\n"; |
|
904 print HTML "<table>\n"; |
|
905 for my $test (@{$tests{crash}}) { |
|
906 my $base = stripExtension($test); |
|
907 my $expectedDir = expectedDirectoryForTest($base); |
|
908 print HTML "<tr>\n"; |
|
909 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$base</a></td>\n"; |
|
910 print HTML htmlForExpectedAndActualResults($base); |
|
911 print HTML "<td><a href=\"$base-$errorTag.txt\">stderr</a></td>\n"; |
|
912 print HTML "</tr>\n"; |
|
913 } |
|
914 print HTML "</table>\n"; |
|
915 } |
|
916 |
|
917 if ($counts{new}) { |
|
918 print HTML "<p>Tests that had no expected results (probably new):</p>\n"; |
|
919 print HTML "<table>\n"; |
|
920 for my $test (@{$tests{new}}) { |
|
921 my $base = stripExtension($test); |
|
922 my $expectedDir = expectedDirectoryForTest($base); |
|
923 print HTML "<tr>\n"; |
|
924 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$base</a></td>\n"; |
|
925 print HTML "<td><a href=\"" . toURL("$expectedDir/$base-$expectedTag.txt") . "\">results</a></td>\n"; |
|
926 if ($pixelTests && -f "$expectedDir/$base-$expectedTag.png") { |
|
927 print HTML "<td><a href=\"" . toURL("$expectedDir/$base-$expectedTag.png") . "\">image</a></td>\n"; |
|
928 } |
|
929 print HTML "</tr>\n"; |
|
930 } |
|
931 print HTML "</table>\n"; |
|
932 } |
|
933 |
|
934 print HTML "</body>\n"; |
|
935 print HTML "</html>\n"; |
|
936 close HTML; |
|
937 |
|
938 if(isQt()) { |
|
939 system "konqueror", $testResults if $launchSafari; |
|
940 } elsif (isCygwin()) { |
|
941 system "cygstart", $testResults if $launchSafari; |
|
942 } else { |
|
943 system "WebKitTools/Scripts/run-safari", $configurationOption, "-NSOpen", $testResults if $launchSafari; |
|
944 } |
|
945 |
|
946 closeCygpaths() if isCygwin(); |
|
947 |
|
948 exit 1; |
|
949 |
|
950 sub countAndPrintLeaks($$$) |
|
951 { |
|
952 my ($dumpToolName, $dumpToolPID, $leaksFilePath) = @_; |
|
953 |
|
954 print "\n" unless $atLineStart; |
|
955 $atLineStart = 1; |
|
956 |
|
957 # We are excluding the following reported leaks so they don't get in our way when looking for WebKit leaks: |
|
958 |
|
959 my @typesToExclude = ( |
|
960 ); |
|
961 |
|
962 # callStacksToExclude is a list of strings that if are ever seen in a leaks call stack are ignored by this |
|
963 # script and not reported as leaks. This allows us ignore known leaks and only be alerted when new leaks occur. |
|
964 # Some leaks are in the old versions of the system frameworks that are being used by the leaks bots. Even though |
|
965 # the leak has been fixed, they will be listed here until the bot has been updated with the newer frameworks. |
|
966 my @callStacksToExclude = ( |
|
967 "Flash_EnforceLocalSecurity" # leaks in Flash plug-in code, Radar 4449747 |
|
968 ); |
|
969 |
|
970 # Leak list for the version of Tiger used on the build bot. |
|
971 if (isTiger()) { |
|
972 push @callStacksToExclude, ( |
|
973 "CFRunLoopRunSpecific \\| malloc_zone_malloc", "CFRunLoopRunSpecific \\| CFAllocatorAllocate ", # leak in CFRunLoopRunSpecific, Radar 4670839 |
|
974 "CGImageSourceGetPropertiesAtIndex", # leak in ImageIO, Radar 4628809 |
|
975 "FOGetCoveredUnicodeChars", # leak in ATS, Radar 3943604 |
|
976 "GetLineDirectionPreference", "InitUnicodeUtilities", # leaks tool falsely reporting leak in CFNotificationCenterAddObserver, Radar 4964790 |
|
977 "ICCFPrefWrapper::GetPrefDictionary", # leaks in Internet Config. code, Radar 4449794 |
|
978 "NSHTTPURLProtocol setResponseHeader:", # leak in multipart/mixed-replace handling in Foundation, no Radar, but fixed in Leopard |
|
979 "NSURLCache cachedResponseForRequest", # leak in CFURL cache, Radar 4768430 |
|
980 "PCFragPrepareClosureFromFile", # leak in Code Fragment Manager, Radar 3426998 |
|
981 "WebCore::Selection::toRange", # bug in 'leaks', Radar 4967949 |
|
982 "WebCore::SubresourceLoader::create", # bug in 'leaks', Radar 4985806 |
|
983 "_CFPreferencesDomainDeepCopyDictionary", # leak in CFPreferences, Radar 4220786 |
|
984 "_objc_msgForward", # leak in NSSpellChecker, Radar 4965278 |
|
985 "gldGetString" # leak in OpenGL, Radar 5013699 |
|
986 ); |
|
987 push @typesToExclude, ( |
|
988 "THRD", # bug in 'leaks', Radar 3387783 |
|
989 "DRHT" # ditto (endian little hate i) |
|
990 ); |
|
991 } |
|
992 |
|
993 # Leak list for the version of Leopard used on the build bot. |
|
994 if (isLeopard()) { |
|
995 push @callStacksToExclude, ( |
|
996 "CFHTTPMessageAppendBytes", #rdar://problem/5435912 47 leaks possibly under CFHTTPMessageAppendBytes |
|
997 "sendDidReceiveDataCallback", #<rdar://problem/5441619> 7 possible leaks under sendDidReceiveDataCallback |
|
998 "_CFHTTPReadStreamReadMark", #<rdar://problem/5441468> 2 leaks in _CFHTTPReadStreamReadMark |
|
999 "httpProtocolStart", #<rdar://problem/5468837> REGRESSION: 18 leaks in httpProtocolStart |
|
1000 "_CFURLConnectionSendCallbacks", #<rdar://problem/5441600> 3 leaks under _CFURLConnectionSendCallbacks potentially in |
|
1001 "SSLHandshake", #Unsure of the beg number, althout I think one existed and this leak is not on the current version of Leopard |
|
1002 ); |
|
1003 } |
|
1004 |
|
1005 my $leaksTool = sourceDir() . "/WebKitTools/Scripts/run-leaks"; |
|
1006 my $excludeString = "--exclude-callstack '" . (join "' --exclude-callstack '", @callStacksToExclude) . "'"; |
|
1007 $excludeString .= " --exclude-type '" . (join "' --exclude-type '", @typesToExclude) . "'" if @typesToExclude; |
|
1008 |
|
1009 print " ? checking for leaks in $dumpToolName\n"; |
|
1010 my $leaksOutput = `$leaksTool $excludeString $dumpToolPID`; |
|
1011 my ($count, $bytes) = $leaksOutput =~ /Process $dumpToolPID: (\d+) leaks? for (\d+) total/; |
|
1012 my ($excluded) = $leaksOutput =~ /(\d+) leaks? excluded/; |
|
1013 |
|
1014 my $adjustedCount = $count; |
|
1015 $adjustedCount -= $excluded if $excluded; |
|
1016 |
|
1017 if (!$adjustedCount) { |
|
1018 print " - no leaks found\n"; |
|
1019 unlink $leaksFilePath; |
|
1020 return 0; |
|
1021 } else { |
|
1022 my $dir = $leaksFilePath; |
|
1023 $dir =~ s|/[^/]+$|| or die; |
|
1024 mkpath $dir; |
|
1025 |
|
1026 if ($excluded) { |
|
1027 print " + $adjustedCount leaks ($bytes bytes including $excluded excluded leaks) were found, details in $leaksFilePath\n"; |
|
1028 } else { |
|
1029 print " + $count leaks ($bytes bytes) were found, details in $leaksFilePath\n"; |
|
1030 } |
|
1031 |
|
1032 open LEAKS, ">", $leaksFilePath or die; |
|
1033 print LEAKS $leaksOutput; |
|
1034 close LEAKS; |
|
1035 } |
|
1036 |
|
1037 return $adjustedCount; |
|
1038 } |
|
1039 |
|
1040 # Break up a path into the directory (with slash) and base name. |
|
1041 sub splitpath($) |
|
1042 { |
|
1043 my ($path) = @_; |
|
1044 |
|
1045 my $pathSeparator = "/"; |
|
1046 my $dirname = dirname($path) . $pathSeparator; |
|
1047 $dirname = "" if $dirname eq "." . $pathSeparator; |
|
1048 |
|
1049 return ($dirname, basename($path)); |
|
1050 } |
|
1051 |
|
1052 # Sort first by directory, then by file, so all paths in one directory are grouped |
|
1053 # rather than being interspersed with items from subdirectories. |
|
1054 # Use numericcmp to sort directory and filenames to make order logical. |
|
1055 sub pathcmp($$) |
|
1056 { |
|
1057 my ($patha, $pathb) = @_; |
|
1058 |
|
1059 my ($dira, $namea) = splitpath($patha); |
|
1060 my ($dirb, $nameb) = splitpath($pathb); |
|
1061 |
|
1062 return numericcmp($dira, $dirb) if $dira ne $dirb; |
|
1063 return numericcmp($namea, $nameb); |
|
1064 } |
|
1065 |
|
1066 # Sort numeric parts of strings as numbers, other parts as strings. |
|
1067 # Makes 1.33 come after 1.3, which is cool. |
|
1068 sub numericcmp($$) |
|
1069 { |
|
1070 my ($aa, $bb) = @_; |
|
1071 |
|
1072 my @a = split /(\d+)/, $aa; |
|
1073 my @b = split /(\d+)/, $bb; |
|
1074 |
|
1075 # Compare one chunk at a time. |
|
1076 # Each chunk is either all numeric digits, or all not numeric digits. |
|
1077 while (@a && @b) { |
|
1078 my $a = shift @a; |
|
1079 my $b = shift @b; |
|
1080 |
|
1081 # Use numeric comparison if chunks are non-equal numbers. |
|
1082 return $a <=> $b if $a =~ /^\d/ && $b =~ /^\d/ && $a != $b; |
|
1083 |
|
1084 # Use string comparison if chunks are any other kind of non-equal string. |
|
1085 return $a cmp $b if $a ne $b; |
|
1086 } |
|
1087 |
|
1088 # One of the two is now empty; compare lengths for result in this case. |
|
1089 return @a <=> @b; |
|
1090 } |
|
1091 |
|
1092 # Sort slowest tests first. |
|
1093 sub slowestcmp($$) |
|
1094 { |
|
1095 my ($testa, $testb) = @_; |
|
1096 |
|
1097 my $dura = $durations{$testa}; |
|
1098 my $durb = $durations{$testb}; |
|
1099 return $durb <=> $dura if $dura != $durb; |
|
1100 return pathcmp($testa, $testb); |
|
1101 } |
|
1102 |
|
1103 sub openDumpTool() |
|
1104 { |
|
1105 return if $isDumpToolOpen; |
|
1106 |
|
1107 # Save some requires variables for the linux environment... |
|
1108 my $homeDir = $ENV{'HOME'}; |
|
1109 my $libraryPath = $ENV{'LD_LIBRARY_PATH'}; |
|
1110 my $dbusAddress = $ENV{'DBUS_SESSION_BUS_ADDRESS'}; |
|
1111 my $display = $ENV{'DISPLAY'}; |
|
1112 my $testfonts = $ENV{'WEBKIT_TESTFONTS'}; |
|
1113 |
|
1114 my $homeDrive = $ENV{'HOMEDRIVE'}; |
|
1115 my $homePath = $ENV{'HOMEPATH'}; |
|
1116 |
|
1117 local %ENV; |
|
1118 if (isQt()) { |
|
1119 if (defined $display) { |
|
1120 $ENV{DISPLAY} = $display; |
|
1121 } else { |
|
1122 $ENV{DISPLAY} = ":1"; |
|
1123 } |
|
1124 $ENV{'WEBKIT_TESTFONTS'} = $testfonts; |
|
1125 $ENV{HOME} = $homeDir; |
|
1126 if (defined $libraryPath) { |
|
1127 $ENV{LD_LIBRARY_PATH} = $libraryPath; |
|
1128 } |
|
1129 if (defined $dbusAddress) { |
|
1130 $ENV{DBUS_SESSION_BUS_ADDRESS} = $dbusAddress; |
|
1131 } |
|
1132 } |
|
1133 $ENV{DYLD_FRAMEWORK_PATH} = $productDir; |
|
1134 $ENV{XML_CATALOG_FILES} = ""; # work around missing /etc/catalog <rdar://problem/4292995> |
|
1135 $ENV{MallocStackLogging} = 1 if $shouldCheckLeaks; |
|
1136 $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc; |
|
1137 |
|
1138 if (isCygwin()) { |
|
1139 $ENV{HOMEDRIVE} = $homeDrive; |
|
1140 $ENV{HOMEPATH} = $homePath; |
|
1141 setPathForRunningWebKitApp(\%ENV) if isCygwin(); |
|
1142 } |
|
1143 |
|
1144 my @args = (); |
|
1145 if ($useValgrind) { |
|
1146 push @args, $dumpTool; |
|
1147 } |
|
1148 push @args, @toolArgs; |
|
1149 if ($useValgrind) { |
|
1150 $dumpTool = "valgrind"; |
|
1151 } |
|
1152 $dumpToolPID = open3(\*OUT, \*IN, \*ERROR, $dumpTool, @args) or die "Failed to start tool: $dumpTool\n"; |
|
1153 $isDumpToolOpen = 1; |
|
1154 $dumpToolCrashed = 0; |
|
1155 } |
|
1156 |
|
1157 sub closeDumpTool() |
|
1158 { |
|
1159 return if !$isDumpToolOpen; |
|
1160 |
|
1161 close IN; |
|
1162 close OUT; |
|
1163 close ERROR; |
|
1164 waitpid $dumpToolPID, 0; |
|
1165 $isDumpToolOpen = 0; |
|
1166 } |
|
1167 |
|
1168 sub dumpToolDidCrash() |
|
1169 { |
|
1170 return 1 if $dumpToolCrashed; |
|
1171 return 0 unless $isDumpToolOpen; |
|
1172 |
|
1173 my $pid = waitpid(-1, WNOHANG); |
|
1174 return $pid == $dumpToolPID; |
|
1175 } |
|
1176 |
|
1177 sub openHTTPDIfNeeded() |
|
1178 { |
|
1179 return if $isHttpdOpen; |
|
1180 |
|
1181 mkdir "/tmp/WebKit"; |
|
1182 |
|
1183 if (-f "/tmp/WebKit/httpd.pid") { |
|
1184 my $oldPid = `cat /tmp/WebKit/httpd.pid`; |
|
1185 chomp $oldPid; |
|
1186 if (0 != kill 0, $oldPid) { |
|
1187 print "\nhttpd is already running: pid $oldPid, killing...\n"; |
|
1188 kill 15, $oldPid; |
|
1189 |
|
1190 my $retryCount = 20; |
|
1191 while ((0 != kill 0, $oldPid) && $retryCount) { |
|
1192 sleep 1; |
|
1193 --$retryCount; |
|
1194 } |
|
1195 |
|
1196 die "Timed out waiting for httpd to quit" unless $retryCount; |
|
1197 } |
|
1198 } |
|
1199 |
|
1200 my $httpdPath = "/usr/sbin/httpd"; |
|
1201 my $httpdConfig; |
|
1202 if (isCygwin()) { |
|
1203 my $windowsConfDirectory = "$testDirectory/http/conf/"; |
|
1204 unless (-x "/usr/lib/apache/libphp4.dll") { |
|
1205 copy("$windowsConfDirectory/libphp4.dll", "/usr/lib/apache/libphp4.dll"); |
|
1206 chmod(0755, "/usr/lib/apache/libphp4.dll"); |
|
1207 } |
|
1208 $httpdConfig = "$windowsConfDirectory/cygwin-httpd.conf"; |
|
1209 } else { |
|
1210 $httpdConfig = "$testDirectory/http/conf/httpd.conf"; |
|
1211 $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|; |
|
1212 } |
|
1213 my $documentRoot = "$testDirectory/http/tests"; |
|
1214 my $typesConfig = "$testDirectory/http/conf/mime.types"; |
|
1215 my $listen = "127.0.0.1:$httpdPort"; |
|
1216 my $absTestResultsDirectory = File::Spec->rel2abs(glob $testResultsDirectory); |
|
1217 my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem"; |
|
1218 |
|
1219 mkpath $absTestResultsDirectory; |
|
1220 |
|
1221 my @args = ( |
|
1222 "-f", "$httpdConfig", |
|
1223 "-C", "DocumentRoot \"$documentRoot\"", |
|
1224 "-C", "Listen $listen", |
|
1225 "-c", "TypesConfig \"$typesConfig\"", |
|
1226 "-c", "CustomLog \"$absTestResultsDirectory/access_log.txt\" common", |
|
1227 "-c", "ErrorLog \"$absTestResultsDirectory/error_log.txt\"", |
|
1228 # Apache wouldn't run CGIs with permissions==700 otherwise |
|
1229 "-c", "User \"#$<\"" |
|
1230 ); |
|
1231 |
|
1232 # FIXME: Enable this on Windows once <rdar://problem/5345985> is fixed |
|
1233 push(@args, "-c", "SSLCertificateFile \"$sslCertificate\"") unless isCygwin(); |
|
1234 |
|
1235 open2(\*HTTPDIN, \*HTTPDOUT, $httpdPath, @args); |
|
1236 |
|
1237 my $retryCount = 20; |
|
1238 while (system("/usr/bin/curl -q --silent --stderr - --output /dev/null $listen") && $retryCount) { |
|
1239 sleep 1; |
|
1240 --$retryCount; |
|
1241 } |
|
1242 |
|
1243 die "Timed out waiting for httpd to start" unless $retryCount; |
|
1244 |
|
1245 $isHttpdOpen = 1; |
|
1246 } |
|
1247 |
|
1248 sub closeHTTPD() |
|
1249 { |
|
1250 return if !$isHttpdOpen; |
|
1251 |
|
1252 close HTTPDIN; |
|
1253 close HTTPDOUT; |
|
1254 |
|
1255 kill 15, `cat /tmp/WebKit/httpd.pid` if -f "/tmp/WebKit/httpd.pid"; |
|
1256 |
|
1257 $isHttpdOpen = 0; |
|
1258 } |
|
1259 |
|
1260 sub fileNameWithNumber($$) |
|
1261 { |
|
1262 my ($base, $number) = @_; |
|
1263 return "$base$number" if ($number > 1); |
|
1264 return $base; |
|
1265 } |
|
1266 |
|
1267 sub processIgnoreTests($) { |
|
1268 my @ignoreList = split(/\s*,\s*/, shift); |
|
1269 my $addIgnoredDirectories = sub { |
|
1270 return () if exists $ignoredLocalDirectories{basename($File::Find::dir)}; |
|
1271 $ignoredDirectories{File::Spec->abs2rel($File::Find::dir, $testDirectory)} = 1; |
|
1272 return @_; |
|
1273 }; |
|
1274 foreach my $item (@ignoreList) { |
|
1275 my $path = catfile($testDirectory, $item); |
|
1276 if (-d $path) { |
|
1277 $ignoredDirectories{$item} = 1; |
|
1278 find({ preprocess => $addIgnoredDirectories, wanted => sub {} }, $path); |
|
1279 } |
|
1280 elsif (-f $path) { |
|
1281 $ignoredFiles{$item} = 1; |
|
1282 } |
|
1283 else { |
|
1284 print "ignoring '$item' on ignore-tests list\n"; |
|
1285 } |
|
1286 } |
|
1287 } |
|
1288 |
|
1289 sub stripExtension($) |
|
1290 { |
|
1291 my ($test) = @_; |
|
1292 |
|
1293 $test =~ s/\.[a-zA-Z]+$//; |
|
1294 return $test; |
|
1295 } |
|
1296 |
|
1297 sub isTextOnlyTest($) |
|
1298 { |
|
1299 my ($actual) = @_; |
|
1300 my $isText; |
|
1301 if ($actual =~ /^layer at/ms) { |
|
1302 $isText = 0; |
|
1303 } else { |
|
1304 $isText = 1; |
|
1305 } |
|
1306 return $isText; |
|
1307 } |
|
1308 |
|
1309 sub expectedDirectoryForTest($;$) |
|
1310 { |
|
1311 my ($base, $isText) = @_; |
|
1312 |
|
1313 my @directories = @platformHierarchy; |
|
1314 push @directories, map { catdir($platformBaseDirectory, $_) } qw(mac-leopard mac) if isCygwin(); |
|
1315 push @directories, $expectedDirectory; |
|
1316 |
|
1317 # If we already have expected results, just return their location. |
|
1318 foreach my $directory (@directories) { |
|
1319 return $directory if (-f "$directory/$base-$expectedTag.txt"); |
|
1320 } |
|
1321 |
|
1322 # For platform-specific tests, the results should go right next to the test itself. |
|
1323 # Note: The return value of this subroutine will be concatenated with $base |
|
1324 # to determine the location of the new results, so returning $expectedDirectory |
|
1325 # will put the results right next to the test. |
|
1326 return $expectedDirectory if $base =~ /^platform/; |
|
1327 |
|
1328 # For cross-platform tests, text-only results should go in the cross-platform directory, |
|
1329 # while render tree dumps should go in the least-specific platform directory. |
|
1330 return $isText ? $expectedDirectory : $platformHierarchy[$#platformHierarchy]; |
|
1331 } |
|
1332 |
|
1333 sub printFailureMessageForTest($$) |
|
1334 { |
|
1335 my ($test, $description) = @_; |
|
1336 |
|
1337 unless ($verbose) { |
|
1338 print "\n" unless $atLineStart; |
|
1339 print "$test -> "; |
|
1340 } |
|
1341 print "$description\n"; |
|
1342 $atLineStart = 1; |
|
1343 } |
|
1344 |
|
1345 my %cygpaths = (); |
|
1346 |
|
1347 sub openCygpathIfNeeded($) |
|
1348 { |
|
1349 my ($options) = @_; |
|
1350 |
|
1351 return unless isCygwin(); |
|
1352 return $cygpaths{$options} if $cygpaths{$options} && $cygpaths{$options}->{"open"}; |
|
1353 |
|
1354 local (*CYGPATHIN, *CYGPATHOUT); |
|
1355 my $pid = open2(\*CYGPATHIN, \*CYGPATHOUT, "cygpath -f - $options"); |
|
1356 my $cygpath = { |
|
1357 "pid" => $pid, |
|
1358 "in" => *CYGPATHIN, |
|
1359 "out" => *CYGPATHOUT, |
|
1360 "open" => 1 |
|
1361 }; |
|
1362 |
|
1363 $cygpaths{$options} = $cygpath; |
|
1364 |
|
1365 return $cygpath; |
|
1366 } |
|
1367 |
|
1368 sub closeCygpaths() |
|
1369 { |
|
1370 return unless isCygwin(); |
|
1371 |
|
1372 foreach my $cygpath (values(%cygpaths)) { |
|
1373 close $cygpath->{"in"}; |
|
1374 close $cygpath->{"out"}; |
|
1375 waitpid($cygpath->{"pid"}, 0); |
|
1376 $cygpath->{"open"} = 0; |
|
1377 |
|
1378 } |
|
1379 } |
|
1380 |
|
1381 sub convertPathUsingCygpath($$) |
|
1382 { |
|
1383 my ($path, $options) = @_; |
|
1384 |
|
1385 my $cygpath = openCygpathIfNeeded($options); |
|
1386 local *inFH = $cygpath->{"in"}; |
|
1387 local *outFH = $cygpath->{"out"}; |
|
1388 print outFH $path . "\n"; |
|
1389 chomp(my $convertedPath = <inFH>); |
|
1390 return $convertedPath; |
|
1391 } |
|
1392 |
|
1393 sub toWindowsPath($) |
|
1394 { |
|
1395 my ($path) = @_; |
|
1396 return unless isCygwin(); |
|
1397 |
|
1398 return convertPathUsingCygpath($path, "-w"); |
|
1399 } |
|
1400 |
|
1401 sub toURL($) |
|
1402 { |
|
1403 my ($path) = @_; |
|
1404 return $path unless isCygwin(); |
|
1405 |
|
1406 return "file:///" . convertPathUsingCygpath($path, "-m"); |
|
1407 } |
|
1408 |
|
1409 sub validateSkippedArg($$;$) |
|
1410 { |
|
1411 my ($option, $value, $value2) = @_; |
|
1412 my %validSkippedValues = map { $_ => 1 } qw(default ignore only); |
|
1413 $value = lc($value); |
|
1414 die "Invalid argument '" . $value . "' for option $option" unless $validSkippedValues{$value}; |
|
1415 $treatSkipped = $value; |
|
1416 } |
|
1417 |
|
1418 sub htmlForExpectedAndActualResults($) |
|
1419 { |
|
1420 my ($base) = @_; |
|
1421 |
|
1422 return "<td></td><td></td><td></td>\n" unless -s "$testResultsDirectory/$base-$diffsTag.txt"; |
|
1423 |
|
1424 return "<td><a href=\"$base-$expectedTag.txt\">expected</a></td>\n" |
|
1425 . "<td><a href=\"$base-$actualTag.txt\">actual</a></td>\n" |
|
1426 . "<td><a href=\"$base-$diffsTag.txt\">diffs</a></td>\n"; |
|
1427 } |
|
1428 |
|
1429 sub deleteExpectedAndActualResults($) |
|
1430 { |
|
1431 my ($base) = @_; |
|
1432 |
|
1433 unlink "$testResultsDirectory/$base-$actualTag.txt"; |
|
1434 unlink "$testResultsDirectory/$base-$diffsTag.txt"; |
|
1435 unlink "$testResultsDirectory/$base-$errorTag.txt"; |
|
1436 } |
|
1437 |
|
1438 sub recordActualResultsAndDiff($$) |
|
1439 { |
|
1440 my ($base, $actual) = @_; |
|
1441 |
|
1442 return unless length($actual); |
|
1443 |
|
1444 open ACTUAL, ">", "$testResultsDirectory/$base-$actualTag.txt" or die "Couldn't open actual results file for $base"; |
|
1445 print ACTUAL $actual; |
|
1446 close ACTUAL; |
|
1447 |
|
1448 my $expectedDir = expectedDirectoryForTest($base); |
|
1449 copy("$expectedDir/$base-$expectedTag.txt", "$testResultsDirectory/$base-$expectedTag.txt"); |
|
1450 |
|
1451 system "diff -u \"$testResultsDirectory/$base-$expectedTag.txt\" \"$testResultsDirectory/$base-$actualTag.txt\" > \"$testResultsDirectory/$base-$diffsTag.txt\""; |
|
1452 } |
|
1453 |
|
1454 sub buildPlatformHierarchy() |
|
1455 { |
|
1456 mkpath($platformTestDirectory) if ($platform eq "undefined" && !-d "$platformTestDirectory"); |
|
1457 |
|
1458 my @platforms = split('-', $platform); |
|
1459 my @hierarchy; |
|
1460 for (my $i=0; $i < @platforms; $i++) { |
|
1461 my $scoped = catdir($platformBaseDirectory, join('-', @platforms[0..($#platforms - $i)])); |
|
1462 push(@hierarchy, $scoped) if (-d $scoped); |
|
1463 } |
|
1464 |
|
1465 return @hierarchy; |
|
1466 } |