Skip to content

Commit 615b8ff

Browse files
committed
add host call test cases
Signed-off-by: Robin Freyler <[email protected]>
1 parent 1a37eb3 commit 615b8ff

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

tests/call.wast

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,71 @@
160160
(invoke "call-iota-3" (i64.const -3))
161161
(i64.const -2) (i64.const -1) (i64.const 0)
162162
)
163+
164+
;; The exported functions call the imported identity host functions `n` times.
165+
;; The host functions are supposed to be identity functions with fixed arity.
166+
;;
167+
;; After successful execution the exported functions returns 0.
168+
(module
169+
(import "wasmitest" "identity-0" (func $identity-0))
170+
(import "wasmitest" "identity-1" (func $identity-1 (param i64) (result i64)))
171+
(import "wasmitest" "identity-2" (func $identity-2 (param i64 i64) (result i64 i64)))
172+
173+
(func (export "n-times-identity-0") (param $n i64) (result i64)
174+
(loop $continue
175+
(if
176+
(i64.eqz (local.get $n))
177+
(then
178+
(return (i64.const 0))
179+
)
180+
)
181+
(call $identity-0)
182+
(local.set $n (i64.sub (local.get $n) (i64.const 1)))
183+
(br $continue)
184+
)
185+
(unreachable)
186+
)
187+
188+
(func (export "n-times-identity-1") (param $n i64) (result i64)
189+
(loop $continue
190+
(if
191+
(i64.eqz (local.get $n))
192+
(then
193+
(return (i64.const 0))
194+
)
195+
)
196+
(drop (call $identity-1 (local.get $n)))
197+
(local.set $n (i64.sub (local.get $n) (i64.const 1)))
198+
(br $continue)
199+
)
200+
(unreachable)
201+
)
202+
203+
(func (export "n-times-identity-2") (param $n i64) (result i64)
204+
(loop $continue
205+
(if
206+
(i64.eqz (local.get $n))
207+
(then
208+
(return (i64.const 0))
209+
)
210+
)
211+
(call $identity-2
212+
(local.get $n) (local.get $n)
213+
)
214+
;; drop all return values from the host function call
215+
(drop) (drop)
216+
(local.set $n (i64.sub (local.get $n) (i64.const 1)))
217+
(br $continue)
218+
)
219+
(unreachable)
220+
)
221+
)
222+
(assert_return (invoke "n-times-identity-0" (i64.const 0)) (i64.const 0))
223+
(assert_return (invoke "n-times-identity-0" (i64.const 1)) (i64.const 0))
224+
(assert_return (invoke "n-times-identity-0" (i64.const 10)) (i64.const 0))
225+
(assert_return (invoke "n-times-identity-1" (i64.const 0)) (i64.const 0))
226+
(assert_return (invoke "n-times-identity-1" (i64.const 1)) (i64.const 0))
227+
(assert_return (invoke "n-times-identity-1" (i64.const 10)) (i64.const 0))
228+
(assert_return (invoke "n-times-identity-2" (i64.const 0)) (i64.const 0))
229+
(assert_return (invoke "n-times-identity-2" (i64.const 1)) (i64.const 0))
230+
(assert_return (invoke "n-times-identity-2" (i64.const 10)) (i64.const 0))

tests/return-call.wast

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,81 @@
324324
(assert_return (invoke "is-odd" (i32.const 7)) (i32.const 1))
325325
(assert_return (invoke "is-odd" (i32.const 8)) (i32.const 0))
326326
(assert_return (invoke "is-odd" (i32.const 9)) (i32.const 1))
327+
328+
;; The exported functions call the imported identity host functions `n` times.
329+
;; The host functions are supposed to be identity functions with fixed arity.
330+
;;
331+
;; After successful execution the exported functions returns 0.
332+
(module
333+
(import "wasmitest" "identity-0" (func $identity-0))
334+
(import "wasmitest" "identity-1" (func $identity-1 (param i64) (result i64)))
335+
(import "wasmitest" "identity-2" (func $identity-2 (param i64 i64) (result i64 i64)))
336+
337+
(func $forward-identity-0
338+
(return_call $identity-0)
339+
)
340+
(func $forward-identity-1 (param i64) (result i64)
341+
(return_call $identity-1 (local.get 0))
342+
)
343+
(func $forward-identity-2 (param i64 i64) (result i64 i64)
344+
(return_call $identity-2 (local.get 0) (local.get 1))
345+
)
346+
347+
(func (export "n-times-identity-0") (param $n i64) (result i64)
348+
(loop $continue
349+
(if
350+
(i64.eqz (local.get $n))
351+
(then
352+
(return (i64.const 0))
353+
)
354+
)
355+
(call $forward-identity-0)
356+
(local.set $n (i64.sub (local.get $n) (i64.const 1)))
357+
(br $continue)
358+
)
359+
(unreachable)
360+
)
361+
362+
(func (export "n-times-identity-1") (param $n i64) (result i64)
363+
(loop $continue
364+
(if
365+
(i64.eqz (local.get $n))
366+
(then
367+
(return (i64.const 0))
368+
)
369+
)
370+
(drop (call $forward-identity-1 (local.get $n)))
371+
(local.set $n (i64.sub (local.get $n) (i64.const 1)))
372+
(br $continue)
373+
)
374+
(unreachable)
375+
)
376+
377+
(func (export "n-times-identity-2") (param $n i64) (result i64)
378+
(loop $continue
379+
(if
380+
(i64.eqz (local.get $n))
381+
(then
382+
(return (i64.const 0))
383+
)
384+
)
385+
(call $forward-identity-2
386+
(local.get $n) (local.get $n)
387+
)
388+
;; drop all return values from the host function call
389+
(drop) (drop)
390+
(local.set $n (i64.sub (local.get $n) (i64.const 1)))
391+
(br $continue)
392+
)
393+
(unreachable)
394+
)
395+
)
396+
(assert_return (invoke "n-times-identity-0" (i64.const 0)) (i64.const 0))
397+
(assert_return (invoke "n-times-identity-0" (i64.const 1)) (i64.const 0))
398+
(assert_return (invoke "n-times-identity-0" (i64.const 10)) (i64.const 0))
399+
(assert_return (invoke "n-times-identity-1" (i64.const 0)) (i64.const 0))
400+
(assert_return (invoke "n-times-identity-1" (i64.const 1)) (i64.const 0))
401+
(assert_return (invoke "n-times-identity-1" (i64.const 10)) (i64.const 0))
402+
(assert_return (invoke "n-times-identity-2" (i64.const 0)) (i64.const 0))
403+
(assert_return (invoke "n-times-identity-2" (i64.const 1)) (i64.const 0))
404+
(assert_return (invoke "n-times-identity-2" (i64.const 10)) (i64.const 0))

0 commit comments

Comments
 (0)