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