Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit cfc95e7

Browse files
authored
Merge pull request #212 from bytecodealliance/dicej/test-for-209
add test coverage for issue 209
2 parents 41765de + f50cf89 commit cfc95e7

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
;;! component_model_async = true
2+
;;! reference_types = true
3+
;;! gc_types = true
4+
;;! multi_memory = true
5+
6+
;; This test defines components $C and $D where $D imports and calls $C
7+
;; $C.f waits on an empty waitable set
8+
;; $D.g calls $C.f and then waits for it to finish, which fails due to deadlock
9+
;;
10+
;; (Copied from
11+
;; https://github.com/WebAssembly/component-model/blob/89dcdd7b52989c60e03386ea7f1e216d89e854c5/test/async/deadlock.wast)
12+
(component definition $Tester
13+
(component $C
14+
(core module $Memory (memory (export "mem") 1))
15+
(core instance $memory (instantiate $Memory))
16+
(core module $CM
17+
(import "" "mem" (memory 1))
18+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
19+
20+
(func (export "f") (result i32)
21+
;; wait on a new empty waitable set
22+
(local $ws i32)
23+
(local.set $ws (call $waitable-set.new))
24+
(i32.or (i32.const 2 (; WAIT ;)) (i32.shl (local.get $ws) (i32.const 4)))
25+
)
26+
(func (export "cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)
27+
unreachable
28+
)
29+
)
30+
(canon waitable-set.new (core func $waitable-set.new))
31+
(core instance $cm (instantiate $CM (with "" (instance
32+
(export "mem" (memory $memory "mem"))
33+
(export "waitable-set.new" (func $waitable-set.new))
34+
))))
35+
(func (export "f") (result u32) (canon lift
36+
(core func $cm "f")
37+
async (memory $memory "mem") (callback (func $cm "cb"))
38+
))
39+
)
40+
41+
(component $D
42+
(import "f" (func $f (result u32)))
43+
44+
(core module $Memory (memory (export "mem") 1))
45+
(core instance $memory (instantiate $Memory))
46+
(core module $DM
47+
(import "" "mem" (memory 1))
48+
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
49+
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
50+
(import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))
51+
(import "" "f" (func $f (param i32) (result i32)))
52+
53+
(func (export "g") (result i32)
54+
(local $ws i32) (local $ret i32) (local $subtaski i32)
55+
(local.set $ret (call $f (i32.const 0)))
56+
(local.set $subtaski (i32.shr_u (local.get $ret) (i32.const 4)))
57+
(local.set $ws (call $waitable-set.new))
58+
(call $waitable.join (local.get $subtaski) (local.get $ws))
59+
(call $waitable-set.wait (local.get $ws) (i32.const 0))
60+
unreachable
61+
)
62+
)
63+
(canon waitable.join (core func $waitable.join))
64+
(canon waitable-set.new (core func $waitable-set.new))
65+
(canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))
66+
(canon lower (func $f) async (memory $memory "mem") (core func $f'))
67+
(core instance $dm (instantiate $DM (with "" (instance
68+
(export "mem" (memory $memory "mem"))
69+
(export "waitable.join" (func $waitable.join))
70+
(export "waitable-set.new" (func $waitable-set.new))
71+
(export "waitable-set.wait" (func $waitable-set.wait))
72+
(export "f" (func $f'))
73+
))))
74+
(func (export "f") (result u32) (canon lift (core func $dm "g")))
75+
)
76+
77+
(instance $c (instantiate $C))
78+
(instance $d (instantiate $D (with "f" (func $c "f"))))
79+
(func (export "f") (alias export $d "f"))
80+
)
81+
(component instance $i1 $Tester)
82+
(assert_trap (invoke "f") "wasm trap: deadlock detected: event loop cannot make further progress")
83+
;; Run it once more to test https://github.com/bytecodealliance/wasip3-prototyping/issues/209
84+
(component instance $i2 $Tester)
85+
(assert_trap (invoke "f") "wasm trap: deadlock detected: event loop cannot make further progress")

0 commit comments

Comments
 (0)