test/script/basic/runsunspider.js

Fri, 11 Oct 2013 14:54:16 +0200

author
jlaskey
date
Fri, 11 Oct 2013 14:54:16 +0200
changeset 619
6cb4f20d971f
parent 475
17a947418e65
child 624
b3ee112a328e
permissions
-rw-r--r--

8026309: latest runsunspider.js tests contains several bugs
Reviewed-by: sundar, lagergren
Contributed-by: james.laskey@oracle.com

     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 -0.16906933525822856;
   209       }
   210     },
   211     { name: 'access-binary-trees.js',
   212       actual: function() {
   213           return ret;
   214       },
   215       expected: function() {
   216           return -1;
   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     /* Test is broken (not initializing dnaOutputString to "")
   248     { name: 'regexp-dna.js',
   249       actual: function() {
   250           return dnaOutputString;
   251       },
   252       expected: function() {
   253           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";
   254       }
   255     },
   256     */
   257     { name: 'math-cordic.js',
   258       actual: function() {
   259           return total;
   260       },
   261       expected: function() {
   262           return 10362.570468755888;
   263       }
   264     },
   265     { name: 'controlflow-recursive.js',
   266       actual: function() {
   267           var ret = 0;
   268           for (var i = 3; i <= 5; i++) {
   269               ret += ack(3,i);
   270               ret += fib(17.0+i);
   271               ret += tak(3*i+3,2*i+2,i+1);
   272           }
   273           return ret;
   274       },
   275       expected: function() {
   276           return 57775;
   277       }
   278     },
   279     { name: 'date-format-tofte.js',
   280       actual: function() {
   281           return shortFormat + longFormat;
   282       },
   283       expected: function() {
   284           return "2008-05-01Thursday, May 01, 2008 6:31:22 PM";
   285       }
   286     },
   287     { name: 'string-tagcloud.js',
   288       actual: function() {
   289           // The result string embeds floating-point numbers, which can vary a bit on different platforms,
   290           // so we truncate them a bit before comparing.
   291           var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' })
   292           return tagcloud_norm.length;
   293       },
   294       expected: function() {
   295           return 295906;
   296       }
   297     },
   298     { name: 'string-unpack-code.js',
   299       actual: function() {
   300           return decompressedMochiKit.length == 106415 &&
   301               decompressedMochiKit[2000] == '5' &&
   302               decompressedMochiKit[12000] == '_' &&
   303               decompressedMochiKit[82556] == '>';
   304       },
   305       expected: function() {
   306           return true;
   307       }
   308     },
   309     //TODO no easy way to sanity check result
   310     { name: 'string-fasta.js' },
   311     //TODO no easy way to sanity check result
   312     { name: 'math-partial-sums.js' },
   313     //TODO no easy way to sanity check result
   314     { name: 'access-nsieve.js' },
   315     //TODO no easy way to sanity check result
   316     { name: '3d-cube.js' },
   317 ];
   319 // handle the case this script may be run by a JS engine that doesn't
   320 // support __DIR__ global variable.
   321 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
   323 var verbose_run = false;
   325 var args = [];
   326 if (typeof $ARGS !== 'undefined') {
   327     args = $ARGS;
   328 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
   329     args = arguments;
   330 }
   332 for (i in args) {
   333     if (args[i] === '--verbose') {
   334         verbose_run = true;
   335         break;
   336     }
   337 }
   339 runsuite(tests);
   341 if (verbose_run) {
   342     print('\n' + runs + "/" + tests.length + " tests were successfully run in " + total_time + " ms ");
   343 }
   345 print("Sunspider finished!");

mercurial