Skip to content

Commit 391fc14

Browse files
authored
Make benchmark suite check for success and correct output (#9015)
1 parent d736ea8 commit 391fc14

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

tests/base64.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ int main(int argc, char **argv) {
150150
free(str3);
151151
}
152152
printf("decode: %d, %.2f\n", s, (float)(clock() - t)/CLOCKS_PER_SEC);
153+
return 0;
153154
}
154155

tests/havlak.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,5 +829,6 @@ int main(int argc, char **argv) {
829829
fprintf(stderr,
830830
"\nFound %d loops (including artificial root node)"
831831
"(%d)\n", num_loops, sum);
832+
return 0;
832833
}
833834

tests/test_benchmark.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ class Benchmarker(object):
5252
def __init__(self, name):
5353
self.name = name
5454

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):
5656
self.times = []
5757
self.reps = reps
5858
for i in range(reps):
5959
start = time.time()
6060
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+
6164
if not output_parser or args == ['0']: # if arg is 0, we are not running code, and have no output to parse
6265
if IGNORE_COMPILATION:
6366
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
199202
self.filename = final
200203

201204
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)
203206

204207
def get_output_files(self):
205208
ret = [self.filename]
@@ -354,7 +357,7 @@ def setUpClass(self):
354357

355358
# avoid depending on argument reception from the commandline
356359
def hardcode_arguments(self, code):
357-
if not code:
360+
if not code or 'int main()' in code:
358361
return code
359362
main_pattern = 'int main(int argc, char **argv)'
360363
assert main_pattern in code
@@ -395,7 +398,7 @@ def do_benchmark(self, name, src, expected_output='FAIL', args=[],
395398
baseline = b
396399
print('Running benchmarker: ' + b.name)
397400
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)
399402
b.display(baseline)
400403
b.cleanup()
401404

@@ -614,9 +617,9 @@ def test_ifs(self):
614617
}
615618
}
616619
617-
printf("ok\n");
620+
printf("ok %d\n", sum);
618621
619-
return sum;
622+
return 0;
620623
}
621624
'''
622625
self.do_benchmark('ifs', src, 'ok')
@@ -652,7 +655,7 @@ def test_conditionals(self):
652655
653656
printf("ok %d\n", x);
654657
655-
return x;
658+
return 0;
656659
}
657660
'''
658661
self.do_benchmark('conditionals', src, 'ok', reps=TEST_REPS, emcc_args=['-s', 'MINIMAL_RUNTIME=0'])
@@ -880,7 +883,7 @@ def output_parser(output):
880883
def test_matrix_multiply(self):
881884
def output_parser(output):
882885
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')])
884887

885888
@non_core
886889
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):
963966
def test_zzz_sqlite(self):
964967
src = open(path_from_root('tests', 'sqlite', 'sqlite3.c'), 'r').read() + open(path_from_root('tests', 'sqlite', 'speedtest1.c'), 'r').read()
965968

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)
967970

968971
def test_zzz_poppler(self):
969972
with open('pre.js', 'w') as f:
@@ -978,12 +981,12 @@ def test_zzz_poppler(self):
978981
'5': 55,
979982
};
980983
if (benchmarkArgument === 0) {
981-
Module.arguments = ['-?'];
982-
Module.printErr = function(){};
984+
Module['arguments'] = ['-?'];
985+
Module['printErr'] = function(){};
983986
} else {
984987
// 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() {
987990
var files = [];
988991
for (var x in FS.root.contents) {
989992
if (x.startsWith('filename-')) {

0 commit comments

Comments
 (0)