3 # Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 # its contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # 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, .xml, and .xhtml 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
47 # Check that we're in the right directory.
48 if (! -d "WebKitTools") {
49 if (-d "../WebKitTools") {
52 if (! -d "WebKitTools") {
53 die "No WebKitTools directory found. Please run this script from the directory containing WebKitTools.\n";
57 # Check that an Xcode product directory is set.
58 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
59 my $productDir = <PRODUCT>;
63 die "No product directory set. Please set the 'Place Build Products' preference to 'Customized location' in XCode Building Preferences.\n";
66 my $result = system "WebKitTools/Scripts/build-dumprendertree";
67 exit $result if $result;
69 my $tool = "$productDir/DumpRenderTree";
71 die "can't find executable DumpRenderTree tool (looked in $productDir)\n" if !-x $tool;
73 my $workingDir = `pwd`;
75 my $WebCoreDirectory = "$workingDir/WebCore";
76 my $testDirectory = "$WebCoreDirectory/layout-tests";
77 my $testResultsDirectory = "/tmp/layout-test-results";
78 my $testResults = "$testResultsDirectory/results.html";
80 $ENV{"DYLD_FRAMEWORK_PATH"} = $productDir;
84 my $findArguments = "\\( -name resources \\! -prune \\) -or -name '*.html' -or -name '*.xml' -or -name '*.xhtml'";
86 for my $test (@ARGV) {
87 $test =~ s/^$testDirectory\///;
89 print "can't run test outside $testDirectory\n";
90 } elsif (-f "$testDirectory/$test") {
91 if ($test !~ /\.(html|xml|xhtml)$/) {
92 print "test $test does not have an .html extension\n";
96 } elsif (-d "$testDirectory/$test") {
97 push @tests, map { chomp; s-^$testDirectory/--; $_; } `find -s $testDirectory/$test $findArguments`;
99 print "test $test not found\n";
103 @tests = map { chomp; s-^$testDirectory/--; $_; } `find -s $testDirectory $findArguments`;
106 die "no tests to run\n" if !@tests;
112 open2(\*IN, \*OUT, $tool, "-") or die;
116 for my $test (@tests) {
117 next if $test eq 'results.html';
120 $base =~ s/\.(html|xml|xhtml)$//;
122 print "running $base test";
126 print OUT "$testDirectory/$test\n";
135 if (open EXPECTED, "<", "$testDirectory/$base-expected.txt") {
142 if (!defined $expected) {
143 print " -> new test\n";
145 open EXPECTED, ">", "$testDirectory/$base-expected.txt" or die "could not create $testDirectory/$base-expected.txt\n";
146 print EXPECTED $actual;
148 unlink "$testResultsDirectory/$base-actual.txt";
149 unlink "$testResultsDirectory/$base-diffs.txt";
150 } elsif ($actual eq $expected) {
151 print " -> succeeded\n";
153 unlink "$testResultsDirectory/$base-actual.txt";
154 unlink "$testResultsDirectory/$base-diffs.txt";
156 print " -> failed\n";
157 $result = "mismatch";
158 my $dir = "$testResultsDirectory/$base";
160 system "mkdir", "-p", $dir;
161 open ACTUAL, ">", "$testResultsDirectory/$base-actual.txt" or die;
162 print ACTUAL $actual;
164 system "diff -u $testDirectory/$base-expected.txt $testResultsDirectory/$base-actual.txt > $testResultsDirectory/$base-diffs.txt";
168 $counts{$result} += 1;
169 push @{$tests{$result}}, $test;
176 match => "succeeded",
177 mismatch => "had incorrect layout",
179 fail => "failed (tool did not execute successfully)",
184 if ($counts{match} && $counts{match} == $count) {
185 print "all test cases succeeded\n";
188 for my $type ("match", "mismatch", "new", "fail") {
189 my $c = $counts{$type};
191 my $t = $text{$type};
195 $message = sprintf "1 test case (%d%%) %s\n", 1 * 100 / $count, $t;
197 $message = sprintf "%d test cases (%d%%) %s\n", $c, $c * 100 / $count, $t;
199 $message =~ s-\(0%\)-(<1%)-;
204 system "mkdir", "-p", $testResultsDirectory;
206 open HTML, ">", $testResults or die;
207 print HTML "<html>\n";
208 print HTML "<head>\n";
209 print HTML "<title>Layout Test Results</title>\n";
210 print HTML "</head>\n";
211 print HTML "<body>\n";
213 if ($counts{mismatch}) {
214 print HTML "<p>Tests where results did not match expected results:</p>\n";
215 print HTML "<table>\n";
216 for my $test (@{$tests{mismatch}}) {
218 $base =~ s/\.(html|xml|xhtml)$//;
220 print HTML "<td><a href=\"$testDirectory/$test\">$base</a></td>\n";
221 print HTML "<td><a href=\"$testDirectory/$base-expected.txt\">expected</a></td>\n";
222 print HTML "<td><a href=\"$base-actual.txt\">actual</a></td>\n";
223 print HTML "<td><a href=\"$base-diffs.txt\">diffs</a></td>\n";
224 print HTML "</tr>\n";
226 print HTML "</table>\n";
230 print HTML "<p>Tests that caused the DumpRenderTree tool to fail:</p>\n";
231 print HTML "<table>\n";
232 for my $test (@{$tests{fail}}) {
234 $base =~ s/\.(html|xml|xhtml)$//;
236 print HTML "<td><a href=\"$testDirectory/$test\">$base</a></td>\n";
237 print HTML "</tr>\n";
239 print HTML "</table>\n";
243 print HTML "<p>Tests that had no expected results (probably new):</p>\n";
244 print HTML "<table>\n";
245 for my $test (@{$tests{new}}) {
247 $base =~ s/\.(html|xml|xhtml)$//;
249 print HTML "<td><a href=\"$testDirectory/$test\">$base</a></td>\n";
250 print HTML "<td><a href=\"$testDirectory/$base-expected.txt\">results</a></td>\n";
251 print HTML "</tr>\n";
253 print HTML "</table>\n";
256 print HTML "</body>\n";
257 print HTML "</html>\n";
260 system "open", $testResults;