Skip to content

Commit 451064e

Browse files
committed
Add some wast tests for async
1 parent 57510bc commit 451064e

6 files changed

Lines changed: 186 additions & 0 deletions

File tree

test/async/deadlock.wast

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
(component
2+
(component $C
3+
(core module $Memory (memory (export "mem") 1))
4+
(core instance $memory (instantiate $Memory))
5+
(core module $CM
6+
(import "" "mem" (memory 1))
7+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
8+
9+
(func (export "f") (result i32)
10+
(local $ws i32)
11+
;; return WAIT on an empty waitable set
12+
(local.set $ws (call $waitable-set.new))
13+
(i32.or (i32.const 2 (; WAIT ;)) (i32.shl (local.get $ws) (i32.const 4)))
14+
)
15+
(func (export "cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)
16+
unreachable
17+
)
18+
)
19+
(canon waitable-set.new (core func $waitable-set.new))
20+
(core instance $cm (instantiate $CM (with "" (instance
21+
(export "mem" (memory $memory "mem"))
22+
(export "waitable-set.new" (func $waitable-set.new))
23+
))))
24+
(func (export "f") (result u32) (canon lift
25+
(core func $cm "f")
26+
async (memory $memory "mem") (callback (func $cm "cb"))
27+
))
28+
)
29+
30+
(component $D
31+
(import "f" (func $f (result u32)))
32+
33+
(core module $Memory (memory (export "mem") 1))
34+
(core instance $memory (instantiate $Memory))
35+
(core module $DM
36+
(import "" "mem" (memory 1))
37+
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
38+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
39+
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
40+
(import "" "f" (func $f (param i32 i32) (result i32)))
41+
42+
(func (export "g") (result i32)
43+
(local $ws i32) (local $ret i32) (local $subtaski i32)
44+
(local.set $ws (call $waitable-set.new))
45+
(local.set $ret (call $f (i32.const 0) (i32.const 0)))
46+
(local.set $subtaski (i32.shr_u (local.get $ret) (i32.const 4)))
47+
(call $waitable.join (local.get $subtaski) (local.get $ws))
48+
(call $waitable-set.wait (local.get $ws) (i32.const 0))
49+
unreachable
50+
)
51+
)
52+
(canon waitable.join (core func $waitable.join))
53+
(canon waitable-set.new (core func $waitable-set.new))
54+
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
55+
(canon lower (func $f) async (memory $memory "mem") (core func $f'))
56+
(core instance $dm (instantiate $DM (with "" (instance
57+
(export "mem" (memory $memory "mem"))
58+
(export "waitable.join" (func $waitable.join))
59+
(export "waitable-set.new" (func $waitable-set.new))
60+
(export "waitable-set.wait" (func $waitable-set.wait))
61+
(export "f" (func $f'))
62+
))))
63+
(func (export "f") (result u32) (canon lift (core func $dm "g")))
64+
)
65+
66+
(instance $c (instantiate $C))
67+
(instance $d (instantiate $D (with "f" (func $c "f"))))
68+
(func (export "f") (alias export $d "f"))
69+
)
70+
(assert_trap (invoke "f") "wasm trap: async-lifted export failed to produce a result")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: particularly multiple into the same buffer and it all happening eagerly w/o blocking

test/async/subtasks.wast

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
(component
2+
(component $C
3+
(core module $Memory (memory (export "mem") 1))
4+
(core instance $memory (instantiate $Memory))
5+
(core module $CM
6+
(import "" "mem" (memory 1))
7+
(import "" "task.return" (func $return (param i32)))
8+
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
9+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
10+
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
11+
12+
(global $ws (mut i32) (i32.const 0))
13+
(func $start (global.set $ws (call $waitable-set.new)))
14+
(start $start)
15+
16+
(func (export "f") (result i32)
17+
(i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))
18+
;; (i32.const 1 (; YIELD ;))
19+
)
20+
(func (export "cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)
21+
unreachable
22+
;; TODO
23+
;; (if (i32.ne (i32.const 4 (; FUTURE_READ ;)) (local.get $event_code))
24+
;; (then unreachable))
25+
(if (i32.ne (i32.const 0 (; NONE ;)) (local.get $event_code))
26+
(then unreachable))
27+
(if (i32.ne (i32.const 0) (local.get $index))
28+
(then unreachable))
29+
(if (i32.ne (i32.const 0) (local.get $payload))
30+
(then unreachable))
31+
32+
(call $return (i32.const 42))
33+
(i32.const 0))
34+
)
35+
(canon task.return (result u32) (core func $task.return))
36+
(canon waitable.join (core func $waitable.join))
37+
(canon waitable-set.new (core func $waitable-set.new))
38+
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
39+
(core instance $cm (instantiate $CM (with "" (instance
40+
(export "mem" (memory $memory "mem"))
41+
(export "task.return" (func $task.return))
42+
(export "waitable.join" (func $waitable.join))
43+
(export "waitable-set.new" (func $waitable-set.new))
44+
(export "waitable-set.wait" (func $waitable-set.wait))
45+
))))
46+
(func (export "f") (result u32) (canon lift
47+
(core func $cm "f")
48+
async (memory $memory "mem") (callback (func $cm "cb"))
49+
))
50+
)
51+
52+
(component $D
53+
(import "f" (func $f (result u32)))
54+
55+
(core module $Memory (memory (export "mem") 1))
56+
(core instance $memory (instantiate $Memory))
57+
(core module $DM
58+
(import "" "mem" (memory 1))
59+
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
60+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
61+
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
62+
(import "" "f" (func $f (param i32 i32) (result i32)))
63+
64+
(global $ws (mut i32) (i32.const 0))
65+
(func $start (global.set $ws (call $waitable-set.new)))
66+
(start $start)
67+
68+
(func (export "g") (result i32)
69+
(local $ret i32) (local $subtaski i32) (local $event_code i32) (local $retp i32)
70+
71+
;; call async import
72+
(local.set $ret (call $f (i32.const 0) (i32.const 0)))
73+
(if (i32.ne (i32.const 1 (; STARTING ;)) (i32.and (local.get $ret) (i32.const 0xf)))
74+
(then unreachable))
75+
(local.set $subtaski (i32.shr_u (local.get $ret) (i32.const 4)))
76+
(if (i32.ne (i32.const 2) (local.get $subtaski))
77+
(then unreachable))
78+
79+
;; wait on the subtask
80+
(call $waitable.join (local.get $subtaski) (global.get $ws))
81+
(local.set $retp (i32.const 0))
82+
(local.set $event_code (call $waitable-set.wait (global.get $ws) (local.get $retp)))
83+
unreachable
84+
(if (i32.ne (i32.const 1 (; SUBTASK ;)) (local.get $event_code))
85+
(then unreachable))
86+
(if (i32.ne (local.get $subtaski) (i32.load (local.get $retp)))
87+
(then unreachable))
88+
(if (i32.ne (i32.const 2 (; RETURNED ;)) (i32.load offset=4 (local.get $retp)))
89+
(then unreachable))
90+
91+
(i32.const 42)
92+
)
93+
)
94+
(canon waitable.join (core func $waitable.join))
95+
(canon waitable-set.new (core func $waitable-set.new))
96+
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
97+
(canon lower (func $f) async (memory $memory "mem") (core func $f'))
98+
(core instance $dm (instantiate $DM (with "" (instance
99+
(export "mem" (memory $memory "mem"))
100+
(export "waitable.join" (func $waitable.join))
101+
(export "waitable-set.new" (func $waitable-set.new))
102+
(export "waitable-set.wait" (func $waitable-set.wait))
103+
(export "f" (func $f'))
104+
))))
105+
(func (export "f") (result u32) (canon lift (core func $dm "g")))
106+
)
107+
108+
(instance $c (instantiate $C))
109+
(instance $d (instantiate $D (with "f" (func $c "f"))))
110+
(func (export "f") (alias export $d "f"))
111+
)
112+
(assert_return (invoke "f") (u32.const 42))

test/async/zero-length.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

test/resources/basic.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

test/values/basic.wast

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

0 commit comments

Comments
 (0)