summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/test_features.py70
-rw-r--r--test/unit/test_memory_packing.py4
-rw-r--r--test/unit/utils.py38
3 files changed, 60 insertions, 52 deletions
diff --git a/test/unit/test_features.py b/test/unit/test_features.py
index 1672b957a..8764bef97 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -1,10 +1,9 @@
import os
-import unittest
from scripts.test.shared import WASM_OPT, run_process
-from utils import input_path, roundtrip
+from utils import BinaryenTestCase
-class FeatureValidationTest(unittest.TestCase):
+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)
@@ -116,53 +115,50 @@ class FeatureValidationTest(unittest.TestCase):
self.check_bulk_mem(module, 'nonzero segment flags (bulk memory is disabled)')
-class TargetFeaturesSectionTest(unittest.TestCase):
- def disassemble(self, filename):
- path = 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
-
+class TargetFeaturesSectionTest(BinaryenTestCase):
def test_atomics(self):
- roundtrip(self, 'atomics_target_feature.wasm')
- module = self.disassemble('atomics_target_feature.wasm')
- self.assertIn('i32.atomic.rmw.add', module)
+ 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):
- roundtrip(self, 'bulkmem_target_feature.wasm')
- module = self.disassemble('bulkmem_target_feature.wasm')
- self.assertIn('memory.copy', module)
+ 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):
- roundtrip(self, 'truncsat_target_feature.wasm')
- module = self.disassemble('truncsat_target_feature.wasm')
- self.assertIn('i32.trunc_sat_f32_u', module)
+ 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_sign_ext(self):
- roundtrip(self, 'signext_target_feature.wasm')
- module = self.disassemble('signext_target_feature.wasm')
- self.assertIn('i32.extend8_s', module)
+ 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):
- roundtrip(self, 'simd_target_feature.wasm')
- module = self.disassemble('simd_target_feature.wasm')
- self.assertIn('i32x4.splat', module)
+ filename = 'simd_target_feature.wasm'
+ self.roundtrip(filename)
+ self.check_features(filename, ['simd'])
+ self.assertIn('i32x4.splat', self.disassemble(filename))
def test_incompatible_features(self):
- path = input_path('signext_target_feature.wasm')
+ path = self.input_path('signext_target_feature.wasm')
p = run_process(
- WASM_OPT + ['--print', '-mvp', '--enable-simd', '-o', os.devnull, path],
+ WASM_OPT + ['--print', '--enable-simd', '-o', os.devnull, path],
check=False, capture_output=True
)
self.assertNotEqual(p.returncode, 0)
- self.assertIn('Fatal: module uses features not explicitly specified, ' +
- 'use --detect-features to resolve',
+ self.assertIn('Fatal: module features do not match specified features. ' +
+ 'Use --detect-features to resolve.',
p.stderr)
def test_incompatible_features_forced(self):
- path = input_path('signext_target_feature.wasm')
+ path = self.input_path('signext_target_feature.wasm')
p = run_process(
WASM_OPT + ['--print', '--detect-features', '-mvp', '--enable-simd',
'-o', os.devnull, path],
@@ -172,11 +168,5 @@ class TargetFeaturesSectionTest(unittest.TestCase):
self.assertIn('all used features should be allowed', p.stderr)
def test_explicit_detect_features(self):
- path = input_path('signext_target_feature.wasm')
- p = run_process(
- WASM_OPT + ['--print', '-mvp', '--detect-features',
- '-o', os.devnull, path],
- check=False, capture_output=True
- )
- self.assertEqual(p.returncode, 0)
- self.assertEqual(p.stderr, '')
+ self.check_features('signext_target_feature.wasm', ['sign-ext', 'simd'],
+ opts=['-mvp', '--detect-features', '--enable-simd'])
diff --git a/test/unit/test_memory_packing.py b/test/unit/test_memory_packing.py
index 0d62b0ed5..a0ccd3006 100644
--- a/test/unit/test_memory_packing.py
+++ b/test/unit/test_memory_packing.py
@@ -1,12 +1,12 @@
import os
-import unittest
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'''
-class MemoryPackingTest(unittest.TestCase):
+class MemoryPackingTest(BinaryenTestCase):
def test_large_segment(self):
data = '"' + (('A' + ('\\00' * 9)) * 100001) + '"'
module = '''
diff --git a/test/unit/utils.py b/test/unit/utils.py
index eaeb29d42..876f2f4ec 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -1,16 +1,34 @@
import os
+import unittest
from scripts.test.shared import WASM_OPT, run_process, options
-def input_path(filename):
- return os.path.join(options.binaryen_test, 'unit', 'input', filename)
+class BinaryenTestCase(unittest.TestCase):
+ 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', '-', path] + opts, check=False,
+ capture_output=True)
+ self.assertEqual(p.returncode, 0)
+ self.assertEqual(p.stderr, '')
+ with open(path, 'rb') as f:
+ self.assertEqual(str(p.stdout), str(f.read()))
-def roundtrip(testcase, filename, opts=[]):
- path = input_path(filename)
- p = run_process(WASM_OPT + ['-g', '-o', '-', path] + opts, check=False,
- capture_output=True)
- testcase.assertEqual(p.returncode, 0)
- testcase.assertEqual(p.stderr, '')
- with open(path, 'rb') as f:
- testcase.assertEqual(str(p.stdout), str(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 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])