Skip to content

Commit 48cc48e

Browse files
committed
Add tests
1 parent c066fcd commit 48cc48e

File tree

4 files changed

+274
-1
lines changed

4 files changed

+274
-1
lines changed

scripts/test/fuzzing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@
100100
'stack_switching_suspend.wast',
101101
'stack_switching_resume.wast',
102102
'stack_switching_resume_throw.wast',
103-
'stack_switching_switch.wast'
103+
'stack_switching_switch.wast',
104+
# TODO: fuzzer support for type imports
105+
'type-imports.wast',
106+
'type-imports.wat'
104107
]
105108

106109

test/lit/basic/type-imports.wast

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: wasm-opt %s -all -o %t.text.wast -g -S
4+
;; RUN: wasm-as %s -all -g -o %t.wasm
5+
;; RUN: wasm-dis %t.wasm -all -o %t.bin.wast
6+
;; RUN: wasm-as %s -all -o %t.nodebug.wasm
7+
;; RUN: wasm-dis %t.nodebug.wasm -all -o %t.bin.nodebug.wast
8+
;; RUN: cat %t.text.wast | filecheck %s --check-prefix=CHECK
9+
;; RUN: cat %t.bin.wast | filecheck %s --check-prefix=CHECK
10+
;; RUN: cat %t.bin.nodebug.wast | filecheck %s --check-prefix=CHECK-BIN-NODEBUG
11+
12+
(module
13+
14+
;; Simple import
15+
;; CHECK: (import "env" "t1" (type $t1 (sub eq)))
16+
(import "env" "t1" (type $t1 (sub eq)))
17+
18+
;; Import with omitted typetype
19+
;; CHECK: (import "env" "t2" (type $t2 (sub any)))
20+
(import "env" "t2" (type $t2))
21+
22+
;; Alternative synyax with both import and export
23+
(type $t3 (export "t3") (import "env" "t3") (sub struct))
24+
25+
;; Use an imported type in a type
26+
;; CHECK: (import "env" "t3" (type $t3 (sub struct)))
27+
28+
;; CHECK: (type $t4 (array (ref $t1)))
29+
(type $t4 (array (field (ref $t1))))
30+
31+
;; CHECK: (type $t5 (struct (field (ref $t1))))
32+
(type $t5 (export "t5") (struct (field (ref $t1))))
33+
34+
;; Import function with imported types
35+
;; CHECK: (type $5 (func (param (ref $t1)) (result (ref $t2))))
36+
37+
;; CHECK: (type $6 (func (param (ref eq) (ref $t2) (ref $t3) (ref $t4)) (result (ref $t2))))
38+
39+
;; CHECK: (type $7 (func (param (ref $t3)) (result (ref struct))))
40+
41+
;; CHECK: (import "env" "g" (func $g (type $5) (param (ref $t1)) (result (ref $t2))))
42+
(import "env" "g" (func $g (param (ref $t1)) (result (ref $t2))))
43+
44+
;; Cast and function call involving imported types
45+
(func (export "f1")
46+
(param $x (ref eq)) (param (ref $t2) (ref $t3) (ref $t4)) (result (ref $t2))
47+
(call $g
48+
(ref.cast (ref $t1)
49+
(local.get $x)
50+
)
51+
)
52+
)
53+
54+
;; Check that the imported type is a subtype of its bound
55+
(func (export "f2") (param $x (ref $t3)) (result (ref struct))
56+
(local.get $x)
57+
)
58+
59+
;; Reexport an imported type
60+
;; CHECK: (export "t3" (type $t3))
61+
62+
;; CHECK: (export "t5" (type $t5))
63+
64+
;; CHECK: (export "t2" (type $t2))
65+
(export "t2" (type $t2))
66+
67+
;; Export a type defined in this module
68+
;; CHECK: (export "t4" (type $t4))
69+
(export "t4" (type $t4))
70+
71+
;; Export an abstract heap type
72+
(export "t6" (type extern))
73+
)
74+
;; CHECK: (export "f1" (func $0))
75+
76+
;; CHECK: (export "f2" (func $1))
77+
78+
;; CHECK: (func $0 (type $6) (param $x (ref eq)) (param $1 (ref $t2)) (param $2 (ref $t3)) (param $3 (ref $t4)) (result (ref $t2))
79+
;; CHECK-NEXT: (call $g
80+
;; CHECK-NEXT: (ref.cast (ref $t1)
81+
;; CHECK-NEXT: (local.get $x)
82+
;; CHECK-NEXT: )
83+
;; CHECK-NEXT: )
84+
;; CHECK-NEXT: )
85+
86+
;; CHECK: (func $1 (type $7) (param $x (ref $t3)) (result (ref struct))
87+
;; CHECK-NEXT: (local.get $x)
88+
;; CHECK-NEXT: )
89+
90+
;; CHECK-BIN-NODEBUG: (import "env" "t1" (type $0 (sub eq)))
91+
92+
;; CHECK-BIN-NODEBUG: (import "env" "t2" (type $1 (sub any)))
93+
94+
;; CHECK-BIN-NODEBUG: (import "env" "t3" (type $2 (sub struct)))
95+
96+
;; CHECK-BIN-NODEBUG: (type $3 (array (ref $0)))
97+
98+
;; CHECK-BIN-NODEBUG: (type $4 (struct (field (ref $0))))
99+
100+
;; CHECK-BIN-NODEBUG: (type $5 (func (param (ref $0)) (result (ref $1))))
101+
102+
;; CHECK-BIN-NODEBUG: (type $6 (func (param (ref eq) (ref $1) (ref $2) (ref $3)) (result (ref $1))))
103+
104+
;; CHECK-BIN-NODEBUG: (type $7 (func (param (ref $2)) (result (ref struct))))
105+
106+
;; CHECK-BIN-NODEBUG: (import "env" "g" (func $fimport$0 (type $5) (param (ref $0)) (result (ref $1))))
107+
108+
;; CHECK-BIN-NODEBUG: (export "t3" (type $2))
109+
110+
;; CHECK-BIN-NODEBUG: (export "t5" (type $4))
111+
112+
;; CHECK-BIN-NODEBUG: (export "t2" (type $1))
113+
114+
;; CHECK-BIN-NODEBUG: (export "t4" (type $3))
115+
116+
;; CHECK-BIN-NODEBUG: (export "f1" (func $0))
117+
118+
;; CHECK-BIN-NODEBUG: (export "f2" (func $1))
119+
120+
;; CHECK-BIN-NODEBUG: (func $0 (type $6) (param $0 (ref eq)) (param $1 (ref $1)) (param $2 (ref $2)) (param $3 (ref $3)) (result (ref $1))
121+
;; CHECK-BIN-NODEBUG-NEXT: (call $fimport$0
122+
;; CHECK-BIN-NODEBUG-NEXT: (ref.cast (ref $0)
123+
;; CHECK-BIN-NODEBUG-NEXT: (local.get $0)
124+
;; CHECK-BIN-NODEBUG-NEXT: )
125+
;; CHECK-BIN-NODEBUG-NEXT: )
126+
;; CHECK-BIN-NODEBUG-NEXT: )
127+
128+
;; CHECK-BIN-NODEBUG: (func $1 (type $7) (param $0 (ref $2)) (result (ref struct))
129+
;; CHECK-BIN-NODEBUG-NEXT: (local.get $0)
130+
;; CHECK-BIN-NODEBUG-NEXT: )

