3 # Copyright (C) 2007 Apple Inc. All rights reserved.
4 # Copyright (C) 2007 Eric Seidel <eric@webkit.org>
6 # Redistribution and use in source and binary forms, with or without
7 # 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.
15 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 my $testRuns = 5; # This number may be different from what ./sunspider defaults to (that's OK)
38 my $programName = basename($0);
40 Usage: $programName --shell=[path] [options]
41 --help Show this help message
42 --shell Path to javascript shell
43 --runs Number of times to run tests (default: $testRuns)
44 --tests Only run tests matching provided pattern
45 --shark Sample with the Mac OS X "Shark" performance testing tool (implies --runs=1)
48 GetOptions('runs=i' => \$testRuns,
49 'shell=s' => \$jsShellPath,
50 'shark' => \$runShark,
51 'tests=s' => \$testsPattern,
52 'help' => \$showHelp);
54 $testRuns = 1 if $runShark;
56 if (!$jsShellPath || $showHelp) {
63 my ($contents, $path) = @_;
64 open FILE, ">", $path or die;
69 # FIXME: these globals are rather poor abstraction
72 my %uniqueCategories = ();
76 open TESTLIST, "<", "tests/LIST" or die;
79 next unless !$testsPattern || /$testsPattern/;
84 if (!$uniqueCategories{$category}) {
85 push @categories, $category;
86 $uniqueCategories{$category} = $category;
94 my $prefix = "var tests = [ " . join(", ", map { '"' . $_ . '"' } @tests) . " ];\n";
95 $prefix .= "var categories = [ " . join(", ", map { '"' . $_ . '"' } @categories) . " ];\n";
98 dumpToFile($prefix, "tmp/sunspider-test-prefix.js");
104 my $shellArgs = "-f tmp/sunspider-test-prefix.js -f resources/sunspider-standalone-driver.js 2> /dev/null";
107 $output = `shark -i -1 -q "$jsShellPath" $shellArgs`;
109 $output = `"$jsShellPath" $shellArgs | grep -v break`;
116 print STDERR "Found " . scalar(@tests) . " tests matching '" . $testsPattern . "'\n";
118 print STDERR "Found " . scalar(@tests) . " tests\n";
120 die "No tests to run" unless scalar(@tests);
121 print STDERR "Running SunSpider once for warmup, then $testRuns time" . ($testRuns == 1 ? "" : "s") . ($runShark ? " under Shark" : "") . "\n";
125 print "Discarded first run.\n";
132 while ($count++ < $testRuns) {
133 $result = runTestsOnce($runShark);
135 push @results, $result;
137 print ",\n" unless ($count == $testRuns);
141 my $output = "var output = [\n" . join(",\n", @results) . "\n];\n";
142 dumpToFile($output, "tmp/sunspider-results.js");
144 system("$jsShellPath", "-f", "tmp/sunspider-test-prefix.js", "-f", "tmp/sunspider-results.js", "-f", "resources/sunspider-analyze-results.js");
148 my $newestMShark = 0;
149 opendir DIR, "." or die;
150 for my $file (readdir DIR) {
151 if ($file =~ /\.mshark$/) {
153 if ($age < $newestAge) {
154 $newestMShark = $file;
160 exec "/usr/bin/open", $newestMShark if $newestMShark;