diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-27 11:54:27 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-27 11:54:27 -0800 |
commit | 908eb57f41c6b538014587497d15b445b5ad82d8 (patch) | |
tree | 264e00ec5ab0961b4bbb8ffba72ee1b3325d14f9 | |
parent | 66b60aebd4f94069136ee6af5e768ad586eb948f (diff) | |
parent | fff86540c3c5147e745a038bffad034ea1058d22 (diff) |
Merge pull request #187 from ehsan/handle_broken_lli
Make the test runner handle broken lli's correctly
-rwxr-xr-x | tests/runner.py | 109 |
1 files changed, 74 insertions, 35 deletions
diff --git a/tests/runner.py b/tests/runner.py index 68ad6361..97d3b6fb 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -14,7 +14,7 @@ will use 4 processes. To install nose do something like ''' from subprocess import Popen, PIPE, STDOUT -import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib, webbrowser +import os, unittest, tempfile, shutil, time, inspect, sys, math, glob, tempfile, re, difflib, webbrowser, hashlib # Setup @@ -195,9 +195,6 @@ process(sys.argv[1]) assert 'strict warning:' not in ret, 'We should pass all strict mode checks: ' + ret return ret - def run_llvm_interpreter(self, args): - return Popen([EXEC_LLVM] + args, stdout=PIPE, stderr=self.stderr_redirect).communicate()[0] - def build_native(self, filename): Popen([CLANG, '-O2', filename, '-o', filename+'.native'], stdout=PIPE).communicate()[0] @@ -266,7 +263,7 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): class T(RunnerCore): # Short name, to make it more fun to use manually on the commandline ## Does a complete test - builds, runs, checks output, etc. - def do_run(self, src, expected_output=None, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[]): + def do_run(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[]): if force_c or (main_file is not None and main_file[-2:]) == '.c': basename = 'src.c' Building.COMPILER = to_cc(Building.COMPILER) @@ -277,11 +274,6 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): self.build(src, dirname, filename, main_file=main_file, additional_files=additional_files, libraries=libraries, includes=includes, build_ll_hook=build_ll_hook, extra_emscripten_args=extra_emscripten_args, post_build=post_build) - # If not provided with expected output, then generate it right now, using lli - if expected_output is None: - expected_output = self.run_llvm_interpreter([filename + '.o']) - print '[autogenerated expected output: %20s]' % (expected_output[0:30].replace('\n', '|')+'...') - # Run in both JavaScript engines, if optimizing - significant differences there (typed arrays) if js_engines is None: js_engines = JS_ENGINES @@ -656,7 +648,7 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): return 0; } ''' - self.do_run(src)#, '*4294967295,0,4294967219*\n*-1,1,-1,1*\n*-2,1,-2,1*\n*246,296*\n*1,0*') + self.do_run(src, '*4294967295,0,4294967219*\n*-1,1,-1,1*\n*-2,1,-2,1*\n*246,296*\n*1,0*') # Now let's see some code that should just work in USE_TYPED_ARRAYS == 2, but requires # corrections otherwise @@ -858,7 +850,7 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): } ''' - self.do_run(src) + self.do_run(src, '*1800*') generated = open('src.cpp.o.js', 'r').read() assert '__label__ ==' not in generated, 'We should hoist into the loop' @@ -2352,7 +2344,10 @@ def process(filename): return 0; } ''' - self.do_run(src) + def check(result): + return hashlib.sha1(result).hexdigest() + self.do_run(src, '6c9cdfe937383b79e52ca7a2cce83a21d9f5422c', + output_nicerizer = check) def test_memmove(self): src = ''' @@ -2365,7 +2360,7 @@ def process(filename): return 0; } ''' - self.do_run(src) + self.do_run(src, 'memmove can be very very useful') def test_bsearch(self): if Settings.QUANTUM_SIZE == 1: return self.skip('Test cannot work with q1') @@ -3141,21 +3136,21 @@ at function.:blag #include <stdlib.h> int main () { - printf("%d\n", atoi("")); - printf("%d\n", atoi("a")); - printf("%d\n", atoi(" b")); - printf("%d\n", atoi(" c ")); - printf("%d\n", atoi("6")); - printf("%d\n", atoi(" 5")); - printf("%d\n", atoi("4 ")); - printf("%d\n", atoi("3 6")); - printf("%d\n", atoi(" 3 7")); - printf("%d\n", atoi("9 d")); + printf("%d*", atoi("")); + printf("%d*", atoi("a")); + printf("%d*", atoi(" b")); + printf("%d*", atoi(" c ")); + printf("%d*", atoi("6")); + printf("%d*", atoi(" 5")); + printf("%d*", atoi("4 ")); + printf("%d*", atoi("3 6")); + printf("%d*", atoi(" 3 7")); + printf("%d*", atoi("9 d")); printf("%d\n", atoi(" 8 e")); return 0; } ''' - self.do_run(src) + self.do_run(src, '0*0*0*0*6*5*4*3*3*9*8') def test_sscanf(self): src = r''' @@ -3181,7 +3176,8 @@ at function.:blag return 0; } ''' - self.do_run(src) + self.do_run(src, 'en-us : 2*en-r : 99*en : 3*1.234567, 0.000000', + output_nicerizer = lambda x: x.replace('\n', '*')) # Part 2: doubles (issue 148) if Settings.USE_TYPED_ARRAYS == 2: @@ -3232,7 +3228,11 @@ Pass: 123456.789063 123456.789063 Pass: 0.000012 0.000012 Pass: 0.000012 0.000012''') else: - self.do_run(src) + self.do_run(src, '''Pass: 1.234568 1.234568 +Pass: 123456.789000 123456.789000 +Pass: 123456.789000 123456.789000 +Pass: 0.000012 0.000012 +Pass: 0.000012 0.000012''') def test_langinfo(self): src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read() @@ -4457,7 +4457,27 @@ def process(filename): self.do_autodebug(filename) # Compare to each other, and to expected output - self.do_ll_run(path_from_root('tests', filename+'.o.ll.ll')) + self.do_ll_run(path_from_root('tests', filename+'.o.ll.ll'), '''AD:-1,15 +AD:15,0 +AD:21,5 +AD:24,6 +AD:27,101 +AD:30,7009 +AD:37,5 +AD:40,10 +AD:45,7009 +AD:48,7008 +AD:54,7008 +AD:57,7018 +AD:60,10 +AD:63,6 +AD:66,101 +AD:69,7018 +AD:73,101 +AD:77,7018 +AD:81,101 +AD:85,7018 +*10,6,101,7018,101,7018,101,7018*''') assert open('stdout').read().startswith('AD:-1'), 'We must note when we enter functions' # Test using build_ll_hook @@ -4476,8 +4496,17 @@ def process(filename): return 0; } ''' - self.do_run(src, build_ll_hook=self.do_autodebug) - self.do_run(src, 'AD:', build_ll_hook=self.do_autodebug) + self.do_run(src, '''AD:-1,13 +AD:13,0 +AD:16,25 +AD:20,51 +AD:23,25 +AD:26,25 +AD:29,11.520000 +AD:31,25 +AD:33,51 +AD:36,11.520000 +*25,51,11.52*''', build_ll_hook=self.do_autodebug) def test_profiling(self): src = ''' @@ -5372,10 +5401,16 @@ Options that are modified or new in %s include: for args in [['-c'], ['-o', 'src.o'], ['-o', 'src.bc'], ['-o', 'js']]: target = args[1] if len(args) == 2 else 'hello_world.o' clear() - output = Popen([compiler, path_from_root('tests', 'hello_world' + suffix)] + args, stdout=PIPE, stderr=PIPE).communicate() + Popen([compiler, path_from_root('tests', 'hello_world' + suffix)] + args, stdout=PIPE, stderr=PIPE).communicate() + syms = Building.llvm_nm(target) + assert len(syms.defs) == 1 and 'main' in syms.defs, 'Failed to generate valid bitcode' + if target == 'js': # make sure emcc can recognize the target as a bitcode file + shutil.move(target, target + '.bc') + target += '.bc' + output = Popen([compiler, target, '-o', target + '.js'], stdout = PIPE, stderr = PIPE).communicate() assert len(output[0]) == 0, output[0] - assert os.path.exists(target), 'Expected %s to exist since args are %s : %s' % (target, str(args), '\n'.join(output)) - self.assertContained('hello, world!', self.run_llvm_interpreter([target])) + assert os.path.exists(target + '.js'), 'Expected %s to exist since args are %s : %s' % (target + '.js', str(args), '\n'.join(output)) + self.assertContained('hello, world!', run_js(target + '.js')) # emcc src.ll ==> generates .js clear() @@ -5520,8 +5555,12 @@ Options that are modified or new in %s include: try_delete(target) assert not os.path.exists(target) output = Popen([compiler, 'twopart_main.o', 'twopart_side.o', '-o', 'combined.bc'] + args, stdout=PIPE, stderr=PIPE).communicate() - assert os.path.exists('combined.bc'), '\n'.join(output) - self.assertContained('side got: hello from main, over', self.run_llvm_interpreter(['combined.bc'])) + syms = Building.llvm_nm('combined.bc') + assert len(syms.defs) == 2 and 'main' in syms.defs, 'Failed to generate valid bitcode' + output = Popen([compiler, 'combined.bc', '-o', 'combined.bc.js'], stdout = PIPE, stderr = PIPE).communicate() + assert len(output[0]) == 0, output[0] + assert os.path.exists('combined.bc.js'), 'Expected %s to exist' % ('combined.bc.js') + self.assertContained('side got: hello from main, over', run_js('combined.bc.js')) # --js-transform <transform> clear() |