3 # Copyright (C) 2010 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 -q|--quite Less verbose output
57 -d|--dump-tests Dump the names of testcases without running them
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";
135 if (architecture()) {
136 $result = system "arch", "-" . architecture(), $apiTesterPath, $test, @ARGV;
138 $result = system $apiTesterPath, $test, @ARGV;
140 } elsif (isAppleWinWebKit()) {
141 my $apiTesterNameSuffix;
142 if (configurationForVisualStudio() ne "Debug_All") {
143 $apiTesterNameSuffix = "";
145 $apiTesterNameSuffix = "_debug";
147 my $apiTesterPath = File::Spec->catfile(productDir(), "TestWebKitAPI$apiTesterNameSuffix.exe");
148 $result = system $apiTesterPath, $test, @ARGV;
150 die "run-api-tests is not supported on this platform.\n"
154 print BOLD GREEN, "Passed", RESET, "\n";
156 print BOLD RED, "Failed", RESET, "\n";
165 if (isAppleMacWebKit()) {
166 my $productDir = productDir();
167 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
168 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
169 my $apiTesterPath = "$productDir/TestWebKitAPI";
171 my ($pid, $childIn, $childOut);
172 if (architecture()) {
173 $pid = open3($childIn, $childOut, ">&STDERR", "arch", "-" . architecture(), $apiTesterPath, "--dump-tests") or die "Failed to build list of tests!";
175 $pid = open3($childIn, $childOut, ">&STDERR", $apiTesterPath, "--dump-tests") or die "Failed to build list of tests!";
178 @tests = <$childOut>;
185 print STDERR "Failed to build list of tests!\n";
186 exit exitStatus($result);
188 } elsif (isAppleWinWebKit()) {
189 my $apiTesterNameSuffix;
190 if (configurationForVisualStudio() ne "Debug_All") {
191 $apiTesterNameSuffix = "";
193 $apiTesterNameSuffix = "_debug";
195 my $apiTesterPath = File::Spec->catfile(productDir(), "TestWebKitAPI$apiTesterNameSuffix.exe");
196 open(TESTS, "-|", $apiTesterPath, "--dump-tests") or die $!;
198 close(TESTS) or die $!;
200 die "run-api-tests is not supported on this platform.\n"
204 for my $test (@tests) {
205 $test =~ s/[\r\n]*$//;
206 my ($suite, $testName) = split(/\//, $test);
207 push @{$keyedTests{$suite}}, $testName;
217 my $buildTestTool = "build-api-tests";
218 print STDERR "Running $buildTestTool\n";
221 my ($childIn, $childOut, $childErr);
223 open(DEVNULL, ">", File::Spec->devnull()) or die "Failed to open /dev/null";
224 $childOut = ">&DEVNULL";
225 $childErr = ">&DEVNULL";
227 # When not quiet, let the child use our stdout/stderr.
228 $childOut = ">&STDOUT";
229 $childErr = ">&STDERR";
232 my @args = argumentsForConfiguration();
233 my $buildProcess = open3($childIn, $childOut, $childErr, "Tools/Scripts/$buildTestTool", @args) or die "Failed to run " . $buildTestTool;
235 waitpid $buildProcess, 0;
236 my $buildResult = $?;
240 close DEVNULL if ($quiet);
243 print STDERR "Compiling TestWebKitAPI failed!\n";
244 exit exitStatus($buildResult);