test/script/basic/run-octane.js

Wed, 03 Apr 2013 11:13:08 +0200

author
attila
date
Wed, 03 Apr 2013 11:13:08 +0200
changeset 166
51da1afbab26
parent 139
390d44ba90cf
child 295
1f57afd14cc1
permissions
-rw-r--r--

8011362: Overloaded method resolution foiled by nulls
Reviewed-by: hannesw, 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  * @subtest
    26  */
    28 var tests = [
    29     "box2d.js",
    30     "code-load.js",
    31     "crypto.js", 
    32     "deltablue.js", 
    33     "earley-boyer.js", 
    34     "gbemu.js",
    35     "mandreel.js",
    36     "navier-stokes.js", 
    37     "pdfjs.js",
    38     "raytrace.js",
    39     "regexp.js", 
    40     "richards.js", 
    41     "splay.js" 
    42 ];
    44 // hack, teardown breaks things defined in the global space, making it impossible
    45 // to do multiple consecutive benchmark runs with the same harness. I think it's a bug
    46 // that the setup and teardown aren't each others constructor and destructor but rather
    47 // that the benchmarks rely on partial global state. For shame, Octane! 
    48 var ignoreTeardown = [
    49     { name: "box2d.js" },
    50     { name: "gbemu.js" },
    51 ];
    54 //TODO mandreel can be compiled as a test, but not run multiple times unless modified to not have global state
    55 var compileOnly = {
    56     "mandreel.js" : true
    57 };
    59 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
    61 // TODO: why is this path hard coded when it's defined in project properties?
    62 var path = dir + "../external/octane/";
    64 var runtime = "";
    65 var verbose = false;
    67 var numberOfIterations = 5;
    69 function endsWith(str, suffix) {
    70     return str.indexOf(suffix, str.length - suffix.length) !== -1;
    71 }
    73 function should_compile_only(name) {
    74     return (typeof compile_only !== 'undefined') || compileOnly[name] === true;
    75 }
    77 function run_one_benchmark(arg, iters) {
    79     var file_name;
    80     var file = arg.split('/');
    81     if (file.length == 1) {
    82         file = arg.split('\\');
    83     }    
    85     //trim off trailing path separators
    86     while (file[file.length - 1].indexOf(".js") == -1) {
    87 	file.pop();
    88     }
    89     file_name = file[file.length - 1];
    91     var compile_and_return = should_compile_only(file_name);
    92     if (compile_and_return) {
    93 	if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them
    94 	    return;
    95 	}
    96 	print("Compiling... " + file_name);
    97     }
    99     load(path + 'base.js');
   100     load(arg);
   102     if (compile_and_return) {
   103 	print("Compiled OK: " + file_name);
   104 	print("");
   105 	return;
   106     }
   108     var success = true;
   109     var hiscore = 0;
   110     var loscore = 10e8;
   111     var current_name;
   113     function PrintResult(name, result) {
   114 	current_name = name;
   115     }
   117     function PrintError(name, error) {
   118 	current_name = name;
   119 	PrintResult(name, error);
   120 	success = false;
   121     }
   123     function PrintScore(score) {
   124 	if (success) {
   125 	    if (+score >= hiscore) {
   126 		hiscore = +score;
   127 	    }
   128 	    if (+score <= loscore) {
   129 		loscore = +score;
   130 	    }
   131 	}
   133 	if (verbose) {
   134 	    print("Score: " + score);
   135 	}
   136     }
   138     if (iters == undefined) {
   139 	iters = numberOfIterations;
   140     } else {
   141 	numberOfIterations = iters;
   142     }
   144     print(runtime + ": running " + file_name + "...");
   146     for (var i = 0; i < numberOfIterations; i++) {
   147 	var callbacks =
   148 	    { NotifyResult: PrintResult,
   149 	      NotifyError: PrintError,
   150 	      NotifyScore: PrintScore };	
   152 	for (j in ignoreTeardown) {
   153 	    var ignore = ignoreTeardown[j];
   154 	    if (endsWith(arg, ignore.name)) {
   155 		var teardownOverride = ignore.teardown;
   156 		if (!teardownOverride) {
   157 		    teardownOverride = function() {};
   158 		}
   160 		for (k in BenchmarkSuite.suites) {
   161 		    var benchmarks = BenchmarkSuite.suites[k].benchmarks;
   162 		    for (l in benchmarks) {
   163 			benchmarks[l].TearDown = teardownOverride;
   164 		    }
   165                 }
   166 		break;
   167 	    }
   168 	}
   170 	BenchmarkSuite.RunSuites(callbacks);
   171     }
   173     var start = "Score: ";
   174     if (runtime != "") {
   175 	start = runtime + ": ";
   176     } 
   177     print(start + current_name + ' (version ' + BenchmarkSuite.version + '): ' + loscore + '-' + hiscore);
   178 }
   180 function run_suite(tests, iters) {
   181     for (var idx = 0; idx < tests.length; idx++) {
   182 	run_one_benchmark(tests[idx], iters);
   183     }
   184 }
   186 runtime = "command line";
   188 var args = [];
   189 if (typeof $ARGS !== 'undefined') {
   190     args = $ARGS;
   191 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
   192     args = arguments;
   193 }  
   195 var new_args = [];
   196 for (i in args) {
   197     if (args[i].toString().indexOf(' ') != -1) {
   198 	args[i] = args[i].replace(/\/$/, '');
   199 	var s = args[i].split(' ');
   200 	for (j in s) {
   201 	    new_args.push(s[j]);
   202 	}
   203     } else {
   204 	new_args.push(args[i]);
   205     }
   206 }
   208 if (new_args.length != 0) {
   209     args = new_args;
   210 }
   212 var tests_found = [];
   213 var iters = undefined;
   215 for (var i = 0; i < args.length; i++) { 
   216     arg = args[i];
   217     if (arg == "--iterations") {
   218 	iters = +args[++i];
   219     } else if (arg == "--runtime") {
   220 	runtime = args[++i];
   221     } else if (arg == "--verbose") {
   222 	verbose = true;
   223     } else if (arg == "") {
   224 	continue; //skip
   225     } else {
   226 	tests_found.push(arg);
   227     }
   228 }
   230 if (tests_found.length == 0) {    
   231     for (i in tests) {
   232 	tests_found.push(path + tests[i]);
   233     }
   234 } 
   236 tests_found.sort();
   238 run_suite(tests_found, iters);

mercurial