@@ -52,12 +52,15 @@ class Benchmarker(object):
52
52
def __init__ (self , name ):
53
53
self .name = name
54
54
55
- def bench (self , args , output_parser = None , reps = TEST_REPS ):
55
+ def bench (self , args , output_parser = None , reps = TEST_REPS , expected_output = None ):
56
56
self .times = []
57
57
self .reps = reps
58
58
for i in range (reps ):
59
59
start = time .time ()
60
60
output = self .run (args )
61
+ if expected_output is not None and expected_output not in output :
62
+ raise ValueError ('Incorrect benchmark output:\n ' + output )
63
+
61
64
if not output_parser or args == ['0' ]: # if arg is 0, we are not running code, and have no output to parse
62
65
if IGNORE_COMPILATION :
63
66
curr = float (re .search (r'took +([\d\.]+) milliseconds' , output ).group (1 )) / 1000
@@ -199,7 +202,7 @@ def build(self, parent, filename, args, shared_args, emcc_args, native_args, nat
199
202
self .filename = final
200
203
201
204
def run (self , args ):
202
- return jsrun .run_js (self .filename , engine = self .engine , args = args , stderr = PIPE , full_output = True , assert_returncode = None )
205
+ return jsrun .run_js (self .filename , engine = self .engine , args = args , stderr = PIPE , full_output = True )
203
206
204
207
def get_output_files (self ):
205
208
ret = [self .filename ]
@@ -354,7 +357,7 @@ def setUpClass(self):
354
357
355
358
# avoid depending on argument reception from the commandline
356
359
def hardcode_arguments (self , code ):
357
- if not code :
360
+ if not code or 'int main()' in code :
358
361
return code
359
362
main_pattern = 'int main(int argc, char **argv)'
360
363
assert main_pattern in code
@@ -395,7 +398,7 @@ def do_benchmark(self, name, src, expected_output='FAIL', args=[],
395
398
baseline = b
396
399
print ('Running benchmarker: ' + b .name )
397
400
b .build (self , filename , args , shared_args , emcc_args , native_args , native_exec , lib_builder , has_output_parser = output_parser is not None )
398
- b .bench (args , output_parser , reps )
401
+ b .bench (args , output_parser , reps , expected_output )
399
402
b .display (baseline )
400
403
b .cleanup ()
401
404
@@ -614,9 +617,9 @@ def test_ifs(self):
614
617
}
615
618
}
616
619
617
- printf("ok\n");
620
+ printf("ok %d \n", sum );
618
621
619
- return sum ;
622
+ return 0 ;
620
623
}
621
624
'''
622
625
self .do_benchmark ('ifs' , src , 'ok' )
@@ -652,7 +655,7 @@ def test_conditionals(self):
652
655
653
656
printf("ok %d\n", x);
654
657
655
- return x ;
658
+ return 0 ;
656
659
}
657
660
'''
658
661
self .do_benchmark ('conditionals' , src , 'ok' , reps = TEST_REPS , emcc_args = ['-s' , 'MINIMAL_RUNTIME=0' ])
@@ -880,7 +883,7 @@ def output_parser(output):
880
883
def test_matrix_multiply (self ):
881
884
def output_parser (output ):
882
885
return float (re .search (r'Total elapsed: ([\d\.]+)' , output ).group (1 ))
883
- self .do_benchmark ('matrix_multiply' , open (path_from_root ('tests' , 'matrix_multiply.cpp' )).read (), 'Total time :' , output_parser = output_parser , shared_args = ['-I' + path_from_root ('tests' )])
886
+ self .do_benchmark ('matrix_multiply' , open (path_from_root ('tests' , 'matrix_multiply.cpp' )).read (), 'Total elapsed :' , output_parser = output_parser , shared_args = ['-I' + path_from_root ('tests' )])
884
887
885
888
@non_core
886
889
def test_zzz_java_nbody (self ): # tests xmlvm compiled java, including bitcasts of doubles, i64 math, etc.
@@ -963,7 +966,7 @@ def lib_builder(name, native, env_init):
963
966
def test_zzz_sqlite (self ):
964
967
src = open (path_from_root ('tests' , 'sqlite' , 'sqlite3.c' ), 'r' ).read () + open (path_from_root ('tests' , 'sqlite' , 'speedtest1.c' ), 'r' ).read ()
965
968
966
- self .do_benchmark ('sqlite' , src , 'ok .' , shared_args = ['-I' + path_from_root ('tests' , 'sqlite' )], emcc_args = ['-s' , 'FILESYSTEM=1' ], force_c = True )
969
+ self .do_benchmark ('sqlite' , src , 'TOTAL.. .' , shared_args = ['-I' + path_from_root ('tests' , 'sqlite' )], emcc_args = ['-s' , 'FILESYSTEM=1' ], force_c = True )
967
970
968
971
def test_zzz_poppler (self ):
969
972
with open ('pre.js' , 'w' ) as f :
@@ -978,12 +981,12 @@ def test_zzz_poppler(self):
978
981
'5': 55,
979
982
};
980
983
if (benchmarkArgument === 0) {
981
- Module. arguments = ['-?'];
982
- Module. printErr = function(){};
984
+ Module[' arguments'] = ['-?'];
985
+ Module[' printErr'] = function(){};
983
986
} else {
984
987
// Add 'filename' after 'input.pdf' to write the output so it can be verified.
985
- Module. arguments = ['-scale-to', '1024', 'input.pdf', '-f', '1', '-l', '' + benchmarkArgumentToPageCount[benchmarkArgument]];
986
- Module. postRun = function() {
988
+ Module[' arguments'] = ['-scale-to', '1024', 'input.pdf', '-f', '1', '-l', '' + benchmarkArgumentToPageCount[benchmarkArgument]];
989
+ Module[' postRun'] = function() {
987
990
var files = [];
988
991
for (var x in FS.root.contents) {
989
992
if (x.startsWith('filename-')) {
0 commit comments