Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions test/async/trap-if-sync-and-waitable-set.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
;; Tests the trap conditions associated with mixing synchronous and
;; asynchronous waiting on the same waitable.
;; asynchronous waiting on the same waitable. For streams and futures, only
;; the synchronous forms of {read,write,cancel-read,cancel-write} trap when
;; the waitable is in a waitable set. For subtask.cancel, *both* the sync and
;; async forms trap: even the async form waits on the subtask (claiming it and
;; consuming its resolution event), which a waitable set could otherwise
;; "steal".
(component definition $Tester
(component $C
(core module $CM
Expand Down Expand Up @@ -37,6 +42,7 @@
(import "" "waitable-set.new" (func $waitable-set.new (result i32)))
(import "" "waitable.join" (func $waitable.join (param i32 i32)))
(import "" "subtask.cancel-sync" (func $subtask.cancel-sync (param i32) (result i32)))
(import "" "subtask.cancel-async" (func $subtask.cancel-async (param i32) (result i32)))
(import "" "future.new" (func $future.new (result i64)))
(import "" "future.read-sync" (func $future.read-sync (param i32 i32) (result i32)))
(import "" "future.write-sync" (func $future.write-sync (param i32 i32) (result i32)))
Expand Down Expand Up @@ -184,7 +190,7 @@
unreachable
)

(func (export "sync-subtask-cancel-when-in-set")
(func (export "subtask-cancel-sync-when-in-set")
(local $ret i32) (local $sub i32)
(local.set $ret (call $blocks-forever (i32.const 0)))
(if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))
Expand All @@ -194,6 +200,16 @@
(drop (call $subtask.cancel-sync (local.get $sub)))
unreachable
)
(func (export "subtask-cancel-async-when-in-set")
(local $ret i32) (local $sub i32)
(local.set $ret (call $blocks-forever (i32.const 0)))
(if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))
(then unreachable))
(local.set $sub (i32.shr_u (local.get $ret) (i32.const 4)))
(call $waitable.join (local.get $sub) (call $waitable-set.new))
(drop (call $subtask.cancel-async (local.get $sub)))
unreachable
)
)

(core type $start-func-ty (func (param i32)))
Expand All @@ -204,6 +220,7 @@
(core func $waitable-set.new (canon waitable-set.new))
(core func $waitable.join (canon waitable.join))
(core func $subtask.cancel-sync (canon subtask.cancel))
(core func $subtask.cancel-async (canon subtask.cancel async))
(type $future (future))
(type $stream (stream u8))
(core func $future.new (canon future.new $future))
Expand All @@ -229,6 +246,7 @@
(export "waitable-set.new" (func $waitable-set.new))
(export "waitable.join" (func $waitable.join))
(export "subtask.cancel-sync" (func $subtask.cancel-sync))
(export "subtask.cancel-async" (func $subtask.cancel-async))
(export "future.new" (func $future.new))
(export "future.read-sync" (func $future.read-sync))
(export "future.write-sync" (func $future.write-sync))
Expand Down Expand Up @@ -259,7 +277,8 @@
(func (export "sync-future-cancel-write-when-in-set") async (canon lift (core func $m "sync-future-cancel-write-when-in-set")))
(func (export "sync-stream-cancel-read-when-in-set") async (canon lift (core func $m "sync-stream-cancel-read-when-in-set")))
(func (export "sync-stream-cancel-write-when-in-set") async (canon lift (core func $m "sync-stream-cancel-write-when-in-set")))
(func (export "sync-subtask-cancel-when-in-set") async (canon lift (core func $m "sync-subtask-cancel-when-in-set")))
(func (export "subtask-cancel-sync-when-in-set") async (canon lift (core func $m "subtask-cancel-sync-when-in-set")))
(func (export "subtask-cancel-async-when-in-set") async (canon lift (core func $m "subtask-cancel-async-when-in-set")))
)
(instance $main (instantiate $Main (with "c" (instance $c))))
(func (export "join-during-sync-future-read") (alias export $main "join-during-sync-future-read"))
Expand All @@ -274,7 +293,8 @@
(func (export "sync-future-cancel-write-when-in-set") (alias export $main "sync-future-cancel-write-when-in-set"))
(func (export "sync-stream-cancel-read-when-in-set") (alias export $main "sync-stream-cancel-read-when-in-set"))
(func (export "sync-stream-cancel-write-when-in-set") (alias export $main "sync-stream-cancel-write-when-in-set"))
(func (export "sync-subtask-cancel-when-in-set") (alias export $main "sync-subtask-cancel-when-in-set"))
(func (export "subtask-cancel-sync-when-in-set") (alias export $main "subtask-cancel-sync-when-in-set"))
(func (export "subtask-cancel-async-when-in-set") (alias export $main "subtask-cancel-async-when-in-set"))
)

(component instance $i $Tester)
Expand Down Expand Up @@ -302,4 +322,6 @@
(component instance $i $Tester)
(assert_trap (invoke "sync-stream-cancel-write-when-in-set") "waitable cannot be used synchronously while added to a waitable set")
(component instance $i $Tester)
(assert_trap (invoke "sync-subtask-cancel-when-in-set") "waitable cannot be used synchronously while added to a waitable set")
(assert_trap (invoke "subtask-cancel-sync-when-in-set") "waitable cannot be used synchronously while added to a waitable set")
(component instance $i $Tester)
(assert_trap (invoke "subtask-cancel-async-when-in-set") "waitable cannot be used synchronously while added to a waitable set")
1 change: 1 addition & 0 deletions test/nyi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
./async/reentrance.wast
./async/sync-streams.wast
./validation/kebab.wast
./async/trap-if-sync-and-waitable-set.wast
Loading