...
1;; Auxiliary module to import from
2
3(module
4 (func (export "func"))
5 (func (export "func-i32") (param i32))
6 (func (export "func-f32") (param f32))
7 (func (export "func->i32") (result i32) (i32.const 22))
8 (func (export "func->f32") (result f32) (f32.const 11))
9 (func (export "func-i32->i32") (param i32) (result i32) (local.get 0))
10 (func (export "func-i64->i64") (param i64) (result i64) (local.get 0))
11 (global (export "global-i32") i32 (i32.const 55))
12 (global (export "global-f32") f32 (f32.const 44))
13 (global (export "global-mut-i64") (mut i64) (i64.const 66))
14 (table (export "table-10-inf") 10 funcref)
15 (table (export "table-10-20") 10 20 funcref)
16 (memory (export "memory-2-inf") 2)
17 ;; Multiple memories are not yet supported
18 ;; (memory (export "memory-2-4") 2 4)
19)
20
21(register "test")
22
23
24;; Functions
25
26(module
27 (type $func_i32 (func (param i32)))
28 (type $func_i64 (func (param i64)))
29 (type $func_f32 (func (param f32)))
30 (type $func_f64 (func (param f64)))
31
32 (import "spectest" "print_i32" (func (param i32)))
33 (func (import "spectest" "print_i64") (param i64))
34 (import "spectest" "print_i32" (func $print_i32 (param i32)))
35 (import "spectest" "print_i64" (func $print_i64 (param i64)))
36 (import "spectest" "print_f32" (func $print_f32 (param f32)))
37 (import "spectest" "print_f64" (func $print_f64 (param f64)))
38 (import "spectest" "print_i32_f32" (func $print_i32_f32 (param i32 f32)))
39 (import "spectest" "print_f64_f64" (func $print_f64_f64 (param f64 f64)))
40 (func $print_i32-2 (import "spectest" "print_i32") (param i32))
41 (func $print_f64-2 (import "spectest" "print_f64") (param f64))
42 (import "test" "func-i64->i64" (func $i64->i64 (param i64) (result i64)))
43
44 (func (export "p1") (import "spectest" "print_i32") (param i32))
45 (func $p (export "p2") (import "spectest" "print_i32") (param i32))
46 (func (export "p3") (export "p4") (import "spectest" "print_i32") (param i32))
47 (func (export "p5") (import "spectest" "print_i32") (type 0))
48 (func (export "p6") (import "spectest" "print_i32") (type 0) (param i32) (result))
49
50 (import "spectest" "print_i32" (func (type $forward)))
51 (func (import "spectest" "print_i32") (type $forward))
52 (type $forward (func (param i32)))
53
54 (table funcref (elem $print_i32 $print_f64))
55
56 (func (export "print32") (param $i i32)
57 (local $x f32)
58 (local.set $x (f32.convert_i32_s (local.get $i)))
59 (call 0 (local.get $i))
60 (call $print_i32_f32
61 (i32.add (local.get $i) (i32.const 1))
62 (f32.const 42)
63 )
64 (call $print_i32 (local.get $i))
65 (call $print_i32-2 (local.get $i))
66 (call $print_f32 (local.get $x))
67 (call_indirect (type $func_i32) (local.get $i) (i32.const 0))
68 )
69
70 (func (export "print64") (param $i i64)
71 (local $x f64)
72 (local.set $x (f64.convert_i64_s (call $i64->i64 (local.get $i))))
73 (call 1 (local.get $i))
74 (call $print_f64_f64
75 (f64.add (local.get $x) (f64.const 1))
76 (f64.const 53)
77 )
78 (call $print_i64 (local.get $i))
79 (call $print_f64 (local.get $x))
80 (call $print_f64-2 (local.get $x))
81 (call_indirect (type $func_f64) (local.get $x) (i32.const 1))
82 )
83)
84
85(assert_return (invoke "print32" (i32.const 13)))
86(assert_return (invoke "print64" (i64.const 24)))
87
88(assert_invalid
89 (module
90 (type (func (result i32)))
91 (import "test" "func" (func (type 1)))
92 )
93 "unknown type"
94)
95
96;; Export sharing name with import
97(module
98 (import "spectest" "print_i32" (func $imported_print (param i32)))
99 (func (export "print_i32") (param $i i32)
100 (call $imported_print (local.get $i))
101 )
102)
103
104(assert_return (invoke "print_i32" (i32.const 13)))
105
106;; Export sharing name with import
107(module
108 (import "spectest" "print_i32" (func $imported_print (param i32)))
109 (func (export "print_i32") (param $i i32) (param $j i32) (result i32)
110 (i32.add (local.get $i) (local.get $j))
111 )
112)
113
114(assert_return (invoke "print_i32" (i32.const 5) (i32.const 11)) (i32.const 16))
115
116(module (import "test" "func" (func)))
117(module (import "test" "func-i32" (func (param i32))))
118(module (import "test" "func-f32" (func (param f32))))
119(module (import "test" "func->i32" (func (result i32))))
120(module (import "test" "func->f32" (func (result f32))))
121(module (import "test" "func-i32->i32" (func (param i32) (result i32))))
122(module (import "test" "func-i64->i64" (func (param i64) (result i64))))
123
124(assert_unlinkable
125 (module (import "test" "unknown" (func)))
126 "unknown import"
127)
128(assert_unlinkable
129 (module (import "spectest" "unknown" (func)))
130 "unknown import"
131)
132
133(assert_unlinkable
134 (module (import "test" "func" (func (param i32))))
135 "incompatible import type"
136)
137(assert_unlinkable
138 (module (import "test" "func" (func (result i32))))
139 "incompatible import type"
140)
141(assert_unlinkable
142 (module (import "test" "func" (func (param i32) (result i32))))
143 "incompatible import type"
144)
145(assert_unlinkable
146 (module (import "test" "func-i32" (func)))
147 "incompatible import type"
148)
149(assert_unlinkable
150 (module (import "test" "func-i32" (func (result i32))))
151 "incompatible import type"
152)
153(assert_unlinkable
154 (module (import "test" "func-i32" (func (param f32))))
155 "incompatible import type"
156)
157(assert_unlinkable
158 (module (import "test" "func-i32" (func (param i64))))
159 "incompatible import type"
160)
161(assert_unlinkable
162 (module (import "test" "func-i32" (func (param i32) (result i32))))
163 "incompatible import type"
164)
165(assert_unlinkable
166 (module (import "test" "func->i32" (func)))
167 "incompatible import type"
168)
169(assert_unlinkable
170 (module (import "test" "func->i32" (func (param i32))))
171 "incompatible import type"
172)
173(assert_unlinkable
174 (module (import "test" "func->i32" (func (result f32))))
175 "incompatible import type"
176)
177(assert_unlinkable
178 (module (import "test" "func->i32" (func (result i64))))
179 "incompatible import type"
180)
181(assert_unlinkable
182 (module (import "test" "func->i32" (func (param i32) (result i32))))
183 "incompatible import type"
184)
185(assert_unlinkable
186 (module (import "test" "func-i32->i32" (func)))
187 "incompatible import type"
188)
189(assert_unlinkable
190 (module (import "test" "func-i32->i32" (func (param i32))))
191 "incompatible import type"
192)
193(assert_unlinkable
194 (module (import "test" "func-i32->i32" (func (result i32))))
195 "incompatible import type"
196)
197
198(assert_unlinkable
199 (module (import "test" "global-i32" (func (result i32))))
200 "incompatible import type"
201)
202(assert_unlinkable
203 (module (import "test" "table-10-inf" (func)))
204 "incompatible import type"
205)
206(assert_unlinkable
207 (module (import "test" "memory-2-inf" (func)))
208 "incompatible import type"
209)
210(assert_unlinkable
211 (module (import "spectest" "global_i32" (func)))
212 "incompatible import type"
213)
214(assert_unlinkable
215 (module (import "spectest" "table" (func)))
216 "incompatible import type"
217)
218(assert_unlinkable
219 (module (import "spectest" "memory" (func)))
220 "incompatible import type"
221)
222
223
224;; Globals
225
226(module
227 (import "spectest" "global_i32" (global i32))
228 (global (import "spectest" "global_i32") i32)
229
230 (import "spectest" "global_i32" (global $x i32))
231 (global $y (import "spectest" "global_i32") i32)
232
233 (import "spectest" "global_i64" (global i64))
234 (import "spectest" "global_f32" (global f32))
235 (import "spectest" "global_f64" (global f64))
236
237 (func (export "get-0") (result i32) (global.get 0))
238 (func (export "get-1") (result i32) (global.get 1))
239 (func (export "get-x") (result i32) (global.get $x))
240 (func (export "get-y") (result i32) (global.get $y))
241)
242
243(assert_return (invoke "get-0") (i32.const 666))
244(assert_return (invoke "get-1") (i32.const 666))
245(assert_return (invoke "get-x") (i32.const 666))
246(assert_return (invoke "get-y") (i32.const 666))
247
248(module (import "test" "global-i32" (global i32)))
249(module (import "test" "global-f32" (global f32)))
250(module (import "test" "global-mut-i64" (global (mut i64))))
251
252(assert_unlinkable
253 (module (import "test" "unknown" (global i32)))
254 "unknown import"
255)
256(assert_unlinkable
257 (module (import "spectest" "unknown" (global i32)))
258 "unknown import"
259)
260
261(assert_unlinkable
262 (module (import "test" "global-i32" (global i64)))
263 "incompatible import type"
264)
265(assert_unlinkable
266 (module (import "test" "global-i32" (global f32)))
267 "incompatible import type"
268)
269(assert_unlinkable
270 (module (import "test" "global-i32" (global f64)))
271 "incompatible import type"
272)
273(assert_unlinkable
274 (module (import "test" "global-i32" (global (mut i32))))
275 "incompatible import type"
276)
277(assert_unlinkable
278 (module (import "test" "global-f32" (global i32)))
279 "incompatible import type"
280)
281(assert_unlinkable
282 (module (import "test" "global-f32" (global i64)))
283 "incompatible import type"
284)
285(assert_unlinkable
286 (module (import "test" "global-f32" (global f64)))
287 "incompatible import type"
288)
289(assert_unlinkable
290 (module (import "test" "global-f32" (global (mut f32))))
291 "incompatible import type"
292)
293(assert_unlinkable
294 (module (import "test" "global-mut-i64" (global (mut i32))))
295 "incompatible import type"
296)
297(assert_unlinkable
298 (module (import "test" "global-mut-i64" (global (mut f32))))
299 "incompatible import type"
300)
301(assert_unlinkable
302 (module (import "test" "global-mut-i64" (global (mut f64))))
303 "incompatible import type"
304)
305(assert_unlinkable
306 (module (import "test" "global-mut-i64" (global i64)))
307 "incompatible import type"
308)
309
310(assert_unlinkable
311 (module (import "test" "func" (global i32)))
312 "incompatible import type"
313)
314(assert_unlinkable
315 (module (import "test" "table-10-inf" (global i32)))
316 "incompatible import type"
317)
318(assert_unlinkable
319 (module (import "test" "memory-2-inf" (global i32)))
320 "incompatible import type"
321)
322(assert_unlinkable
323 (module (import "spectest" "print_i32" (global i32)))
324 "incompatible import type"
325)
326(assert_unlinkable
327 (module (import "spectest" "table" (global i32)))
328 "incompatible import type"
329)
330(assert_unlinkable
331 (module (import "spectest" "memory" (global i32)))
332 "incompatible import type"
333)
334
335
336;; Tables
337
338(module
339 (type (func (result i32)))
340 (import "spectest" "table" (table $tab 10 20 funcref))
341 (elem (table $tab) (i32.const 1) func $f $g)
342
343 (func (export "call") (param i32) (result i32)
344 (call_indirect $tab (type 0) (local.get 0))
345 )
346 (func $f (result i32) (i32.const 11))
347 (func $g (result i32) (i32.const 22))
348)
349
350(assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
351(assert_return (invoke "call" (i32.const 1)) (i32.const 11))
352(assert_return (invoke "call" (i32.const 2)) (i32.const 22))
353(assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
354(assert_trap (invoke "call" (i32.const 100)) "undefined element")
355
356
357(module
358 (type (func (result i32)))
359 (table $tab (import "spectest" "table") 10 20 funcref)
360 (elem (table $tab) (i32.const 1) func $f $g)
361
362 (func (export "call") (param i32) (result i32)
363 (call_indirect $tab (type 0) (local.get 0))
364 )
365 (func $f (result i32) (i32.const 11))
366 (func $g (result i32) (i32.const 22))
367)
368
369(assert_trap (invoke "call" (i32.const 0)) "uninitialized element")
370(assert_return (invoke "call" (i32.const 1)) (i32.const 11))
371(assert_return (invoke "call" (i32.const 2)) (i32.const 22))
372(assert_trap (invoke "call" (i32.const 3)) "uninitialized element")
373(assert_trap (invoke "call" (i32.const 100)) "undefined element")
374
375
376(module
377 (import "spectest" "table" (table 0 funcref))
378 (import "spectest" "table" (table 0 funcref))
379 (table 10 funcref)
380 (table 10 funcref)
381)
382
383(module (import "test" "table-10-inf" (table 10 funcref)))
384(module (import "test" "table-10-inf" (table 5 funcref)))
385(module (import "test" "table-10-inf" (table 0 funcref)))
386(module (import "test" "table-10-20" (table 10 funcref)))
387(module (import "test" "table-10-20" (table 5 funcref)))
388(module (import "test" "table-10-20" (table 0 funcref)))
389(module (import "test" "table-10-20" (table 10 20 funcref)))
390(module (import "test" "table-10-20" (table 5 20 funcref)))
391(module (import "test" "table-10-20" (table 0 20 funcref)))
392(module (import "test" "table-10-20" (table 10 25 funcref)))
393(module (import "test" "table-10-20" (table 5 25 funcref)))
394(module (import "test" "table-10-20" (table 0 25 funcref)))
395(module (import "spectest" "table" (table 10 funcref)))
396(module (import "spectest" "table" (table 5 funcref)))
397(module (import "spectest" "table" (table 0 funcref)))
398(module (import "spectest" "table" (table 10 20 funcref)))
399(module (import "spectest" "table" (table 5 20 funcref)))
400(module (import "spectest" "table" (table 0 20 funcref)))
401(module (import "spectest" "table" (table 10 25 funcref)))
402(module (import "spectest" "table" (table 5 25 funcref)))
403
404(assert_unlinkable
405 (module (import "test" "unknown" (table 10 funcref)))
406 "unknown import"
407)
408(assert_unlinkable
409 (module (import "spectest" "unknown" (table 10 funcref)))
410 "unknown import"
411)
412
413(assert_unlinkable
414 (module (import "test" "table-10-inf" (table 12 funcref)))
415 "incompatible import type"
416)
417(assert_unlinkable
418 (module (import "test" "table-10-inf" (table 10 20 funcref)))
419 "incompatible import type"
420)
421(assert_unlinkable
422 (module (import "test" "table-10-20" (table 12 20 funcref)))
423 "incompatible import type"
424)
425(assert_unlinkable
426 (module (import "test" "table-10-20" (table 10 18 funcref)))
427 "incompatible import type"
428)
429(assert_unlinkable
430 (module (import "spectest" "table" (table 12 funcref)))
431 "incompatible import type"
432)
433(assert_unlinkable
434 (module (import "spectest" "table" (table 10 15 funcref)))
435 "incompatible import type"
436)
437
438(assert_unlinkable
439 (module (import "test" "func" (table 10 funcref)))
440 "incompatible import type"
441)
442(assert_unlinkable
443 (module (import "test" "global-i32" (table 10 funcref)))
444 "incompatible import type"
445)
446(assert_unlinkable
447 (module (import "test" "memory-2-inf" (table 10 funcref)))
448 "incompatible import type"
449)
450(assert_unlinkable
451 (module (import "spectest" "print_i32" (table 10 funcref)))
452 "incompatible import type"
453)
454
455
456
457;; Memories
458
459(module
460 (import "spectest" "memory" (memory 1 2))
461 (data (memory 0) (i32.const 10) "\10")
462
463 (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
464)
465
466(assert_return (invoke "load" (i32.const 0)) (i32.const 0))
467(assert_return (invoke "load" (i32.const 10)) (i32.const 16))
468(assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
469(assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")
470
471(module
472 (memory (import "spectest" "memory") 1 2)
473 (data (memory 0) (i32.const 10) "\10")
474
475 (func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
476)
477(assert_return (invoke "load" (i32.const 0)) (i32.const 0))
478(assert_return (invoke "load" (i32.const 10)) (i32.const 16))
479(assert_return (invoke "load" (i32.const 8)) (i32.const 0x100000))
480(assert_trap (invoke "load" (i32.const 1000000)) "out of bounds memory access")
481
482(assert_invalid
483 (module (import "" "" (memory 1)) (import "" "" (memory 1)))
484 "multiple memories"
485)
486(assert_invalid
487 (module (import "" "" (memory 1)) (memory 0))
488 "multiple memories"
489)
490(assert_invalid
491 (module (memory 0) (memory 0))
492 "multiple memories"
493)
494
495(module (import "test" "memory-2-inf" (memory 2)))
496(module (import "test" "memory-2-inf" (memory 1)))
497(module (import "test" "memory-2-inf" (memory 0)))
498(module (import "spectest" "memory" (memory 1)))
499(module (import "spectest" "memory" (memory 0)))
500(module (import "spectest" "memory" (memory 1 2)))
501(module (import "spectest" "memory" (memory 0 2)))
502(module (import "spectest" "memory" (memory 1 3)))
503(module (import "spectest" "memory" (memory 0 3)))
504
505(assert_unlinkable
506 (module (import "test" "unknown" (memory 1)))
507 "unknown import"
508)
509(assert_unlinkable
510 (module (import "spectest" "unknown" (memory 1)))
511 "unknown import"
512)
513
514(assert_unlinkable
515 (module (import "test" "memory-2-inf" (memory 3)))
516 "incompatible import type"
517)
518(assert_unlinkable
519 (module (import "test" "memory-2-inf" (memory 2 3)))
520 "incompatible import type"
521)
522(assert_unlinkable
523 (module (import "spectest" "memory" (memory 2)))
524 "incompatible import type"
525)
526(assert_unlinkable
527 (module (import "spectest" "memory" (memory 1 1)))
528 "incompatible import type"
529)
530
531(assert_unlinkable
532 (module (import "test" "func-i32" (memory 1)))
533 "incompatible import type"
534)
535(assert_unlinkable
536 (module (import "test" "global-i32" (memory 1)))
537 "incompatible import type"
538)
539(assert_unlinkable
540 (module (import "test" "table-10-inf" (memory 1)))
541 "incompatible import type"
542)
543(assert_unlinkable
544 (module (import "spectest" "print_i32" (memory 1)))
545 "incompatible import type"
546)
547(assert_unlinkable
548 (module (import "spectest" "global_i32" (memory 1)))
549 "incompatible import type"
550)
551(assert_unlinkable
552 (module (import "spectest" "table" (memory 1)))
553 "incompatible import type"
554)
555
556(assert_unlinkable
557 (module (import "spectest" "memory" (memory 2)))
558 "incompatible import type"
559)
560(assert_unlinkable
561 (module (import "spectest" "memory" (memory 1 1)))
562 "incompatible import type"
563)
564
565(module
566 (import "spectest" "memory" (memory 0 3)) ;; actual has max size 2
567 (func (export "grow") (param i32) (result i32) (memory.grow (local.get 0)))
568)
569(assert_return (invoke "grow" (i32.const 0)) (i32.const 1))
570(assert_return (invoke "grow" (i32.const 1)) (i32.const 1))
571(assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
572(assert_return (invoke "grow" (i32.const 1)) (i32.const -1))
573(assert_return (invoke "grow" (i32.const 0)) (i32.const 2))
574
575(module $Mgm
576 (memory (export "memory") 1) ;; initial size is 1
577 (func (export "grow") (result i32) (memory.grow (i32.const 1)))
578)
579(register "grown-memory" $Mgm)
580(assert_return (invoke $Mgm "grow") (i32.const 1)) ;; now size is 2
581(module $Mgim1
582 ;; imported memory limits should match, because external memory size is 2 now
583 (memory (export "memory") (import "grown-memory" "memory") 2)
584 (func (export "grow") (result i32) (memory.grow (i32.const 1)))
585)
586(register "grown-imported-memory" $Mgim1)
587(assert_return (invoke $Mgim1 "grow") (i32.const 2)) ;; now size is 3
588(module $Mgim2
589 ;; imported memory limits should match, because external memory size is 3 now
590 (import "grown-imported-memory" "memory" (memory 3))
591 (func (export "size") (result i32) (memory.size))
592)
593(assert_return (invoke $Mgim2 "size") (i32.const 3))
594
595
596;; Syntax errors
597
598(assert_malformed
599 (module quote "(func) (import \"\" \"\" (func))")
600 "import after function"
601)
602(assert_malformed
603 (module quote "(func) (import \"\" \"\" (global i64))")
604 "import after function"
605)
606(assert_malformed
607 (module quote "(func) (import \"\" \"\" (table 0 funcref))")
608 "import after function"
609)
610(assert_malformed
611 (module quote "(func) (import \"\" \"\" (memory 0))")
612 "import after function"
613)
614
615(assert_malformed
616 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (func))")
617 "import after global"
618)
619(assert_malformed
620 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (global f32))")
621 "import after global"
622)
623(assert_malformed
624 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (table 0 funcref))")
625 "import after global"
626)
627(assert_malformed
628 (module quote "(global i64 (i64.const 0)) (import \"\" \"\" (memory 0))")
629 "import after global"
630)
631
632(assert_malformed
633 (module quote "(table 0 funcref) (import \"\" \"\" (func))")
634 "import after table"
635)
636(assert_malformed
637 (module quote "(table 0 funcref) (import \"\" \"\" (global i32))")
638 "import after table"
639)
640(assert_malformed
641 (module quote "(table 0 funcref) (import \"\" \"\" (table 0 funcref))")
642 "import after table"
643)
644(assert_malformed
645 (module quote "(table 0 funcref) (import \"\" \"\" (memory 0))")
646 "import after table"
647)
648
649(assert_malformed
650 (module quote "(memory 0) (import \"\" \"\" (func))")
651 "import after memory"
652)
653(assert_malformed
654 (module quote "(memory 0) (import \"\" \"\" (global i32))")
655 "import after memory"
656)
657(assert_malformed
658 (module quote "(memory 0) (import \"\" \"\" (table 1 3 funcref))")
659 "import after memory"
660)
661(assert_malformed
662 (module quote "(memory 0) (import \"\" \"\" (memory 1 2))")
663 "import after memory"
664)
665
666;; This module is required to validate, regardless of whether it can be
667;; linked. Overloading is not possible in wasm itself, but it is possible
668;; in modules from which wasm can import.
669(module)
670(register "not wasm")
671(assert_unlinkable
672 (module
673 (import "not wasm" "overloaded" (func))
674 (import "not wasm" "overloaded" (func (param i32)))
675 (import "not wasm" "overloaded" (func (param i32 i32)))
676 (import "not wasm" "overloaded" (func (param i64)))
677 (import "not wasm" "overloaded" (func (param f32)))
678 (import "not wasm" "overloaded" (func (param f64)))
679 (import "not wasm" "overloaded" (func (result i32)))
680 (import "not wasm" "overloaded" (func (result i64)))
681 (import "not wasm" "overloaded" (func (result f32)))
682 (import "not wasm" "overloaded" (func (result f64)))
683 (import "not wasm" "overloaded" (global i32))
684 (import "not wasm" "overloaded" (global i64))
685 (import "not wasm" "overloaded" (global f32))
686 (import "not wasm" "overloaded" (global f64))
687 (import "not wasm" "overloaded" (table 0 funcref))
688 (import "not wasm" "overloaded" (memory 0))
689 )
690 "unknown import"
691)
View as plain text