test/lit/merge/type-imports.wat

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: wasm-merge %s first %s.second second -all -S -o - | filecheck %s
4+
5+
(module
6+
;; Bound to an abstract heap type
7+
(import "second" "t1" (type $t1))
8+
9+
;; Bound to a concrete heap type
10+
(import "second" "t2" (type $t2))
11+
12+
;; Bound to an imported type
13+
;; CHECK: (import "third" "t3" (type $t3 (sub struct)))
14+
(import "second" "t3" (type $t3))
15+
16+
;; Left unbound
17+
;; CHECK: (import "third" "t4" (type $t4 (sub any)))
18+
(import "third" "t4" (type $t4))
19+
20+
;; Check the import of a function using imported types
21+
(import "second" "g" (func $g (param (ref $t2))))
22+
23+
;; Check that the function parameters are updated
24+
(func (export "f") (param (ref $t1) (ref $t2) (ref $t3) (ref $t4))
25+
)
26+
27+
;; Check that types in instructions are also updated
28+
(func (export "g1") (param $x (ref any)) (result (ref $t1))
29+
(ref.cast (ref $t1)
30+
(local.get $x)
31+
)
32+
)
33+
34+
(func (export "g2") (param $x (ref any)) (result (ref $t2))
35+
(ref.cast (ref $t2)
36+
(local.get $x)
37+
)
38+
)
39+
40+
(func (export "g3") (param $x (ref any)) (result (ref $t3))
41+
(ref.cast (ref $t3)
42+
(local.get $x)
43+
)
44+
)
45+
46+
(func (export "g4") (param $x (ref any)) (result (ref $t4))
47+
(ref.cast (ref $t4)
48+
(local.get $x)
49+
)
50+
)
51+
52+
;; Check that recursive types are preserved
53+
(rec
54+
;; CHECK: (type $t2 (array i8))
55+
56+
;; CHECK: (rec
57+
;; CHECK-NEXT: (type $r1 (struct (field (ref $r1)) (field (ref $r2)) (field (ref eq))))
58+
(type $r1 (struct (field (ref $r1) (ref $r2) (ref $t1))))
59+
;; CHECK: (type $r2 (struct (field (ref $r1)) (field (ref $r2)) (field (ref $t2))))
60+
(type $r2 (struct (field (ref $r1) (ref $r2) (ref $t2))))
61+
)
62+
63+
(func (export "h") (param $x (ref eq)) (result (ref $r1))
64+
(ref.cast (ref $r1) (local.get $x)))
65+
)
66+
67+
;; CHECK: (type $5 (func (param (ref eq) (ref $t2) (ref $t3) (ref $t4))))
68+
69+
;; CHECK: (type $6 (func (param (ref any)) (result (ref eq))))
70+
71+
;; CHECK: (type $7 (func (param (ref any)) (result (ref $t2))))
72+
73+
;; CHECK: (type $8 (func (param (ref any)) (result (ref $t3))))
74+
75+
;; CHECK: (type $9 (func (param (ref any)) (result (ref $t4))))
76+
77+
;; CHECK: (type $10 (func (param (ref eq)) (result (ref $r1))))
78+
79+
;; CHECK: (type $11 (func (param (ref $t2))))
80+
81+
;; CHECK: (export "t2" (type $t2))
82+
83+
;; CHECK: (export "t3" (type $t3))
84+
85+
;; CHECK: (export "f" (func $0))
86+
87+
;; CHECK: (export "g1" (func $1))
88+
89+
;; CHECK: (export "g2" (func $2))
90+
91+
;; CHECK: (export "g3" (func $3))
92+
93+
;; CHECK: (export "g4" (func $4))
94+
95+
;; CHECK: (export "h" (func $5))
96+
97+
;; CHECK: (export "g" (func $g_7))
98+
99+
;; CHECK: (func $0 (type $5) (param $0 (ref eq)) (param $1 (ref $t2)) (param $2 (ref $t3)) (param $3 (ref $t4))
100+
;; CHECK-NEXT: )
101+
102+
;; CHECK: (func $1 (type $6) (param $x (ref any)) (result (ref eq))
103+
;; CHECK-NEXT: (ref.cast (ref eq)
104+
;; CHECK-NEXT: (local.get $x)
105+
;; CHECK-NEXT: )
106+
;; CHECK-NEXT: )
107+
108+
;; CHECK: (func $2 (type $7) (param $x (ref any)) (result (ref $t2))
109+
;; CHECK-NEXT: (ref.cast (ref $t2)
110+
;; CHECK-NEXT: (local.get $x)
111+
;; CHECK-NEXT: )
112+
;; CHECK-NEXT: )
113+
114+
;; CHECK: (func $3 (type $8) (param $x (ref any)) (result (ref $t3))
115+
;; CHECK-NEXT: (ref.cast (ref $t3)
116+
;; CHECK-NEXT: (local.get $x)
117+
;; CHECK-NEXT: )
118+
;; CHECK-NEXT: )
119+
120+
;; CHECK: (func $4 (type $9) (param $x (ref any)) (result (ref $t4))
121+
;; CHECK-NEXT: (ref.cast (ref $t4)
122+
;; CHECK-NEXT: (local.get $x)
123+
;; CHECK-NEXT: )
124+
;; CHECK-NEXT: )
125+
126+
;; CHECK: (func $5 (type $10) (param $x (ref eq)) (result (ref $r1))
127+
;; CHECK-NEXT: (ref.cast (ref $r1)
128+
;; CHECK-NEXT: (local.get $x)
129+
;; CHECK-NEXT: )
130+
;; CHECK-NEXT: )
131+
132+
;; CHECK: (func $g_7 (type $11) (param $0 (ref $t2))
133+
;; CHECK-NEXT: )
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(module
2+
(export "t1" (type eq))
3+
(import "third" "t3" (type $t3 (sub struct)))
4+
(type $t2 (export "t2") (array i8))
5+
(export "t3" (type $t3))
6+
(func $g (export "g") (param (ref $t2)))
7+
)

0 commit comments

Comments
 (0)