test/script/basic/runsunspider.js

Wed, 04 Jun 2014 16:39:04 +0530

author
sundar
date
Wed, 04 Jun 2014 16:39:04 +0530
changeset 867
85ad3ce0796f
parent 624
b3ee112a328e
child 952
6d5471a497fb
child 963
e2497b11a021
permissions
-rw-r--r--

8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook
Reviewed-by: attila, lagergren, hannesw

     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  */
    24 /**
    25  * runsunspider : runs the sunspider tests and checks for compliance
    26  *
    27  * @subtest
    28  */
    30 /**
    31  * This is not a test, but a test "framework" for running sunspider tests.
    32  */
    34 function assertEq(a, b) {
    35     if (a !== b) {
    36         throw "ASSERTION FAILED: " + a + " should be " + b;
    37     }
    38 }
    40 var runs = 0;
    41 var iterations__ = 1;
    42 var total_time = 0;
    44 function runbench(name) {
    45     var filename = name.split("/").pop();
    46     if (verbose_run) {
    47         print("Running " + filename);
    48     }
    50     var start = new Date;
    51     for (var i = 0; i < iterations__; i++) {
    52         load(name);
    53     }
    54     var stop = new Date - start;
    55     total_time += stop;
    57     if (verbose_run) {
    58         print(filename + " done in " + stop + " ms");
    59     }
    60     runs++;
    61 }
    63 var m_w = 4711;
    64 var m_z = 17;
    65 var MAXINT = 0x7fffffff;
    67 //produce deterministic random numbers for test suite
    68 function pseudorandom() {
    69     m_z = 36969 * (m_z & 65535) + (m_z >> 16);
    70     m_w = 18000 * (m_w & 65535) + (m_w >> 16);
    71     return (Math.abs((m_z << 16) + m_w) & MAXINT) / MAXINT;
    72 }
    74 function runsuite(tests) {
    75     var changed = false;
    77     var oldRandom = Math.random;
    78     Math.random = pseudorandom;
    80     try {
    81         for (var n = 0; n < tests.length; n++) {
    82             path = dir + '../external/sunspider/tests/sunspider-1.0/' + tests[n].name
    83             runbench(path);
    84             if (typeof tests[n].actual !== 'undefined') {
    85                 assertEq(tests[n].actual(), tests[n].expected());
    86             }
    87             changed = true;
    88         }
    89         // no scripting or something, silently fail
    90     } finally {
    91     }
    92     Math.random = oldRandom;
    94     return changed;
    95 }
    97 function hash(str) {
    98     var s = "" + str;
    99     var h = 0;
   100     var off = 0;
   101     for (var i = 0; i < s.length; i++) {
   102         h = 31 * h + s.charCodeAt(off++);
   103         h &= 0x7fffffff;
   104     }
   105     return h ^ s.length;
   106 }
   108 var tests = [
   109     { name: 'string-base64.js',
   110       actual: function() {
   111           return hash(str);
   112       },
   113       expected: function() {
   114           return 1544571068;
   115       }
   116     },
   117     { name: 'string-validate-input.js',
   118       actual: function() {
   119           return hash(endResult);
   120       },
   121       expected: function() {
   122           return 2016572373;
   123       }
   124     },
   125     { name: 'date-format-xparb.js',
   126       actual: function() {
   127           return shortFormat + longFormat;
   128       },
   129       expected: function() {
   130           return "2017-09-05Tuesday, September 05, 2017 8:43:48 AM";
   131       }
   132     },
   133     { name: '3d-morph.js',
   134       actual: function() {
   135           var acceptableDelta = 4e-15;
   136           return (testOutput - 6.394884621840902e-14) < acceptableDelta;
   137       },
   138       expected: function() {
   139           return true;
   140       }
   141     },
   142     { name: 'crypto-aes.js',
   143       actual: function() {
   144           return plainText;
   145       },
   146       expected: function() {
   147           return decryptedText;
   148       }
   149     },
   150     { name: 'crypto-md5.js',
   151       actual: function() {
   152           return md5Output;
   153       },
   154       expected: function() {
   155           return "a831e91e0f70eddcb70dc61c6f82f6cd";
   156       }
   157     },
   158     { name: 'crypto-sha1.js',
   159       actual: function() {
   160           return sha1Output;
   161       },
   162       expected: function() {
   163           return "2524d264def74cce2498bf112bedf00e6c0b796d";
   164       }
   165     },
   166     { name: 'bitops-bitwise-and.js',
   167       actual: function() {
   168           return result;
   169       },
   170       expected: function() {
   171           return 0;
   172       }
   173     },
   174     { name: 'bitops-bits-in-byte.js',
   175       actual: function() {
   176           return result;
   177       },
   178       expected: function() {
   179           return 358400;
   180       }
   181     },
   182     { name: 'bitops-nsieve-bits.js',
   183       actual: function() {
   184           var ret = 0;
   185           for (var i = 0; i < result.length; ++i) {
   186               ret += result[i];
   187           }
   188           ret += result.length;
   189           return ret;
   190       },
   191       expected: function() {
   192           return -1286749539853;
   193       }
   194     },
   195     { name: 'bitops-3bit-bits-in-byte.js',
   196       actual: function() {
   197           return sum;
   198       },
   199       expected: function() {
   200           return 512000;
   201       }
   202     },
   203     { name: 'access-nbody.js',
   204       actual: function() {
   205           return ret;
   206       },
   207       expected: function() {
   208             return -1.3524862408537381;
   209       }
   210     },
   211     { name: 'access-binary-trees.js',
   212       actual: function() {
   213           return ret;
   214       },
   215       expected: function() {
   216           return -4;
   217       }
   218     },
   219     { name: 'access-fannkuch.js',
   220       actual: function() {
   221           return ret;
   222       },
   223       expected: function() {
   224           return 22;
   225       }
   226     },
   227     { name: 'math-spectral-norm.js',
   228       actual: function() {
   229           var ret = '';
   230           for (var i = 6; i <= 48; i *= 2) {
   231               ret += spectralnorm(i) + ',';
   232           }
   233           return ret;
   234       },
   235       expected: function() {
   236           return "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,";
   237       }
   238     },
   239     { name: '3d-raytrace.js',
   240       actual: function() {
   241           return hash(testOutput);
   242       },
   243       expected: function() {
   244           return 230692593;
   245       }
   246     },
   247     { name: 'regexp-dna.js',
   248       actual: function() {
   249           return dnaOutputString;
   250       },
   251       expected: function() {
   252           return "agggtaaa|tttaccct 0\n[cgt]gggtaaa|tttaccc[acg] 9\na[act]ggtaaa|tttacc[agt]t 27\nag[act]gtaaa|tttac[agt]ct 24\nagg[act]taaa|ttta[agt]cct 30\naggg[acg]aaa|ttt[cgt]ccct 9\nagggt[cgt]aa|tt[acg]accct 12\nagggta[cgt]a|t[acg]taccct 9\nagggtaa[cgt]|[acg]ttaccct 15\n";
   253       }
   254     },
   255     { name: 'math-cordic.js',
   256       actual: function() {
   257           return total;
   258       },
   259       expected: function() {
   260           return 10362.570468755888;
   261       }
   262     },
   263     { name: 'controlflow-recursive.js',
   264       actual: function() {
   265           var ret = 0;
   266           for (var i = 3; i <= 5; i++) {
   267               ret += ack(3,i);
   268               ret += fib(17.0+i);
   269               ret += tak(3*i+3,2*i+2,i+1);
   270           }
   271           return ret;
   272       },
   273       expected: function() {
   274           return 57775;
   275       }
   276     },
   277     { name: 'date-format-tofte.js',
   278       actual: function() {
   279           return shortFormat + longFormat;
   280       },
   281       expected: function() {
   282           return "2008-05-01Thursday, May 01, 2008 6:31:22 PM";
   283       }
   284     },
   285     { name: 'string-tagcloud.js',
   286       actual: function() {
   287           // The result string embeds floating-point numbers, which can vary a bit on different platforms,
   288           // so we truncate them a bit before comparing.
   289           var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' })
   290           return tagcloud_norm.length;
   291       },
   292       expected: function() {
   293           return 295906;
   294       }
   295     },
   296     { name: 'string-unpack-code.js',
   297       actual: function() {
   298           return decompressedMochiKit.length == 106415 &&
   299               decompressedMochiKit[2000] == '5' &&
   300               decompressedMochiKit[12000] == '_' &&
   301               decompressedMochiKit[82556] == '>';
   302       },
   303       expected: function() {
   304           return true;
   305       }
   306     },
   307     //TODO no easy way to sanity check result
   308     { name: 'string-fasta.js' },
   309     //TODO no easy way to sanity check result
   310     { name: 'math-partial-sums.js' },
   311     //TODO no easy way to sanity check result
   312     { name: 'access-nsieve.js' },
   313     //TODO no easy way to sanity check result
   314     { name: '3d-cube.js' },
   315 ];
   317 // handle the case this script may be run by a JS engine that doesn't
   318 // support __DIR__ global variable.
   319 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
   321 var verbose_run = false;
   323 var args = [];
   324 if (typeof $ARGS !== 'undefined') {
   325     args = $ARGS;
   326 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
   327     args = arguments;
   328 }
   330 for (i in args) {
   331     if (args[i] === '--verbose') {
   332         verbose_run = true;
   333         break;
   334     }
   335 }
   337 runsuite(tests);
   339 if (verbose_run) {
   340     print('\n' + runs + "/" + tests.length + " tests were successfully run in " + total_time + " ms ");
   341 }
   343 print("Sunspider finished!");

mercurial