3 # Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
4 # Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 # its contributors may be used to endorse or promote products derived
17 # from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # Script to run the Web Kit Open Source Project layout tests.
32 # Run all the tests passed in on the command line.
33 # If no tests are passed, find all the .html, .shtml, .xml, .xhtml, .pl, .php (and svg) files in the test directory.
36 # Compare against the existing file xxx-expected.txt.
37 # If there is a mismatch, generate xxx-actual.txt and xxx-diffs.txt.
40 # the number of tests that got the expected results
41 # the number of tests that ran, but did not get the expected results
42 # the number of tests that failed to run
43 # the number of tests that were run but had no expected results to compare against
54 use File::Spec::Functions;
58 use Time::HiRes qw(time);
60 use lib $FindBin::Bin;
67 sub countAndPrintLeaks($$$);
68 sub fileNameWithNumber($$);
70 sub openHTTPDIfNeeded();
72 sub processIgnoreTests($);
75 sub isTextOnlyTest($);
76 sub expectedDirectoryForTest($);
82 my $shouldCheckLeaks = '';
83 my $configuration = '';
86 my $httpdSSLPort = 8443;
91 my $repaintSweepHorizontally = '';
92 my $repaintTests = '';
93 my $report10Slowest = 0;
96 my $treatSkipped = "default";
97 my $testsPerDumpTool = 1000;
99 my $testOnlySVGs = '';
100 my $testResultsDirectory = "/tmp/layout-test-results";
104 my $strictTesting = 0;
105 my $generateNewResults = 1;
106 my $stripEditingCallbacks = isCygwin();
109 my $expectedTag = "expected";
110 my $actualTag = "actual";
111 my $diffsTag = "diffs";
113 my $programName = basename($0);
114 my $launchSafariDefault = $launchSafari ? "launch" : "do not launch";
115 my $httpDefault = $testHTTP ? "run" : "do not run";
118 Usage: $programName [options] [testdir|testpath ...]
119 -c|--configuration config Set DumpRenderTree build configuration
120 -g|--guard-malloc Enable malloc guard
121 --help Show this help message
122 -h|--horizontal-sweep Change repaint to sweep horizontally instead of vertically (implies --repaint-tests)
123 --[no-]http Run (or do not run) http tests (default: $httpDefault)
124 -i|--ignore-tests Comma-separated list of directories or tests to ignore
125 --[no-]launch-safari Launch (or do not launch) Safari to display test results (default: $launchSafariDefault)
126 -l|--leaks Enable leaks checking
127 --[no-]new-test-results Generate results for new tests
128 -p|--pixel-tests Enable pixel tests
129 --port Web server port to use with http tests
130 -q|--quiet Less verbose output
131 -r|--repaint-tests Run repaint tests (implies --pixel-tests)
132 --reset-results Reset ALL results (including pixel tests if --pixel-tests is set)
133 -o|--results-directory Output results directory (default: $testResultsDirectory)
134 --root Path to root tools build
135 -1|--singly Isolate each test case run (implies --verbose)
136 --skipped=[default|ignore|only] Specifies how to treat the Skipped file
137 default: Tests/directories listed in the Skipped file are not tested
138 ignore: The Skipped file is ignored
139 only: Only those tests/directories listed in the Skipped file will be run
140 --slowest Report the 10 slowest tests
141 --strict Do a comparison with the output on Mac (Qt only)
142 --[no-]strip-editing-callbacks Remove editing callbacks from expected results
143 --svg Run only SVG tests (implies --pixel-tests)
144 -t|--threaded Run a concurrent JavaScript thead with each test
145 --valgrind Run DumpRenderTree inside valgrind (Qt/Linux only)
146 -v|--verbose More verbose output (overrides --quiet)
149 my $getOptionsResult = GetOptions(
150 'c|configuration=s' => \$configuration,
151 'debug|devel' => sub { $configuration = "Debug" },
152 'guard-malloc|g' => \$guardMalloc,
153 'help' => \$showHelp,
154 'horizontal-sweep|h' => \$repaintSweepHorizontally,
155 'http!' => \$testHTTP,
156 'ignore-tests|i=s' => \$ignoreTests,
157 'launch-safari!' => \$launchSafari,
158 'leaks|l' => \$shouldCheckLeaks,
159 'pixel-tests|p' => \$pixelTests,
160 'port=i' => \$httpdPort,
161 'quiet|q' => \$quiet,
162 'release|deploy' => sub { $configuration = "Release" },
163 'repaint-tests|r' => \$repaintTests,
164 'reset-results' => \$resetResults,
165 'new-test-results!' => \$generateNewResults,
166 'results-directory|o=s' => \$testResultsDirectory,
167 'singly|1' => sub { $testsPerDumpTool = 1; },
168 'nthly=i' => \$testsPerDumpTool,
169 'skipped=s' => \$treatSkipped,
170 'slowest' => \$report10Slowest,
171 'svg' => \$testOnlySVGs,
172 'threaded|t' => \$threaded,
173 'verbose|v' => \$verbose,
174 'valgrind' => \$useValgrind,
175 'strict' => \$strictTesting,
176 'strip-editing-callbacks!' => \$stripEditingCallbacks,
180 if (!$getOptionsResult || $showHelp || ($treatSkipped ne "default" && $treatSkipped ne "ignore" && $treatSkipped ne "only")) {
185 my $ignoreSkipped = $treatSkipped eq "ignore";
186 my $skippedOnly = $treatSkipped eq "only";
188 !$skippedOnly || @ARGV == 0 or die "--skipped=only cannot be used when tests are specified on the command line.";
190 setConfiguration($configuration);
192 my $configurationOption = "--" . lc($configuration);
194 $repaintTests = 1 if $repaintSweepHorizontally;
196 $pixelTests = 1 if $testOnlySVGs;
197 $pixelTests = 1 if $repaintTests;
199 $verbose = 1 if $testsPerDumpTool == 1;
201 if ($shouldCheckLeaks && $testsPerDumpTool > 1000) {
202 print STDERR "\nWARNING: Running more than 1000 tests at a time with MallocStackLogging enabled may cause a crash.\n\n";
205 # Force --no-http for Qt/Linux, for now.
206 $testHTTP = 0 if isQt();
208 setConfigurationProductDir(Cwd::abs_path($root)) if (defined($root));
209 my $productDir = productDir();
210 $productDir .= "/WebKitTools/DumpRenderTree/DumpRenderTree.qtproj" if (isQt());
217 $buildResult = buildVisualStudioProject("WebKitTools/DumpRenderTree/DumpRenderTree.vcproj/DumpRenderTree.sln");
219 $buildResult = system "WebKitTools/Scripts/build-dumprendertree", $configurationOption;
223 print STDERR "Compiling DumpRenderTree failed!\n";
224 exit WEXITSTATUS($buildResult);
228 my $dumpToolName = "DumpRenderTree";
229 $dumpToolName .= "_debug" if isCygwin() && $configuration ne "Release";
230 my $dumpTool = "$productDir/$dumpToolName";
231 die "can't find executable $dumpToolName (looked in $productDir)\n" unless -x $dumpTool;
233 my $imageDiffTool = "$productDir/ImageDiff";
234 die "can't find executable $imageDiffTool (looked in $productDir)\n" if $pixelTests && !-x $imageDiffTool;
236 checkFrameworks() unless isCygwin();
238 my $layoutTestsName = "LayoutTests";
239 my $testDirectory = File::Spec->rel2abs($layoutTestsName);
240 my $platformTestDirectory = $testDirectory;
241 my $expectedDirectory = $testDirectory;
243 $platformTestDirectory = "$testDirectory/mac/leopard";
245 $expectedDirectory = "LayoutTests/qt/";
246 $platformTestDirectory = $expectedDirectory;
247 } elsif (isCygwin()) {
248 $expectedDirectory = $testDirectory;
249 $platformTestDirectory = File::Spec->rel2abs("LayoutTests/win/");
252 $expectedDirectory = $ENV{"WebKitExpectedTestResultsDirectory"} if $ENV{"WebKitExpectedTestResultsDirectory"};
255 $testDirectory .= "/svg";
256 $expectedDirectory .= "/svg";
259 my $testResults = catfile($testResultsDirectory, "results.html");
261 print "Running tests from $testDirectory\n";
266 system "ln", "-s", $testDirectory, "/tmp/LayoutTests" unless -x "/tmp/LayoutTests";
268 my %ignoredFiles = ();
269 my %ignoredDirectories = ();
270 my %ignoredLocalDirectories = map { $_ => 1 } qw(.svn _svn resources);
271 my %supportedFileExtensions = map { $_ => 1 } qw(html shtml xml xhtml pl php);
273 %supportedFileExtensions = map { $_ => 1 } qw(svg xml);
274 } elsif (checkWebCoreSVGSupport($testOnlySVGs)) {
275 $supportedFileExtensions{'svg'} = 1;
276 } elsif (isCygwin()) {
277 # FIXME: We should fix webkitdirs.pm:hasSVGSupport() to do the correct
278 # check for Windows instead of forcing this here.
279 $supportedFileExtensions{'svg'} = 1;
281 $ignoredLocalDirectories{'svg'} = 1;
284 $ignoredDirectories{'http'} = 1;
288 processIgnoreTests($ignoreTests);
291 if (!$ignoreSkipped && open SKIPPED, "<", "$platformTestDirectory/Skipped") {
292 if ($verbose && !$skippedOnly) {
293 print "Skipped tests:\n";
300 if ($skipped && $skipped !~ /^#/) {
302 push(@ARGV, $skipped);
307 processIgnoreTests($skipped);
315 my $directoryFilter = sub {
316 return () if exists $ignoredLocalDirectories{basename($File::Find::dir)};
317 return () if exists $ignoredDirectories{File::Spec->abs2rel($File::Find::dir, $testDirectory)};
321 my $fileFilter = sub {
323 if ($filename =~ /\.([^.]+)$/) {
324 if (exists $supportedFileExtensions{$1}) {
325 my $path = File::Spec->abs2rel(catfile($File::Find::dir, $filename), $testDirectory);
326 push @tests, $path if !exists $ignoredFiles{$path};
331 for my $test (@ARGV) {
332 $test =~ s/^($layoutTestsName|$testDirectory)\///;
333 my $fullPath = catfile($testDirectory, $test);
334 if (file_name_is_absolute($test)) {
335 print "can't run test $test outside $testDirectory\n";
336 } elsif (-f $fullPath) {
337 my ($filename, $pathname, $fileExtension) = fileparse($test, qr{\.[^.]+$});
338 if (!exists $supportedFileExtensions{substr($fileExtension, 1)}) {
339 print "test $test does not have a supported extension\n";
340 } elsif ($testHTTP || $pathname !~ /^http\//) {
343 } elsif (-d $fullPath) {
344 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $fullPath);
346 print "test $test not found\n";
350 find({ preprocess => $directoryFilter, wanted => $fileFilter }, $testDirectory);
353 die "no tests to run\n" if !@tests;
355 @tests = sort pathcmp @tests;
362 my $leaksOutputFileNumber = 1;
366 push @toolArgs, "--dump-all-pixels" if $pixelTests && $resetResults;
367 push @toolArgs, "--pixel-tests" if $pixelTests;
368 push @toolArgs, "--repaint" if $repaintTests;
369 push @toolArgs, "--horizontal-sweep" if $repaintSweepHorizontally;
370 push @toolArgs, "--threaded" if $threaded;
371 push @toolArgs, "--paint" if $shouldCheckLeaks; # Otherwise, DRT won't exercise painting leaks.
376 my $imageDiffToolPID;
379 $ENV{MallocStackLogging} = 1 if $shouldCheckLeaks;
380 $imageDiffToolPID = open2(\*DIFFIN, \*DIFFOUT, $imageDiffTool, "") or die "unable to open $imageDiffTool\n";
384 my $isDumpToolOpen = 0;
387 my $lastDirectory = "";
391 print "Testing ", scalar @tests, " test cases.\n";
392 my $overallStartTime = time;
394 for my $test (@tests) {
395 next if $test eq 'results.html';
400 $base =~ s/\.[a-zA-Z]+$//;
403 print "running $test -> ";
408 if ($dir ne $lastDirectory) {
409 print "\n" unless $atLineStart;
411 $lastDirectory = $dir;
419 my $startTime = time if $report10Slowest;
421 if ($test !~ /^http\//) {
422 my $testPath = "$testDirectory/$test";
424 $testPath = toWindowsPath($testPath);
426 $testPath = canonpath($testPath);
428 print OUT "$testPath\n";
431 if ($test !~ /^http\/tests\/local\// && $test !~ /^http\/tests\/ssl\//) {
432 my $path = canonpath($test);
433 $path =~ s/^http\/tests\///;
434 print OUT "http://127.0.0.1:$httpdPort/$path\n";
435 } elsif ($test =~ /^http\/tests\/ssl\//) {
436 my $path = canonpath($test);
437 $path =~ s/^http\/tests\///;
438 print OUT "https://127.0.0.1:$httpdSSLPort/$path\n";
440 my $testPath = "$testDirectory/$test";
442 $testPath = toWindowsPath($testPath);
445 $testPath = canonpath($testPath);
447 print OUT "$testPath\n";
456 $actual =~ s/\r//g if isCygwin();
458 my $isText = isTextOnlyTest($actual);
460 $durations{$test} = time - $startTime if $report10Slowest;
463 my $expectedDir = expectedDirectoryForTest($base);
465 if (!$resetResults && open EXPECTED, "<", "$expectedDir/$base-$expectedTag.txt") {
468 next if $stripEditingCallbacks && $_ =~ /^EDITING DELEGATE:/;
474 if (!isOSX() && $strictTesting && !$isText) {
475 if (!$resetResults && open EXPECTED, "<", "$expectedDirectory/$base-$expectedTag.txt") {
484 if ($shouldCheckLeaks && $testsPerDumpTool == 1) {
490 my $diffPercentage = "";
491 my $diffResult = "passed";
494 die "Pixel tests currently don't work when using a custom expected test results directory" if $testDirectory ne $expectedDir;
497 my $expectedHash = "";
498 my $actualPNGSize = 0;
501 if (/ActualHash: ([a-f0-9]{32})/) {
503 } elsif (/BaselineHash: ([a-f0-9]{32})/) {
505 } elsif (/Content-length: (\d+)\s*/) {
507 read(IN, $actualPNG, $actualPNGSize);
511 if ($expectedHash ne $actualHash && -f "$testDirectory/$base-$expectedTag.png") {
512 my $expectedPNGSize = -s "$testDirectory/$base-$expectedTag.png";
513 my $expectedPNG = "";
514 open EXPECTEDPNG, "$testDirectory/$base-$expectedTag.png";
515 read(EXPECTEDPNG, $expectedPNG, $expectedPNGSize);
517 print DIFFOUT "Content-length: $actualPNGSize\n";
518 print DIFFOUT $actualPNG;
520 print DIFFOUT "Content-length: $expectedPNGSize\n";
521 print DIFFOUT $expectedPNG;
524 last if /^error/ || /^diff:/;
525 if (/Content-length: (\d+)\s*/) {
526 read(DIFFIN, $diffPNG, $1);
530 if (/^diff: (.+)% (passed|failed)/) {
531 $diffPercentage = $1;
536 if ($actualPNGSize && ($resetResults || !-f "$testDirectory/$base-$expectedTag.png")) {
537 open EXPECTED, ">", "$testDirectory/$base-expected.png" or die "could not create $testDirectory/$base-expected.png\n";
538 print EXPECTED $actualPNG;
542 # update the expected hash if the image diff said that there was no difference
543 if ($actualHash ne "" && ($resetResults || !-f "$testDirectory/$base-$expectedTag.checksum")) {
544 open EXPECTED, ">", "$testDirectory/$base-$expectedTag.checksum" or die "could not create $testDirectory/$base-$expectedTag.checksum\n";
545 print EXPECTED $actualHash;
550 if (!isOSX() && $strictTesting && !$isText) {
551 if (defined $expectedMac) {
552 my $simplified_actual;
553 $simplified_actual = $actual;
554 $simplified_actual =~ s/at \(-?[0-9]+,-?[0-9]+\) *//g;
555 $simplified_actual =~ s/size -?[0-9]+x-?[0-9]+ *//g;
556 $simplified_actual =~ s/text run width -?[0-9]+: //g;
557 $simplified_actual =~ s/text run width -?[0-9]+ [a-zA-Z ]+: //g;
558 $simplified_actual =~ s/RenderButton {BUTTON} .*/RenderButton {BUTTON}/g;
559 $simplified_actual =~ s/RenderImage {INPUT} .*/RenderImage {INPUT}/g;
560 $simplified_actual =~ s/RenderBlock {INPUT} .*/RenderBlock {INPUT}/g;
561 $simplified_actual =~ s/RenderTextControl {INPUT} .*/RenderTextControl {INPUT}/g;
562 $simplified_actual =~ s/\([0-9]+px/px/g;
563 $simplified_actual =~ s/ *" *\n +" */ /g;
564 $simplified_actual =~ s/" +$/"/g;
566 $simplified_actual =~ s/- /-/g;
567 $simplified_actual =~ s/\n( *)"\s+/\n$1"/g;
568 $simplified_actual =~ s/\s+"\n/"\n/g;
570 $expectedMac =~ s/at \(-?[0-9]+,-?[0-9]+\) *//g;
571 $expectedMac =~ s/size -?[0-9]+x-?[0-9]+ *//g;
572 $expectedMac =~ s/text run width -?[0-9]+: //g;
573 $expectedMac =~ s/text run width -?[0-9]+ [a-zA-Z ]+: //g;
574 $expectedMac =~ s/RenderButton {BUTTON} .*/RenderButton {BUTTON}/g;
575 $expectedMac =~ s/RenderImage {INPUT} .*/RenderImage {INPUT}/g;
576 $expectedMac =~ s/RenderBlock {INPUT} .*/RenderBlock {INPUT}/g;
577 $expectedMac =~ s/RenderTextControl {INPUT} .*/RenderTextControl {INPUT}/g;
578 $expectedMac =~ s/\([0-9]+px/px/g;
579 $expectedMac =~ s/ *" *\n +" */ /g;
580 $expectedMac =~ s/" +$/"/g;
582 $expectedMac =~ s/- /-/g;
583 $expectedMac =~ s/\n( *)"\s+/\n$1"/g;
584 $expectedMac =~ s/\s+"\n/"\n/g;
586 if ($simplified_actual ne $expectedMac) {
587 open ACTUAL, ">", "/tmp/actual.txt" or die;
588 print ACTUAL $simplified_actual;
590 open ACTUAL, ">", "/tmp/expected.txt" or die;
591 print ACTUAL $expectedMac;
593 system "diff -u \"/tmp/expected.txt\" \"/tmp/actual.txt\" > \"/tmp/simplified.diff\"";
595 $diffResult = "failed";
598 system "cat /tmp/simplified.diff";
605 if (!defined $expected) {
607 print "new " . ($resetResults ? "result" : "test") ."\n";
612 if ($generateNewResults || $resetResults) {
613 # Create the path if needed
614 mkpath(catfile($expectedDir, dirname($base))) if $testDirectory ne $expectedDir;
616 open EXPECTED, ">", "$expectedDir/$base-$expectedTag.txt" or die "could not create $expectedDir/$base-$expectedTag.txt\n";
617 print EXPECTED $actual;
620 unlink "$testResultsDirectory/$base-$actualTag.txt";
621 unlink "$testResultsDirectory/$base-$diffsTag.txt";
622 unless ($resetResults) {
623 # Always print the file name for new tests, as they will probably need some manual inspection.
624 # in verbose mode we already printed the test case, so no need to do it again.
626 print "\n" unless $atLineStart;
632 } elsif ($actual eq $expected && $diffResult eq "passed") {
638 unlink "$testResultsDirectory/$base-$actualTag.txt";
639 unlink "$testResultsDirectory/$base-$diffsTag.txt";
642 print "\n" unless $atLineStart;
648 $result = "mismatch";
650 my $dir = "$testResultsDirectory/$base";
651 $dir =~ s|/([^/]+)$|| or die "Failed to find test name from base\n";
655 open ACTUAL, ">", "$testResultsDirectory/$base-$actualTag.txt" or die;
656 print ACTUAL $actual;
659 system "diff -u \"$expectedDir/$base-$expectedTag.txt\" \"$testResultsDirectory/$base-$actualTag.txt\" > \"$testResultsDirectory/$base-$diffsTag.txt\"";
661 if ($pixelTests && $diffPNG && $diffPNG ne "") {
662 $imagesPresent{$base} = 1;
664 open ACTUAL, ">", "$testResultsDirectory/$base-$actualTag.png" or die;
665 print ACTUAL $actualPNG;
668 open DIFF, ">", "$testResultsDirectory/$base-$diffsTag.png" or die;
672 copy("$expectedDir/$base-$expectedTag.png", "$testResultsDirectory/$base-$expectedTag.png");
674 open DIFFHTML, ">$testResultsDirectory/$base-$diffsTag.html" or die;
675 print DIFFHTML "<html>\n";
676 print DIFFHTML "<head>\n";
677 print DIFFHTML "<title>$base Image Compare</title>\n";
678 print DIFFHTML "<script language=\"Javascript\" type=\"text/javascript\">\n";
679 print DIFFHTML "var currentImage = 0;\n";
680 print DIFFHTML "var imageNames = new Array(\"Actual\", \"Expected\");\n";
681 print DIFFHTML "var imagePaths = new Array(\"$testName-$actualTag.png\", \"$testName-$expectedTag.png\");\n";
682 if (-f "$testDirectory/$base-w3c.png") {
683 copy("$testDirectory/$base-w3c.png", "$testResultsDirectory/$base-w3c.png");
684 print DIFFHTML "imageNames.push(\"W3C\");\n";
685 print DIFFHTML "imagePaths.push(\"$testName-w3c.png\");\n";
687 print DIFFHTML "function animateImage() {\n";
688 print DIFFHTML " var image = document.getElementById(\"animatedImage\");\n";
689 print DIFFHTML " var imageText = document.getElementById(\"imageText\");\n";
690 print DIFFHTML " image.src = imagePaths[currentImage];\n";
691 print DIFFHTML " imageText.innerHTML = imageNames[currentImage] + \" Image\";\n";
692 print DIFFHTML " currentImage = (currentImage + 1) % imageNames.length;\n";
693 print DIFFHTML " setTimeout('animateImage()',2000);\n";
694 print DIFFHTML "}\n";
695 print DIFFHTML "</script>\n";
696 print DIFFHTML "</head>\n";
697 print DIFFHTML "<body onLoad=\"animateImage();\">\n";
698 print DIFFHTML "<table>\n";
699 if ($diffPercentage) {
700 print DIFFHTML "<tr>\n";
701 print DIFFHTML "<td>Difference between images: <a href=\"$testName-$diffsTag.png\">$diffPercentage%</a></td>\n";
702 print DIFFHTML "</tr>\n";
704 print DIFFHTML "<tr>\n";
705 print DIFFHTML "<td id=\"imageText\" style=\"text-weight: bold;\">Actual Image</td>\n";
706 print DIFFHTML "</tr>\n";
707 print DIFFHTML "<tr>\n";
708 print DIFFHTML "<td><img src=\"$testName-$actualTag.png\" id=\"animatedImage\"></td>\n";
709 print DIFFHTML "</tr>\n";
710 print DIFFHTML "</table>\n";
711 print DIFFHTML "</body>\n";
712 print DIFFHTML "</html>\n";
716 if (($count + 1) % $testsPerDumpTool == 0 || $count == $#tests) {
717 if ($shouldCheckLeaks) {
719 if ($testsPerDumpTool == 1) {
720 $fileName = "$testResultsDirectory/$base-leaks.txt";
722 $fileName = "$testResultsDirectory/" . fileNameWithNumber($dumpToolName, $leaksOutputFileNumber) . "-leaks.txt";
724 my $leakCount = countAndPrintLeaks($dumpToolName, $dumpToolPID, $fileName);
725 $totalLeaks += $leakCount;
726 $leaksOutputFileNumber++ if ($leakCount);
734 push @{$tests{$result}}, $test;
735 $testType{$test} = $isText;
737 printf "\n%0.2fs total testing time\n", (time - $overallStartTime) . "";
739 !$isDumpToolOpen || die "Failed to close $dumpToolName.\n";
743 # Because multiple instances of this script are running concurrently we cannot
744 # safely delete this symlink.
745 # system "rm /tmp/LayoutTests";
747 # FIXME: Do we really want to check the image-comparison tool for leaks every time?
748 if ($shouldCheckLeaks && $pixelTests) {
749 $totalLeaks += countAndPrintLeaks("ImageDiff", $imageDiffToolPID, "$testResultsDirectory/ImageDiff-leaks.txt");
753 print "\nWARNING: $totalLeaks total leaks found!\n";
754 print "See above for individual leaks results.\n" if ($leaksOutputFileNumber > 2);
760 if ($report10Slowest) {
761 print "\n\nThe 10 slowest tests:\n\n";
763 for my $test (sort slowestcmp keys %durations) {
764 printf "%0.2f secs: %s\n", $durations{$test}, $test;
765 last if ++$count == 10;
771 if ($skippedOnly && $counts{"match"}) {
772 print "The following tests are in the Skipped file (" . File::Spec->abs2rel("$platformTestDirectory/Skipped", $testDirectory) . "), but succeeded:\n";
773 foreach my $test (@{$tests{"match"}}) {
778 if ($resetResults || ($counts{match} && $counts{match} == $count)) {
779 print "all $count test cases succeeded\n";
786 match => "succeeded",
787 mismatch => "had incorrect layout",
789 fail => "failed (tool did not execute successfully)",
792 for my $type ("match", "mismatch", "new", "fail") {
793 my $c = $counts{$type};
795 my $t = $text{$type};
799 $message = sprintf "1 test case (%d%%) %s\n", 1 * 100 / $count, $t;
801 $message = sprintf "%d test cases (%d%%) %s\n", $c, $c * 100 / $count, $t;
803 $message =~ s-\(0%\)-(<1%)-;
808 mkpath $testResultsDirectory;
810 open HTML, ">", $testResults or die;
811 print HTML "<html>\n";
812 print HTML "<head>\n";
813 print HTML "<title>Layout Test Results</title>\n";
814 print HTML "</head>\n";
815 print HTML "<body>\n";
817 if ($counts{mismatch}) {
818 print HTML "<p>Tests where results did not match expected results:</p>\n";
819 print HTML "<table>\n";
820 for my $test (@{$tests{mismatch}}) {
822 $base =~ s/\.[a-zA-Z]+$//;
823 my $expectedDir = expectedDirectoryForTest($base);
824 copy("$expectedDir/$base-$expectedTag.txt", "$testResultsDirectory/$base-$expectedTag.txt");
826 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$test</a></td>\n";
827 if (-s "$testResultsDirectory/$base-$diffsTag.txt") {
828 print HTML "<td><a href=\"$base-$expectedTag.txt\">expected</a></td>\n";
829 print HTML "<td><a href=\"$base-$actualTag.txt\">actual</a></td>\n";
830 print HTML "<td><a href=\"$base-$diffsTag.txt\">diffs</a></td>\n";
832 print HTML "<td></td><td></td><td></td>\n";
835 if ($imagesPresent{$base}) {
836 print HTML "<td><a href=\"$base-$expectedTag.png\">expected image</a></td>\n";
837 print HTML "<td><a href=\"$base-$diffsTag.html\">image diffs</a></td>\n";
839 print HTML "<td></td><td></td>\n";
842 print HTML "</tr>\n";
844 print HTML "</table>\n";
848 print HTML "<p>Tests that caused the DumpRenderTree tool to fail:</p>\n";
849 print HTML "<table>\n";
850 for my $test (@{$tests{fail}}) {
852 $base =~ s/\.[a-zA-Z]+$//;
853 my $expectedDir = expectedDirectoryForTest($base);
855 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$base</a></td>\n";
856 print HTML "</tr>\n";
858 print HTML "</table>\n";
862 print HTML "<p>Tests that had no expected results (probably new):</p>\n";
863 print HTML "<table>\n";
864 for my $test (@{$tests{new}}) {
866 $base =~ s/\.[a-zA-Z]+$//;
867 my $expectedDir = expectedDirectoryForTest($base);
869 print HTML "<td><a href=\"" . toURL("$testDirectory/$test") . "\">$base</a></td>\n";
870 print HTML "<td><a href=\"" . toURL("$expectedDir/$base-$expectedTag.txt") . "\">results</a></td>\n";
871 if ($pixelTests && -f "$expectedDir/$base-$expectedTag.png") {
872 print HTML "<td><a href=\"" . toURL("$expectedDir/$base-$expectedTag.png") . "\">image</a></td>\n";
874 print HTML "</tr>\n";
876 print HTML "</table>\n";
879 print HTML "</body>\n";
880 print HTML "</html>\n";
884 system "konqueror", $testResults if $launchSafari;
885 } elsif (isCygwin()) {
886 system "cygstart", $testResults if $launchSafari;
888 system "WebKitTools/Scripts/run-safari", $configurationOption, "-NSOpen", $testResults if $launchSafari;
891 closeCygpaths() if isCygwin();
895 sub countAndPrintLeaks($$$)
897 my ($dumpToolName, $dumpToolPID, $leaksFilePath) = @_;
899 print "\n" unless $atLineStart;
902 # We are excluding the following reported leaks so they don't get in our way when looking for WebKit leaks:
904 my @typesToExclude = (
905 "THRD", # bug in 'leaks', Radar 3387783
906 "DRHT" # ditto (endian little hate i)
909 my @callStacksToExclude = (
910 "Flash_EnforceLocalSecurity" # leaks in Flash plug-in code, Radar 4449747
914 push @callStacksToExclude, (
915 "CFRunLoopRunSpecific \\| malloc_zone_malloc", "CFRunLoopRunSpecific \\| CFAllocatorAllocate ", # leak in CFRunLoopRunSpecific, Radar 4670839
916 "CGImageSourceGetPropertiesAtIndex", # leak in ImageIO, Radar 4628809
917 "FOGetCoveredUnicodeChars", # leak in ATS, Radar 3943604
918 "GetLineDirectionPreference", "InitUnicodeUtilities", # leaks tool falsely reporting leak in CFNotificationCenterAddObserver, Radar 4964790
919 "ICCFPrefWrapper::GetPrefDictionary", # leaks in Internet Config. code, Radar 4449794
920 "NSHTTPURLProtocol setResponseHeader:", # leak in multipart/mixed-replace handling in Foundation, no Radar, but fixed in Leopard
921 "NSURLCache cachedResponseForRequest", # leak in CFURL cache, Radar 4768430
922 "PCFragPrepareClosureFromFile", # leak in Code Fragment Manager, Radar 3426998
923 "WebCore::Selection::toRange", # bug in 'leaks', Radar 4967949
924 "WebCore::SubresourceLoader::create", # bug in 'leaks', Radar 4985806
925 "_CFPreferencesDomainDeepCopyDictionary", # leak in CFPreferences, Radar 4220786
926 "_objc_msgForward", # leak in NSSpellChecker, Radar 4965278
927 "gldGetString" # leak in OpenGL, Radar 5013699
932 push @callStacksToExclude, (
933 "glvmInitializeLLVM", # leak in OpenGL, Radar 5329956
934 "GetProcessForPID", # leak in Process Manager, Radar 5329842
935 "HIView::SendGetPartRegionOrShape", # leak in High Level Toolbox, Radars 5329755 & 5329717
936 "AddImageByTypeInfo", # leak in Launch Services, Radar 5329735
937 "fileProtocolStart \\| _LSCopyTypeIdentifierForItemRefInfo", # leak in CFNetwork, Radar 5329625
938 "CGContextDrawImage", # leak in CoreGraphics, Radar 5002510
942 my $leaksTool = sourceDir() . "/WebKitTools/Scripts/run-leaks";
943 my $excludeString = "--exclude-callstack '" . (join "' --exclude-callstack '", @callStacksToExclude) . "' " .
944 "--exclude-type '" . (join "' --exclude-type '", @typesToExclude) . "'";
946 print " ? checking for leaks in $dumpToolName\n";
947 my $leaksOutput = `$leaksTool $excludeString $dumpToolPID`;
948 my ($count, $bytes) = $leaksOutput =~ /Process $dumpToolPID: (\d+) leaks? for (\d+) total/;
949 my ($excluded) = $leaksOutput =~ /(\d+) leaks? excluded/;
951 my $adjustedCount = $count;
952 $adjustedCount -= $excluded if $excluded;
954 if (!$adjustedCount) {
955 print " - no leaks found\n";
956 unlink $leaksFilePath;
959 my $dir = $leaksFilePath;
960 $dir =~ s|/[^/]+$|| or die;
964 print " + $adjustedCount leaks ($bytes bytes including $excluded excluded leaks) were found, details in $leaksFilePath\n";
966 print " + $count leaks ($bytes bytes) were found, details in $leaksFilePath\n";
969 open LEAKS, ">", $leaksFilePath or die;
970 print LEAKS $leaksOutput;
974 return $adjustedCount;
977 # Break up a path into the directory (with slash) and base name.
982 my $pathSeparator = "/";
983 my $dirname = dirname($path) . $pathSeparator;
984 $dirname = "" if $dirname eq "." . $pathSeparator;
986 return ($dirname, basename($path));
989 # Sort first by directory, then by file, so all paths in one directory are grouped
990 # rather than being interspersed with items from subdirectories.
991 # Use numericcmp to sort directory and filenames to make order logical.
994 my ($patha, $pathb) = @_;
996 my ($dira, $namea) = splitpath($patha);
997 my ($dirb, $nameb) = splitpath($pathb);
999 return numericcmp($dira, $dirb) if $dira ne $dirb;
1000 return numericcmp($namea, $nameb);
1003 # Sort numeric parts of strings as numbers, other parts as strings.
1004 # Makes 1.33 come after 1.3, which is cool.
1009 my @a = split /(\d+)/, $aa;
1010 my @b = split /(\d+)/, $bb;
1012 # Compare one chunk at a time.
1013 # Each chunk is either all numeric digits, or all not numeric digits.
1018 # Use numeric comparison if chunks are non-equal numbers.
1019 return $a <=> $b if $a =~ /^\d/ && $b =~ /^\d/ && $a != $b;
1021 # Use string comparison if chunks are any other kind of non-equal string.
1022 return $a cmp $b if $a ne $b;
1025 # One of the two is now empty; compare lengths for result in this case.
1029 # Sort slowest tests first.
1032 my ($testa, $testb) = @_;
1034 my $dura = $durations{$testa};
1035 my $durb = $durations{$testb};
1036 return $durb <=> $dura if $dura != $durb;
1037 return pathcmp($testa, $testb);
1042 return if $isDumpToolOpen;
1044 # Save some requires variables for the linux environment...
1045 my $homeDir = $ENV{'HOME'};
1046 my $libraryPath = $ENV{'LD_LIBRARY_PATH'};
1047 my $dbusAddress = $ENV{'DBUS_SESSION_BUS_ADDRESS'};
1048 my $display = $ENV{'DISPLAY'};
1049 my $testfonts = $ENV{'WEBKIT_TESTFONTS'};
1051 my $homeDrive = $ENV{'HOMEDRIVE'};
1052 my $homePath = $ENV{'HOMEPATH'};
1057 if (defined $display) {
1058 $ENV{DISPLAY} = $display;
1060 $ENV{DISPLAY} = ":1";
1062 $ENV{'WEBKIT_TESTFONTS'} = $testfonts;
1063 $ENV{HOME} = $homeDir;
1064 if (defined $libraryPath) {
1065 $ENV{LD_LIBRARY_PATH} = $libraryPath;
1067 if (defined $dbusAddress) {
1068 $ENV{DBUS_SESSION_BUS_ADDRESS} = $dbusAddress;
1071 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1072 $ENV{XML_CATALOG_FILES} = ""; # work around missing /etc/catalog <rdar://problem/4292995>
1073 $ENV{MallocStackLogging} = 1 if $shouldCheckLeaks;
1074 $ENV{DYLD_INSERT_LIBRARIES} = "/usr/lib/libgmalloc.dylib" if $guardMalloc;
1077 $ENV{HOMEDRIVE} = $homeDrive;
1078 $ENV{HOMEPATH} = $homePath;
1083 push @args, $dumpTool;
1085 push @args, @toolArgs;
1087 $dumpTool = "valgrind";
1089 $dumpToolPID = open2(\*IN, \*OUT, $dumpTool, @args) or die "Failed to start tool: $dumpTool\n";
1090 $isDumpToolOpen = 1;
1095 return if !$isDumpToolOpen;
1099 waitpid $dumpToolPID, 0;
1100 $isDumpToolOpen = 0;
1103 sub openHTTPDIfNeeded()
1105 return if $isHttpdOpen;
1107 mkdir "/tmp/WebKit";
1109 if (-f "/tmp/WebKit/httpd.pid") {
1110 my $oldPid = `cat /tmp/WebKit/httpd.pid`;
1112 if (0 != kill 0, $oldPid) {
1113 print "\nhttpd is already running: pid $oldPid, killing...\n";
1116 my $retryCount = 20;
1117 while ((0 != kill 0, $oldPid) && $retryCount) {
1122 die "Timed out waiting for httpd to quit" unless $retryCount;
1126 my $httpdPath = "/usr/sbin/httpd";
1129 my $windowsConfDirectory = "$testDirectory/http/conf/";
1130 unless (-x "/usr/lib/apache/libphp4.dll") {
1131 copy("$windowsConfDirectory/libphp4.dll", "/usr/lib/apache/libphp4.dll");
1132 chmod(0755, "/usr/lib/apache/libphp4.dll");
1134 $httpdConfig = "$windowsConfDirectory/cygwin-httpd.conf";
1136 $httpdConfig = "$testDirectory/http/conf/httpd.conf";
1137 $httpdConfig = "$testDirectory/http/conf/apache2-httpd.conf" if `$httpdPath -v` =~ m|Apache/2|;
1139 my $documentRoot = "$testDirectory/http/tests";
1140 my $typesConfig = "$testDirectory/http/conf/mime.types";
1141 my $listen = "127.0.0.1:$httpdPort";
1142 my $absTestResultsDirectory = File::Spec->rel2abs(glob $testResultsDirectory);
1143 my $sslCertificate = "$testDirectory/http/conf/webkit-httpd.pem";
1145 mkpath $absTestResultsDirectory;
1147 open2(\*HTTPDIN, \*HTTPDOUT, $httpdPath,
1148 "-f", "$httpdConfig",
1149 "-C", "DocumentRoot \"$documentRoot\"",
1150 "-C", "Listen $listen",
1151 "-c", "SSLCertificateFile $sslCertificate",
1152 "-c", "TypesConfig \"$typesConfig\"",
1153 "-c", "CustomLog \"$absTestResultsDirectory/access_log.txt\" common",
1154 "-c", "ErrorLog \"$absTestResultsDirectory/error_log.txt\"",
1155 # Apache wouldn't run CGIs with permissions==700 otherwise
1156 "-c", "User \"#$<\"");
1158 my $retryCount = 20;
1159 while (system("/usr/bin/curl -q --silent --stderr - --output /dev/null $listen") && $retryCount) {
1164 die "Timed out waiting for httpd to start" unless $retryCount;
1171 return if !$isHttpdOpen;
1176 kill 15, `cat /tmp/WebKit/httpd.pid` if -f "/tmp/WebKit/httpd.pid";
1181 sub fileNameWithNumber($$)
1183 my ($base, $number) = @_;
1184 return "$base$number" if ($number > 1);
1188 sub processIgnoreTests($) {
1189 my @ignoreList = split(/\s*,\s*/, shift);
1190 my $addIgnoredDirectories = sub {
1191 return () if exists $ignoredLocalDirectories{basename($File::Find::dir)};
1192 $ignoredDirectories{File::Spec->abs2rel($File::Find::dir, $testDirectory)} = 1;
1195 foreach my $item (@ignoreList) {
1196 my $path = catfile($testDirectory, $item);
1198 $ignoredDirectories{$item} = 1;
1199 find({ preprocess => $addIgnoredDirectories, wanted => sub {} }, $path);
1202 $ignoredFiles{$item} = 1;
1205 print "ignoring '$item' on ignore-tests list\n";
1210 sub isTextOnlyTest($)
1214 if ($actual =~ /^layer at/ms) {
1222 sub expectedDirectoryForTest($)
1225 return (-f "$platformTestDirectory/$base-$expectedTag.txt") ? $platformTestDirectory : $expectedDirectory;
1230 sub openCygpathIfNeeded($)
1234 return unless isCygwin();
1235 return $cygpaths{$options} if $cygpaths{$options} && $cygpaths{$options}->{"open"};
1237 local (*CYGPATHIN, *CYGPATHOUT);
1238 my $pid = open2(\*CYGPATHIN, \*CYGPATHOUT, "cygpath -f - $options");
1242 "out" => *CYGPATHOUT,
1246 $cygpaths{$options} = $cygpath;
1253 return unless isCygwin();
1255 foreach my $cygpath (values(%cygpaths)) {
1256 close $cygpath->{"in"};
1257 close $cygpath->{"out"};
1258 waitpid($cygpath->{"pid"}, 0);
1259 $cygpath->{"open"} = 0;
1264 sub convertPathUsingCygpath($$)
1266 my ($path, $options) = @_;
1268 my $cygpath = openCygpathIfNeeded($options);
1269 local *inFH = $cygpath->{"in"};
1270 local *outFH = $cygpath->{"out"};
1271 print outFH $path . "\n";
1272 chomp(my $convertedPath = <inFH>);
1273 return $convertedPath;
1276 sub toWindowsPath($)
1279 return unless isCygwin();
1281 return convertPathUsingCygpath($path, "-w");
1287 return $path unless isCygwin();
1289 return "file:///" . convertPathUsingCygpath($path, "-m");