diff options
Diffstat (limited to 'tests/runner.py')
-rw-r--r-- | tests/runner.py | 877 |
1 files changed, 475 insertions, 402 deletions
diff --git a/tests/runner.py b/tests/runner.py index 49339f51..ae72ec49 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -21,6 +21,8 @@ def path_from_root(*pathelems): return os.path.join(__rootpath__, *pathelems) exec(open(path_from_root('tools', 'shared.py'), 'r').read()) +sys.path += [path_from_root('')] + # Sanity check for config try: @@ -90,8 +92,29 @@ class RunnerCore(unittest.TestCase): shutil.move(filename + '.o.ll', filename + '.o.ll.post') # for comparisons later Building.llvm_dis(filename) + # Generate JS from ll, and optionally modify the generated JS with a post_build function. Note + # that post_build is called on unoptimized JS, so we send it to emcc (otherwise, if run after + # emcc, it would not apply on the optimized/minified JS) + def ll_to_js(self, filename, extra_emscripten_args, post_build): + if self.emcc_args is None: + Building.emscripten(filename, append_ext=True, extra_args=extra_emscripten_args) + if post_build is not None: + exec post_build in locals() + shutil.copyfile(filename + '.o.js', filename + '.o.js.prepost.js') + process(filename + '.o.js') + else: + if post_build is not None: + os.environ['EMCC_JS_PROCESSOR'] = post_build + else: + try: + del os.environ['EMCC_JS_PROCESSOR'] + except: + pass + Building.emcc(filename + '.o.ll', Settings.serialize() + self.emcc_args, filename + '.o.js') + # Build JavaScript code from source code - def build(self, src, dirname, filename, output_processor=None, main_file=None, additional_files=[], libraries=[], includes=[], build_ll_hook=None, extra_emscripten_args=[]): + def build(self, src, dirname, filename, output_processor=None, main_file=None, additional_files=[], libraries=[], includes=[], build_ll_hook=None, extra_emscripten_args=[], post_build=None): + # Copy over necessary files for compiling the source if main_file is None: f = open(filename, 'w') @@ -138,7 +161,11 @@ class RunnerCore(unittest.TestCase): # Finalize self.prep_ll_run(filename, filename + '.o', build_ll_hook=build_ll_hook) - Building.emscripten(filename, output_processor, extra_args=extra_emscripten_args) + # BC => JS + self.ll_to_js(filename, extra_emscripten_args, post_build) + + if output_processor is not None: + output_processor(open(filename + '.o.js').read()) def run_generated_code(self, engine, filename, args=[], check_timeout=True): stdout = os.path.join(self.get_dir(), 'stdout') # use files, as PIPE can get too full and hang us @@ -233,10 +260,7 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): filename = os.path.join(dirname, basename) if not no_build: 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) - - if post_build is not None: - post_build(filename + '.o.js') + 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: @@ -261,18 +285,19 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): # No building - just process an existing .ll file (or .bc, which we turn into .ll) def do_ll_run(self, ll_file, expected_output=None, args=[], js_engines=None, output_nicerizer=None, post_build=None, force_recompile=False, build_ll_hook=None, extra_emscripten_args=[]): - filename = os.path.join(self.get_dir(), 'src.cpp') self.prep_ll_run(filename, ll_file, force_recompile, build_ll_hook) - Building.emscripten(filename, extra_args=extra_emscripten_args) + + self.ll_to_js(filename, extra_emscripten_args, post_build) + self.do_run(None, expected_output, args, no_build=True, js_engines=js_engines, output_nicerizer=output_nicerizer, - post_build=post_build) + post_build=None) # post_build was already done in ll_to_js, this do_run call is just to test the output def test_hello_world(self): src = ''' @@ -782,10 +807,6 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): ''' self.do_run(src, '*yes*') - # Test for issue 39 - if not Building.LLVM_OPTS: - self.do_ll_run(path_from_root('tests', 'issue_39.ll'), '*yes*') - def test_if_else(self): src = ''' #include <stdio.h> @@ -1624,9 +1645,11 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): } ''' - def check(filename): - src = open(filename, 'r').read() - # TODO: restore this (see comment in emscripten.h) assert '// hello from the source' in src + check = ''' +def process(filename): + src = open(filename, 'r').read() + # TODO: restore this (see comment in emscripten.h) assert '// hello from the source' in src +''' self.do_run(src, 'hello world!\n*100*', post_build=check) @@ -2406,14 +2429,16 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): } ''' Settings.BUILD_AS_SHARED_LIB = 0 - def add_pre_run_and_checks(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);''' - ) - open(filename, 'w').write(src) + add_pre_run_and_checks = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);" + ) + open(filename, 'w').write(src) +''' self.do_run(src, 'Constructing main object.\nConstructing lib object.\n', - post_build=add_pre_run_and_checks) + post_build=add_pre_run_and_checks) def test_dlfcn_qsort(self): if Settings.USE_TYPED_ARRAYS == 2: @@ -2493,15 +2518,17 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): ''' Settings.BUILD_AS_SHARED_LIB = 0 Settings.EXPORTED_FUNCTIONS = ['_main'] - def add_pre_run_and_checks(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);''' - ) - open(filename, 'w').write(src) + add_pre_run_and_checks = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);" + ) + open(filename, 'w').write(src) +''' self.do_run(src, 'Sort with main comparison: 5 4 3 2 1 *Sort with lib comparison: 1 2 3 4 5 *', - output_nicerizer=lambda x: x.replace('\n', '*'), - post_build=add_pre_run_and_checks) + output_nicerizer=lambda x: x.replace('\n', '*'), + post_build=add_pre_run_and_checks) def test_dlfcn_data_and_fptr(self): if Building.LLVM_OPTS: return self.skip('LLVM opts will optimize out parent_func') @@ -2591,12 +2618,14 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): Settings.BUILD_AS_SHARED_LIB = 0 Settings.EXPORTED_FUNCTIONS = ['_main'] Settings.EXPORTED_GLOBALS = [] - def add_pre_run_and_checks(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);''' - ) - open(filename, 'w').write(src) + add_pre_run_and_checks = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);" + ) + open(filename, 'w').write(src) +''' self.do_run(src, 'In func: 13*First calling main_fptr from lib.*Second calling lib_fptr from main.*parent_func called from child*parent_func called from child*Var: 42*', output_nicerizer=lambda x: x.replace('\n', '*'), post_build=add_pre_run_and_checks) @@ -2639,16 +2668,18 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): Settings.BUILD_AS_SHARED_LIB = 0 Settings.INCLUDE_FULL_LIBRARY = 1 Settings.EXPORTED_FUNCTIONS = ['_main'] - def add_pre_run_and_checks(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);''' - ) - open(filename, 'w').write(src) + add_pre_run_and_checks = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);" + ) + open(filename, 'w').write(src) +''' self.do_run(src, 'Parent global: 123.*Parent global: 456.*', - output_nicerizer=lambda x: x.replace('\n', '*'), - post_build=add_pre_run_and_checks, - extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/time.h,libc/langinfo.h']) + output_nicerizer=lambda x: x.replace('\n', '*'), + post_build=add_pre_run_and_checks, + extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/time.h,libc/langinfo.h']) Settings.INCLUDE_FULL_LIBRARY = 0 def test_dlfcn_varargs(self): @@ -2697,14 +2728,16 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): ''' Settings.BUILD_AS_SHARED_LIB = 0 Settings.EXPORTED_FUNCTIONS = ['_main'] - def add_pre_run_and_checks(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);''' - ) - open(filename, 'w').write(src) + add_pre_run_and_checks = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);" + ) + open(filename, 'w').write(src) +''' self.do_run(src, '100\n200\n13\n42\n', - post_build=add_pre_run_and_checks) + post_build=add_pre_run_and_checks) def test_rand(self): src = r''' @@ -2975,23 +3008,27 @@ at function.:blag self.do_run(src, expected, extra_emscripten_args=['-H', 'libc/langinfo.h']) def test_files(self): - Settings.CORRECT_SIGNS = 1 # Just so our output is what we expect. Can flip them both. - def post(filename): - src = open(filename, 'r').read().replace('FS.init();', '').replace( # Disable normal initialization, replace with ours - '// {{PRE_RUN_ADDITIONS}}', - ''' - FS.createDataFile('/', 'somefile.binary', [100, 200, 50, 25, 10, 77, 123], true, false); // 200 becomes -56, since signed chars are used in memory - FS.createLazyFile('/', 'test.file', 'test.file', true, false); - FS.root.write = true; - var test_files_input = 'hi there!'; - var test_files_input_index = 0; - FS.init(function() { - return test_files_input.charCodeAt(test_files_input_index++) || null; - }); - ''' - ) - open(filename, 'w').write(src) + if self.emcc_args is not None and '-O2' in self.emcc_args: + self.emcc_args += ['--closure', '1'] # Use closure here, to test we don't break FS stuff + Settings.CORRECT_SIGNS = 1 # Just so our output is what we expect. Can flip them both. + post = ''' +def process(filename): + src = open(filename, 'r').read().replace('FS.init();', '').replace( # Disable normal initialization, replace with ours + '// {{PRE_RUN_ADDITIONS}}', + \'\'\' + FS.createDataFile('/', 'somefile.binary', [100, 200, 50, 25, 10, 77, 123], true, false); // 200 becomes -56, since signed chars are used in memory + FS.createLazyFile('/', 'test.file', 'test.file', true, false); + FS.root.write = true; + var test_files_input = 'hi there!'; + var test_files_input_index = 0; + FS.init(function() { + return test_files_input.charCodeAt(test_files_input_index++) || null; + }); + \'\'\' + ) + open(filename, 'w').write(src) +''' other = open(os.path.join(self.get_dir(), 'test.file'), 'w') other.write('some data'); other.close() @@ -3001,20 +3038,21 @@ at function.:blag post_build=post, extra_emscripten_args=['-H', 'libc/fcntl.h']) def test_folders(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - ''' - FS.createFolder('/', 'test', true, false); - FS.createPath('/', 'test/hello/world/', true, false); - FS.createPath('/test', 'goodbye/world/', true, false); - FS.createPath('/test/goodbye', 'noentry', false, false); - FS.createDataFile('/test', 'freeforall.ext', 'abc', true, true); - FS.createDataFile('/test', 'restricted.ext', 'def', false, false); - ''' - ) - open(filename, 'w').write(src) - + add_pre_run = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + \'\'\' + FS.createFolder('/', 'test', true, false); + FS.createPath('/', 'test/hello/world/', true, false); + FS.createPath('/test', 'goodbye/world/', true, false); + FS.createPath('/test/goodbye', 'noentry', false, false); + FS.createDataFile('/test', 'freeforall.ext', 'abc', true, true); + FS.createDataFile('/test', 'restricted.ext', 'def', false, false); + \'\'\' + ) + open(filename, 'w').write(src) +''' src = r''' #include <stdio.h> #include <dirent.h> @@ -3079,69 +3117,79 @@ at function.:blag self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected), post_build=add_pre_run) def test_stat(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - ''' - var f1 = FS.createFolder('/', 'test', true, true); - var f2 = FS.createDataFile(f1, 'file', 'abcdef', true, true); - var f3 = FS.createLink(f1, 'link', 'file', true, true); - var f4 = FS.createDevice(f1, 'device', function(){}, function(){}); - f1.timestamp = f2.timestamp = f3.timestamp = f4.timestamp = new Date(1200000000000); - ''' - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + \'\'\' + var f1 = FS.createFolder('/', 'test', true, true); + var f2 = FS.createDataFile(f1, 'file', 'abcdef', true, true); + var f3 = FS.createLink(f1, 'link', 'file', true, true); + var f4 = FS.createDevice(f1, 'device', function(){}, function(){}); + f1.timestamp = f2.timestamp = f3.timestamp = f4.timestamp = new Date(1200000000000); + \'\'\' + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'stat', 'src.c'), 'r').read() expected = open(path_from_root('tests', 'stat', 'output.txt'), 'r').read() self.do_run(src, expected, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h']) def test_fcntl(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - "FS.createDataFile('/', 'test', 'abcdef', true, true);" - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createDataFile('/', 'test', 'abcdef', true, true);" + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'fcntl', 'src.c'), 'r').read() expected = open(path_from_root('tests', 'fcntl', 'output.txt'), 'r').read() self.do_run(src, expected, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h']) def test_fcntl_open(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - ''' - FS.createDataFile('/', 'test-file', 'abcdef', true, true); - FS.createFolder('/', 'test-folder', true, true); - FS.root.write = true; - ''' - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + \'\'\' + FS.createDataFile('/', 'test-file', 'abcdef', true, true); + FS.createFolder('/', 'test-folder', true, true); + FS.root.write = true; + \'\'\' + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'fcntl-open', 'src.c'), 'r').read() expected = open(path_from_root('tests', 'fcntl-open', 'output.txt'), 'r').read() self.do_run(src, expected, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h']) def test_fcntl_misc(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - "FS.createDataFile('/', 'test', 'abcdef', true, true);" - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createDataFile('/', 'test', 'abcdef', true, true);" + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'fcntl-misc', 'src.c'), 'r').read() expected = open(path_from_root('tests', 'fcntl-misc', 'output.txt'), 'r').read() self.do_run(src, expected, post_build=add_pre_run, extra_emscripten_args=['-H', 'libc/fcntl.h']) def test_poll(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - ''' - FS.createDataFile('/', 'file', 'abcdef', true, true); - FS.createDevice('/', 'device', function() {}, function() {}); - ''' - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + \'\'\' + FS.createDataFile('/', 'file', 'abcdef', true, true); + FS.createDevice('/', 'device', function() {}, function() {}); + \'\'\' + ) + open(filename, 'w').write(src) +''' src = r''' #include <stdio.h> #include <errno.h> @@ -3283,22 +3331,23 @@ at function.:blag self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected)) def test_utime(self): - def add_pre_run_and_checks(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - ''' - var TEST_F1 = FS.createFolder('/', 'writeable', true, true); - var TEST_F2 = FS.createFolder('/', 'unwriteable', true, false); - ''' - ).replace( - '// {{POST_RUN_ADDITIONS}}', - ''' - print('first changed: ' + (TEST_F1.timestamp == 1200000000000)); - print('second changed: ' + (TEST_F2.timestamp == 1200000000000)); - ''' - ) - open(filename, 'w').write(src) - + add_pre_run_and_checks = ''' +def process(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + \'\'\' + var TEST_F1 = FS.createFolder('/', 'writeable', true, true); + var TEST_F2 = FS.createFolder('/', 'unwriteable', true, false); + \'\'\' + ).replace( + '// {{POST_RUN_ADDITIONS}}', + \'\'\' + print('first changed: ' + (TEST_F1.timestamp == 1200000000000)); + print('second changed: ' + (TEST_F2.timestamp == 1200000000000)); + \'\'\' + ) + open(filename, 'w').write(src) +''' src = r''' #include <stdio.h> #include <errno.h> @@ -3329,11 +3378,14 @@ at function.:blag def test_fs_base(self): Settings.INCLUDE_FULL_LIBRARY = 1 try: - def addJS(filename): - src = open(filename, 'r').read().replace('FS.init();', '').replace( # Disable normal initialization, replace with ours - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'filesystem', 'src.js'), 'r').read()) - open(filename, 'w').write(src) + addJS = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace('FS.init();', '').replace( # Disable normal initialization, replace with ours + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'filesystem', 'src.js'), 'r').read()) + open(filename, 'w').write(src) +''' src = 'int main() {return 0;}\n' expected = open(path_from_root('tests', 'filesystem', 'output.txt'), 'r').read() self.do_run(src, expected, post_build=addJS, extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/langinfo.h,libc/time.h']) @@ -3341,23 +3393,29 @@ at function.:blag Settings.INCLUDE_FULL_LIBRARY = 0 def test_unistd_access(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'access.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'access.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'access.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'access.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) def test_unistd_curdir(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'curdir.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'curdir.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'curdir.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'curdir.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) @@ -3373,12 +3431,15 @@ at function.:blag self.do_run(src, expected, extra_emscripten_args=['-H', 'libc/unistd.h']) def test_unistd_ttyname(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'ttyname.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'ttyname.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'ttyname.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'ttyname.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) @@ -3394,12 +3455,15 @@ at function.:blag self.do_run(src, expected) def test_unistd_truncate(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'truncate.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'truncate.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'truncate.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'truncate.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) @@ -3410,12 +3474,15 @@ at function.:blag self.do_run(src, expected) def test_unistd_isatty(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'isatty.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'isatty.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'isatty.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'isatty.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) @@ -3431,23 +3498,29 @@ at function.:blag self.do_run(src, expected) def test_unistd_unlink(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'unlink.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'unlink.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'unlink.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'unlink.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) def test_unistd_links(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'links.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'links.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'links.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'links.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) @@ -3458,12 +3531,15 @@ at function.:blag self.do_run(src, expected) def test_unistd_io(self): - def add_pre_run(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - open(path_from_root('tests', 'unistd', 'io.js'), 'r').read() - ) - open(filename, 'w').write(src) + add_pre_run = ''' +def process(filename): + import tools.shared as shared + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + open(shared.path_from_root('tests', 'unistd', 'io.js'), 'r').read() + ) + open(filename, 'w').write(src) +''' src = open(path_from_root('tests', 'unistd', 'io.c'), 'r').read() expected = open(path_from_root('tests', 'unistd', 'io.out'), 'r').read() self.do_run(src, expected, post_build=add_pre_run) @@ -3625,7 +3701,7 @@ at function.:blag self.do_run(src, '*1,0*', ['200', '1'], extra_emscripten_args=['-m']) self.do_run(src, '*400,0*', ['400', '400'], extra_emscripten_args=['-m'], no_build=True) - if self.use_defaults: # TODO: do this in other passes too, passing their opts into emcc + if self.emcc_args == []: # TODO: do this in other passes too, passing their opts into emcc # emcc should build in dlmalloc automatically, and do all the sign correction etc. for it try_delete(os.path.join(self.get_dir(), 'src.cpp.o.js')) @@ -3683,20 +3759,25 @@ at function.:blag # print opt, "FAIL" def test_lua(self): - if Settings.QUANTUM_SIZE == 1: return self.skip('TODO: make this work') - - # Overflows in luaS_newlstr hash loop - Settings.SAFE_HEAP = 0 # Has various warnings, with copied HEAP_HISTORY values (fixed if we copy 'null' as the type) - Settings.CORRECT_OVERFLOWS = 1 - Settings.CHECK_OVERFLOWS = 0 - Settings.CORRECT_SIGNS = 1 # Not sure why, but needed - Settings.INIT_STACK = 1 # TODO: Investigate why this is necessary - - self.do_ll_run(path_from_root('tests', 'lua', 'lua.ll'), - 'hello lua world!\n17\n1\n2\n3\n4\n7', - args=['-e', '''print("hello lua world!");print(17);for x = 1,4 do print(x) end;print(10-3)'''], - output_nicerizer=lambda string: string.replace('\n\n', '\n').replace('\n\n', '\n'), - extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/langinfo.h,libc/time.h']) + try: + os.environ['EMCC_LEAVE_INPUTS_RAW'] = '1' + + if Settings.QUANTUM_SIZE == 1: return self.skip('TODO: make this work') + + # Overflows in luaS_newlstr hash loop + Settings.SAFE_HEAP = 0 # Has various warnings, with copied HEAP_HISTORY values (fixed if we copy 'null' as the type) + Settings.CORRECT_OVERFLOWS = 1 + Settings.CHECK_OVERFLOWS = 0 + Settings.CORRECT_SIGNS = 1 # Not sure why, but needed + Settings.INIT_STACK = 1 # TODO: Investigate why this is necessary + + self.do_ll_run(path_from_root('tests', 'lua', 'lua.ll'), + 'hello lua world!\n17\n1\n2\n3\n4\n7', + args=['-e', '''print("hello lua world!");print(17);for x = 1,4 do print(x) end;print(10-3)'''], + output_nicerizer=lambda string: string.replace('\n\n', '\n').replace('\n\n', '\n'), + extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/langinfo.h,libc/time.h']) + finally: + del os.environ['EMCC_LEAVE_INPUTS_RAW'] def get_build_dir(self): return os.path.join(self.get_dir(), 'building') @@ -3713,16 +3794,18 @@ at function.:blag if Settings.CORRECT_SIGNS == 0: Settings.CORRECT_SIGNS = 1 # Not sure why, but needed - def post(filename): - # Embed the font into the document - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createDataFile('/', 'font.ttf', %s, true, false);''' % str( - map(ord, open(path_from_root('tests', 'freetype', 'LiberationSansBold.ttf'), 'rb').read()) - ) - ) - open(filename, 'w').write(src) - + post = ''' +def process(filename): + import tools.shared as shared + # Embed the font into the document + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createDataFile('/', 'font.ttf', %s, true, false);" % str( + map(ord, open(shared.path_from_root('tests', 'freetype', 'LiberationSansBold.ttf'), 'rb').read()) + ) + ) + open(filename, 'w').write(src) +''' # Main self.do_run(open(path_from_root('tests', 'freetype', 'main.c'), 'r').read(), open(path_from_root('tests', 'freetype', 'ref.txt'), 'r').read(), @@ -3739,7 +3822,7 @@ at function.:blag pgo_data = read_pgo_data(path_from_root('tests', 'sqlite', 'sqlite-autooptimize.fails.txt')) - Settings.CORRECT_SIGNS = 2 + Settings.CORRECT_SIGNS = 1 # XXX: in default, we fail with 2 here, even though the pgo_data should be correct (and works in s_0_0). Investigate this. Settings.CORRECT_SIGNS_LINES = pgo_data['signs_lines'] Settings.CORRECT_OVERFLOWS = 0 Settings.CORRECT_ROUNDINGS = 0 @@ -3750,18 +3833,20 @@ at function.:blag Settings.INVOKE_RUN = 0 # We append code that does run() ourselves - def post(filename): - src = open(filename, 'a') - src.write(''' - FS.init(); - FS.root.write = true; - FS.ignorePermissions = true; // /dev is read-only - FS.createPath('/', 'dev/shm/tmp', true, true); - FS.ignorePermissions = false; - FS.currentPath = '/dev/shm/tmp'; - run(); - ''') - src.close() + post = ''' +def process(filename): + src = open(filename, 'a') + src.write(\'\'\' + FS.init(); + FS.root.write = true; + FS.ignorePermissions = true; // /dev is read-only + FS.createPath('/', 'dev/shm/tmp', true, true); + FS.ignorePermissions = false; + FS.currentPath = '/dev/shm/tmp'; + run(); + \'\'\') + src.close() +''' self.do_run(r''' #define SQLITE_DISABLE_LFS @@ -3807,7 +3892,7 @@ at function.:blag js_engines=[SPIDERMONKEY_ENGINE]) # V8 issue 1407 def test_poppler(self): - if not self.use_defaults: return self.skip('very slow, we only do this in default') + if not self.emcc_args == []: return self.skip('very slow, we only do this in default') Settings.SAFE_HEAP = 0 # Has variable object @@ -3827,20 +3912,22 @@ at function.:blag input_file.write(str(map(ord, open(path_from_root('tests', 'poppler', 'paper.pdf'), 'rb').read()))) input_file.close() - def post(filename): - # To avoid loading this large file to memory and altering it, we simply append to the end - src = open(filename, 'a') - src.write( - ''' - FS.ignorePermissions = true; - FS.createDataFile('/', 'paper.pdf', eval(read('paper.pdf.js')), true, false); - FS.root.write = true; - FS.ignorePermissions = false; - run(); - print("Data: " + JSON.stringify(FS.root.contents['filename-1.ppm'].contents.map(function(x) { return unSign(x, 8) }))); - ''' - ) - src.close() + post = ''' +def process(filename): + # To avoid loading this large file to memory and altering it, we simply append to the end + src = open(filename, 'a') + src.write( + \'\'\' + FS.ignorePermissions = true; + FS.createDataFile('/', 'paper.pdf', eval(read('paper.pdf.js')), true, false); + FS.root.write = true; + FS.ignorePermissions = false; + run(); + print("Data: " + JSON.stringify(FS.root.contents['filename-1.ppm'].contents.map(function(x) { return unSign(x, 8) }))); + \'\'\' + ) + src.close() +''' #fontconfig = self.get_library('fontconfig', [os.path.join('src', '.libs', 'libfontconfig.a')]) # Used in file, but not needed, mostly @@ -3873,19 +3960,21 @@ at function.:blag Settings.CORRECT_SIGNS = 2 Settings.CORRECT_SIGNS_LINES = ["mqc.c:566", "mqc.c:317"] - original_j2k = path_from_root('tests', 'openjpeg', 'syntensity_lobby_s.j2k') - - def post(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''FS.createDataFile('/', 'image.j2k', %s, true, false);FS.root.write = true;''' % line_splitter(str( - map(ord, open(original_j2k, 'rb').read()) - )) - ).replace( - '// {{POST_RUN_ADDITIONS}}', - '''print("Data: " + JSON.stringify(FS.root.contents['image.raw'].contents));''' - ) - open(filename, 'w').write(src) + post = ''' +def process(filename): + import tools.shared as shared + original_j2k = shared.path_from_root('tests', 'openjpeg', 'syntensity_lobby_s.j2k') + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + "FS.createDataFile('/', 'image.j2k', %s, true, false);FS.root.write = true;" % shared.line_splitter(str( + map(ord, open(original_j2k, 'rb').read()) + )) + ).replace( + '// {{POST_RUN_ADDITIONS}}', + "print('Data: ' + JSON.stringify(FS.root.contents['image.raw'].contents));" + ) + open(filename, 'w').write(src) +''' shutil.copy(path_from_root('tests', 'openjpeg', 'opj_config.h'), self.get_dir()) @@ -3967,31 +4056,37 @@ at function.:blag # They are only valid enough for us to read for test purposes, not for llvm-as # to process. def test_cases(self): - self.banned_js_engines = [NODE_JS] # node issue 1669, exception causes stdout not to be flushed + try: + self.banned_js_engines = [NODE_JS] # node issue 1669, exception causes stdout not to be flushed - Settings.CHECK_OVERFLOWS = 0 - if Building.LLVM_OPTS: return self.skip("Our code is not exactly 'normal' llvm assembly") + os.environ['EMCC_LEAVE_INPUTS_RAW'] = '1' + + Settings.CHECK_OVERFLOWS = 0 + if Building.LLVM_OPTS: return self.skip("Our code is not exactly 'normal' llvm assembly") + + for name in glob.glob(path_from_root('tests', 'cases', '*.ll')): + shortname = name.replace('.ll', '') + if '' not in shortname: continue + print "Testing case '%s'..." % shortname + output_file = path_from_root('tests', 'cases', shortname + '.txt') + if Settings.QUANTUM_SIZE == 1: + q1_output_file = path_from_root('tests', 'cases', shortname + '_q1.txt') + if os.path.exists(q1_output_file): + output_file = q1_output_file + if os.path.exists(output_file): + output = open(output_file, 'r').read() + else: + output = 'hello, world!' + if output.rstrip() != 'skip': + self.do_ll_run(path_from_root('tests', 'cases', name), output) + # Optional source checking, a python script that gets a global generated with the source + src_checker = path_from_root('tests', 'cases', shortname + '.py') + if os.path.exists(src_checker): + generated = open('src.cpp.o.js').read() + exec(open(src_checker).read()) - for name in glob.glob(path_from_root('tests', 'cases', '*.ll')): - shortname = name.replace('.ll', '') - if '' not in shortname: continue - print "Testing case '%s'..." % shortname - output_file = path_from_root('tests', 'cases', shortname + '.txt') |