diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/test_asyncify.py | 26 | ||||
-rw-r--r-- | test/unit/test_datacount.py | 10 | ||||
-rw-r--r-- | test/unit/test_features.py | 43 | ||||
-rw-r--r-- | test/unit/test_finalize.py | 9 | ||||
-rw-r--r-- | test/unit/test_memory_packing.py | 15 | ||||
-rw-r--r-- | test/unit/test_parsing_error.py | 11 | ||||
-rw-r--r-- | test/unit/test_tail_call_type.py | 17 | ||||
-rw-r--r-- | test/unit/test_warnings.py | 12 | ||||
-rw-r--r-- | test/unit/utils.py | 19 |
9 files changed, 91 insertions, 71 deletions
diff --git a/test/unit/test_asyncify.py b/test/unit/test_asyncify.py index 052dedb0e..800f86ed7 100644 --- a/test/unit/test_asyncify.py +++ b/test/unit/test_asyncify.py @@ -2,19 +2,19 @@ import os import subprocess import tempfile -from scripts.test.shared import WASM_OPT, WASM_DIS, WASM_SHELL, NODEJS, run_process -from .utils import BinaryenTestCase +from scripts.test import shared +from . import utils -class AsyncifyTest(BinaryenTestCase): +class AsyncifyTest(utils.BinaryenTestCase): def test_asyncify_js(self): def test(args): print(args) - run_process(WASM_OPT + args + [self.input_path('asyncify-sleep.wast'), '--asyncify', '-o', 'a.wasm']) - run_process(WASM_OPT + args + [self.input_path('asyncify-coroutine.wast'), '--asyncify', '-o', 'b.wasm']) - run_process(WASM_OPT + args + [self.input_path('asyncify-stackOverflow.wast'), '--asyncify', '-o', 'c.wasm']) + shared.run_process(shared.WASM_OPT + args + [self.input_path('asyncify-sleep.wast'), '--asyncify', '-o', 'a.wasm']) + shared.run_process(shared.WASM_OPT + args + [self.input_path('asyncify-coroutine.wast'), '--asyncify', '-o', 'b.wasm']) + shared.run_process(shared.WASM_OPT + args + [self.input_path('asyncify-stackOverflow.wast'), '--asyncify', '-o', 'c.wasm']) print(' file size: %d' % os.path.getsize('a.wasm')) - run_process([NODEJS, self.input_path('asyncify.js')]) + shared.run_process([shared.NODEJS, self.input_path('asyncify.js')]) test(['-g']) test([]) @@ -24,9 +24,9 @@ class AsyncifyTest(BinaryenTestCase): test(['-Os', '-g']) def test_asyncify_pure_wasm(self): - run_process(WASM_OPT + [self.input_path('asyncify-pure.wast'), '--asyncify', '-o', 'a.wasm']) - run_process(WASM_DIS + ['a.wasm', '-o', 'a.wast']) - output = run_process(WASM_SHELL + ['a.wast'], capture_output=True).stdout + shared.run_process(shared.WASM_OPT + [self.input_path('asyncify-pure.wast'), '--asyncify', '-o', 'a.wasm']) + shared.run_process(shared.WASM_DIS + ['a.wasm', '-o', 'a.wast']) + output = shared.run_process(shared.WASM_SHELL + ['a.wast'], capture_output=True).stdout with open(self.input_path('asyncify-pure.txt'), 'r') as f: self.assertEqual(f.read(), output) @@ -45,7 +45,7 @@ class AsyncifyTest(BinaryenTestCase): ('--pass-arg=asyncify-whitelist@DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)', None), ]: print(arg, warning) - err = run_process(WASM_OPT + ['-q', self.input_path('asyncify-pure.wast'), '--asyncify', arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.strip() + err = shared.run_process(shared.WASM_OPT + ['-q', self.input_path('asyncify-pure.wast'), '--asyncify', arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.strip() if warning: self.assertIn('warning', err) self.assertIn(warning, err) @@ -53,13 +53,13 @@ class AsyncifyTest(BinaryenTestCase): self.assertNotIn('warning', err) def test_asyncify_blacklist_and_whitelist(self): - proc = run_process(WASM_OPT + [self.input_path('asyncify-pure.wast'), '--asyncify', '--pass-arg=asyncify-whitelist@main', '--pass-arg=asyncify-blacklist@main'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False) + proc = shared.run_process(shared.WASM_OPT + [self.input_path('asyncify-pure.wast'), '--asyncify', '--pass-arg=asyncify-whitelist@main', '--pass-arg=asyncify-blacklist@main'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False) self.assertNotEqual(proc.returncode, 0, 'must error on using both lists at once') self.assertIn('It makes no sense to use both a blacklist and a whitelist with asyncify', proc.stdout) def test_asyncify_imports(self): def test(args): - return run_process(WASM_OPT + [self.input_path('asyncify-sleep.wast'), '--asyncify', '--print'] + args, stdout=subprocess.PIPE).stdout + return shared.run_process(shared.WASM_OPT + [self.input_path('asyncify-sleep.wast'), '--asyncify', '--print'] + args, stdout=subprocess.PIPE).stdout normal = test(['--pass-arg=asyncify-imports@env.sleep']) temp = tempfile.NamedTemporaryFile().name diff --git a/test/unit/test_datacount.py b/test/unit/test_datacount.py index 4358f3320..b996865a5 100644 --- a/test/unit/test_datacount.py +++ b/test/unit/test_datacount.py @@ -1,15 +1,15 @@ -from scripts.test.shared import WASM_OPT, run_process -from .utils import BinaryenTestCase +from scripts.test import shared +from . import utils -class DataCountTest(BinaryenTestCase): +class DataCountTest(utils.BinaryenTestCase): def test_datacount(self): self.roundtrip('bulkmem_data.wasm') def test_bad_datacount(self): path = self.input_path('bulkmem_bad_datacount.wasm') - p = run_process(WASM_OPT + ['-g', '-o', '-', path], check=False, - capture_output=True) + p = shared.run_process(shared.WASM_OPT + ['-g', '-o', '-', path], + check=False, capture_output=True) self.assertNotEqual(p.returncode, 0) self.assertIn('Number of segments does not agree with DataCount section', p.stderr) diff --git a/test/unit/test_features.py b/test/unit/test_features.py index c031c07fa..dece97ec5 100644 --- a/test/unit/test_features.py +++ b/test/unit/test_features.py @@ -1,17 +1,21 @@ import os -from scripts.test.shared import WASM_OPT, run_process -from .utils import BinaryenTestCase +from scripts.test import shared +from . import utils -class FeatureValidationTest(BinaryenTestCase): + +class FeatureValidationTest(utils.BinaryenTestCase): def check_feature(self, module, error, flag): - p = run_process(WASM_OPT + ['--mvp-features', '--print', '-o', os.devnull], - input=module, check=False, capture_output=True) + p = shared.run_process(shared.WASM_OPT + + ['--mvp-features', '--print', '-o', os.devnull], + input=module, check=False, capture_output=True) self.assertIn(error, p.stderr) self.assertIn('Fatal: error in validating input', p.stderr) self.assertNotEqual(p.returncode, 0) - p = run_process(WASM_OPT + ['--mvp-features', flag, '--print', '-o', os.devnull], - input=module, check=False, capture_output=True) + p = shared.run_process(shared.WASM_OPT + + ['--mvp-features', flag, '--print', '-o', + os.devnull], + input=module, check=False, capture_output=True) self.assertEqual(p.returncode, 0) def check_simd(self, module, error): @@ -187,7 +191,7 @@ class FeatureValidationTest(BinaryenTestCase): self.check_exception_handling(module, 'Module has events') -class TargetFeaturesSectionTest(BinaryenTestCase): +class TargetFeaturesSectionTest(utils.BinaryenTestCase): def test_atomics(self): filename = 'atomics_target_feature.wasm' self.roundtrip(filename) @@ -245,8 +249,9 @@ class TargetFeaturesSectionTest(BinaryenTestCase): def test_incompatible_features(self): path = self.input_path('signext_target_feature.wasm') - p = run_process( - WASM_OPT + ['--print', '--enable-simd', '-o', os.devnull, path], + p = shared.run_process( + shared.WASM_OPT + ['--print', '--enable-simd', '-o', os.devnull, + path], check=False, capture_output=True ) self.assertNotEqual(p.returncode, 0) @@ -256,9 +261,9 @@ class TargetFeaturesSectionTest(BinaryenTestCase): def test_incompatible_features_forced(self): path = self.input_path('signext_target_feature.wasm') - p = run_process( - WASM_OPT + ['--print', '--detect-features', '-mvp', '--enable-simd', - '-o', os.devnull, path], + p = shared.run_process( + shared.WASM_OPT + ['--print', '--detect-features', '-mvp', + '--enable-simd', '-o', os.devnull, path], check=False, capture_output=True ) self.assertNotEqual(p.returncode, 0) @@ -269,11 +274,15 @@ class TargetFeaturesSectionTest(BinaryenTestCase): opts=['-mvp', '--detect-features', '--enable-simd']) def test_emit_all_features(self): - p = run_process(WASM_OPT + ['--emit-target-features', '-all', '-o', '-'], - input="(module)", check=False, capture_output=True, decode_output=False) + p = shared.run_process(shared.WASM_OPT + + ['--emit-target-features', '-all', '-o', '-'], + input="(module)", check=False, + capture_output=True, decode_output=False) self.assertEqual(p.returncode, 0) - p2 = run_process(WASM_OPT + ['--print-features', '-o', os.devnull], - input=p.stdout, check=False, capture_output=True) + p2 = shared.run_process(shared.WASM_OPT + + ['--print-features', '-o', os.devnull], + input=p.stdout, check=False, + capture_output=True) self.assertEqual(p2.returncode, 0) self.assertEqual([ '--enable-threads', diff --git a/test/unit/test_finalize.py b/test/unit/test_finalize.py index cdcfe27e8..14b752a87 100644 --- a/test/unit/test_finalize.py +++ b/test/unit/test_finalize.py @@ -1,12 +1,13 @@ -from scripts.test.shared import WASM_EMSCRIPTEN_FINALIZE, run_process -from .utils import BinaryenTestCase import os +from scripts.test import shared +from . import utils -class EmscriptenFinalizeTest(BinaryenTestCase): + +class EmscriptenFinalizeTest(utils.BinaryenTestCase): def test_em_asm_mangled_string(self): input_dir = os.path.dirname(__file__) - p = run_process(WASM_EMSCRIPTEN_FINALIZE + [ + p = shared.run_process(shared.WASM_EMSCRIPTEN_FINALIZE + [ os.path.join(input_dir, 'input', 'em_asm_mangled_string.wast'), '-o', os.devnull, '--global-base=1024' ], check=False, capture_output=True) self.assertNotEqual(p.returncode, 0) diff --git a/test/unit/test_memory_packing.py b/test/unit/test_memory_packing.py index c8c331800..357752f10 100644 --- a/test/unit/test_memory_packing.py +++ b/test/unit/test_memory_packing.py @@ -1,12 +1,13 @@ import os -from scripts.test.shared import WASM_OPT, run_process -from .utils import BinaryenTestCase + +from scripts.test import shared +from . import utils """Test that MemoryPacking correctly respects the web limitations by not generating more than 100K data segments""" -class MemoryPackingTest(BinaryenTestCase): +class MemoryPackingTest(utils.BinaryenTestCase): def test_large_segment(self): data = '"' + (('A' + ('\\00' * 9)) * 100001) + '"' module = ''' @@ -17,8 +18,8 @@ class MemoryPackingTest(BinaryenTestCase): ''' % data opts = ['--memory-packing', '--disable-bulk-memory', '--print', '-o', os.devnull] - p = run_process(WASM_OPT + opts, input=module, check=False, - capture_output=True) + p = shared.run_process(shared.WASM_OPT + opts, input=module, + check=False, capture_output=True) output = [ '(data (i32.const 999970) "A")', '(data (i32.const 999980) "A")', @@ -33,8 +34,8 @@ class MemoryPackingTest(BinaryenTestCase): module = '(module (memory 256 256) %s)' % data opts = ['--memory-packing', '--enable-bulk-memory', '--print', '-o', os.devnull] - p = run_process(WASM_OPT + opts, input=module, check=False, - capture_output=True) + p = shared.run_process(shared.WASM_OPT + opts, input=module, + check=False, capture_output=True) self.assertEqual(p.returncode, 0) self.assertIn('Some VMs may not accept this binary', p.stderr) self.assertIn('Run the limit-segments pass to merge segments.', p.stderr) diff --git a/test/unit/test_parsing_error.py b/test/unit/test_parsing_error.py index b9bab3d76..c9128045e 100644 --- a/test/unit/test_parsing_error.py +++ b/test/unit/test_parsing_error.py @@ -1,9 +1,10 @@ -from scripts.test.shared import WASM_OPT, run_process -from .utils import BinaryenTestCase import os +from scripts.test import shared +from . import utils -class ParsingErrorTest(BinaryenTestCase): + +class ParsingErrorTest(utils.BinaryenTestCase): def test_parsing_error_msg(self): module = ''' (module @@ -12,7 +13,7 @@ class ParsingErrorTest(BinaryenTestCase): ) ) ''' - p = run_process(WASM_OPT + ['--print', '-o', os.devnull], input=module, - check=False, capture_output=True) + p = shared.run_process(shared.WASM_OPT + ['--print', '-o', os.devnull], + input=module, check=False, capture_output=True) self.assertNotEqual(p.returncode, 0) self.assertIn("parse exception: abc (at 4:4)", p.stderr) diff --git a/test/unit/test_tail_call_type.py b/test/unit/test_tail_call_type.py index 9fb8cd156..01c6ca88e 100644 --- a/test/unit/test_tail_call_type.py +++ b/test/unit/test_tail_call_type.py @@ -1,9 +1,10 @@ -from scripts.test.shared import WASM_OPT, run_process -from .utils import BinaryenTestCase import os +from scripts.test import shared +from . import utils -class TailCallTypeTest(BinaryenTestCase): + +class TailCallTypeTest(utils.BinaryenTestCase): def test_return_call(self): module = ''' (module @@ -15,8 +16,9 @@ class TailCallTypeTest(BinaryenTestCase): ) ) ''' - p = run_process(WASM_OPT + ['--enable-tail-call', '-o', os.devnull], - input=module, check=False, capture_output=True) + p = shared.run_process(shared.WASM_OPT + + ['--enable-tail-call', '-o', os.devnull], + input=module, check=False, capture_output=True) self.assertNotEqual(p.returncode, 0) self.assertIn( 'return_call callee return type must match caller return type', @@ -34,8 +36,9 @@ class TailCallTypeTest(BinaryenTestCase): ) ) ''' - p = run_process(WASM_OPT + ['--enable-tail-call', '-o', os.devnull], - input=module, check=False, capture_output=True) + p = shared.run_process(shared.WASM_OPT + + ['--enable-tail-call', '-o', os.devnull], + input=module, check=False, capture_output=True) self.assertNotEqual(p.returncode, 0) self.assertIn( 'return_call_indirect callee return type must match caller return type', diff --git a/test/unit/test_warnings.py b/test/unit/test_warnings.py index 9fb43a12b..0717ae823 100644 --- a/test/unit/test_warnings.py +++ b/test/unit/test_warnings.py @@ -1,18 +1,18 @@ import subprocess -from scripts.test.shared import WASM_OPT, run_process -from .utils import BinaryenTestCase +from scripts.test import shared +from . import utils -class WarningsText(BinaryenTestCase): +class WarningsText(utils.BinaryenTestCase): def test_warn_on_no_passes(self): - err = run_process(WASM_OPT + [self.input_path('asyncify-pure.wast'), '-o', 'a.wasm'], stderr=subprocess.PIPE).stderr + err = shared.run_process(shared.WASM_OPT + [self.input_path('asyncify-pure.wast'), '-o', 'a.wasm'], stderr=subprocess.PIPE).stderr self.assertIn('warning: no passes specified, not doing any work', err) def test_warn_on_no_output(self): - err = run_process(WASM_OPT + [self.input_path('asyncify-pure.wast'), '-O1'], stderr=subprocess.PIPE).stderr + err = shared.run_process(shared.WASM_OPT + [self.input_path('asyncify-pure.wast'), '-O1'], stderr=subprocess.PIPE).stderr self.assertIn('warning: no output file specified, not emitting output', err) def test_quiet_suppresses_warnings(self): - err = run_process(WASM_OPT + [self.input_path('asyncify-pure.wast'), '-q'], stderr=subprocess.PIPE).stderr + err = shared.run_process(shared.WASM_OPT + [self.input_path('asyncify-pure.wast'), '-q'], stderr=subprocess.PIPE).stderr self.assertNotIn('warning', err) diff --git a/test/unit/utils.py b/test/unit/utils.py index 6aa00aa4f..a9bfc3740 100644 --- a/test/unit/utils.py +++ b/test/unit/utils.py @@ -1,15 +1,18 @@ import os import unittest -from scripts.test.shared import WASM_OPT, run_process, options + +from scripts.test import shared class BinaryenTestCase(unittest.TestCase): def input_path(self, filename): - return os.path.join(options.binaryen_test, 'unit', 'input', filename) + return os.path.join(shared.options.binaryen_test, 'unit', 'input', + filename) def roundtrip(self, filename, opts=[]): path = self.input_path(filename) - p = run_process(WASM_OPT + ['-g', '-o', 'a.wasm', path] + opts) + p = shared.run_process(shared.WASM_OPT + ['-g', '-o', 'a.wasm', path] + + opts) self.assertEqual(p.returncode, 0) with open(path, 'rb') as f: with open('a.wasm', 'rb') as g: @@ -17,16 +20,18 @@ class BinaryenTestCase(unittest.TestCase): def disassemble(self, filename): path = self.input_path(filename) - p = run_process(WASM_OPT + ['--print', '-o', os.devnull, path], check=False, - capture_output=True) + p = shared.run_process(shared.WASM_OPT + + ['--print', '-o', os.devnull, path], + check=False, capture_output=True) self.assertEqual(p.returncode, 0) self.assertEqual(p.stderr, '') return p.stdout def check_features(self, filename, features, opts=[]): path = self.input_path(filename) - cmd = WASM_OPT + ['--print-features', '-o', os.devnull, path] + opts - p = run_process(cmd, check=False, capture_output=True) + cmd = shared.WASM_OPT + \ + ['--print-features', '-o', os.devnull, path] + opts + p = shared.run_process(cmd, check=False, capture_output=True) self.assertEqual(p.returncode, 0) self.assertEqual(p.stderr, '') self.assertEqual(p.stdout.split('\n')[:-1], |