test/script/basic/runsunspider.js

Thu, 31 Aug 2017 15:30:47 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:30:47 +0800
changeset 952
6d5471a497fb
parent 624
b3ee112a328e
parent 0
b1a7da25b547
child 1205
4112748288bb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /**
aoqi@0 25 * runsunspider : runs the sunspider tests and checks for compliance
aoqi@0 26 *
aoqi@0 27 * @subtest
aoqi@0 28 */
aoqi@0 29
aoqi@0 30 /**
aoqi@0 31 * This is not a test, but a test "framework" for running sunspider tests.
aoqi@0 32 */
aoqi@0 33
aoqi@0 34 function assertEq(a, b) {
aoqi@0 35 if (a !== b) {
aoqi@0 36 throw "ASSERTION FAILED: " + a + " should be " + b;
aoqi@0 37 }
aoqi@0 38 }
aoqi@0 39
aoqi@0 40 var runs = 0;
aoqi@0 41 var iterations__ = 1;
aoqi@0 42 var total_time = 0;
aoqi@0 43
aoqi@0 44 function runbench(name) {
aoqi@0 45 var filename = name.split("/").pop();
aoqi@0 46 if (verbose_run) {
aoqi@0 47 print("Running " + filename);
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 var start = new Date;
aoqi@0 51 for (var i = 0; i < iterations__; i++) {
aoqi@0 52 load(name);
aoqi@0 53 }
aoqi@0 54 var stop = new Date - start;
aoqi@0 55 total_time += stop;
aoqi@0 56
aoqi@0 57 if (verbose_run) {
aoqi@0 58 print(filename + " done in " + stop + " ms");
aoqi@0 59 }
aoqi@0 60 runs++;
aoqi@0 61 }
aoqi@0 62
aoqi@0 63 var m_w = 4711;
aoqi@0 64 var m_z = 17;
aoqi@0 65 var MAXINT = 0x7fffffff;
aoqi@0 66
aoqi@0 67 //produce deterministic random numbers for test suite
aoqi@0 68 function pseudorandom() {
aoqi@0 69 m_z = 36969 * (m_z & 65535) + (m_z >> 16);
aoqi@0 70 m_w = 18000 * (m_w & 65535) + (m_w >> 16);
aoqi@0 71 return (Math.abs((m_z << 16) + m_w) & MAXINT) / MAXINT;
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 function runsuite(tests) {
aoqi@0 75 var changed = false;
aoqi@0 76
aoqi@0 77 var oldRandom = Math.random;
aoqi@0 78 Math.random = pseudorandom;
aoqi@0 79
aoqi@0 80 try {
aoqi@0 81 for (var n = 0; n < tests.length; n++) {
aoqi@0 82 path = dir + '../external/sunspider/tests/sunspider-1.0/' + tests[n].name
aoqi@0 83 runbench(path);
aoqi@0 84 if (typeof tests[n].actual !== 'undefined') {
aoqi@0 85 assertEq(tests[n].actual(), tests[n].expected());
aoqi@0 86 }
aoqi@0 87 changed = true;
aoqi@0 88 }
aoqi@0 89 // no scripting or something, silently fail
aoqi@0 90 } finally {
aoqi@0 91 }
aoqi@0 92 Math.random = oldRandom;
aoqi@0 93
aoqi@0 94 return changed;
aoqi@0 95 }
aoqi@0 96
aoqi@0 97 function hash(str) {
aoqi@0 98 var s = "" + str;
aoqi@0 99 var h = 0;
aoqi@0 100 var off = 0;
aoqi@0 101 for (var i = 0; i < s.length; i++) {
aoqi@0 102 h = 31 * h + s.charCodeAt(off++);
aoqi@0 103 h &= 0x7fffffff;
aoqi@0 104 }
aoqi@0 105 return h ^ s.length;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 var tests = [
aoqi@0 109 { name: 'string-base64.js',
aoqi@0 110 actual: function() {
aoqi@0 111 return hash(str);
aoqi@0 112 },
aoqi@0 113 expected: function() {
aoqi@0 114 return 1544571068;
aoqi@0 115 }
aoqi@0 116 },
aoqi@0 117 { name: 'string-validate-input.js',
aoqi@0 118 actual: function() {
aoqi@0 119 return hash(endResult);
aoqi@0 120 },
aoqi@0 121 expected: function() {
aoqi@0 122 return 2016572373;
aoqi@0 123 }
aoqi@0 124 },
aoqi@0 125 { name: 'date-format-xparb.js',
aoqi@0 126 actual: function() {
aoqi@0 127 return shortFormat + longFormat;
aoqi@0 128 },
aoqi@0 129 expected: function() {
aoqi@0 130 return "2017-09-05Tuesday, September 05, 2017 8:43:48 AM";
aoqi@0 131 }
aoqi@0 132 },
aoqi@0 133 { name: '3d-morph.js',
aoqi@0 134 actual: function() {
aoqi@0 135 var acceptableDelta = 4e-15;
aoqi@0 136 return (testOutput - 6.394884621840902e-14) < acceptableDelta;
aoqi@0 137 },
aoqi@0 138 expected: function() {
aoqi@0 139 return true;
aoqi@0 140 }
aoqi@0 141 },
aoqi@0 142 { name: 'crypto-aes.js',
aoqi@0 143 actual: function() {
aoqi@0 144 return plainText;
aoqi@0 145 },
aoqi@0 146 expected: function() {
aoqi@0 147 return decryptedText;
aoqi@0 148 }
aoqi@0 149 },
aoqi@0 150 { name: 'crypto-md5.js',
aoqi@0 151 actual: function() {
aoqi@0 152 return md5Output;
aoqi@0 153 },
aoqi@0 154 expected: function() {
aoqi@0 155 return "a831e91e0f70eddcb70dc61c6f82f6cd";
aoqi@0 156 }
aoqi@0 157 },
aoqi@0 158 { name: 'crypto-sha1.js',
aoqi@0 159 actual: function() {
aoqi@0 160 return sha1Output;
aoqi@0 161 },
aoqi@0 162 expected: function() {
aoqi@0 163 return "2524d264def74cce2498bf112bedf00e6c0b796d";
aoqi@0 164 }
aoqi@0 165 },
aoqi@0 166 { name: 'bitops-bitwise-and.js',
aoqi@0 167 actual: function() {
aoqi@0 168 return result;
aoqi@0 169 },
aoqi@0 170 expected: function() {
aoqi@0 171 return 0;
aoqi@0 172 }
aoqi@0 173 },
aoqi@0 174 { name: 'bitops-bits-in-byte.js',
aoqi@0 175 actual: function() {
aoqi@0 176 return result;
aoqi@0 177 },
aoqi@0 178 expected: function() {
aoqi@0 179 return 358400;
aoqi@0 180 }
aoqi@0 181 },
aoqi@0 182 { name: 'bitops-nsieve-bits.js',
aoqi@0 183 actual: function() {
aoqi@0 184 var ret = 0;
aoqi@0 185 for (var i = 0; i < result.length; ++i) {
aoqi@0 186 ret += result[i];
aoqi@0 187 }
aoqi@0 188 ret += result.length;
aoqi@0 189 return ret;
aoqi@0 190 },
aoqi@0 191 expected: function() {
aoqi@0 192 return -1286749539853;
aoqi@0 193 }
aoqi@0 194 },
aoqi@0 195 { name: 'bitops-3bit-bits-in-byte.js',
aoqi@0 196 actual: function() {
aoqi@0 197 return sum;
aoqi@0 198 },
aoqi@0 199 expected: function() {
aoqi@0 200 return 512000;
aoqi@0 201 }
aoqi@0 202 },
aoqi@0 203 { name: 'access-nbody.js',
aoqi@0 204 actual: function() {
aoqi@0 205 return ret;
aoqi@0 206 },
aoqi@0 207 expected: function() {
aoqi@0 208 return -1.3524862408537381;
aoqi@0 209 }
aoqi@0 210 },
aoqi@0 211 { name: 'access-binary-trees.js',
aoqi@0 212 actual: function() {
aoqi@0 213 return ret;
aoqi@0 214 },
aoqi@0 215 expected: function() {
aoqi@0 216 return -4;
aoqi@0 217 }
aoqi@0 218 },
aoqi@0 219 { name: 'access-fannkuch.js',
aoqi@0 220 actual: function() {
aoqi@0 221 return ret;
aoqi@0 222 },
aoqi@0 223 expected: function() {
aoqi@0 224 return 22;
aoqi@0 225 }
aoqi@0 226 },
aoqi@0 227 { name: 'math-spectral-norm.js',
aoqi@0 228 actual: function() {
aoqi@0 229 var ret = '';
aoqi@0 230 for (var i = 6; i <= 48; i *= 2) {
aoqi@0 231 ret += spectralnorm(i) + ',';
aoqi@0 232 }
aoqi@0 233 return ret;
aoqi@0 234 },
aoqi@0 235 expected: function() {
aoqi@0 236 return "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,";
aoqi@0 237 }
aoqi@0 238 },
aoqi@0 239 { name: '3d-raytrace.js',
aoqi@0 240 actual: function() {
aoqi@0 241 return hash(testOutput);
aoqi@0 242 },
aoqi@0 243 expected: function() {
aoqi@0 244 return 230692593;
aoqi@0 245 }
aoqi@0 246 },
aoqi@0 247 { name: 'regexp-dna.js',
aoqi@0 248 actual: function() {
aoqi@0 249 return dnaOutputString;
aoqi@0 250 },
aoqi@0 251 expected: function() {
aoqi@0 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";
aoqi@0 253 }
aoqi@0 254 },
aoqi@0 255 { name: 'math-cordic.js',
aoqi@0 256 actual: function() {
aoqi@0 257 return total;
aoqi@0 258 },
aoqi@0 259 expected: function() {
aoqi@0 260 return 10362.570468755888;
aoqi@0 261 }
aoqi@0 262 },
aoqi@0 263 { name: 'controlflow-recursive.js',
aoqi@0 264 actual: function() {
aoqi@0 265 var ret = 0;
aoqi@0 266 for (var i = 3; i <= 5; i++) {
aoqi@0 267 ret += ack(3,i);
aoqi@0 268 ret += fib(17.0+i);
aoqi@0 269 ret += tak(3*i+3,2*i+2,i+1);
aoqi@0 270 }
aoqi@0 271 return ret;
aoqi@0 272 },
aoqi@0 273 expected: function() {
aoqi@0 274 return 57775;
aoqi@0 275 }
aoqi@0 276 },
aoqi@0 277 { name: 'date-format-tofte.js',
aoqi@0 278 actual: function() {
aoqi@0 279 return shortFormat + longFormat;
aoqi@0 280 },
aoqi@0 281 expected: function() {
aoqi@0 282 return "2008-05-01Thursday, May 01, 2008 6:31:22 PM";
aoqi@0 283 }
aoqi@0 284 },
aoqi@0 285 { name: 'string-tagcloud.js',
aoqi@0 286 actual: function() {
aoqi@0 287 // The result string embeds floating-point numbers, which can vary a bit on different platforms,
aoqi@0 288 // so we truncate them a bit before comparing.
aoqi@0 289 var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' })
aoqi@0 290 return tagcloud_norm.length;
aoqi@0 291 },
aoqi@0 292 expected: function() {
aoqi@0 293 return 295906;
aoqi@0 294 }
aoqi@0 295 },
aoqi@0 296 { name: 'string-unpack-code.js',
aoqi@0 297 actual: function() {
aoqi@0 298 return decompressedMochiKit.length == 106415 &&
aoqi@0 299 decompressedMochiKit[2000] == '5' &&
aoqi@0 300 decompressedMochiKit[12000] == '_' &&
aoqi@0 301 decompressedMochiKit[82556] == '>';
aoqi@0 302 },
aoqi@0 303 expected: function() {
aoqi@0 304 return true;
aoqi@0 305 }
aoqi@0 306 },
aoqi@0 307 //TODO no easy way to sanity check result
aoqi@0 308 { name: 'string-fasta.js' },
aoqi@0 309 //TODO no easy way to sanity check result
aoqi@0 310 { name: 'math-partial-sums.js' },
aoqi@0 311 //TODO no easy way to sanity check result
aoqi@0 312 { name: 'access-nsieve.js' },
aoqi@0 313 //TODO no easy way to sanity check result
aoqi@0 314 { name: '3d-cube.js' },
aoqi@0 315 ];
aoqi@0 316
aoqi@0 317 // handle the case this script may be run by a JS engine that doesn't
aoqi@0 318 // support __DIR__ global variable.
aoqi@0 319 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
aoqi@0 320
aoqi@0 321 var verbose_run = false;
aoqi@0 322
aoqi@0 323 var args = [];
aoqi@0 324 if (typeof $ARGS !== 'undefined') {
aoqi@0 325 args = $ARGS;
aoqi@0 326 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
aoqi@0 327 args = arguments;
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 for (i in args) {
aoqi@0 331 if (args[i] === '--verbose') {
aoqi@0 332 verbose_run = true;
aoqi@0 333 break;
aoqi@0 334 }
aoqi@0 335 }
aoqi@0 336
aoqi@0 337 runsuite(tests);
aoqi@0 338
aoqi@0 339 if (verbose_run) {
aoqi@0 340 print('\n' + runs + "/" + tests.length + " tests were successfully run in " + total_time + " ms ");
aoqi@0 341 }
aoqi@0 342
aoqi@0 343 print("Sunspider finished!");

mercurial