1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  * 
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  * 
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  * 
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  * 
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * runsunspider : runs the sunspider tests and checks for compliance
  26  *
  27  * @test
  28  * @option -timezone=PST
  29  * @runif external.sunspider
  30  */
  31 
  32 /*
  33  * Copyright (c) 2010-2011, Oracle and/or its affiliates. All rights reserved.
  34  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  35  *
  36  * This code is free software; you can redistribute it and/or modify it
  37  * under the terms of the GNU General Public License version 2 only, as
  38  * published by the Free Software Foundation.  Oracle designates this
  39  * particular file as subject to the "Classpath" exception as provided
  40  * by Oracle in the LICENSE file that accompanied this code.
  41  *
  42  * This code is distributed in the hope that it will be useful, but WITHOUT
  43  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  44  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  45  * version 2 for more details (a copy is included in the LICENSE file that
  46  * accompanied this code).
  47  *
  48  * You should have received a copy of the GNU General Public License version
  49  * 2 along with this work; if not, write to the Free Software Foundation,
  50  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  51  *
  52  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  53  * or visit www.oracle.com if you need additional information or have any
  54  * questions.
  55  */
  56 
  57 /**
  58  * This is not a test, but a test "framework" for running sunspider tests.
  59  *
  60  */
  61 
  62 function assertEq(a, b) {
  63     if (a !== b) {
  64         throw "ASSERTION FAILED: " + a + " should be " + b;
  65     }
  66 }
  67 
  68 var runs = 0;
  69 var iterations__ = 1;
  70 var total_time = 0;
  71 
  72 function runbench(name) {
  73     var filename = name.split("/").pop();
  74     if (verbose_run) {
  75         print("Running " + filename);
  76     }
  77 
  78     var start = new Date;
  79     for (var i = 0; i < iterations__; i++) {
  80         load(name);    
  81     }
  82     var stop = new Date - start;
  83     total_time += stop;
  84     
  85     if (verbose_run) {
  86         print(filename + " done in " + stop + " ms"); 
  87     } 
  88     runs++;
  89 }
  90     
  91 function runsuite(args) {
  92     var changed = false;
  93 
  94     try {
  95         for (var n = 0; n < args.length; n++) {
  96             if (args[n] == undefined) {
  97                 continue;
  98             }
  99             if (args[n].indexOf('--') == 0) {
 100                 continue; //ignore param
 101             }
 102             runbench(args[n]);
 103             changed = true;
 104         }
 105 
 106     } catch (e) {
 107         print("error: " + e);
 108         if (e.toString().indexOf(args) == 1) {
 109             throw e;
 110         }
 111         // no scripting or something, silently fail
 112     }
 113     return changed;
 114 }
 115 
 116 var args;
 117 if (typeof $ARGS !== 'undefined') {
 118     args = $ARGS;
 119 } else if (typeof arguments !== 'undefined') {
 120     args = arguments;
 121 } 
 122 
 123 var tests = [
 124              'check-3d-cube.js',
 125              'check-access-nsieve.js',
 126              'check-crypto-aes.js',   
 127              'check-math-spectral-norm.js',
 128              'check-3d-morph.js',
 129              'check-bitops-3bit-bits-in-byte.js',
 130              'check-crypto-md5.js',
 131              'check-mont.js',
 132              'check-3d-raytrace.js',
 133              'check-bitops-bits-in-byte.js',
 134              'check-crypto-sha1.js',
 135              'check-regexp-dna.js',
 136              'check-access-binary-trees.js',
 137              'check-bitops-bitwise-and.js',
 138              'check-date-format-tofte.js',
 139              'check-string-fasta.js',
 140              'check-access-fannkuch.js',
 141              'check-bitops-nsieve-bits.js',
 142              'check-math-cordic.js',
 143              'check-string-tagcloud.js',
 144              'check-access-nbody.js',
 145              'check-controlflow-recursive.js',
 146              'check-math-partial-sums.js',
 147              'check-string-unpack-code.js'
 148              ];
 149 
 150 // handle the case this script may be run by a JS engine that doesn't
 151 // support __DIR__ global variable.
 152 var dir = (typeof(__DIR__) == 'undefined')? "test/script/basic/" : __DIR__;
 153 
 154 for (i in tests) {
 155     tests[i] = dir + '../external/sunspider/' + tests[i];
 156 }
 157 
 158 var verbose_run = false;
 159 
 160 // check for a fileset from ant and split it - special case call from ant build.xml
 161 if (args.length == 1 && args[0].toString().indexOf(' ') != -1) {
 162     args[0] = args[0].replace(/\/$/, '');
 163     args = args[0].split(' ');
 164     verbose_run = true; //for a file set, always run verbose for ant sunspider output
 165 } 
 166 
 167 
 168 var tests_found = [];
 169 
 170 for (i in args) {
 171     var arg = args[i];
 172     if (arg.indexOf('--') == 0) {
 173         if (arg == '--verbose') {
 174             verbose_run = true;
 175         } 
 176     } else {
 177         tests_found.push(arg);
 178     }
 179 }
 180 
 181 if (tests_found.length == 0) {    
 182     tests_found = tests;
 183 }
 184 
 185 runsuite(tests_found);
 186 
 187 if (verbose_run) {
 188     print(runs + "/" + tests_found.length + " tests were successfully run in " + total_time + " ms ");
 189 }
 190 
 191 print("Sunspider finished!");
--- EOF ---