initial import
[vuplus_webkit] / Tools / Scripts / run-javascriptcore-tests
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
4 # Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
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. 
18 #
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.
29
30 # Script to run the WebKit Open Source Project JavaScriptCore tests (adapted from Mozilla).
31
32 use strict;
33 use FindBin;
34 use Getopt::Long qw(:config pass_through);
35 use lib $FindBin::Bin;
36 use webkitdirs;
37 use POSIX;
38
39 # determine configuration
40 setConfiguration();
41 my $configuration = configuration();
42
43 my @testsToSkip = (
44     # Various ecma/Date tests sometimes fail on Windows (but not Mac) https://bugs.webkit.org/show_bug.cgi?id=25160
45     "ecma/Date/15.9.2.1.js",
46     "ecma/Date/15.9.2.2-1.js",
47     "ecma/Date/15.9.2.2-2.js",
48     "ecma/Date/15.9.2.2-3.js",
49     "ecma/Date/15.9.2.2-4.js",
50     "ecma/Date/15.9.2.2-5.js",
51     "ecma/Date/15.9.2.2-6.js",
52     # ecma_3/Date/15.9.5.7.js fails on Mac (but not Windows) https://bugs.webkit.org/show_bug.cgi?id=25161
53     "ecma_3/Date/15.9.5.7.js",
54 );
55
56 my $jsDriverArgs = "-L " . join(" ", @testsToSkip);
57 # These variables are intentionally left undefined.
58 my $root;
59 my $showHelp;
60
61 my $buildJSC = 1;
62
63 my $programName = basename($0);
64 my $buildJSCDefault = $buildJSC ? "will check" : "will not check";
65 my $usage = <<EOF;
66 Usage: $programName [options] [options to pass to build system]
67   --help                        Show this help message
68   --jsDriver-args=              A string of arguments to pass to jsDriver.pl
69   --root=                       Path to pre-built root containing jsc
70   --[no-]build                  Check (or don't check) to see if the jsc build is up-to-date (default: $buildJSCDefault)
71 EOF
72
73 GetOptions(
74     'j|jsDriver-args=s' => \$jsDriverArgs,
75     'root=s' => \$root,
76     'build!' => \$buildJSC,
77     'help' => \$showHelp
78 );
79
80 # Assume any arguments left over from GetOptions are assumed to be build arguments
81 my @buildArgs = @ARGV;
82
83 # Arguments passed to --jsDriver-args (if any) are passed to jsDriver.pl
84 my @jsArgs = split(" ", $jsDriverArgs);
85
86 if ($showHelp) {
87    print STDERR $usage;
88    exit 1;
89 }
90
91 setConfigurationProductDir(Cwd::abs_path($root)) if (defined($root));
92
93 if (!defined($root) && $buildJSC) {
94     chdirWebKit();
95
96     push(@buildArgs, argumentsForConfiguration());
97     
98     print "Running: build-jsc " . join(" ", @buildArgs) . "\n";
99     my $buildResult = system "perl", "Tools/Scripts/build-jsc", @buildArgs;
100     if ($buildResult) {
101         print STDERR "Compiling jsc failed!\n";
102         exit exitStatus($buildResult);
103     }
104 }
105
106
107 my $productDir = jscProductDir();
108 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
109 setPathForRunningWebKitApp(\%ENV) if isCygwin();
110
111 sub testapiPath($)
112 {
113     my ($productDir) = @_;
114     my $jscName = "testapi";
115     $jscName .= "_debug" if configurationForVisualStudio() eq "Debug_All";
116     return "$productDir/$jscName";
117 }
118
119 #run api tests
120 if (isAppleMacWebKit() || isAppleWinWebKit()) {
121     chdirWebKit();
122     chdir($productDir) or die;
123     my $path = testapiPath($productDir);
124     # Use an "indirect object" so that system() won't get confused if the path
125     # contains spaces (see perldoc -f exec).
126     my $testapiResult = system { $path } $path;
127     exit exitStatus($testapiResult)  if $testapiResult;
128 }
129
130 # Find JavaScriptCore directory
131 chdirWebKit();
132 chdir("Source/JavaScriptCore");
133 chdir "tests/mozilla" or die;
134 printf "Running: jsDriver.pl -e squirrelfish -s %s -f actual.html %s\n", jscPath($productDir), join(" ", @jsArgs);
135 my $result = system "perl", "jsDriver.pl", "-e", "squirrelfish", "-s", jscPath($productDir), "-f", "actual.html", @jsArgs;
136 exit exitStatus($result)  if $result;
137
138 my %failures;
139
140 open EXPECTED, "expected.html" or die;
141 while (<EXPECTED>) {
142     last if /failures reported\.$/;
143 }
144 while (<EXPECTED>) {
145     chomp;
146     $failures{$_} = 1;
147 }
148 close EXPECTED;
149
150 my %newFailures;
151
152 open ACTUAL, "actual.html" or die;
153 while (<ACTUAL>) {
154     last if /failures reported\.$/;
155 }
156 while (<ACTUAL>) {
157     chomp;
158     if ($failures{$_}) {
159         delete $failures{$_};
160     } else {
161         $newFailures{$_} = 1;
162     }
163 }
164 close ACTUAL;
165
166 my $numNewFailures = keys %newFailures;
167 if ($numNewFailures) {
168     print "\n** Danger, Will Robinson! Danger! The following failures have been introduced:\n";
169     foreach my $failure (sort keys %newFailures) {
170         print "\t$failure\n";
171     }
172 }
173
174 my $numOldFailures = keys %failures;
175 if ($numOldFailures) {
176     print "\nYou fixed the following test";
177     print "s" if $numOldFailures != 1;
178     print ":\n";
179     foreach my $failure (sort keys %failures) {
180         print "\t$failure\n";
181     }
182 }
183
184 print "\n";
185
186 print "$numNewFailures regression";
187 print "s" if $numNewFailures != 1;
188 print " found.\n";
189
190 print "$numOldFailures test";
191 print "s" if $numOldFailures != 1;
192 print " fixed.\n";
193
194 print "OK.\n" if $numNewFailures == 0;
195 exit(1)  if $numNewFailures;