summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2019-04-15 11:15:17 -0700
committerGitHub <noreply@github.com>2019-04-15 11:15:17 -0700
commita803c119f1a4babb7efc3dda0f475e1e87893475 (patch)
treec9e23c81b8898b5bc9fada2c4c4a7b87c835bc86 /test/unit
parent9495b338121140d585648d64fb99e8ef7f92f867 (diff)
downloadbinaryen-a803c119f1a4babb7efc3dda0f475e1e87893475.tar.gz
binaryen-a803c119f1a4babb7efc3dda0f475e1e87893475.tar.bz2
binaryen-a803c119f1a4babb7efc3dda0f475e1e87893475.zip
DataCount section (#2006)
* DataCount section Read the DataCount section and verify that it agrees with the data section. Also emit the DataCount section when bulk-memory is enabled and there are a nonzero number of segments. Factor out some shared unit test code.
Diffstat (limited to 'test/unit')
-rwxr-xr-xtest/unit/input/bulkmem_bad_datacount.wasmbin0 -> 177 bytes
-rwxr-xr-xtest/unit/input/bulkmem_data.wasmbin0 -> 177 bytes
-rw-r--r--test/unit/test_datacount.py16
-rw-r--r--test/unit/test_features.py33
-rw-r--r--test/unit/utils.py16
5 files changed, 43 insertions, 22 deletions
diff --git a/test/unit/input/bulkmem_bad_datacount.wasm b/test/unit/input/bulkmem_bad_datacount.wasm
new file mode 100755
index 000000000..e7b6e4bb7
--- /dev/null
+++ b/test/unit/input/bulkmem_bad_datacount.wasm
Binary files differ
diff --git a/test/unit/input/bulkmem_data.wasm b/test/unit/input/bulkmem_data.wasm
new file mode 100755
index 000000000..aa9e535b5
--- /dev/null
+++ b/test/unit/input/bulkmem_data.wasm
Binary files differ
diff --git a/test/unit/test_datacount.py b/test/unit/test_datacount.py
new file mode 100644
index 000000000..87ddbd58d
--- /dev/null
+++ b/test/unit/test_datacount.py
@@ -0,0 +1,16 @@
+import unittest
+from scripts.test.shared import WASM_OPT, run_process
+from utils import roundtrip, input_path
+
+
+class DataCountTest(unittest.TestCase):
+ def test_datacount(self):
+ roundtrip(self, 'bulkmem_data.wasm')
+
+ def test_bad_datacount(self):
+ path = 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 f130e1408..1672b957a 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -1,6 +1,7 @@
import os
import unittest
-from scripts.test.shared import WASM_OPT, run_process, options
+from scripts.test.shared import WASM_OPT, run_process
+from utils import input_path, roundtrip
class FeatureValidationTest(unittest.TestCase):
@@ -117,50 +118,40 @@ class FeatureValidationTest(unittest.TestCase):
class TargetFeaturesSectionTest(unittest.TestCase):
def disassemble(self, filename):
- path = os.path.join(options.binaryen_test, 'unit', 'input', 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
- def roundtrip(self, filename):
- path = os.path.join(options.binaryen_test, 'unit', 'input', filename)
- p = run_process(WASM_OPT + ['-g', '-o', '-', path], 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 test_atomics(self):
- self.roundtrip('atomics_target_feature.wasm')
+ roundtrip(self, 'atomics_target_feature.wasm')
module = self.disassemble('atomics_target_feature.wasm')
self.assertIn('i32.atomic.rmw.add', module)
def test_bulk_memory(self):
- self.roundtrip('bulkmem_target_feature.wasm')
+ roundtrip(self, 'bulkmem_target_feature.wasm')
module = self.disassemble('bulkmem_target_feature.wasm')
self.assertIn('memory.copy', module)
def test_nontrapping_fptoint(self):
- self.roundtrip('truncsat_target_feature.wasm')
+ roundtrip(self, 'truncsat_target_feature.wasm')
module = self.disassemble('truncsat_target_feature.wasm')
self.assertIn('i32.trunc_sat_f32_u', module)
def test_sign_ext(self):
- self.roundtrip('signext_target_feature.wasm')
+ roundtrip(self, 'signext_target_feature.wasm')
module = self.disassemble('signext_target_feature.wasm')
self.assertIn('i32.extend8_s', module)
def test_simd(self):
- self.roundtrip('simd_target_feature.wasm')
+ roundtrip(self, 'simd_target_feature.wasm')
module = self.disassemble('simd_target_feature.wasm')
self.assertIn('i32x4.splat', module)
def test_incompatible_features(self):
- path = os.path.join(options.binaryen_test, 'unit', 'input',
- 'signext_target_feature.wasm')
+ path = input_path('signext_target_feature.wasm')
p = run_process(
WASM_OPT + ['--print', '-mvp', '--enable-simd', '-o', os.devnull, path],
check=False, capture_output=True
@@ -171,8 +162,7 @@ class TargetFeaturesSectionTest(unittest.TestCase):
p.stderr)
def test_incompatible_features_forced(self):
- path = os.path.join(options.binaryen_test, 'unit', 'input',
- 'signext_target_feature.wasm')
+ path = input_path('signext_target_feature.wasm')
p = run_process(
WASM_OPT + ['--print', '--detect-features', '-mvp', '--enable-simd',
'-o', os.devnull, path],
@@ -182,8 +172,7 @@ class TargetFeaturesSectionTest(unittest.TestCase):
self.assertIn('all used features should be allowed', p.stderr)
def test_explicit_detect_features(self):
- path = os.path.join(options.binaryen_test, 'unit', 'input',
- 'signext_target_feature.wasm')
+ path = input_path('signext_target_feature.wasm')
p = run_process(
WASM_OPT + ['--print', '-mvp', '--detect-features',
'-o', os.devnull, path],
diff --git a/test/unit/utils.py b/test/unit/utils.py
new file mode 100644
index 000000000..eaeb29d42
--- /dev/null
+++ b/test/unit/utils.py
@@ -0,0 +1,16 @@
+import os
+from scripts.test.shared import WASM_OPT, run_process, options
+
+
+def input_path(filename):
+ return os.path.join(options.binaryen_test, 'unit', 'input', filename)
+
+
+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()))