3 # Copyright (C) 2010, 2011 Apple 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
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 # THE POSSIBILITY OF SUCH DAMAGE.
27 # - Command line option to run a single test.
28 # - Command line option to run all tests in a suite.
35 use Getopt::Long qw(:config pass_through);
37 use lib $FindBin::Bin;
39 use Term::ANSIColor qw(:constants);
43 sub runAllTestsInSuite($);
52 my $programName = basename($0);
54 Usage: $programName [options]
55 --help Show this help message
56 -v|--verbose Verbose output
57 -d|--dump-tests Dump the names of testcases without running them
62 'verbose|v' => \$verbose,
73 setPathForRunningWebKitApp(\%ENV);
74 my %testsToRun = populateTests();
85 print "Dumping test cases\n";
86 print "------------------\n";
87 for my $suite (keys %testsToRun) {
89 print map { " " . $_ . "\n" } @{ $testsToRun{$suite} };
91 print "------------------\n";
97 for my $suite (keys %testsToRun) {
98 my $failed = runAllTestsInSuite($suite);
106 sub runAllTestsInSuite($)
109 print "Suite: $suite\n";
112 for my $test (@{$testsToRun{$suite}}) {
113 my $failed = runTest($suite, $test);
124 my ($suite, $testName) = @_;
125 my $test = $suite . "/" . $testName;
127 print " Test: $testName -> ";
130 if (isAppleMacWebKit()) {
131 my $productDir = productDir();
132 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
133 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
134 my $apiTesterPath = "$productDir/TestWebKitAPI";
137 my ($childIn, $childOut, $childErr);
139 open(DEVNULL, ">", File::Spec->devnull()) or die "Failed to open /dev/null";
140 $childOut = ">&DEVNULL";
141 $childErr = ">&DEVNULL";
143 $childOut = ">&STDOUT";
144 $childErr = ">&STDERR";
148 if (architecture()) {
149 $pid = open3($childIn, $childOut, $childErr, "arch", "-" . architecture(), $apiTesterPath, $test, @ARGV) or die "Failed to run test: $test.";
151 $pid = open3($childIn, $childOut, $childErr, $apiTesterPath, $test, @ARGV) or die "Failed to run test: $test.";
157 close(DEVNULL) unless ($verbose);
161 } elsif (isAppleWinWebKit()) {
162 my $apiTesterNameSuffix;
163 if (configurationForVisualStudio() ne "Debug_All") {
164 $apiTesterNameSuffix = "";
166 $apiTesterNameSuffix = "_debug";
168 my $apiTesterPath = File::Spec->catfile(productDir(), "TestWebKitAPI$apiTesterNameSuffix.exe");
169 $result = system $apiTesterPath, $test, @ARGV;
171 die "run-api-tests is not supported on this platform.\n"
175 print BOLD GREEN, "Passed", RESET, "\n";
177 print BOLD RED, "Failed", RESET, "\n";
186 if (isAppleMacWebKit()) {
187 my $productDir = productDir();
188 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
189 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
190 my $apiTesterPath = "$productDir/TestWebKitAPI";
193 my ($childIn, $childOut, $childErr);
195 open(DEVNULL, ">", File::Spec->devnull()) or die "Failed to open /dev/null";
196 $childErr = ">&DEVNULL";
198 $childErr = ">&STDERR";
202 if (architecture()) {
203 $pid = open3($childIn, $childOut, $childErr, "arch", "-" . architecture(), $apiTesterPath, "--dump-tests") or die "Failed to build list of tests!";
205 $pid = open3($childIn, $childOut, $childErr, $apiTesterPath, "--dump-tests") or die "Failed to build list of tests!";
209 @tests = <$childOut>;
212 close(DEVNULL) unless ($verbose);
218 print STDERR "Failed to build list of tests!\n";
219 exit exitStatus($result);
221 } elsif (isAppleWinWebKit()) {
222 my $apiTesterNameSuffix;
223 if (configurationForVisualStudio() ne "Debug_All") {
224 $apiTesterNameSuffix = "";
226 $apiTesterNameSuffix = "_debug";
228 my $apiTesterPath = File::Spec->catfile(productDir(), "TestWebKitAPI$apiTesterNameSuffix.exe");
229 open(TESTS, "-|", $apiTesterPath, "--dump-tests") or die $!;
231 close(TESTS) or die $!;
233 die "run-api-tests is not supported on this platform.\n"
237 for my $test (@tests) {
238 $test =~ s/[\r\n]*$//;
239 my ($suite, $testName) = split(/\//, $test);
240 push @{$keyedTests{$suite}}, $testName;
250 my $buildTestTool = "build-api-tests";
251 print STDERR "Running $buildTestTool\n";
254 my ($childIn, $childOut, $childErr);
256 open(DEVNULL, ">", File::Spec->devnull()) or die "Failed to open /dev/null";
257 $childOut = ">&DEVNULL";
258 $childErr = ">&DEVNULL";
260 # When not quiet, let the child use our stdout/stderr.
261 $childOut = ">&STDOUT";
262 $childErr = ">&STDERR";
265 my @args = argumentsForConfiguration();
266 my $buildProcess = open3($childIn, $childOut, $childErr, "Tools/Scripts/$buildTestTool", @args) or die "Failed to run " . $buildTestTool;
271 close(DEVNULL) unless ($verbose);
273 waitpid($buildProcess, 0);
274 my $buildResult = $?;
277 print STDERR "Compiling TestWebKitAPI failed!\n";
278 exit exitStatus($buildResult);