Skip to content

Commit 1a37eb3

Browse files
committed
add host-calling return_call .wast tests
Signed-off-by: Robin Freyler <[email protected]>
1 parent e29d5cc commit 1a37eb3

File tree

5 files changed

+1042
-0
lines changed

5 files changed

+1042
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,47 @@ In particular this repository contains the following subsets of the official Was
1111
- This has been modified to remove references from Wasm proposals unsupported by Wasmi such as the `exceptions` and `function-references` proposal.
1212
- At the time of writing this the Wasm spec testsuite is about to be moved over to Wasm 3.0 while Wasmi does not even support all of Wasm 2.0.
1313
Therefore, for a subset of the Wasm spec testsuite features we rely on this fork to provide the proper tests that can be consumed by Wasmi.
14+
15+
## Wasmi Test Module
16+
17+
Similar to the Wasm spec testsuite the Wasmi tests also require a specific test module setup.
18+
The Wasmi test module (exported as `"wasmitest"`) requires the following function definitions used to test host function calls.
19+
20+
See below for their definitions in WebAssembly Text (Wat) format:
21+
22+
```wasm
23+
(func (export "identity-0"))
24+
25+
(func (export "identity-1") (param i64) (result i64)
26+
(local.get 0)
27+
)
28+
29+
(func (export "identity-2") (param i64 i64) (result i64 i64)
30+
(local.get 0)
31+
)
32+
33+
(func (export "offset-1") (param i64) (result i64)
34+
(i64.add (local.get 0) (i64.const 1))
35+
)
36+
37+
(func (export "offset-2") (param i64 i64) (result i64 i64)
38+
(i64.add (local.get 0) (i64.const 1))
39+
(i64.add (local.get 1) (i64.const 2))
40+
)
41+
42+
(func (export "sum-3") (param i64 i64 i64) (result i64)
43+
(i64.add
44+
(local.get 0)
45+
(i64.add
46+
(local.get 1)
47+
(local.get 2)
48+
)
49+
)
50+
)
51+
52+
(func (export "iota-3") (param i64) (result i64 i64 i64)
53+
(i64.add (local.get 0) (i64.const 1))
54+
(i64.add (local.get 0) (i64.const 2))
55+
(i64.add (local.get 0) (i64.const 3))
56+
)
57+
```

