Wed, 15 May 2013 20:21:59 +0200
8014647: Allow class-based overrides to be initialized with a ScriptFunction
Reviewed-by: hannesw, jlaskey, sundar
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 runbench(tests[n].name);
83 if (typeof tests[n].actual !== 'undefined') {
84 assertEq(tests[n].actual(), tests[n].expected());
85 }
86 changed = true;
87 }
88 } catch (e) {
89 print("error: " + e.printStackTrace());
90 if (e.toString().indexOf(tests) == 1) {
91 throw e;
92 }
93 // no scripting or something, silently fail
94 } finally {
95 Math.random = oldRandom;
96 }
98 return changed;
99 }
101 function hash(str) {
102 var s = "" + str;
103 var h = 0;
104 var off = 0;
105 for (var i = 0; i < s.length; i++) {
106 h = 31 * h + s.charCodeAt(off++);
107 h &= 0x7fffffff;
108 }
109 return h ^ s.length;
110 }
112 var tests = [
113 { name: 'string-base64.js',
114 actual: function() {
115 return hash(str);
116 },
117 expected: function() {
118 return 1544571068;
119 }
120 },
121 { name: 'string-validate-input.js',
122 actual: function() {
123 return hash(endResult);
124 },
125 expected: function() {
126 return 2016572373;
127 }
128 },
129 { name: 'date-format-xparb.js',
130 actual: function() {
131 return shortFormat + longFormat;
132 },
133 expected: function() {
134 return "2017-09-05Tuesday, September 05, 2017 8:43:48 AM";
135 }
136 },
137 { name: '3d-morph.js',
138 actual: function() {
139 var acceptableDelta = 4e-15;
140 return (testOutput - 6.394884621840902e-14) < acceptableDelta;
141 },
142 expected: function() {
143 return true;
144 }
145 },
146 { name: 'crypto-aes.js',
147 actual: function() {
148 return plainText;
149 },
150 expected: function() {
151 return decryptedText;
152 }
153 },
154 { name: 'crypto-md5.js',
155 actual: function() {
156 return md5Output;
157 },
158 expected: function() {
159 return "a831e91e0f70eddcb70dc61c6f82f6cd";
160 }
161 },
162 { name: 'crypto-sha1.js',
163 actual: function() {
164 return sha1Output;
165 },
166 expected: function() {
167 return "2524d264def74cce2498bf112bedf00e6c0b796d";
168 }
169 },
170 { name: 'bitops-bitwise-and.js',
171 actual: function() {
172 return result;
173 },
174 expected: function() {
175 return 0;
176 }
177 },
178 { name: 'bitops-bits-in-byte.js',
179 actual: function() {
180 return result;
181 },
182 expected: function() {
183 return 358400;
184 }
185 },
186 { name: 'bitops-nsieve-bits.js',
187 actual: function() {
188 var ret = 0;
189 for (var i = 0; i < result.length; ++i) {
190 ret += result[i];
191 }
192 ret += result.length;
193 return ret;
194 },
195 expected: function() {
196 return -1286749539853;
197 }
198 },
199 { name: 'bitops-3bit-bits-in-byte.js',
200 actual: function() {
201 return sum;
202 },
203 expected: function() {
204 return 512000;
205 }
206 },
207 { name: 'access-nbody.js',
208 actual: function() {
209 return ret;
210 },
211 expected: function() {
212 return -0.16906933525822856;
213 }
214 },
215 { name: 'access-binary-trees.js',
216 actual: function() {
217 return ret;
218 },
219 expected: function() {
220 return -1;
221 }
222 },
223 { name: 'access-fannkuch.js',
224 actual: function() {
225 return ret;
226 },
227 expected: function() {
228 return 22;
229 }
230 },
231 { name: 'math-spectral-norm.js',
232 actual: function() {
233 var ret = '';
234 for (var i = 6; i <= 48; i *= 2) {
235 ret += spectralnorm(i) + ',';
236 }
237 return ret;
238 },
239 expected: function() {
240 return "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,";
241 }
242 },
243 { name: '3d-raytrace.js',
244 actual: function() {
245 return hash(testOutput);
246 },
247 expected: function() {
248 return 230692593;
249 }
250 },
251 { name: 'regexp-dna.js',
252 actual: function() {
253 return dnaOutputString;
254 },
255 expected: function() {
256 return "undefinedagggtaaa|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";
257 }
258 },
259 { name: 'math-cordic.js',
260 actual: function() {
261 return total;
262 },
263 expected: function() {
264 return 10362.570468755888;
265 }
266 },
267 { name: 'controlflow-recursive.js',
268 actual: function() {
269 var ret = 0;
270 for (var i = 3; i <= 5; i++) {
271 ret += ack(3,i);
272 ret += fib(17.0+i);
273 ret += tak(3*i+3,2*i+2,i+1);
274 }
275 return ret;
276 },
277 expected: function() {
278 return 57775;
279 }
280 },
281 { name: 'date-format-tofte.js',
282 actual: function() {
283 return shortFormat + longFormat;
284 },
285 expected: function() {
286 return "2008-05-01Thursday, May 01, 2008 6:31:22 PM";
287 }
288 },
289 { name: 'string-tagcloud.js',
290 actual: function() {
291 // The result string embeds floating-point numbers, which can vary a bit on different platforms,
292 // so we truncate them a bit before comparing.
293 var tagcloud_norm = tagcloud.replace(/([0-9.]+)px/g, function(str, p1) { return p1.substr(0, 10) + 'px' })
294 return tagcloud_norm.length;
295 },
296 expected: function() {
297 return 295906;
298 }
299 },
300 { name: 'string-unpack-code.js',
301 actual: function() {
302 return decompressedMochiKit.length == 106415 &&
303 decompressedMochiKit[2000] == '5' &&
304 decompressedMochiKit[12000] == '_' &&
305 decompressedMochiKit[82556] == '>';
306 },
307 expected: function() {
308 return true;
309 }
310 },
311 //TODO no easy way to sanity check result
312 { name: 'string-fasta.js' },
313 //TODO no easy way to sanity check result
314 { name: 'math-partial-sums.js' },
315 //TODO no easy way to sanity check result
316 { name: 'access-nsieve.js' },
317 //TODO no easy way to sanity check result
318 { name: '3d-cube.js' },
319 ];
321 // handle the case this script may be run by a JS engine that doesn't
322 // support __DIR__ global variable.
323 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
325 for (i in tests) {
326 tests[i].name = dir + '../external/sunspider/tests/sunspider-1.0/' + tests[i].name;
327 }
329 var verbose_run = false;
331 var args = [];
332 if (typeof $ARGS !== 'undefined') {
333 args = $ARGS;
334 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
335 args = arguments;
336 }
338 for (i in args) {
339 if (args[i] === '--verbose') {
340 verbose_run = true;
341 break;
342 }
343 }
345 runsuite(tests);
347 if (verbose_run) {
348 print('\n' + runs + "/" + tests.length + " tests were successfully run in " + total_time + " ms ");
349 }
351 print("Sunspider finished!");