summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_asyncify.py80
-rw-r--r--test/unit/test_datacount.py18
-rw-r--r--test/unit/test_features.py503
-rw-r--r--test/unit/test_memory_packing.py64
-rw-r--r--test/unit/test_parsing_error.py24
-rw-r--r--test/unit/test_tail_call_type.py36
-rw-r--r--test/unit/utils.py48
7 files changed, 386 insertions, 387 deletions
diff --git a/test/unit/test_asyncify.py b/test/unit/test_asyncify.py
index f2d7839b6..a8161cc1d 100644
--- a/test/unit/test_asyncify.py
+++ b/test/unit/test_asyncify.py
@@ -6,47 +6,47 @@ from .utils import BinaryenTestCase
class AsyncifyTest(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'])
- print(' file size: %d' % os.path.getsize('a.wasm'))
- run_process([NODEJS, self.input_path('asyncify.js')])
+ 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'])
+ print(' file size: %d' % os.path.getsize('a.wasm'))
+ run_process([NODEJS, self.input_path('asyncify.js')])
- test(['-g'])
- test([])
- test(['-O1'])
- test(['--optimize-level=1'])
- test(['-O3'])
- test(['-Os', '-g'])
+ test(['-g'])
+ test([])
+ test(['-O1'])
+ test(['--optimize-level=1'])
+ test(['-O3'])
+ 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
- with open(self.input_path('asyncify-pure.txt'), 'r') as f:
- self.assertEqual(f.read(), output)
+ 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
+ with open(self.input_path('asyncify-pure.txt'), 'r') as f:
+ self.assertEqual(f.read(), output)
- def test_asyncify_list_bad(self):
- for arg, warning in [
- ('--pass-arg=asyncify-blacklist@nonexistent', 'nonexistent'),
- ('--pass-arg=asyncify-whitelist@nonexistent', 'nonexistent'),
- ('--pass-arg=asyncify-blacklist@main', None),
- ('--pass-arg=asyncify-whitelist@main', None),
- ('--pass-arg=asyncify-whitelist@main', None),
- ('--pass-arg=asyncify-whitelist@DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)', None),
- ]:
- print(arg, warning)
- err = run_process(WASM_OPT + [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)
- else:
- self.assertNotIn('warning', err)
+ def test_asyncify_list_bad(self):
+ for arg, warning in [
+ ('--pass-arg=asyncify-blacklist@nonexistent', 'nonexistent'),
+ ('--pass-arg=asyncify-whitelist@nonexistent', 'nonexistent'),
+ ('--pass-arg=asyncify-blacklist@main', None),
+ ('--pass-arg=asyncify-whitelist@main', None),
+ ('--pass-arg=asyncify-whitelist@main', None),
+ ('--pass-arg=asyncify-whitelist@DOS_ReadFile(unsigned short, unsigned char*, unsigned short*, bool)', None),
+ ]:
+ print(arg, warning)
+ err = run_process(WASM_OPT + [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)
+ else:
+ 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)
- 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_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)
+ 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)
diff --git a/test/unit/test_datacount.py b/test/unit/test_datacount.py
index d0d8e9f2b..4358f3320 100644
--- a/test/unit/test_datacount.py
+++ b/test/unit/test_datacount.py
@@ -3,13 +3,13 @@ from .utils import BinaryenTestCase
class DataCountTest(BinaryenTestCase):
- def test_datacount(self):
- self.roundtrip('bulkmem_data.wasm')
+ 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)
- self.assertNotEqual(p.returncode, 0)
- self.assertIn('Number of segments does not agree with DataCount section',
- p.stderr)
+ 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)
+ 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 3fd362aed..53037307d 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -4,258 +4,257 @@ from .utils import BinaryenTestCase
class FeatureValidationTest(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)
- 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)
- self.assertEqual(p.returncode, 0)
-
- def check_simd(self, module, error):
- self.check_feature(module, error, '--enable-simd')
-
- def check_sign_ext(self, module, error):
- self.check_feature(module, error, '--enable-sign-ext')
-
- def check_bulk_mem(self, module, error):
- self.check_feature(module, error, '--enable-bulk-memory')
-
- def check_exception_handling(self, module, error):
- self.check_feature(module, error, '--enable-exception-handling')
-
- def check_tail_call(self, module, error):
- self.check_feature(module, error, '--enable-tail-call')
-
- def test_v128_signature(self):
- module = '''
- (module
- (func $foo (param $0 v128) (result v128)
- (local.get $0)
- )
- )
- '''
- self.check_simd(module, 'all used types should be allowed')
-
- def test_v128_global(self):
- module = '''
- (module
- (global $foo (mut v128) (v128.const i32x4 0 0 0 0))
- )
- '''
- self.check_simd(module, 'all used types should be allowed')
-
- def test_v128_local(self):
- module = '''
- (module
- (func $foo
- (local v128)
- )
- )
- '''
- self.check_simd(module, 'all used types should be allowed')
-
- def test_simd_const(self):
- module = '''
- (module
- (func $foo
- (drop (v128.const i32x4 0 0 0 0))
- )
- )
- '''
- self.check_simd(module, 'all used features should be allowed')
-
- def test_simd_load(self):
- module = '''
- (module
- (memory 1 1)
- (func $foo
- (drop (v128.load (i32.const 0)))
- )
- )
- '''
- self.check_simd(module, 'SIMD operation (SIMD is disabled)')
-
- def test_simd_splat(self):
- module = '''
- (module
- (func $foo
- (drop (i32x4.splat (i32.const 0)))
- )
- )
- '''
- self.check_simd(module, 'all used features should be allowed')
-
- def test_sign_ext(self):
- module = '''
- (module
- (func $foo
- (drop (i32.extend8_s (i32.const 7)))
- )
- )
- '''
- self.check_sign_ext(module, 'all used features should be allowed')
-
- def test_bulk_mem_inst(self):
- module = '''
- (module
- (memory 1 1)
- (func $foo
- (memory.copy (i32.const 0) (i32.const 8) (i32.const 8))
- )
- )
- '''
- self.check_bulk_mem(module,
- 'Bulk memory operation (bulk memory is disabled')
-
- def test_bulk_mem_segment(self):
- module = '''
- (module
- (memory 256 256)
- (data passive "42")
- )
- '''
- self.check_bulk_mem(module, 'nonzero segment flags (bulk memory is disabled)')
-
- def test_tail_call(self):
- module = '''
- (module
- (func $bar)
- (func $foo
- (return_call $bar)
- )
- )
- '''
- self.check_tail_call(module, 'return_call requires tail calls to be enabled')
-
- def test_tail_call_indirect(self):
- module = '''
- (module
- (type $T (func))
- (table $0 1 1 funcref)
- (func $foo
- (return_call_indirect (type $T)
- (i32.const 0)
- )
- )
- )
- '''
- self.check_tail_call(module, 'return_call_indirect requires tail calls to be enabled')
-
- def test_exnref_local(self):
- module = '''
- (module
- (func $foo
- (local exnref)
- )
- )
- '''
- self.check_exception_handling(module, 'all used types should be allowed')
-
- def test_event(self):
- module = '''
- (module
- (event $e (attr 0) (param i32))
- (func $foo
- (throw $e (i32.const 0))
- )
- )
- '''
- self.check_exception_handling(module, 'Module has events')
+ 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)
+ 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)
+ self.assertEqual(p.returncode, 0)
+
+ def check_simd(self, module, error):
+ self.check_feature(module, error, '--enable-simd')
+
+ def check_sign_ext(self, module, error):
+ self.check_feature(module, error, '--enable-sign-ext')
+
+ def check_bulk_mem(self, module, error):
+ self.check_feature(module, error, '--enable-bulk-memory')
+
+ def check_exception_handling(self, module, error):
+ self.check_feature(module, error, '--enable-exception-handling')
+
+ def check_tail_call(self, module, error):
+ self.check_feature(module, error, '--enable-tail-call')
+
+ def test_v128_signature(self):
+ module = '''
+ (module
+ (func $foo (param $0 v128) (result v128)
+ (local.get $0)
+ )
+ )
+ '''
+ self.check_simd(module, 'all used types should be allowed')
+
+ def test_v128_global(self):
+ module = '''
+ (module
+ (global $foo (mut v128) (v128.const i32x4 0 0 0 0))
+ )
+ '''
+ self.check_simd(module, 'all used types should be allowed')
+
+ def test_v128_local(self):
+ module = '''
+ (module
+ (func $foo
+ (local v128)
+ )
+ )
+ '''
+ self.check_simd(module, 'all used types should be allowed')
+
+ def test_simd_const(self):
+ module = '''
+ (module
+ (func $foo
+ (drop (v128.const i32x4 0 0 0 0))
+ )
+ )
+ '''
+ self.check_simd(module, 'all used features should be allowed')
+
+ def test_simd_load(self):
+ module = '''
+ (module
+ (memory 1 1)
+ (func $foo
+ (drop (v128.load (i32.const 0)))
+ )
+ )
+ '''
+ self.check_simd(module, 'SIMD operation (SIMD is disabled)')
+
+ def test_simd_splat(self):
+ module = '''
+ (module
+ (func $foo
+ (drop (i32x4.splat (i32.const 0)))
+ )
+ )
+ '''
+ self.check_simd(module, 'all used features should be allowed')
+
+ def test_sign_ext(self):
+ module = '''
+ (module
+ (func $foo
+ (drop (i32.extend8_s (i32.const 7)))
+ )
+ )
+ '''
+ self.check_sign_ext(module, 'all used features should be allowed')
+
+ def test_bulk_mem_inst(self):
+ module = '''
+ (module
+ (memory 1 1)
+ (func $foo
+ (memory.copy (i32.const 0) (i32.const 8) (i32.const 8))
+ )
+ )
+ '''
+ self.check_bulk_mem(module,
+ 'Bulk memory operation (bulk memory is disabled')
+
+ def test_bulk_mem_segment(self):
+ module = '''
+ (module
+ (memory 256 256)
+ (data passive "42")
+ )
+ '''
+ self.check_bulk_mem(module, 'nonzero segment flags (bulk memory is disabled)')
+
+ def test_tail_call(self):
+ module = '''
+ (module
+ (func $bar)
+ (func $foo
+ (return_call $bar)
+ )
+ )
+ '''
+ self.check_tail_call(module, 'return_call requires tail calls to be enabled')
+
+ def test_tail_call_indirect(self):
+ module = '''
+ (module
+ (type $T (func))
+ (table $0 1 1 funcref)
+ (func $foo
+ (return_call_indirect (type $T)
+ (i32.const 0)
+ )
+ )
+ )
+ '''
+ self.check_tail_call(module, 'return_call_indirect requires tail calls to be enabled')
+
+ def test_exnref_local(self):
+ module = '''
+ (module
+ (func $foo
+ (local exnref)
+ )
+ )
+ '''
+ self.check_exception_handling(module, 'all used types should be allowed')
+
+ def test_event(self):
+ module = '''
+ (module
+ (event $e (attr 0) (param i32))
+ (func $foo
+ (throw $e (i32.const 0))
+ )
+ )
+ '''
+ self.check_exception_handling(module, 'Module has events')
class TargetFeaturesSectionTest(BinaryenTestCase):
- def test_atomics(self):
- filename = 'atomics_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['threads'])
- self.assertIn('i32.atomic.rmw.add', self.disassemble(filename))
-
- def test_bulk_memory(self):
- filename = 'bulkmem_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['bulk-memory'])
- self.assertIn('memory.copy', self.disassemble(filename))
-
- def test_nontrapping_fptoint(self):
- filename = 'truncsat_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['nontrapping-float-to-int'])
- self.assertIn('i32.trunc_sat_f32_u', self.disassemble(filename))
-
- def test_mutable_globals(self):
- filename = 'mutable_globals_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['mutable-globals'])
- self.assertIn('(import "env" "global-mut" (global $gimport$0 (mut i32)))',
- self.disassemble(filename))
-
- def test_sign_ext(self):
- filename = 'signext_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['sign-ext'])
- self.assertIn('i32.extend8_s', self.disassemble(filename))
-
- def test_simd(self):
- filename = 'simd_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['simd'])
- self.assertIn('i32x4.splat', self.disassemble(filename))
-
- def test_tailcall(self):
- filename = 'tail_call_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['tail-call'])
- self.assertIn('return_call', self.disassemble(filename))
-
- def test_exception_handling(self):
- filename = 'exception_handling_target_feature.wasm'
- self.roundtrip(filename)
- self.check_features(filename, ['exception-handling'])
- self.assertIn('throw', self.disassemble(filename))
-
- 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],
- check=False, capture_output=True
- )
- self.assertNotEqual(p.returncode, 0)
- self.assertIn('Fatal: module features do not match specified features. ' +
- 'Use --detect-features to resolve.',
- p.stderr)
-
- 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],
- check=False, capture_output=True
- )
- self.assertNotEqual(p.returncode, 0)
- self.assertIn('all used features should be allowed', p.stderr)
-
- def test_explicit_detect_features(self):
- self.check_features('signext_target_feature.wasm', ['sign-ext', 'simd'],
- 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)
- self.assertEqual(p.returncode, 0)
- p2 = run_process(WASM_OPT + ['--print-features', '-o', os.devnull],
- input=p.stdout, check=False, capture_output=True)
- self.assertEqual(p2.returncode, 0)
- self.assertEqual([
- '--enable-threads',
- '--enable-bulk-memory',
- '--enable-exception-handling',
- '--enable-mutable-globals',
- '--enable-nontrapping-float-to-int',
- '--enable-sign-ext',
- '--enable-simd',
- '--enable-tail-call'
- ], p2.stdout.split())
+ def test_atomics(self):
+ filename = 'atomics_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['threads'])
+ self.assertIn('i32.atomic.rmw.add', self.disassemble(filename))
+
+ def test_bulk_memory(self):
+ filename = 'bulkmem_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['bulk-memory'])
+ self.assertIn('memory.copy', self.disassemble(filename))
+
+ def test_nontrapping_fptoint(self):
+ filename = 'truncsat_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['nontrapping-float-to-int'])
+ self.assertIn('i32.trunc_sat_f32_u', self.disassemble(filename))
+
+ def test_mutable_globals(self):
+ filename = 'mutable_globals_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['mutable-globals'])
+ self.assertIn('(import "env" "global-mut" (global $gimport$0 (mut i32)))',
+ self.disassemble(filename))
+
+ def test_sign_ext(self):
+ filename = 'signext_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['sign-ext'])
+ self.assertIn('i32.extend8_s', self.disassemble(filename))
+
+ def test_simd(self):
+ filename = 'simd_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['simd'])
+ self.assertIn('i32x4.splat', self.disassemble(filename))
+
+ def test_tailcall(self):
+ filename = 'tail_call_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['tail-call'])
+ self.assertIn('return_call', self.disassemble(filename))
+
+ def test_exception_handling(self):
+ filename = 'exception_handling_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['exception-handling'])
+ self.assertIn('throw', self.disassemble(filename))
+
+ 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],
+ check=False, capture_output=True
+ )
+ self.assertNotEqual(p.returncode, 0)
+ self.assertIn('Fatal: module features do not match specified features. ' +
+ 'Use --detect-features to resolve.',
+ p.stderr)
+
+ 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],
+ check=False, capture_output=True
+ )
+ self.assertNotEqual(p.returncode, 0)
+ self.assertIn('all used features should be allowed', p.stderr)
+
+ def test_explicit_detect_features(self):
+ self.check_features('signext_target_feature.wasm', ['sign-ext', 'simd'],
+ 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)
+ self.assertEqual(p.returncode, 0)
+ p2 = run_process(WASM_OPT + ['--print-features', '-o', os.devnull],
+ input=p.stdout, check=False, capture_output=True)
+ self.assertEqual(p2.returncode, 0)
+ self.assertEqual([
+ '--enable-threads',
+ '--enable-bulk-memory',
+ '--enable-exception-handling',
+ '--enable-mutable-globals',
+ '--enable-nontrapping-float-to-int',
+ '--enable-sign-ext',
+ '--enable-simd',
+ '--enable-tail-call'
+ ], p2.stdout.split())
diff --git a/test/unit/test_memory_packing.py b/test/unit/test_memory_packing.py
index 5d64ccc6c..c8c331800 100644
--- a/test/unit/test_memory_packing.py
+++ b/test/unit/test_memory_packing.py
@@ -2,39 +2,39 @@ import os
from scripts.test.shared import WASM_OPT, run_process
from .utils import BinaryenTestCase
-'''Test that MemoryPacking correctly respects the web limitations by not
-generating more than 100K data segments'''
+"""Test that MemoryPacking correctly respects the web limitations by not
+generating more than 100K data segments"""
class MemoryPackingTest(BinaryenTestCase):
- def test_large_segment(self):
- data = '"' + (('A' + ('\\00' * 9)) * 100001) + '"'
- module = '''
- (module
- (memory 256 256)
- (data (i32.const 0) %s)
- )
- ''' % data
- opts = ['--memory-packing', '--disable-bulk-memory', '--print',
- '-o', os.devnull]
- p = run_process(WASM_OPT + opts, input=module, check=False,
- capture_output=True)
- output = [
- '(data (i32.const 999970) "A")',
- '(data (i32.const 999980) "A")',
- '(data (i32.const 999990) "A' + ('\\00' * 9) + 'A")'
- ]
- self.assertEqual(p.returncode, 0)
- for line in output:
- self.assertIn(line, p.stdout)
+ def test_large_segment(self):
+ data = '"' + (('A' + ('\\00' * 9)) * 100001) + '"'
+ module = '''
+ (module
+ (memory 256 256)
+ (data (i32.const 0) %s)
+ )
+ ''' % data
+ opts = ['--memory-packing', '--disable-bulk-memory', '--print',
+ '-o', os.devnull]
+ p = run_process(WASM_OPT + opts, input=module, check=False,
+ capture_output=True)
+ output = [
+ '(data (i32.const 999970) "A")',
+ '(data (i32.const 999980) "A")',
+ '(data (i32.const 999990) "A' + ('\\00' * 9) + 'A")'
+ ]
+ self.assertEqual(p.returncode, 0)
+ for line in output:
+ self.assertIn(line, p.stdout)
- def test_large_segment_unmergeable(self):
- data = '\n'.join('(data (i32.const %i) "A")' % i for i in range(100001))
- 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)
- 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)
+ def test_large_segment_unmergeable(self):
+ data = '\n'.join('(data (i32.const %i) "A")' % i for i in range(100001))
+ 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)
+ 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 fde77c6c2..b9bab3d76 100644
--- a/test/unit/test_parsing_error.py
+++ b/test/unit/test_parsing_error.py
@@ -4,15 +4,15 @@ import os
class ParsingErrorTest(BinaryenTestCase):
- def test_parsing_error_msg(self):
- module = '''
- (module
- (func $foo
- (abc)
- )
- )
- '''
- p = run_process(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:6)", p.stderr)
+ def test_parsing_error_msg(self):
+ module = '''
+(module
+ (func $foo
+ (abc)
+ )
+)
+'''
+ p = run_process(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 42da89d26..9fb8cd156 100644
--- a/test/unit/test_tail_call_type.py
+++ b/test/unit/test_tail_call_type.py
@@ -4,8 +4,8 @@ import os
class TailCallTypeTest(BinaryenTestCase):
- def test_return_call(self):
- module = '''
+ def test_return_call(self):
+ module = '''
(module
(func $foo (result f32)
(return_call $bar)
@@ -14,16 +14,16 @@ class TailCallTypeTest(BinaryenTestCase):
(i32.const 1)
)
)
- '''
- p = run_process(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',
- p.stderr)
+'''
+ p = run_process(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',
+ p.stderr)
- def test_return_call_indirect(self):
- module = '''
+ def test_return_call_indirect(self):
+ module = '''
(module
(type $T (func (result i32)))
(table $0 1 1 funcref)
@@ -33,10 +33,10 @@ class TailCallTypeTest(BinaryenTestCase):
)
)
)
- '''
- p = run_process(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',
- p.stderr)
+'''
+ p = run_process(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',
+ p.stderr)
diff --git a/test/unit/utils.py b/test/unit/utils.py
index 6b18235b5..6aa00aa4f 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -4,30 +4,30 @@ from scripts.test.shared import WASM_OPT, run_process, options
class BinaryenTestCase(unittest.TestCase):
- def input_path(self, filename):
- return os.path.join(options.binaryen_test, 'unit', 'input', filename)
+ def input_path(self, filename):
+ return os.path.join(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)
- self.assertEqual(p.returncode, 0)
- with open(path, 'rb') as f:
- with open('a.wasm', 'rb') as g:
- self.assertEqual(g.read(), f.read())
+ def roundtrip(self, filename, opts=[]):
+ path = self.input_path(filename)
+ p = run_process(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:
+ self.assertEqual(g.read(), f.read())
- def disassemble(self, filename):
- path = self.input_path(filename)
- p = run_process(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 disassemble(self, filename):
+ path = self.input_path(filename)
+ p = run_process(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)
- self.assertEqual(p.returncode, 0)
- self.assertEqual(p.stderr, '')
- self.assertEqual(p.stdout.split('\n')[:-1],
- ['--enable-' + f for f in features])
+ 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)
+ self.assertEqual(p.returncode, 0)
+ self.assertEqual(p.stderr, '')
+ self.assertEqual(p.stdout.split('\n')[:-1],
+ ['--enable-' + f for f in features])