1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/script/basic/runsunspider.js Wed Apr 27 01:36:41 2016 +0800 1.3 @@ -0,0 +1,343 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * runsunspider : runs the sunspider tests and checks for compliance 1.29 + * 1.30 + * @subtest 1.31 + */ 1.32 + 1.33 +/** 1.34 + * This is not a test, but a test "framework" for running sunspider tests. 1.35 + */ 1.36 + 1.37 +function assertEq(a, b) { 1.38 + if (a !== b) { 1.39 + throw "ASSERTION FAILED: " + a + " should be " + b; 1.40 + } 1.41 +} 1.42 + 1.43 +var runs = 0; 1.44 +var iterations__ = 1; 1.45 +var total_time = 0; 1.46 + 1.47 +function runbench(name) { 1.48 + var filename = name.split("/").pop(); 1.49 + if (verbose_run) { 1.50 + print("Running " + filename); 1.51 + } 1.52 + 1.53 + var start = new Date; 1.54 + for (var i = 0; i < iterations__; i++) { 1.55 + load(name); 1.56 + } 1.57 + var stop = new Date - start; 1.58 + total_time += stop; 1.59 + 1.60 + if (verbose_run) { 1.61 + print(filename + " done in " + stop + " ms"); 1.62 + } 1.63 + runs++; 1.64 +} 1.65 + 1.66 +var m_w = 4711; 1.67 +var m_z = 17; 1.68 +var MAXINT = 0x7fffffff; 1.69 + 1.70 +//produce deterministic random numbers for test suite 1.71 +function pseudorandom() { 1.72 + m_z = 36969 * (m_z & 65535) + (m_z >> 16); 1.73 + m_w = 18000 * (m_w & 65535) + (m_w >> 16); 1.74 + return (Math.abs((m_z << 16) + m_w) & MAXINT) / MAXINT; 1.75 +} 1.76 + 1.77 +function runsuite(tests) { 1.78 + var changed = false; 1.79 + 1.80 + var oldRandom = Math.random; 1.81 + Math.random = pseudorandom; 1.82 + 1.83 + try { 1.84 + for (var n = 0; n < tests.length; n++) { 1.85 + path = dir + '../external/sunspider/tests/sunspider-1.0/' + tests[n].name 1.86 + runbench(path); 1.87 + if (typeof tests[n].actual !== 'undefined') { 1.88 + assertEq(tests[n].actual(), tests[n].expected()); 1.89 + } 1.90 + changed = true; 1.91 + } 1.92 + // no scripting or something, silently fail 1.93 + } finally { 1.94 + } 1.95 + Math.random = oldRandom; 1.96 + 1.97 + return changed; 1.98 +} 1.99 + 1.100 +function hash(str) { 1.101 + var s = "" + str; 1.102 + var h = 0; 1.103 + var off = 0; 1.104 + for (var i = 0; i < s.length; i++) { 1.105 + h = 31 * h + s.charCodeAt(off++); 1.106 + h &= 0x7fffffff; 1.107 + } 1.108 + return h ^ s.length; 1.109 +} 1.110 + 1.111 +var tests = [ 1.112 + { name: 'string-base64.js', 1.113 + actual: function() { 1.114 + return hash(str); 1.115 + }, 1.116 + expected: function() { 1.117 + return 1544571068; 1.118 + } 1.119 + }, 1.120 + { name: 'string-validate-input.js', 1.121 + actual: function() { 1.122 + return hash(endResult); 1.123 + }, 1.124 + expected: function() { 1.125 + return 2016572373; 1.126 + } 1.127 + }, 1.128 + { name: 'date-format-xparb.js', 1.129 + actual: function() { 1.130 + return shortFormat + longFormat; 1.131 + }, 1.132 + expected: function() { 1.133 + return "2017-09-05Tuesday, September 05, 2017 8:43:48 AM"; 1.134 + } 1.135 + }, 1.136 + { name: '3d-morph.js', 1.137 + actual: function() { 1.138 + var acceptableDelta = 4e-15; 1.139 + return (testOutput - 6.394884621840902e-14) < acceptableDelta; 1.140 + }, 1.141 + expected: function() { 1.142 + return true; 1.143 + } 1.144 + }, 1.145 + { name: 'crypto-aes.js', 1.146 + actual: function() { 1.147 + return plainText; 1.148 + }, 1.149 + expected: function() { 1.150 + return decryptedText; 1.151 + } 1.152 + }, 1.153 + { name: 'crypto-md5.js', 1.154 + actual: function() { 1.155 + return md5Output; 1.156 + }, 1.157 + expected: function() { 1.158 + return "a831e91e0f70eddcb70dc61c6f82f6cd"; 1.159 + } 1.160 + }, 1.161 + { name: 'crypto-sha1.js', 1.162 + actual: function() { 1.163 + return sha1Output; 1.164 + }, 1.165 + expected: function() { 1.166 + return "2524d264def74cce2498bf112bedf00e6c0b796d"; 1.167 + } 1.168 + }, 1.169 + { name: 'bitops-bitwise-and.js', 1.170 + actual: function() { 1.171 + return result; 1.172 + }, 1.173 + expected: function() { 1.174 + return 0; 1.175 + } 1.176 + }, 1.177 + { name: 'bitops-bits-in-byte.js', 1.178 + actual: function() { 1.179 + return result; 1.180 + }, 1.181 + expected: function() { 1.182 + return 358400; 1.183 + } 1.184 + }, 1.185 + { name: 'bitops-nsieve-bits.js', 1.186 + actual: function() { 1.187 + var ret = 0; 1.188 + for (var i = 0; i < result.length; ++i) { 1.189 + ret += result[i]; 1.190 + } 1.191 + ret += result.length; 1.192 + return ret; 1.193 + }, 1.194 + expected: function() { 1.195 + return -1286749539853; 1.196 + } 1.197 + }, 1.198 + { name: 'bitops-3bit-bits-in-byte.js', 1.199 + actual: function() { 1.200 + return sum; 1.201 + }, 1.202 + expected: function() { 1.203 + return 512000; 1.204 + } 1.205 + }, 1.206 + { name: 'access-nbody.js', 1.207 + actual: function() { 1.208 + return ret; 1.209 + }, 1.210 + expected: function() { 1.211 + return -1.3524862408537381; 1.212 + } 1.213 + }, 1.214 + { name: 'access-binary-trees.js', 1.215 + actual: function() { 1.216 + return ret; 1.217 + }, 1.218 + expected: function() { 1.219 + return -4; 1.220 + } 1.221 + }, 1.222 + { name: 'access-fannkuch.js', 1.223 + actual: function() { 1.224 + return ret; 1.225 + }, 1.226 + expected: function() { 1.227 + return 22; 1.228 + } 1.229 + }, 1.230 + { name: 'math-spectral-norm.js', 1.231 + actual: function() { 1.232 + var ret = ''; 1.233 + for (var i = 6; i <= 48; i *= 2) { 1.234 + ret += spectralnorm(i) + ','; 1.235 + } 1.236 + return ret; 1.237 + }, 1.238 + expected: function() { 1.239 + return "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,"; 1.240 + } 1.241 + }, 1.242 + { name: '3d-raytrace.js', 1.243 + actual: function() { 1.244 + return hash(testOutput); 1.245 + }, 1.246 + expected: function() { 1.247 + return 230692593; 1.248 + } 1.249 + }, 1.250 + { name: 'regexp-dna.js', 1.251 + actual: function() { 1.252 + return dnaOutputString; 1.253 + }, 1.254 + expected: function() { 1.255 + 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"; 1.256 + } 1.257 + }, 1.258 + { name: 'math-cordic.js', 1.259 + actual: function() { 1.260 + return total; 1.261 + }, 1.262 + expected: function() { 1.263 + return 10362.570468755888; 1.264 + } 1.265 + }, 1.266 + { name: 'controlflow-recursive.js', 1.267 + actual: function() { 1.268 + var ret = 0; 1.269 + for (var i = 3; i <= 5; i++) { 1.270 + ret += ack(3,i); 1.271 + ret += fib(17.0+i); 1.272 + ret += tak(3*i+3,2*i+2,i+1); 1.273 + } 1.274 + return ret; 1.275 + }, 1.276 + expected: function() { 1.277 + return 57775; 1.278 + } 1.279 + }, 1.280 + { name: 'date-format-tofte.js', 1.281 + actual: function() { 1.282 + return shortFormat + longFormat; 1.283 + }, 1.284 + expected: function() { 1.285 + return "2008-05-01Thursday, May 01, 2008 6:31:22 PM"; 1.286 + } 1.287 + }, 1.288 + { name: 'string-tagcloud.js', 1.289 + actual: function() { 1.290 + // The result string embeds floating-point numbers, which can vary a bit on different platforms, 1.291 + // so we truncate them a bit before comparing. 1.292 + var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' }) 1.293 + return tagcloud_norm.length; 1.294 + }, 1.295 + expected: function() { 1.296 + return 295906; 1.297 + } 1.298 + }, 1.299 + { name: 'string-unpack-code.js', 1.300 + actual: function() { 1.301 + return decompressedMochiKit.length == 106415 && 1.302 + decompressedMochiKit[2000] == '5' && 1.303 + decompressedMochiKit[12000] == '_' && 1.304 + decompressedMochiKit[82556] == '>'; 1.305 + }, 1.306 + expected: function() { 1.307 + return true; 1.308 + } 1.309 + }, 1.310 + //TODO no easy way to sanity check result 1.311 + { name: 'string-fasta.js' }, 1.312 + //TODO no easy way to sanity check result 1.313 + { name: 'math-partial-sums.js' }, 1.314 + //TODO no easy way to sanity check result 1.315 + { name: 'access-nsieve.js' }, 1.316 + //TODO no easy way to sanity check result 1.317 + { name: '3d-cube.js' }, 1.318 +]; 1.319 + 1.320 +// handle the case this script may be run by a JS engine that doesn't 1.321 +// support __DIR__ global variable. 1.322 +var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__; 1.323 + 1.324 +var verbose_run = false; 1.325 + 1.326 +var args = []; 1.327 +if (typeof $ARGS !== 'undefined') { 1.328 + args = $ARGS; 1.329 +} else if (typeof arguments !== 'undefined' && arguments.length != 0) { 1.330 + args = arguments; 1.331 +} 1.332 + 1.333 +for (i in args) { 1.334 + if (args[i] === '--verbose') { 1.335 + verbose_run = true; 1.336 + break; 1.337 + } 1.338 +} 1.339 + 1.340 +runsuite(tests); 1.341 + 1.342 +if (verbose_run) { 1.343 + print('\n' + runs + "/" + tests.length + " tests were successfully run in " + total_time + " ms "); 1.344 +} 1.345 + 1.346 +print("Sunspider finished!");