summaryrefslogtreecommitdiff
path: root/test/unit/test_features.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/test_features.py')
-rw-r--r--test/unit/test_features.py70
1 files changed, 30 insertions, 40 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'])