Skip to content

Commit 2c5096b

Browse files
committed
Add some wast tests for async
1 parent 935c478 commit 2c5096b

6 files changed

Lines changed: 203 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: deadlock detected: event loop cannot make further progress")
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: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
(component
2+
;; This test has two components $C and $D, where $D imports and calls $C
3+
(component $C
4+
(core module $Memory (memory (export "mem") 1))
5+
(core instance $memory (instantiate $Memory))
6+
(core module $CM
7+
(import "" "mem" (memory 1))
8+
(import "" "task.return" (func $return (param i32)))
9+
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
10+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
11+
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
12+
13+
(global $ws (mut i32) (i32.const 0))
14+
(func $start (global.set $ws (call $waitable-set.new)))
15+
(start $start)
16+
17+
(func (export "blocker") (result i32)
18+
(i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))
19+
)
20+
(func (export "blocker_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+
(func (export "unblocker") (result i32)
36+
unreachable
37+
)
38+
(func (export "unblocker_cb") (param i32 i32 i32) (result i32)
39+
unreachable
40+
)
41+
)
42+
(canon task.return (result u32) (core func $task.return))
43+
(canon waitable.join (core func $waitable.join))
44+
(canon waitable-set.new (core func $waitable-set.new))
45+
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
46+
(core instance $cm (instantiate $CM (with "" (instance
47+
(export "mem" (memory $memory "mem"))
48+
(export "task.return" (func $task.return))
49+
(export "waitable.join" (func $waitable.join))
50+
(export "waitable-set.new" (func $waitable-set.new))
51+
(export "waitable-set.wait" (func $waitable-set.wait))
52+
))))
53+
(func (export "blocker") (result u32) (canon lift
54+
(core func $cm "blocker")
55+
async (memory $memory "mem") (callback (func $cm "blocker_cb"))
56+
))
57+
(func (export "unblocker") (result u32) (canon lift
58+
(core func $cm "unblocker")
59+
async (memory $memory "mem") (callback (func $cm "unblocker_cb"))
60+
))
61+
)
62+
63+
(component $D
64+
(import "blocker" (func $blocker (result u32)))
65+
(import "unblocker" (func $unblocker (result u32)))
66+
67+
(core module $Memory (memory (export "mem") 1))
68+
(core instance $memory (instantiate $Memory))
69+
(core module $DM
70+
(import "" "mem" (memory 1))
71+
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
72+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
73+
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
74+
(import "" "blocker" (func $blocker (param i32 i32) (result i32)))
75+
(import "" "unblocker" (func $unblocker (param i32 i32) (result i32)))
76+
77+
(global $ws (mut i32) (i32.const 0))
78+
(func $start (global.set $ws (call $waitable-set.new)))
79+
(start $start)
80+
81+
(func (export "run") (result i32)
82+
(local $ret i32) (local $subtaski i32) (local $event_code i32) (local $retp i32)
83+
84+
;; call 'blocker', which, true to its name, will block on an empty waitable set
85+
(local.set $ret (call $blocker (i32.const 0) (i32.const 0)))
86+
(if (i32.ne (i32.const 1 (; STARTING ;)) (i32.and (local.get $ret) (i32.const 0xf)))
87+
(then unreachable))
88+
(local.set $subtaski (i32.shr_u (local.get $ret) (i32.const 4)))
89+
(if (i32.ne (i32.const 2) (local.get $subtaski))
90+
(then unreachable))
91+
92+
;; call 'unblocker' to unblock the 'blocker' subtask
93+
;; TODO...
94+
95+
96+
;; wait on the subtask
97+
(call $waitable.join (local.get $subtaski) (global.get $ws))
98+
(local.set $retp (i32.const 0))
99+
(local.set $event_code (call $waitable-set.wait (global.get $ws) (local.get $retp)))
100+
unreachable
101+
(if (i32.ne (i32.const 1 (; SUBTASK ;)) (local.get $event_code))
102+
(then unreachable))
103+
(if (i32.ne (local.get $subtaski) (i32.load (local.get $retp)))
104+
(then unreachable))
105+
(if (i32.ne (i32.const 2 (; RETURNED ;)) (i32.load offset=4 (local.get $retp)))
106+
(then unreachable))
107+
108+
(i32.const 42)
109+
)
110+
)
111+
(canon waitable.join (core func $waitable.join))
112+
(canon waitable-set.new (core func $waitable-set.new))
113+
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
114+
(canon lower (func $blocker) async (memory $memory "mem") (core func $blocker'))
115+
(core instance $dm (instantiate $DM (with "" (instance
116+
(export "mem" (memory $memory "mem"))
117+
(export "waitable.join" (func $waitable.join))
118+
(export "waitable-set.new" (func $waitable-set.new))
119+
(export "waitable-set.wait" (func $waitable-set.wait))
120+
(export "blocker" (func $blocker'))
121+
))))
122+
(func (export "run") (result u32) (canon lift (core func $dm "run")))
123+
)
124+
125+
(instance $c (instantiate $C))
126+
(instance $d (instantiate $D (with "blocker" (func $c "blocker"))))
127+
(func (export "run") (alias export $d "run"))
128+
)
129+
(assert_return (invoke "run") (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)