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