1#!/usr/bin/perl -w
2
3# Copyright (C) 2007 Apple 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# 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.
14#
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. 
26
27use strict;
28use FindBin;
29use Getopt::Long qw(:config pass_through);
30use lib $FindBin::Bin;
31use webkitdirs;
32use POSIX;
33
34# determine configuration, but default to "Release" instead of last-used configuration
35setConfiguration("Release");
36setConfiguration();
37my $configuration = configuration();
38
39my $root;
40my $testRuns = 10; # This number may be different from what sunspider defaults to (that's OK)
41my $runShark = 0;
42my $runShark20 = 0;
43my $runSharkCache = 0;
44my $suite = "";
45my $ubench = 0;
46my $v8suite = 0;
47my $parseonly = 0;
48my $setBaseline = 0;
49my $showHelp = 0;
50my $testsPattern;
51my $noBuild = 0;
52
53my $programName = basename($0);
54my $usage = <<EOF;
55Usage: $programName [options] [options to pass to build system]
56  --help            Show this help message
57  --set-baseline    Set baseline for future comparisons
58  --root            Path to root tools build
59  --runs            Number of times to run tests (default: $testRuns)
60  --tests           Only run tests matching provided pattern
61  --shark           Sample with the Mac OS X "Shark" performance testing tool (implies --runs=1)
62  --shark20         Like --shark, but with a 20 microsecond sampling interval
63  --shark-cache     Like --shark, but performs a L2 cache-miss sample instead of time sample
64  --suite           Select a specific benchmark suite. The default is sunspider-0.9.1
65  --ubench          Use microbenchmark suite instead of regular tests. Same as --suite=ubench
66  --v8-suite        Use the V8 benchmark suite. Same as --suite=v8-v4
67  --parse-only      Use the parse-only benchmark suite. Same as --suite=parse-only
68  --no-build        Do not try to build JSC before running the tests.
69EOF
70
71GetOptions('root=s' => sub { my ($x, $value) = @_; $root = $value; setConfigurationProductDir(Cwd::abs_path($root)); },
72           'runs=i' => \$testRuns,
73           'set-baseline' => \$setBaseline,
74           'shark' => \$runShark,
75           'shark20' => \$runShark20,
76           'shark-cache' => \$runSharkCache,
77           'suite=s' => \$suite,
78           'ubench' => \$ubench,
79           'v8-suite' => \$v8suite,
80           'parse-only' => \$parseonly,
81           'tests=s' => \$testsPattern,
82           'help' => \$showHelp,
83           'no-build' => \$noBuild);
84
85if ($showHelp) {
86   print STDERR $usage;
87   exit 1;
88}
89
90sub buildJSC
91{
92    if (!defined($root)){
93        push(@ARGV,  "--" . $configuration);
94        
95        chdirWebKit();
96        my $buildResult = system currentPerlPath(), "Tools/Scripts/build-jsc", @ARGV;
97        if ($buildResult) {
98            print STDERR "Compiling jsc failed!\n";
99            exit exitStatus($buildResult);
100        }
101    }
102}
103
104sub setupEnvironmentForExecution($)
105{
106    my ($productDir) = @_;
107    print "Starting sunspider with DYLD_FRAMEWORK_PATH set to point to built JavaScriptCore in $productDir.\n";
108    $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
109    # FIXME: Other platforms may wish to augment this method to use LD_LIBRARY_PATH, etc.
110}
111
112unless ($noBuild) {
113    buildJSC();
114}
115
116chdirWebKit();
117chdir("PerformanceTests/SunSpider");
118
119my $productDir = jscProductDir();
120
121setupEnvironmentForExecution($productDir);
122my @args = ("--shell", jscPath($productDir), "--runs", $testRuns);
123# This code could be removed if we chose to pass extra args to sunspider instead of Xcode
124push @args, "--set-baseline" if $setBaseline;
125push @args, "--shark" if $runShark;
126push @args, "--shark20" if $runShark20;
127push @args, "--shark-cache" if $runSharkCache;
128push @args, "--suite=${suite}" if $suite;
129push @args, "--ubench" if $ubench;
130push @args, "--v8-suite" if $v8suite;
131push @args, "--parse-only" if $parseonly;
132push @args, "--tests", $testsPattern if $testsPattern;
133
134exec currentPerlPath(), "./sunspider", @args;
135