Skip to content

Commit 4f775ed

Browse files
committed
Add a few more spec tests
1 parent baa86dc commit 4f775ed

2 files changed

Lines changed: 207 additions & 0 deletions

File tree

test/core/compact-import-section/binary-compact-imports.wast

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,37 @@
179179
"\0b" ;; end
180180
)
181181
(assert_return (invoke "test") (i32.const 0xab))
182+
183+
184+
;; Not enough imports in each group
185+
186+
(assert_malformed
187+
(module binary
188+
"\00asm" "\01\00\00\00"
189+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
190+
"\02\0a" ;; Import section
191+
"\01" ;; 1 group
192+
"\01a" ;; "a"
193+
"\00" "\7f" ;; "" + 0x7f
194+
"\02" ;; 2 items
195+
"\01b" "\00\00" ;; "b" (func (type 0))
196+
;; <-- second item missing
197+
)
198+
"unexpected end"
199+
)
200+
201+
(assert_malformed
202+
(module binary
203+
"\00asm" "\01\00\00\00"
204+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
205+
"\02\0a" ;; Import section
206+
"\01" ;; 1 group
207+
"\01a" ;; "a"
208+
"\00" "\7e" ;; "" + 0x7e
209+
"\00\00" ;; (func (type 0))
210+
"\02" ;; 2 items
211+
"\01b" ;; "b"
212+
;; <-- second item missing
213+
)
214+
"unexpected end"
215+
)

test/core/compact-import-section/imports-compact.wast

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,176 @@
122122
(module quote "(import \"test\" (item \"foo\") (func $foo))")
123123
"identifier not allowed"
124124
)
125+
126+
127+
;; All externtype kinds in a single encoding-1 group
128+
129+
(module
130+
(func (export "f") (result i32) (i32.const 1000))
131+
(table (export "t") 30 funcref)
132+
(memory (export "m") 1)
133+
(global (export "g") i32 (i32.const 700))
134+
(tag (export "e") (param i32))
135+
)
136+
(register "test-all")
137+
138+
(module
139+
(import "test-all"
140+
(item "f" (func (result i32)))
141+
(item "t" (table 3 funcref))
142+
(item "m" (memory 1))
143+
(item "g" (global i32))
144+
(item "e" (tag (param i32)))
145+
)
146+
147+
(func (export "check") (result i32)
148+
call 0 ;; 1000
149+
table.size 0 ;; 30
150+
memory.size ;; 1
151+
global.get 0 ;; 700
152+
i32.add
153+
i32.add
154+
i32.add
155+
)
156+
157+
(func (export "throw-and-catch") (param i32) (result i32)
158+
(block $h (result i32)
159+
(try_table (result i32) (catch 0 $h)
160+
(throw 0 (local.get 0))
161+
)
162+
)
163+
)
164+
)
165+
166+
(assert_return (invoke "check") (i32.const 1731))
167+
(assert_return (invoke "throw-and-catch" (i32.const 42)) (i32.const 42))
168+
169+
170+
;; Test encoding 2 for all externtypes
171+
172+
(module
173+
(func (export "f1") (result i32) (i32.const 1))
174+
(func (export "f2") (result i32) (i32.const 10))
175+
(table (export "t1") 2 funcref)
176+
(table (export "t2") 20 funcref)
177+
(memory (export "m1") 3)
178+
(memory (export "m2") 30)
179+
(global (export "g1") i32 (i32.const 4))
180+
(global (export "g2") i32 (i32.const 40))
181+
(tag (export "e1") (param i32))
182+
(tag (export "e2") (param i32))
183+
)
184+
(register "test-pairs")
185+
186+
(module
187+
(import "test-pairs" (item "f1") (item "f2") (func (result i32)))
188+
(func (export "sum") (result i32)
189+
(i32.add (call 0) (call 1))
190+
)
191+
)
192+
(assert_return (invoke "sum") (i32.const 11))
193+
194+
(module
195+
(import "test-pairs" (item "t1") (item "t2") (table 1 funcref))
196+
(func (export "sizes") (result i32)
197+
(i32.add (table.size 0) (table.size 1))
198+
)
199+
)
200+
(assert_return (invoke "sizes") (i32.const 22))
201+
202+
(module
203+
(import "test-pairs" (item "m1") (item "m2") (memory 1))
204+
(func (export "sizes") (result i32)
205+
(i32.add (memory.size 0) (memory.size 1))
206+
)
207+
)
208+
(assert_return (invoke "sizes") (i32.const 33))
209+
210+
(module
211+
(import "test-pairs" (item "g1") (item "g2") (global i32))
212+
(func (export "sum") (result i32)
213+
(i32.add (global.get 0) (global.get 1))
214+
)
215+
)
216+
(assert_return (invoke "sum") (i32.const 44))
217+
218+
(module
219+
(import "test-pairs" (item "e1") (item "e2") (tag (param i32)))
220+
(func (export "throw-1") (result i32)
221+
(block $h (result i32)
222+
(try_table (result i32) (catch 0 $h)
223+
(throw 0 (i32.const 5))
224+
)
225+
)
226+
)
227+
(func (export "throw-2") (result i32)
228+
(block $h (result i32)
229+
(try_table (result i32) (catch 1 $h)
230+
(throw 1 (i32.const 50))
231+
)
232+
)
233+
)
234+
)
235+
(assert_return (invoke "throw-1") (i32.const 5))
236+
(assert_return (invoke "throw-2") (i32.const 50))
237+
238+
(assert_unlinkable
239+
(module (import "test-pairs" (item "t1") (item "t2") (table 1 externref)))
240+
"incompatible import type"
241+
)
242+
243+
244+
;; Mixed traditional + compact, same module name, index allocation
245+
246+
(module
247+
(func (export "f0") (result i32) (i32.const 1))
248+
(func (export "f1") (result i32) (i32.const 20))
249+
(func (export "f2") (result i32) (i32.const 300))
250+
(global (export "g0") i32 (i32.const 4000))
251+
(global (export "g1") i32 (i32.const 50000))
252+
(global (export "g2") i32 (i32.const 600000))
253+
)
254+
(register "mixed")
255+
256+
(module
257+
;; Non-compact encoding
258+
(import "mixed" "f0" (func (result i32))) ;; func 0
259+
(import "mixed" "f1" (func (result i32))) ;; func 1
260+
261+
;; Encoding 1
262+
(import "mixed"
263+
(item "g2" (global i32)) ;; global 0
264+
(item "f2" (func (result i32)))) ;; func 2
265+
266+
;; Encoding 2
267+
(import "mixed" (item "g0") (item "g1") (global i32)) ;; globals 1, 2
268+
269+
(func (export "check") (result i32)
270+
call 0
271+
call 1
272+
call 2
273+
global.get 0
274+
global.get 1
275+
global.get 2
276+
i32.add
277+
i32.add
278+
i32.add
279+
i32.add
280+
i32.add
281+
)
282+
)
283+
(assert_return (invoke "check") (i32.const 654321))
284+
285+
286+
;; Empty item name inside a compact group
287+
288+
(module
289+
(func (export "") (result i32) (i32.const 0xab))
290+
)
291+
(register "")
292+
293+
(module
294+
(import "" (item "" (func (result i32))))
295+
(func (export "call-empty") (result i32) call 0)
296+
)
297+
(assert_return (invoke "call-empty") (i32.const 0xab))

0 commit comments

Comments
 (0)