Skip to content

Commit ba05ecd

Browse files
authored
Merge pull request #31 from keithw/add-test
[test] Add more custom-page-sizes tests
2 parents 0ed11fd + e8ce6ec commit ba05ecd

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

test/core/custom-page-sizes/custom-page-sizes-invalid.wast

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"invalid custom page size"
55
)
66

7+
(assert_malformed
8+
(module quote "(memory 0 (pagesize 0))")
9+
"invalid custom page size"
10+
)
11+
712
;; Power-of-two page sizes that are not 1 or 64KiB.
813
(assert_invalid
914
(module (memory 0 (pagesize 2)))

test/core/custom-page-sizes/custom-page-sizes.wast

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,33 @@
106106
(module
107107
(memory (import "m" "large-pages-memory") 0 (pagesize 65536))
108108
)
109+
110+
;; Inline data segments
111+
112+
;; pagesize 0
113+
(assert_malformed (module quote "(memory (pagesize 0) (data))") "invalid custom page size")
114+
115+
;; pagesize 1
116+
(module
117+
(memory (pagesize 1) (data "xyz"))
118+
(func (export "size") (result i32)
119+
memory.size)
120+
(func (export "grow") (param i32) (result i32)
121+
(memory.grow (local.get 0)))
122+
(func (export "load") (param i32) (result i32)
123+
(i32.load8_u (local.get 0))))
124+
125+
(assert_return (invoke "size") (i32.const 3))
126+
(assert_return (invoke "load" (i32.const 0)) (i32.const 120))
127+
(assert_return (invoke "load" (i32.const 1)) (i32.const 121))
128+
(assert_return (invoke "load" (i32.const 2)) (i32.const 122))
129+
(assert_trap (invoke "load" (i32.const 3)) "out of bounds")
130+
(assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
131+
132+
;; pagesize 65536
133+
(module
134+
(memory (pagesize 65536) (data "xyz"))
135+
(func (export "size") (result i32)
136+
memory.size))
137+
138+
(assert_return (invoke "size") (i32.const 1))
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
;; Maximum memory sizes.
2+
;;
3+
;; These modules are valid, but instantiating them is unnecessary
4+
;; and would only allocate very large memories and slow down running
5+
;; the spec tests. Therefore, add a missing import so that it cannot
6+
;; be instantiated and use `assert_unlinkable`. This approach
7+
;; enforces that the module itself is still valid, but that its
8+
;; instantiation fails early (hopefully before any memories are
9+
;; actually allocated).
10+
11+
;; i32 (pagesize 1)
12+
(assert_unlinkable
13+
(module
14+
(import "test" "unknown" (func))
15+
(memory 0xFFFF_FFFF (pagesize 1)))
16+
"unknown import")
17+
18+
;; i64 (pagesize 1)
19+
(assert_unlinkable
20+
(module
21+
(import "test" "import" (func))
22+
(memory i64 0xFFFF_FFFF_FFFF_FFFF (pagesize 1)))
23+
"unknown import")
24+
25+
;; i32 (default pagesize)
26+
(assert_unlinkable
27+
(module
28+
(import "test" "unknown" (func))
29+
(memory 65536 (pagesize 65536)))
30+
"unknown import")
31+
32+
;; i64 (default pagesize)
33+
(assert_unlinkable
34+
(module
35+
(import "test" "unknown" (func))
36+
(memory i64 0x1_0000_0000_0000 (pagesize 65536)))
37+
"unknown import")
38+
39+
;; Memory size just over the maximum.
40+
;;
41+
;; These are malformed (for pagesize 1)
42+
;; or invalid (for other pagesizes).
43+
44+
;; i32 (pagesize 1)
45+
(assert_malformed
46+
(module quote "(memory 0x1_0000_0000 (pagesize 1))")
47+
"constant out of range")
48+
49+
;; i64 (pagesize 1)
50+
(assert_malformed
51+
(module quote "(memory i64 0x1_0000_0000_0000_0000 (pagesize 1))")
52+
"constant out of range")
53+
54+
;; i32 (default pagesize)
55+
(assert_invalid
56+
(module
57+
(memory 65537 (pagesize 65536)))
58+
"memory size must be at most")
59+
60+
;; i64 (default pagesize)
61+
(assert_invalid
62+
(module
63+
(memory i64 0x1_0000_0000_0001 (pagesize 65536)))
64+
"memory size must be at most")

0 commit comments

Comments
 (0)