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 # Copyright (C) 2007 Eric Seidel <eric@webkit.org>
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
18 # its contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
22 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # Script to run the Web Kit Open Source Project layout tests.
34 # Run all the tests passed in on the command line.
35 # If no tests are passed, find all the .html, .shtml, .xml, .xhtml, .pl, .php (and svg) files in the test directory.
38 # Compare against the existing file xxx-expected.txt.
39 # If there is a mismatch, generate xxx-actual.txt and xxx-diffs.txt.
42 # the number of tests that got the expected results
43 # the number of tests that ran, but did not get the expected results
44 # the number of tests that failed to run
45 # the number of tests that were run but had no expected results to compare against
56 use File::Spec::Functions;
61 use Time::HiRes qw(time);
63 use List::Util 'shuffle';
65 use lib $FindBin::Bin;
71 sub dumpToolDidCrash();
73 sub countAndPrintLeaks($$$);
74 sub fileNameWithNumber($$);
76 sub openHTTPDIfNeeded();
78 sub processIgnoreTests($);
81 sub stripExtension($);
82 sub isTextOnlyTest($);
83 sub expectedDirectoryForTest($;$;$);
84 sub printFailureMessageForTest($$);
88 sub validateSkippedArg($$;$);
89 sub htmlForExpectedAndActualResults($);
90 sub deleteExpectedAndActualResults($);
91 sub recordActualResultsAndDiff($$);
92 sub buildPlatformHierarchy();
93 sub epiloguesAndPrologues($$);
94 sub parseLeaksandPrintUniqueLeaks();
97 my $addPlatformExceptions = 0;
98 my $configuration = configuration();
100 my $httpdPort = 8000;
101 my $httpdSSLPort = 8443;
102 my $ignoreTests = '';
103 my $launchSafari = 1;
107 my $repaintSweepHorizontally = '';
108 my $repaintTests = '';
109 my $report10Slowest = 0;
110 my $resetResults = 0;
111 my $shouldCheckLeaks = 0;
113 my $testsPerDumpTool = 1000;
116 my $testResultsDirectory = "/tmp/layout-test-results";
119 my $treatSkipped = "default";
122 my $strictTesting = 0;
123 my $generateNewResults = 1;
124 my $stripEditingCallbacks = isCygwin();
126 my $reverseTests = 0;
127 my $randomizeTests = 0;
131 # Default to --no-http for Qt, Gtk and wx for now.
132 $testHTTP = 0 if (isQt() || isGtk() || isWx());
134 my $expectedTag = "expected";
135 my $actualTag = "actual";
136 my $diffsTag = "diffs";
137 my $errorTag = "stderr";
140 $platform = "mac-tiger";
141 } elsif (isLeopard()) {
142 $platform = "mac-leopard";
149 } elsif (isCygwin()) {
153 if (!defined($platform)) {
154 print "WARNING: Your platform is not recognized. Any platform-specific results will be generated in platform/undefined.\n";
155 $platform = "undefined";
158 my $programName = basename($0);
159 my $launchSafariDefault = $launchSafari ? "launch" : "do not launch";
160 my $httpDefault = $testHTTP ? "run" : "do not run";
162 # FIXME: "--strict" should be renamed to qt-mac-comparison, or something along those lines.
164 Usage: $programName [options] [testdir|testpath ...]
165 --add-platform-exceptions Put new results for non-platform-specific failing tests into the platform-specific results directory
166 -c|--configuration config Set DumpRenderTree build configuration
167 -g|--guard-malloc Enable malloc guard
168 --help Show this help message
169 -h|--horizontal-sweep Change repaint to sweep horizontally instead of vertically (implies --repaint-tests)
170 --[no-]http Run (or do not run) http tests (default: $httpDefault)
171 -i|--ignore-tests Comma-separated list of directories or tests to ignore
172 --[no-]launch-safari Launch (or do not launch) Safari to display test results (default: $launchSafariDefault)
173 -l|--leaks Enable leaks checking
174 --[no-]new-test-results Generate results for new tests
175 -p|--pixel-tests Enable pixel tests
176 --platform Override the detected platform to use for tests and results (default: $platform)
177 --port Web server port to use with http tests
178 -q|--quiet Less verbose output
179 -r|--repaint-tests Run repaint tests (implies --pixel-tests)
180 --reset-results Reset ALL results (including pixel tests if --pixel-tests is set)
181 -o|--results-directory Output results directory (default: $testResultsDirectory)
182 --random Run the tests in a random order
183 --reverse Run the tests in reverse alphabetical order
184 --root Path to root tools build
185 -1|--singly Isolate each test case run (implies --verbose)
186 --skipped=[default|ignore|only] Specifies how to treat the Skipped file
187 default: Tests/directories listed in the Skipped file are not tested
188 ignore: The Skipped file is ignored
189 only: Only those tests/directories listed in the Skipped file will be run
190 --slowest Report the 10 slowest tests
191 --strict Do a comparison with the output on Mac (Qt only)
192 --[no-]strip-editing-callbacks Remove editing callbacks from expected results
193 -t|--threaded Run a concurrent JavaScript thead with each test
194 --threshold t Ignore pixel value deviations less than or equal to t
195 --valgrind Run DumpRenderTree inside valgrind (Qt/Linux only)
196 -v|--verbose More verbose output (overrides --quiet)
197 -m|--merge-leak-depth arg Merges leak callStacks and prints the number of unique leaks beneath a callstack depth of arg. Defaults to 5.
200 my $getOptionsResult = GetOptions(
201 'c|configuration=s' => \$configuration,
202 'debug|devel' => sub { $configuration = "Debug" },
203 'guard-malloc|g' => \$guardMalloc,
204 'help' => \$showHelp,
205 'horizontal-sweep|h' => \$repaintSweepHorizontally,
206 'http!' => \$testHTTP,
207 'ignore-tests|i=s' => \$ignoreTests,
208 'launch-safari!' => \$launchSafari,
209 'leaks|l' => \$shouldCheckLeaks,
210 'pixel-tests|p' => \$pixelTests,
211 'platform=s' => \$platform,
212 'port=i' => \$httpdPort,
213 'quiet|q' => \$quiet,
214 'release|deploy' => sub { $configuration = "Release" },
215 'repaint-tests|r' => \$repaintTests,
216 'reset-results' => \$resetResults,
217 'new-test-results!' => \$generateNewResults,
218 'results-directory|o=s' => \$testResultsDirectory,
219 'singly|1' => sub { $testsPerDumpTool = 1; },
220 'nthly=i' => \$testsPerDumpTool,
221 'skipped=s' => \&validateSkippedArg,
222 'slowest' => \$report10Slowest,
223 'threaded|t' => \$threaded,
224 'threshold=i' => \$threshold,
225 'verbose|v' => \$verbose,
226 'valgrind' => \$useValgrind,
227 'strict' => \$strictTesting,
228 'strip-editing-callbacks!' => \$stripEditingCallbacks,
229 'random' => \$randomizeTests,
230 'reverse' => \$reverseTests,
232 'add-platform-exceptions' => \$addPlatformExceptions,
233 'merge-leak-depth|m:5' => \$mergeDepth,
236 if (!$getOptionsResult || $showHelp) {
241 my $ignoreSkipped = $treatSkipped eq "ignore";
242 my $skippedOnly = $treatSkipped eq "only";
244 !$skippedOnly || @ARGV == 0 or die "--skipped=only cannot be used when tests are specified on the command line.";
246 setConfiguration($configuration);
248 my $configurationOption = "--" . lc($configuration);
250 $repaintTests = 1 if $repaintSweepHorizontally;
252 $pixelTests = 1 if $repaintTests;
253 $pixelTests = 1 if $threshold > 0;
255 $verbose = 1 if $testsPerDumpTool == 1;
257 if ($shouldCheckLeaks && $testsPerDumpTool > 1000) {
258 print STDERR "\nWARNING: Running more than 1000 tests at a time with MallocStackLogging enabled may cause a crash.\n\n";
261 # Stack logging does not play well with QuickTime on Tiger (rdar://problem/5537157)
262 $testMedia = 0 if $shouldCheckLeaks && isTiger();
264 setConfigurationProductDir(Cwd::abs_path($root)) if (defined($root));
265 my $productDir = productDir();
266 $productDir .= "/bin" if (isQt());
269 if ($ENV{WEBKITAUTOTOOLS}) {
270 $productDir .= "/Programs";
272 $productDir .= "/WebKitTools/DumpRenderTree/gtk";
279 # Push the parameters to build-dumprendertree as an array
281 push(@args, "--" . $configuration);
282 push(@args, "--qt") if isQt();
283 push(@args, "--gtk") if isGtk();
285 my $buildResult = system "WebKitTools/Scripts/build-dumprendertree", @args;
287 print STDERR "Compiling DumpRenderTree failed!\n";
288 exit exitStatus($buildResult);
292 my $dumpToolName = "DumpRenderTree";
293 $dumpToolName .= "_debug" if isCygwin() && $configuration ne "Release";
294 my $dumpTool = "$productDir/$dumpToolName";
295 die "can't find executable $dumpToolName (looked in $productDir)\n" unless -x $dumpTool;
297 my $imageDiffTool = "$productDir/ImageDiff";
298 die "can't find executable $imageDiffTool (looked in $productDir)\n" if $pixelTests && !-x $imageDiffTool;
300 checkFrameworks() unless isCygwin();
302 my $layoutTestsName = "LayoutTests";
303 my $testDirectory = File::Spec->rel2abs($layoutTestsName);
304 my $expectedDirectory = $testDirectory;
305 my $platformBaseDirectory = catdir($testDirectory, "platform");
306 my $platformTestDirectory = catdir($platformBaseDirectory, $platform);
307 my @platformHierarchy = buildPlatformHierarchy();
309 $expectedDirectory = $ENV{"WebKitExpectedTestResultsDirectory"} if $ENV{"WebKitExpectedTestResultsDirectory"};
311 my $testResults = catfile($testResultsDirectory, "results.html");
313 print "Running tests from $testDirectory\n";
318 system "ln", "-s", $testDirectory, "/tmp/LayoutTests" unless -x "/tmp/LayoutTests";
320 my %ignoredFiles = ();
321 my %ignoredDirectories = map { $_ => 1 } qw(platform);
322 my %ignoredLocalDirectories = map { $_ => 1 } qw(.svn _svn resources);
323 my %supportedFileExtensions = map { $_ => 1 } qw(html shtml xml xhtml pl php);
324 if (checkWebCoreSVGSupport(0)) {
325 $supportedFileExtensions{'svg'} = 1;
326 } elsif (isCygwin()) {
327 # FIXME: We should fix webkitdirs.pm:hasSVGSupport() to do the correct
328 # check for Windows instead of forcing this here.
329 $supportedFileExtensions{'svg'} = 1;
331 $ignoredLocalDirectories{'svg'} = 1;
334 $ignoredDirectories{'http'} = 1;
338 $ignoredDirectories{'media'} = 1;
339 $ignoredDirectories{'http/tests/media'} = 1;
343 processIgnoreTests($ignoreTests);
346 if (!$ignoreSkipped) {
347 foreach my $level (@platformHierarchy) {
348 if (open SKIPPED, "<", "$level/Skipped") {
349 if ($verbose && !$skippedOnly) {
350 my ($dir, $name) = splitpath($level);
351 print "Skipped tests in $name:\n";
357 $skipped =~ s/^[ \n\r]+//;
358 $skipped =~ s/[ \n\r]+$//;
359 if ($skipped && $skipped !~ /^#/) {
361 push(@ARGV, $skipped);
366 processIgnoreTests($skipped);
376 my $directoryFilter = sub {
377 return () if exists $ignoredLocalDirectories{basename($File::Find::dir)};
378 return () if exists $ignoredDirectories{File::Spec->abs2rel($File::Find::dir, $testDirectory)};
382 my $fileFilter = sub {
384 if ($filename =~ /\.([^.]+)$/) {
385 if (exists $supportedFileExtensions{$1}) {
386 my $path = File::Spec->abs2rel(catfile($File::Find::dir, $filename), $testDirectory);
387 push @tests, $path if !exists $ignoredFiles{$path};
392 for my $test (@ARGV) {
393 $test =~ s/^($layoutTestsName|$testDirectory)\///;
394 my $fullPath = catfile($testDirectory, $test);
395 if (file_name_is_absolute($test)) {
396 print "can't run test $test outside $testDirectory\n";
397 } elsif (-f $fullPath) {
398 my ($filename, $pathname, $fileExtension) = fileparse($test, qr{\.[^.]+$});
399 if (!exists $supportedFileExtensions{substr($fileExtension, 1)}) {
400 print "test $test does not have a supported extension\n";
401 } elsif ($testHTTP || $pathname !~ /^http\//) {
404 } elsif (-d $fullPath) {
405 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $fullPath);
407 for my $level (@platformHierarchy) {
408 my $platformPath = catfile($level, $test);
409 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $platformPath) if (-d $platformPath);
412 print "test $test not found\n";
416 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $testDirectory);
418 for my $level (@platformHierarchy) {
419 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $level);
423 die "no tests to run\n" if !@tests;
425 @tests = sort pathcmp @tests;
430 my %imageDifferences;
433 my $leaksOutputFileNumber = 1;
437 push @toolArgs, "--dump-all-pixels" if $pixelTests && $resetResults;
438 push @toolArgs, "--pixel-tests" if $pixelTests;
439 push @toolArgs, "--repaint" if $repaintTests;
440 push @toolArgs, "--horizontal-sweep" if $repaintSweepHorizontally;
441 push @toolArgs, "--threaded" if $threaded;
444 my @diffToolArgs = ();
445 push @diffToolArgs, "--threshold", $threshold;
449 my $imageDiffToolPID;
452 $ENV{MallocStackLogging} = 1 if $shouldCheckLeaks;
453 $imageDiffToolPID = open2(\*DIFFIN, \*DIFFOUT, $imageDiffTool, @diffToolArgs) or die "unable to open $imageDiffTool\n";
457 my $isDumpToolOpen = 0;
458 my $dumpToolCrashed = 0;
461 my $lastDirectory = "";
465 sub catch_pipe { $dumpToolCrashed = 1; }
466 $SIG{"PIPE"} = "catch_pipe";
468 print "Testing ", scalar @tests, " test cases.\n";
469 my $overallStartTime = time;
471 my %expectedResultDirectory;
474 @tests = reverse @tests if $reverseTests;
477 @tests = shuffle(@tests) if $randomizeTests;
479 for my $test (@tests) {
480 next if $test eq 'results.html';
482 my $newDumpTool = not $isDumpToolOpen;
485 my $base = stripExtension($test);
490 if ($newDumpTool || $dir ne $lastDirectory) {
491 foreach my $logue (epiloguesAndPrologues($newDumpTool ? "" : $lastDirectory, $dir)) {
493 $logue = toWindowsPath($logue);
495 $logue = canonpath($logue);
498 print "running epilogue or prologue $logue\n";
500 print OUT "$logue\n";
501 # Discard the output.
509 print "running $test -> ";
512 if ($dir ne $lastDirectory) {
513 print "\n" unless $atLineStart;
520 $lastDirectory = $dir;
524 my $startTime = time if $report10Slowest;
526 if ($test !~ /^http\//) {
527 my $testPath = "$testDirectory/$test";
529 $testPath = toWindowsPath($testPath);
531 $testPath = canonpath($testPath);
533 print OUT "$testPath\n";
536 if ($test !~ /^http\/tests\/local\// && $test !~ /^http\/tests\/ssl\// && $test !~ /^http\/tests\/media\//) {
537 my $path = canonpath($test);
538 $path =~ s/^http\/tests\///;
539 print OUT "http://127.0.0.1:$httpdPort/$path\n";
540 } elsif ($test =~ /^http\/tests\/ssl\//) {
541 my $path = canonpath($test);
542 $path =~ s/^http\/tests\///;
543 print OUT "https://127.0.0.1:$httpdSSLPort/$path\n";
545 my $testPath = "$testDirectory/$test";
547 $testPath = toWindowsPath($testPath);
549 $testPath = canonpath($testPath);
551 print OUT "$testPath\n";
561 my $isText = isTextOnlyTest($actual);
563 $durations{$test} = time - $startTime if $report10Slowest;
566 my $expectedDir = expectedDirectoryForTest($base, $isText, 0);
567 $expectedResultDirectory{$base} = $expectedDir;
569 if (!$resetResults && open EXPECTED, "<", "$expectedDir/$base-$expectedTag.txt") {
572 next if $stripEditingCallbacks && $_ =~ /^EDITING DELEGATE:/;
578 if (!isOSX() && $strictTesting && !$isText) {
579 if (!$resetResults && open EXPECTED, "<", "$testDirectory/platform/mac/$base-$expectedTag.txt") {
588 if ($shouldCheckLeaks && $testsPerDumpTool == 1) {
594 my $diffPercentage = "";
595 my $diffResult = "passed";
598 my $expectedPixelDir = expectedDirectoryForTest($base, $isText, 1);
601 my $expectedHash = "";
602 my $actualPNGSize = 0;
606 if (/ActualHash: ([a-f0-9]{32})/) {
608 } elsif (/BaselineHash: ([a-f0-9]{32})/) {
610 } elsif (/Content-length: (\d+)\s*/) {
612 read(IN, $actualPNG, $actualPNGSize);
616 if ($expectedHash ne $actualHash && -f "$expectedPixelDir/$base-$expectedTag.png") {
617 my $expectedPNGSize = -s "$expectedPixelDir/$base-$expectedTag.png";
618 my $expectedPNG = "";
619 open EXPECTEDPNG, "$expectedPixelDir/$base-$expectedTag.png";
620 read(EXPECTEDPNG, $expectedPNG, $expectedPNGSize);
622 print DIFFOUT "Content-length: $actualPNGSize\n";
623 print DIFFOUT $actualPNG;
625 print DIFFOUT "Content-length: $expectedPNGSize\n";
626 print DIFFOUT $expectedPNG;
629 last if /^error/ || /^diff:/;
630 if (/Content-length: (\d+)\s*/) {
631 read(DIFFIN, $diffPNG, $1);
635 if (/^diff: (.+)% (passed|failed)/) {
636 $diffPercentage = $1;
637 $imageDifferences{$base} = $diffPercentage;
642 if ($actualPNGSize && ($resetResults || !-f "$expectedPixelDir/$base-$expectedTag.png")) {
643 mkpath catfile($expectedPixelDir, dirname($base)) if $testDirectory ne $expectedPixelDir;
644 open EXPECTED, ">", "$expectedPixelDir/$base-expected.png" or die "could not create $expectedPixelDir/$base-expected.png\n";
645 print EXPECTED $actualPNG;
649 # update the expected hash if the image diff said that there was no difference
650 if ($actualHash ne "" && ($resetResults || !-f "$expectedPixelDir/$base-$expectedTag.checksum")) {
651 open EXPECTED, ">", "$expectedPixelDir/$base-$expectedTag.checksum" or die "could not create $expectedPixelDir/$base-$expectedTag.checksum\n";
652 print EXPECTED $actualHash;
657 if (!isOSX() && $strictTesting && !$isText) {
658 if (defined $expectedMac) {
659 my $simplified_actual;
660 $simplified_actual = $actual;
661 $simplified_actual =~ s/at \(-?[0-9]+,-?[0-9]+\) *//g;
662 $simplified_actual =~ s/size -?[0-9]+x-?[0-9]+ *//g;
663 $simplified_actual =~ s/text run width -?[0-9]+: //g;
664 $simplified_actual =~ s/text run width -?[0-9]+ [a-zA-Z ]+: //g;
665 $simplified_actual =~ s/RenderButton {BUTTON} .*/RenderButton {BUTTON}/g;
666 $simplified_actual =~ s/RenderImage {INPUT} .*/RenderImage {INPUT}/g;
667 $simplified_actual =~ s/RenderBlock {INPUT} .*/RenderBlock {INPUT}/g;
668 $simplified_actual =~ s/RenderTextControl {INPUT} .*/RenderTextControl {INPUT}/g;
669 $simplified_actual =~ s/\([0-9]+px/px/g;
670 $simplified_actual =~ s/ *" *\n +" */ /g;
671 $simplified_actual =~ s/" +$/"/g;
673 $simplified_actual =~ s/- /-/g;
674 $simplified_actual =~ s/\n( *)"\s+/\n$1"/g;
675 $simplified_actual =~ s/\s+"\n/"\n/g;
677 $expectedMac =~ s/at \(-?[0-9]+,-?[0-9]+\) *//g;
678 $expectedMac =~ s/size -?[0-9]+x-?[0-9]+ *//g;
679 $expectedMac =~ s/text run width -?[0-9]+: //g;
680 $expectedMac =~ s/text run width -?[0-9]+ [a-zA-Z ]+: //g;
681 $expectedMac =~ s/RenderButton {BUTTON} .*/RenderButton {BUTTON}/g;
682 $expectedMac =~ s/RenderImage {INPUT} .*/RenderImage {INPUT}/g;
683 $expectedMac =~ s/RenderBlock {INPUT} .*/RenderBlock {INPUT}/g;
684 $expectedMac =~ s/RenderTextControl {INPUT} .*/RenderTextControl {INPUT}/g;
685 $expectedMac =~ s/\([0-9]+px/px/g;
686 $expectedMac =~ s/ *" *\n +" */ /g;
687 $expectedMac =~ s/" +$/"/g;
689 $expectedMac =~ s/- /-/g;
690 $expectedMac =~ s/\n( *)"\s+/\n$1"/g;
691 $expectedMac =~ s/\s+"\n/"\n/g;
693 if ($simplified_actual ne $expectedMac) {
694 open ACTUAL, ">", "/tmp/actual.txt" or die;
695 print ACTUAL $simplified_actual;
697 open ACTUAL, ">", "/tmp/expected.txt" or die;
698 print ACTUAL $expectedMac;
700 system "diff -u \"/tmp/expected.txt\" \"/tmp/actual.txt\" > \"/tmp/simplified.diff\"";
702 $diffResult = "failed";
705 system "cat /tmp/simplified.diff";
712 if (dumpToolDidCrash()) {
715 printFailureMessageForTest($test, "crashed");
717 my $dir = "$testResultsDirectory/$base";
718 $dir =~ s|/([^/]+)$|| or die "Failed to find test name from base\n";
721 deleteExpectedAndActualResults($base);
723 open CRASH, ">", "$testResultsDirectory/$base-$errorTag.txt" or die;
727 recordActualResultsAndDiff($base, $actual);
730 } elsif (!defined $expected) {
732 print "new " . ($resetResults ? "result" : "test") ."\n";
737 if ($generateNewResults || $resetResults) {
738 mkpath catfile($expectedDir, dirname($base)) if $testDirectory ne $expectedDir;
739 open EXPECTED, ">", "$expectedDir/$base-$expectedTag.txt" or die "could not create $expectedDir/$base-$expectedTag.txt\n";
740 print EXPECTED $actual;
743 deleteExpectedAndActualResults($base);
744 unless ($resetResults) {
745 # Always print the file name for new tests, as they will probably need some manual inspection.
746 # in verbose mode we already printed the test case, so no need to do it again.
748 print "\n" unless $atLineStart;
751 my $resultsDir = catdir($expectedDir, dirname($base));
752 print "new (results generated in $resultsDir)\n";
755 } elsif ($actual eq $expected && $diffResult eq "passed") {
761 deleteExpectedAndActualResults($base);
763 $result = "mismatch";
765 my $message = $actual eq $expected ? "pixel test failed" : "failed";
767 if ($actual ne $expected && $addPlatformExceptions) {
768 my $testBase = catfile($testDirectory, $base);
769 my $expectedBase = catfile($expectedDir, $base);
770 my $testIsMaximallyPlatformSpecific = $testBase =~ m|^\Q$platformTestDirectory\E/|;
771 my $expectedResultIsMaximallyPlatformSpecific = $expectedBase =~ m|^\Q$platformTestDirectory\E/|;
772 if (!$testIsMaximallyPlatformSpecific && !$expectedResultIsMaximallyPlatformSpecific) {
773 mkpath catfile($platformTestDirectory, dirname($base));
774 my $expectedFile = catfile($platformTestDirectory, "$base-$expectedTag.txt");
775 open EXPECTED, ">", $expectedFile or die "could not create $expectedFile\n";
776 print EXPECTED $actual;
778 $message .= " (results generated in $platformTestDirectory)";
782 printFailureMessageForTest($test, $message);
784 my $dir = "$testResultsDirectory/$base";
785 $dir =~ s|/([^/]+)$|| or die "Failed to find test name from base\n";
789 deleteExpectedAndActualResults($base);
790 recordActualResultsAndDiff($base, $actual);
792 if ($pixelTests && $diffPNG && $diffPNG ne "") {
793 $imagesPresent{$base} = 1;
795 open ACTUAL, ">", "$testResultsDirectory/$base-$actualTag.png" or die;
796 print ACTUAL $actualPNG;
799 open DIFF, ">", "$testResultsDirectory/$base-$diffsTag.png" or die;
803 copy("$expectedDir/$base-$expectedTag.png", "$testResultsDirectory/$base-$expectedTag.png");
805 open DIFFHTML, ">$testResultsDirectory/$base-$diffsTag.html" or die;
806 print DIFFHTML "<html>\n";
807 print DIFFHTML "<head>\n";
808 print DIFFHTML "<title>$base Image Compare</title>\n";
809 print DIFFHTML "<script language=\"Javascript\" type=\"text/javascript\">\n";
810 print DIFFHTML "var currentImage = 0;\n";
811 print DIFFHTML "var imageNames = new Array(\"Actual\", \"Expected\");\n";
812 print DIFFHTML "var imagePaths = new Array(\"$testName-$actualTag.png\", \"$testName-$expectedTag.png\");\n";
813 if (-f "$testDirectory/$base-w3c.png") {
814 copy("$testDirectory/$base-w3c.png", "$testResultsDirectory/$base-w3c.png");
815 print DIFFHTML "imageNames.push(\"W3C\");\n";
816 print DIFFHTML "imagePaths.push(\"$testName-w3c.png\");\n";
818 print DIFFHTML "function animateImage() {\n";
819 print DIFFHTML " var image = document.getElementById(\"animatedImage\");\n";
820 print DIFFHTML " var imageText = document.getElementById(\"imageText\");\n";
821 print DIFFHTML " image.src = imagePaths[currentImage];\n";
822 print DIFFHTML " imageText.innerHTML = imageNames[currentImage] + \" Image\";\n";
823 print DIFFHTML " currentImage = (currentImage + 1) % imageNames.length;\n";
824 print DIFFHTML " setTimeout('animateImage()',2000);\n";
825 print DIFFHTML "}\n";
826 print DIFFHTML "</script>\n";
827 print DIFFHTML "</head>\n";
828 print DIFFHTML "<body onLoad=\"animateImage();\">\n";
829 print DIFFHTML "<table>\n";
830 if ($diffPercentage) {
831 print DIFFHTML "<tr>\n";
832 print DIFFHTML "<td>Difference between images: <a href=\"$testName-$diffsTag.png\">$diffPercentage%</a></td>\n";
833 print DIFFHTML "</tr>\n";
835 print DIFFHTML "<tr>\n";
836 print DIFFHTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">test file</a></td>\n";
837 print DIFFHTML "</tr>\n";
838 print DIFFHTML "<tr>\n";
839 print DIFFHTML "<td id=\"imageText\" style=\"text-weight: bold;\">Actual Image</td>\n";
840 print DIFFHTML "</tr>\n";
841 print DIFFHTML "<tr>\n";
842 print DIFFHTML "<td><img src=\"$testName-$actualTag.png\" id=\"animatedImage\"></td>\n";
843 print DIFFHTML "</tr>\n";
844 print DIFFHTML "</table>\n";
845 print DIFFHTML "</body>\n";
846 print DIFFHTML "</html>\n";
850 if (($count + 1) % $testsPerDumpTool == 0 || $count == $#tests) {
851 if ($shouldCheckLeaks) {
853 if ($testsPerDumpTool == 1) {
854 $fileName = "$testResultsDirectory/$base-leaks.txt";
856 $fileName = "$testResultsDirectory/" . fileNameWithNumber($dumpToolName, $leaksOutputFileNumber) . "-leaks.txt";
858 my $leakCount = countAndPrintLeaks($dumpToolName, $dumpToolPID, $fileName);
859 $totalLeaks += $leakCount;
860 $leaksOutputFileNumber++ if ($leakCount);
868 push @{$tests{$result}}, $test;
869 $testType{$test} = $isText;
871 printf "\n%0.2fs total testing time\n", (time - $overallStartTime) . "";
873 !$isDumpToolOpen || die "Failed to close $dumpToolName.\n";
877 # Because multiple instances of this script are running concurrently we cannot
878 # safely delete this symlink.
879 # system "rm /tmp/LayoutTests";
881 # FIXME: Do we really want to check the image-comparison tool for leaks every time?
882 if ($shouldCheckLeaks && $pixelTests) {
883 $totalLeaks += countAndPrintLeaks("ImageDiff", $imageDiffToolPID, "$testResultsDirectory/ImageDiff-leaks.txt");
888 parseLeaksandPrintUniqueLeaks();
891 print "\nWARNING: $totalLeaks total leaks found!\n";
892 print "See above for individual leaks results.\n" if ($leaksOutputFileNumber > 2);
900 if ($report10Slowest) {
901 print "\n\nThe 10 slowest tests:\n\n";
903 for my $test (sort slowestcmp keys %durations) {
904 printf "%0.2f secs: %s\n", $durations{$test}, $test;
905 last if ++$count == 10;
911 if ($skippedOnly && $counts{"match"}) {
912 print "The following tests are in the Skipped file (" . File::Spec->abs2rel("$platformTestDirectory/Skipped", $testDirectory) . "), but succeeded:\n";
913 foreach my $test (@{$tests{"match"}}) {
918 if ($resetResults || ($counts{match} && $counts{match} == $count)) {
919 print "all $count test cases succeeded\n";
926 match => "succeeded",
927 mismatch => "had incorrect layout",
932 for my $type ("match", "mismatch", "new", "crash") {
933 my $c = $counts{$type};
935 my $t = $text{$type};
939 $message = sprintf "1 test case (%d%%) %s\n", 1 * 100 / $count, $t;
941 $message = sprintf "%d test cases (%d%%) %s\n", $c, $c * 100 / $count, $t;
943 $message =~ s-\(0%\)-(<1%)-;
948 mkpath $testResultsDirectory;
950 open HTML, ">", $testResults or die;
951 print HTML "<html>\n";
952 print HTML "<head>\n";
953 print HTML "<title>Layout Test Results</title>\n";
954 print HTML "</head>\n";
955 print HTML "<body>\n";
957 if ($counts{mismatch}) {
958 print HTML "<p>Tests where results did not match expected results:</p>\n";
959 print HTML "<table>\n";
960 for my $test (@{$tests{mismatch}}) {
961 my $base = stripExtension($test);
963 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$test</a></td>\n";
964 print HTML htmlForExpectedAndActualResults($base);
966 if ($imagesPresent{$base}) {
967 print HTML "<td><a href=\"$base-$expectedTag.png\">expected image</a></td>\n";
968 print HTML "<td><a href=\"$base-$diffsTag.html\">image diffs</a>\n";
969 print HTML "<a href=\"$base-$diffsTag.png\">$imageDifferences{$base}%</a></td>\n";
971 print HTML "<td></td><td></td>\n";
974 print HTML "</tr>\n";
976 print HTML "</table>\n";
979 if ($counts{crash}) {
980 print HTML "<p>Tests that caused the DumpRenderTree tool to crash:</p>\n";
981 print HTML "<table>\n";
982 for my $test (@{$tests{crash}}) {
983 my $base = stripExtension($test);
984 my $expectedDir = $expectedResultDirectory{$base};
986 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$base</a></td>\n";
987 print HTML htmlForExpectedAndActualResults($base);
988 print HTML "<td><a href=\"$base-$errorTag.txt\">stderr</a></td>\n";
989 print HTML "</tr>\n";
991 print HTML "</table>\n";
995 print HTML "<p>Tests that had no expected results (probably new):</p>\n";
996 print HTML "<table>\n";
997 for my $test (@{$tests{new}}) {
998 my $base = stripExtension($test);
999 my $expectedDir = $expectedResultDirectory{$base};
1000 print HTML "<tr>\n";
1001 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$base</a></td>\n";
1002 print HTML "<td><a href=\"" . toURL("$expectedDir/$base-$expectedTag.txt") . "\">results</a></td>\n";
1003 if ($pixelTests && -f "$expectedDir/$base-$expectedTag.png") {
1004 print HTML "<td><a href=\"" . toURL("$expectedDir/$base-$expectedTag.png") . "\">image</a></td>\n";
1006 print HTML "</tr>\n";
1008 print HTML "</table>\n";
1011 print HTML "</body>\n";
1012 print HTML "</html>\n";
1016 system "konqueror", $testResults if $launchSafari;
1018 system "WebKitTools/Scripts/run-launcher", "--gtk", $configurationOption, $testResults if $launchSafari;
1019 } elsif (isCygwin()) {
1020 system "cygstart", $testResults if $launchSafari;
1022 system "WebKitTools/Scripts/run-safari", $configurationOption, "-NSOpen", $testResults if $launchSafari;
1025 closeCygpaths() if isCygwin();
1029 sub countAndPrintLeaks($$$)
1031 my ($dumpToolName, $dumpToolPID, $leaksFilePath) = @_;
1033 print "\n" unless $atLineStart;
1036 # We are excluding the following reported leaks so they don't get in our way when looking for WebKit leaks:
1037 # This allows us ignore known leaks and only be alerted when new leaks occur. Some leaks are in the old
1038 # versions of the system frameworks that are being used by the leaks bots. Even though a leak has been
1039 # fixed, it will be listed here until the bot has been updated with the newer frameworks.
1041 my @typesToExclude = (
1044 my @callStacksToExclude = (
1045 "Flash_EnforceLocalSecurity" # leaks in Flash plug-in code, rdar://problem/4449747
1049 # Leak list for the version of Tiger used on the build bot.
1050 push @callStacksToExclude, (
1051 "CFRunLoopRunSpecific \\| malloc_zone_malloc", "CFRunLoopRunSpecific \\| CFAllocatorAllocate ", # leak in CFRunLoopRunSpecific, rdar://problem/4670839
1052 "CGImageSourceGetPropertiesAtIndex", # leak in ImageIO, rdar://problem/4628809
1053 "FOGetCoveredUnicodeChars", # leak in ATS, rdar://problem/3943604
1054 "GetLineDirectionPreference", "InitUnicodeUtilities", # leaks tool falsely reporting leak in CFNotificationCenterAddObserver, rdar://problem/4964790
1055 "ICCFPrefWrapper::GetPrefDictionary", # leaks in Internet Config. code, rdar://problem/4449794
1056 "NSHTTPURLProtocol setResponseHeader:", # leak in multipart/mixed-replace handling in Foundation, no Radar, but fixed in Leopard
1057 "NSURLCache cachedResponseForRequest", # leak in CFURL cache, rdar://problem/4768430
1058 "PCFragPrepareClosureFromFile", # leak in Code Fragment Manager, rdar://problem/3426998
1059 "WebCore::Selection::toRange", # bug in 'leaks', rdar://problem/4967949
1060 "WebCore::SubresourceLoader::create", # bug in 'leaks', rdar://problem/4985806
1061 "_CFPreferencesDomainDeepCopyDictionary", # leak in CFPreferences, rdar://problem/4220786
1062 "_objc_msgForward", # leak in NSSpellChecker, rdar://problem/4965278
1063 "gldGetString", # leak in OpenGL, rdar://problem/5013699
1064 "_setDefaultUserInfoFromURL", # leak in NSHTTPAuthenticator, rdar://problem/5546453
1065 "SSLHandshake", # leak in SSL, rdar://problem/5546440
1066 "SecCertificateCreateFromData", # leak in SSL code, rdar://problem/4464397
1068 push @typesToExclude, (
1069 "THRD", # bug in 'leaks', rdar://problem/3387783
1070 "DRHT", # ditto (endian little hate i)
1075 # Leak list for the version of Leopard used on the build bot.
1076 push @callStacksToExclude, (
1077 "CFHTTPMessageAppendBytes", # leak in CFNetwork, rdar://problem/5435912
1078 "sendDidReceiveDataCallback", # leak in CFNetwork, rdar://problem/5441619
1079 "_CFHTTPReadStreamReadMark", # leak in CFNetwork, rdar://problem/5441468
1080 "httpProtocolStart", # leak in CFNetwork, rdar://problem/5468837
1081 "_CFURLConnectionSendCallbacks", # leak in CFNetwork, rdar://problem/5441600
1082 "DispatchQTMsg", # leak in Quicktime, PPC only, <rdar://problem/5667132>
1083 "QTMovieContentView createVisualContext", # leak in Quicktime, PPC only, <rdar://problem/5667132>
1087 my $leaksTool = sourceDir() . "/WebKitTools/Scripts/run-leaks";
1088 my $excludeString = "--exclude-callstack '" . (join "' --exclude-callstack '", @callStacksToExclude) . "'";
1089 $excludeString .= " --exclude-type '" . (join "' --exclude-type '", @typesToExclude) . "'" if @typesToExclude;
1091 print " ? checking for leaks in $dumpToolName\n";
1092 my $leaksOutput = `$leaksTool $excludeString $dumpToolPID`;
1093 my ($count, $bytes) = $leaksOutput =~ /Process $dumpToolPID: (\d+) leaks? for (\d+) total/;
1094 my ($excluded) = $leaksOutput =~ /(\d+) leaks? excluded/;
1096 my $adjustedCount = $count;
1097 $adjustedCount -= $excluded if $excluded;
1099 if (!$adjustedCount) {
1100 print " - no leaks found\n";
1101 unlink $leaksFilePath;
1104 my $dir = $leaksFilePath;
1105 $dir =~ s|/[^/]+$|| or die;
1109 print " + $adjustedCount leaks ($bytes bytes including $excluded excluded leaks) were found, details in $leaksFilePath\n";
1111 print " + $count leaks ($bytes bytes) were found, details in $leaksFilePath\n";
1114 open LEAKS, ">", $leaksFilePath or die;
1115 print LEAKS $leaksOutput;
1118 push( @leaksFilenames, $leaksFilePath );
1121 return $adjustedCount;
1124 # Break up a path into the directory (with slash) and base name.
1129 my $pathSeparator = "/";
1130 my $dirname = dirname($path) . $pathSeparator;
1131 $dirname = "" if $dirname eq "." . $pathSeparator;
1133 return ($dirname, basename($path));
1136 # Sort first by directory, then by file, so all paths in one directory are grouped
1137 # rather than being interspersed with items from subdirectories.
1138 # Use numericcmp to sort directory and filenames to make order logical.
1141 my ($patha, $pathb) = @_;
1143 my ($dira, $namea) = splitpath($patha);
1144 my ($dirb, $nameb) = splitpath($pathb);
1146 return numericcmp($dira, $dirb) if $dira ne $dirb;
1147 return numericcmp($namea, $nameb);
1150 # Sort numeric parts of strings as numbers, other parts as strings.
1151 # Makes 1.33 come after 1.3, which is cool.
1156 my @a = split /(\d+)/, $aa;
1157 my @b = split /(\d+)/, $bb;
1159 # Compare one chunk at a time.
1160 # Each chunk is either all numeric digits, or all not numeric digits.
1165 # Use numeric comparison if chunks are non-equal numbers.
1166 return $a <=> $b if $a =~ /^\d/ && $b =~ /^\d/ && $a != $b;
1168 # Use string comparison if chunks are any other kind of non-equal string.
1169 return $a cmp $b if $a ne $b;
1172 # One of the two is now empty; compare lengths for result in this case.
1176 # Sort slowest tests first.
1179 my ($testa, $testb) = @_;
1181 my $dura = $durations{$testa};
1182 my $durb = $durations{$testb};
1183 return $durb <=> $dura if $dura != $durb;
1184 return pathcmp($testa, $testb);
1189 return if $isDumpToolOpen;
1191 # Save some requires variables for the linux environment...
1192 my $homeDir = $ENV{'HOME'};
1193 my $libraryPath = $ENV{'LD_LIBRARY_PATH'};
1194 my $dyldLibraryPath = $ENV{'DYLD_LIBRARY_PATH'};
1195 my $dbusAddress = $ENV{'DBUS_SESSION_BUS_ADDRESS'};
1196 my $display = $ENV{'DISPLAY'};
1197 my $testfonts = $ENV{'WEBKIT_TESTFONTS'};
1199 my $homeDrive = $ENV{'HOMEDRIVE'};
1200 my $homePath = $ENV{'HOMEPATH'};
1203 if (isQt() || isGtk()) {
1204 if (defined $display) {
1205 $ENV{DISPLAY} = $display;
1207 $ENV{DISPLAY} = ":1";
1209 $ENV{'WEBKIT_TESTFONTS'} = $testfonts if defined($testfonts);
1210 $ENV{HOME} = $homeDir;
1211 if (defined $libraryPath) {
1212 $ENV{LD_LIBRARY_PATH} = $libraryPath;
1214 if (defined $dyldLibraryPath) {
1215 $ENV{DYLD_LIBRARY_PATH} = $dyldLibraryPath;
1217 if (defined $dbusAddress) {
1218 $ENV{DBUS_SESSION_BUS_ADDRESS} = $dbusAddress;
1221 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1222 $ENV{XML_CATALOG_FILES} = ""; # work around missing /etc/catalog <rdar://problem/4292995>
1223 $ENV{MallocStackLogging} = 1 if $shouldCheckLeaks;
1224 $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc;
1227 $ENV{HOMEDRIVE} = $homeDrive;
1228 $ENV{HOMEPATH} = $homePath;
1230 $ENV{WEBKIT_TESTFONTS} = $testfonts;
1232 setPathForRunningWebKitApp(\%ENV) if isCygwin();
1237 push @args, $dumpTool;
1239 push @args, @toolArgs;
1241 $dumpTool = "valgrind";
1243 $dumpToolPID = open3(\*OUT, \*IN, \*ERROR, $dumpTool, @args) or die "Failed to start tool: $dumpTool\n";
1244 $isDumpToolOpen = 1;
1245 $dumpToolCrashed = 0;
1250 return if !$isDumpToolOpen;
1255 waitpid $dumpToolPID, 0;
1256 $isDumpToolOpen = 0;
1259 sub dumpToolDidCrash()
1261 return 1 if $dumpToolCrashed;
1262 return 0 unless $isDumpToolOpen;
1264 my $pid = waitpid(-1, WNOHANG);
1265 return $pid == $dumpToolPID;
1268 sub openHTTPDIfNeeded()
1270 return if $isHttpdOpen;
1272 mkdir "/tmp/WebKit";
1274 if (-f "/tmp/WebKit/httpd.pid") {
1275 my $oldPid = `cat /tmp/WebKit/httpd.pid`;
1277 if (0 != kill 0, $oldPid) {
1278 print "\nhttpd is already running: pid $oldPid, killing...\n";
1281 my $retryCount = 20;
1282 while ((0 != kill 0, $oldPid) && $retryCount) {
1287 die "Timed out waiting for httpd to quit" unless $retryCount;
1291 my $httpdPath = "/usr/sbin/httpd";
1294 my $windowsConfDirectory = "$testDirectory/http/conf/";
1295 unless (-x "/usr/lib/apache/libphp4.dll") {
1296 copy("$windowsConfDirectory/libphp4.dll", "/usr/lib/apache/libphp4.dll");
1297 chmod(0755, "/usr/lib/apache/libphp4.dll");
1299 $httpdConfig = "$windowsConfDirectory/cygwin-httpd.conf";
1300 } elsif (isDebianBased()) {
1301 $httpdPath = "/usr/sbin/apache2";
1302 $httpdConfig = "$testDirectory/http/conf/apache2-debian-httpd.conf";
1304 $httpdConfig = "$testDirectory/http/conf/httpd.conf";
1305 $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|;
1307 my $documentRoot = "$testDirectory/http/tests";
1308 my $typesConfig = "$testDirectory/http/conf/mime.types";
1309 my $listen = "127.0.0.1:$httpdPort";
1310 my $absTestResultsDirectory = File::Spec->rel2abs(glob $testResultsDirectory);
1311 my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem";
1313 mkpath $absTestResultsDirectory;
1316 "-f", "$httpdConfig",
1317 "-C", "DocumentRoot \"$documentRoot\"",
1318 "-C", "Listen $listen",
1319 "-c", "TypesConfig \"$typesConfig\"",
1320 "-c", "CustomLog \"$absTestResultsDirectory/access_log.txt\" common",
1321 "-c", "ErrorLog \"$absTestResultsDirectory/error_log.txt\"",
1322 # Apache wouldn't run CGIs with permissions==700 otherwise
1323 "-c", "User \"#$<\""
1326 # FIXME: Enable this on Windows once <rdar://problem/5345985> is fixed
1327 push(@args, "-c", "SSLCertificateFile \"$sslCertificate\"") unless isCygwin();
1329 open2(\*HTTPDIN, \*HTTPDOUT, $httpdPath, @args);
1331 my $retryCount = 20;
1332 while (system("/usr/bin/curl -q --silent --stderr - --output /dev/null $listen") && $retryCount) {
1337 die "Timed out waiting for httpd to start" unless $retryCount;
1344 return if !$isHttpdOpen;
1349 kill 15, `cat /tmp/WebKit/httpd.pid` if -f "/tmp/WebKit/httpd.pid";
1354 sub fileNameWithNumber($$)
1356 my ($base, $number) = @_;
1357 return "$base$number" if ($number > 1);
1361 sub processIgnoreTests($) {
1362 my @ignoreList = split(/\s*,\s*/, shift);
1363 my $addIgnoredDirectories = sub {
1364 return () if exists $ignoredLocalDirectories{basename($File::Find::dir)};
1365 $ignoredDirectories{File::Spec->abs2rel($File::Find::dir, $testDirectory)} = 1;
1368 foreach my $item (@ignoreList) {
1369 my $path = catfile($testDirectory, $item);
1371 $ignoredDirectories{$item} = 1;
1372 find({ preprocess => $addIgnoredDirectories, wanted => sub {} }, $path);
1375 $ignoredFiles{$item} = 1;
1378 print "ignoring '$item' on ignore-tests list\n";
1383 sub stripExtension($)
1387 $test =~ s/\.[a-zA-Z]+$//;
1391 sub isTextOnlyTest($)
1395 if ($actual =~ /^layer at/ms) {
1403 sub expectedDirectoryForTest($;$;$)
1405 my ($base, $isText, $isPixelTest) = @_;
1407 my @directories = @platformHierarchy;
1408 push @directories, map { catdir($platformBaseDirectory, $_) } qw(mac-leopard mac) if isCygwin();
1409 push @directories, $expectedDirectory;
1411 # If we already have expected results, just return their location.
1413 foreach my $directory (@directories) {
1414 return $directory if (-f "$directory/$base-$expectedTag.png");
1417 foreach my $directory (@directories) {
1418 return $directory if (-f "$directory/$base-$expectedTag.txt");
1422 # For platform-specific tests, the results should go right next to the test itself.
1423 # Note: The return value of this subroutine will be concatenated with $base
1424 # to determine the location of the new results, so returning $expectedDirectory
1425 # will put the results right next to the test.
1426 # FIXME: We want to allow platform/mac tests with platform/mac-leopard results,
1427 # so this needs to be enhanced.
1428 return $expectedDirectory if $base =~ /^platform/;
1430 # For cross-platform tests, text-only results should go in the cross-platform directory,
1431 # while render tree dumps should go in the least-specific platform directory.
1432 return $isText ? $expectedDirectory : $platformHierarchy[$#platformHierarchy];
1435 sub printFailureMessageForTest($$)
1437 my ($test, $description) = @_;
1440 print "\n" unless $atLineStart;
1443 print "$description\n";
1449 sub openCygpathIfNeeded($)
1453 return unless isCygwin();
1454 return $cygpaths{$options} if $cygpaths{$options} && $cygpaths{$options}->{"open"};
1456 local (*CYGPATHIN, *CYGPATHOUT);
1457 my $pid = open2(\*CYGPATHIN, \*CYGPATHOUT, "cygpath -f - $options");
1461 "out" => *CYGPATHOUT,
1465 $cygpaths{$options} = $cygpath;
1472 return unless isCygwin();
1474 foreach my $cygpath (values(%cygpaths)) {
1475 close $cygpath->{"in"};
1476 close $cygpath->{"out"};
1477 waitpid($cygpath->{"pid"}, 0);
1478 $cygpath->{"open"} = 0;
1483 sub convertPathUsingCygpath($$)
1485 my ($path, $options) = @_;
1487 my $cygpath = openCygpathIfNeeded($options);
1488 local *inFH = $cygpath->{"in"};
1489 local *outFH = $cygpath->{"out"};
1490 print outFH $path . "\n";
1491 chomp(my $convertedPath = <inFH>);
1492 return $convertedPath;
1495 sub toWindowsPath($)
1498 return unless isCygwin();
1500 return convertPathUsingCygpath($path, "-w");
1506 return $path unless isCygwin();
1508 return "file:///" . convertPathUsingCygpath($path, "-m");
1511 sub validateSkippedArg($$;$)
1513 my ($option, $value, $value2) = @_;
1514 my %validSkippedValues = map { $_ => 1 } qw(default ignore only);
1515 $value = lc($value);
1516 die "Invalid argument '" . $value . "' for option $option" unless $validSkippedValues{$value};
1517 $treatSkipped = $value;
1520 sub htmlForExpectedAndActualResults($)
1524 return "<td></td><td></td><td></td>\n" unless -s "$testResultsDirectory/$base-$diffsTag.txt";
1526 return "<td><a href=\"$base-$expectedTag.txt\">expected</a></td>\n"
1527 . "<td><a href=\"$base-$actualTag.txt\">actual</a></td>\n"
1528 . "<td><a href=\"$base-$diffsTag.txt\">diffs</a></td>\n";
1531 sub deleteExpectedAndActualResults($)
1535 unlink "$testResultsDirectory/$base-$actualTag.txt";
1536 unlink "$testResultsDirectory/$base-$diffsTag.txt";
1537 unlink "$testResultsDirectory/$base-$errorTag.txt";
1540 sub recordActualResultsAndDiff($$)
1542 my ($base, $actual) = @_;
1544 return unless length($actual);
1546 open ACTUAL, ">", "$testResultsDirectory/$base-$actualTag.txt" or die "Couldn't open actual results file for $base";
1547 print ACTUAL $actual;
1550 my $expectedDir = $expectedResultDirectory{$base};
1551 copy("$expectedDir/$base-$expectedTag.txt", "$testResultsDirectory/$base-$expectedTag.txt");
1553 system "diff -u \"$testResultsDirectory/$base-$expectedTag.txt\" \"$testResultsDirectory/$base-$actualTag.txt\" > \"$testResultsDirectory/$base-$diffsTag.txt\"";
1556 sub buildPlatformHierarchy()
1558 mkpath($platformTestDirectory) if ($platform eq "undefined" && !-d "$platformTestDirectory");
1560 my @platforms = split('-', $platform);
1562 for (my $i=0; $i < @platforms; $i++) {
1563 my $scoped = catdir($platformBaseDirectory, join('-', @platforms[0..($#platforms - $i)]));
1564 push(@hierarchy, $scoped) if (-d $scoped);
1570 sub epiloguesAndPrologues($$) {
1571 my ($lastDirectory, $directory) = @_;
1572 my @lastComponents = split('/', $lastDirectory);
1573 my @components = split('/', $directory);
1575 while (@lastComponents) {
1576 if ($lastComponents[0] ne $components[0]) {
1580 shift @lastComponents;
1584 my $leaving = $lastDirectory;
1585 foreach (@lastComponents) {
1586 my $epilogue = $leaving . "/resources/run-webkit-tests-epilogue.html";
1587 foreach (@platformHierarchy) {
1588 push @result, catdir($_, $epilogue) if (stat(catdir($_, $epilogue)));
1590 push @result, catdir($testDirectory, $epilogue) if (stat(catdir($testDirectory, $epilogue)));
1591 $leaving =~ s|(^\|/)[^/]+$||;
1594 my $entering = $leaving;
1595 foreach (@components) {
1596 $entering .= '/' . $_;
1597 my $prologue = $entering . "/resources/run-webkit-tests-prologue.html";
1598 push @result, catdir($testDirectory, $prologue) if (stat(catdir($testDirectory, $prologue)));
1599 foreach (reverse @platformHierarchy) {
1600 push @result, catdir($_, $prologue) if (stat(catdir($_, $prologue)));
1606 sub parseLeaksandPrintUniqueLeaks() {
1607 return unless @leaksFilenames;
1609 my $mergedFilenames = join " ", @leaksFilenames;
1610 my $parseMallocHistoryTool = sourceDir() . "/WebKitTools/Scripts/parse-malloc-history";
1612 open MERGED_LEAKS, "cat $mergedFilenames | $parseMallocHistoryTool --merge-depth $mergeDepth - |" ;
1613 my @leakLines = <MERGED_LEAKS>;
1616 my $uniqueLeakCount = 0;
1618 foreach my $line (@leakLines) {
1619 ++$uniqueLeakCount if ($line =~ /^(\d*)\scalls/);
1620 $totalBytes = $1 if $line =~ /^total\:\s(.*)\s\(/;
1623 print "\nWARNING: $totalLeaks total leaks found for a total of $totalBytes!\n";
1624 print "WARNING: $uniqueLeakCount unique leaks found!\n";
1625 print "See above for individual leaks results.\n" if ($leaksOutputFileNumber > 2);