tests/call-indirect.wast

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
(module
2+
;; We define this module to check if Wasmi's expected test module setup was successful.
3+
(import "wasmitest" "identity-0" (func $identity-0))
4+
(import "wasmitest" "identity-1" (func $identity-1 (param i64) (result i64)))
5+
(import "wasmitest" "identity-2" (func $identity-2 (param i64 i64) (result i64 i64)))
6+
(import "wasmitest" "offset-1" (func $offset-1 (param i64) (result i64)))
7+
(import "wasmitest" "offset-2" (func $offset-2 (param i64 i64) (result i64 i64)))
8+
(import "wasmitest" "sum-3" (func $sum-3 (param i64 i64 i64) (result i64)))
9+
(import "wasmitest" "iota-3" (func $iota-3 (param i64) (result i64 i64 i64)))
10+
11+
(table funcref
12+
(elem
13+
$identity-0 ;; 0
14+
$identity-1 ;; 1
15+
$identity-2 ;; 2
16+
$offset-1 ;; 3
17+
$offset-2 ;; 4
18+
$sum-3 ;; 5
19+
$iota-3 ;; 6
20+
)
21+
)
22+
)
23+
24+
(module
25+
(type $ty (func))
26+
(import "wasmitest" "identity-0" (func $identity-0))
27+
(table $t funcref (elem $identity-0))
28+
(func (export "call-identity-0") (type $ty)
29+
(call_indirect $t (type $ty)
30+
(i32.const 0) ;; index
31+
)
32+
)
33+
)
34+
(assert_return
35+
(invoke "call-identity-0")
36+
)
37+
38+
(module
39+
(type $ty (func (param i64) (result i64)))
40+
(import "wasmitest" "identity-1" (func $identity-1 (type $ty)))
41+
(table $t funcref (elem $identity-1))
42+
(func (export "call-identity-1") (type $ty)
43+
(call_indirect $t (type $ty)
44+
(local.get 0)
45+
(i32.const 0) ;; index
46+
)
47+
)
48+
)
49+
(assert_return
50+
(invoke "call-identity-1" (i64.const 0))
51+
(i64.const 0)
52+
)
53+
(assert_return
54+
(invoke "call-identity-1" (i64.const 1))
55+
(i64.const 1)
56+
)
57+
(assert_return
58+
(invoke "call-identity-1" (i64.const -1))
59+
(i64.const -1)
60+
)
61+
62+
(module
63+
(type $ty (func (param i64 i64) (result i64 i64)))
64+
(import "wasmitest" "identity-2" (func $identity-2 (type $ty)))
65+
(table $t funcref (elem $identity-2))
66+
(func (export "call-identity-2") (type $ty)
67+
(call_indirect $t (type $ty)
68+
(local.get 0)
69+
(local.get 1)
70+
(i32.const 0) ;; index
71+
)
72+
)
73+
)
74+
(assert_return
75+
(invoke "call-identity-2" (i64.const 0) (i64.const 0))
76+
(i64.const 0) (i64.const 0)
77+
)
78+
(assert_return
79+
(invoke "call-identity-2" (i64.const 0) (i64.const 1))
80+
(i64.const 0) (i64.const 1)
81+
)
82+
(assert_return
83+
(invoke "call-identity-2" (i64.const 1) (i64.const 0))
84+
(i64.const 1) (i64.const 0)
85+
)
86+
(assert_return
87+
(invoke "call-identity-2" (i64.const 1) (i64.const 1))
88+
(i64.const 1) (i64.const 1)
89+
)
90+
91+
(module
92+
(type $ty (func (param i64) (result i64)))
93+
(import "wasmitest" "offset-1" (func $offset-1 (type $ty)))
94+
(table $t funcref (elem $offset-1))
95+
(func (export "call-offset-1") (type $ty)
96+
(call_indirect $t (type $ty)
97+
(local.get 0)
98+
(i32.const 0) ;; index
99+
)
100+
)
101+
)
102+
(assert_return
103+
(invoke "call-offset-1" (i64.const 0))
104+
(i64.const 1)
105+
)
106+
(assert_return
107+
(invoke "call-offset-1" (i64.const 1))
108+
(i64.const 2)
109+
)
110+
(assert_return
111+
(invoke "call-offset-1" (i64.const -1))
112+
(i64.const 0)
113+
)
114+
115+
(module
116+
(type $ty (func (param i64 i64) (result i64 i64)))
117+
(import "wasmitest" "offset-2" (func $offset-2 (type $ty)))
118+
(table $t funcref (elem $offset-2))
119+
(func (export "call-offset-2") (type $ty)
120+
(call_indirect $t (type $ty)
121+
(local.get 0)
122+
(local.get 1)
123+
(i32.const 0) ;; index
124+
)
125+
)
126+
)
127+
(assert_return
128+
(invoke "call-offset-2" (i64.const 0) (i64.const 0))
129+
(i64.const 1) (i64.const 2)
130+
)
131+
(assert_return
132+
(invoke "call-offset-2" (i64.const 0) (i64.const 1))
133+
(i64.const 1) (i64.const 3)
134+
)
135+
(assert_return
136+
(invoke "call-offset-2" (i64.const 1) (i64.const 0))
137+
(i64.const 2) (i64.const 2)
138+
)
139+
(assert_return
140+
(invoke "call-offset-2" (i64.const 1) (i64.const 1))
141+
(i64.const 2) (i64.const 3)
142+
)
143+
144+
(module
145+
(type $ty (func (param i64 i64 i64) (result i64)))
146+
(import "wasmitest" "sum-3" (func $sum-3 (type $ty)))
147+
(table $t funcref (elem $sum-3))
148+
(func (export "call-sum-3") (type $ty)
149+
(call_indirect $t (type $ty)
150+
(local.get 0)
151+
(local.get 1)
152+
(local.get 2)
153+
(i32.const 0) ;; index
154+
)
155+
)
156+
)
157+
(assert_return
158+
(invoke "call-sum-3" (i64.const 0) (i64.const 0) (i64.const 0))
159+
(i64.const 0)
160+
)
161+
(assert_return
162+
(invoke "call-sum-3" (i64.const 1) (i64.const 2) (i64.const 3))
163+
(i64.const 6)
164+
)
165+
(assert_return
166+
(invoke "call-sum-3" (i64.const -1) (i64.const 0) (i64.const 1))
167+
(i64.const 0)
168+
)
169+
(assert_return
170+
(invoke "call-sum-3" (i64.const -1) (i64.const -1) (i64.const -1))
171+
(i64.const -3)
172+
)
173+
174+
(module
175+
(type $ty (func (param i64) (result i64 i64 i64)))
176+
(import "wasmitest" "iota-3" (func $iota-3 (type $ty)))
177+
(table $t funcref (elem $iota-3))
178+
(func (export "call-iota-3") (type $ty)
179+
(call_indirect $t (type $ty)
180+
(local.get 0)
181+
(i32.const 0) ;; index
182+
)
183+
)
184+
)
185+
(assert_return
186+
(invoke "call-iota-3" (i64.const 0))
187+
(i64.const 1) (i64.const 2) (i64.const 3)
188+
)
189+
(assert_return
190+
(invoke "call-iota-3" (i64.const 100))
191+
(i64.const 101) (i64.const 102) (i64.const 103)
192+
)
193+
(assert_return
194+
(invoke "call-iota-3" (i64.const -3))
195+
(i64.const -2) (i64.const -1) (i64.const 0)
196+
)

0 commit comments

Comments
 (0)