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.
31 use POSIX qw(strftime);
37 my $testRuns = 5; # This number may be different from what ./sunspider defaults to (that's OK)
39 my $programName = basename($0);
41 Usage: $programName --shell=[path] [options]
42 --help Show this help message
43 --shell Path to javascript shell
44 --runs Number of times to run tests (default: $testRuns)
45 --tests Only run tests matching provided pattern
46 --shark Sample with the Mac OS X "Shark" performance testing tool (implies --runs=1)
49 GetOptions('runs=i' => \$testRuns,
50 'shell=s' => \$jsShellPath,
51 'shark' => \$runShark,
52 'tests=s' => \$testsPattern,
53 'help' => \$showHelp);
55 $testRuns = 1 if $runShark;
57 if (!$jsShellPath || $showHelp) {
64 my ($contents, $path) = @_;
65 open FILE, ">", $path or die;
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;
92 my $timeString = strftime "%Y-%m-%d-%H:%M:%S", localtime $^T;
93 my $prefixFile = "tmp/sunspider-test-prefix.js";
94 my $resultsFile = "tmp/sunspider-results-$timeString.js";
98 my $prefix = "var tests = [ " . join(", ", map { '"' . $_ . '"' } @tests) . " ];\n";
99 $prefix .= "var categories = [ " . join(", ", map { '"' . $_ . '"' } @categories) . " ];\n";
102 dumpToFile($prefix, $prefixFile);
108 my $shellArgs = "-f $prefixFile -f resources/sunspider-standalone-driver.js 2> /dev/null";
111 $output = `shark -i -1 -q "$jsShellPath" $shellArgs`;
113 $output = `"$jsShellPath" $shellArgs | grep -v break`;
120 print STDERR "Found " . scalar(@tests) . " tests matching '" . $testsPattern . "'\n";
122 print STDERR "Found " . scalar(@tests) . " tests\n";
124 die "No tests to run" unless scalar(@tests);
125 print STDERR "Running SunSpider once for warmup, then " . ($runShark ? "under Shark" : "$testRuns time" . ($testRuns == 1 ? "" : "s")) . "\n";
129 print "Discarded first run.\n";
136 while ($count++ < $testRuns) {
137 $result = runTestsOnce($runShark);
138 $result =~ s/\r\n/\n/g;
140 push @results, $result;
142 print ",\n" unless ($count == $testRuns);
146 my $output = "var output = [\n" . join(",\n", @results) . "\n];\n";
147 dumpToFile($output, $resultsFile);
149 system("$jsShellPath", "-f", $prefixFile, "-f", $resultsFile, "-f", "resources/sunspider-analyze-results.js");
153 my $newestMShark = 0;
154 opendir DIR, "." or die;
155 for my $file (readdir DIR) {
156 if ($file =~ /\.mshark$/) {
158 if ($age < $newestAge) {
159 $newestMShark = $file;
166 my $profileFile = "tmp/sunspider-profile-$timeString.mshark";
167 rename $newestMShark, $profileFile or die;
168 exec "/usr/bin/open", $profileFile;