summaryrefslogtreecommitdiff
path: root/test/unit/test_memory_packing.py
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2019-04-08 15:49:26 -0700
committerGitHub <noreply@github.com>2019-04-08 15:49:26 -0700
commitc5ad2e5ecc517030aa242c18fd738b9d79f11429 (patch)
tree7b12d8c5896d5a0d1806efefc9abc5267e5f99eb /test/unit/test_memory_packing.py
parent3eb9b27246d5d021d68b9a854c064d5a537728dd (diff)
downloadbinaryen-c5ad2e5ecc517030aa242c18fd738b9d79f11429.tar.gz
binaryen-c5ad2e5ecc517030aa242c18fd738b9d79f11429.tar.bz2
binaryen-c5ad2e5ecc517030aa242c18fd738b9d79f11429.zip
Move segment merging to fit web limits into its own pass (#1980)
It was previously part of writing a binary, but changing the number of segments at such a late stage would not work in the presence of bulk memory's datacount section. Also updates the memory packing pass to respect the web's limits on the number of data segments.
Diffstat (limited to 'test/unit/test_memory_packing.py')
-rw-r--r--test/unit/test_memory_packing.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/unit/test_memory_packing.py b/test/unit/test_memory_packing.py
new file mode 100644
index 000000000..0d62b0ed5
--- /dev/null
+++ b/test/unit/test_memory_packing.py
@@ -0,0 +1,40 @@
+import os
+import unittest
+from scripts.test.shared import WASM_OPT, run_process
+
+'''Test that MemoryPacking correctly respects the web limitations by not
+generating more than 100K data segments'''
+
+
+class MemoryPackingTest(unittest.TestCase):
+ 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)