From 795dae28504a3960226702122bbcc7f55430ce5e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 4 Feb 2026 08:04:09 -0800 Subject: [PATCH] Update wast tests for thread index changes Numbers in tests were updated to account for #600 --- test/async/async-calls-sync.wast | 32 +++++++------- test/async/cancel-stream.wast | 4 +- test/async/drop-stream.wast | 4 +- test/async/drop-waitable-set.wast | 4 +- test/async/empty-wait.wast | 6 +-- test/async/futures-must-write.wast | 4 +- test/async/partial-stream-copies.wast | 14 +++---- test/async/passing-resources.wast | 6 +-- test/resources/multiple-resources.wast | 8 ++-- test/wasmtime/resources.wast | 58 +++++++++++++------------- 10 files changed, 70 insertions(+), 70 deletions(-) diff --git a/test/async/async-calls-sync.wast b/test/async/async-calls-sync.wast index 7e04398b..5172bb40 100644 --- a/test/async/async-calls-sync.wast +++ b/test/async/async-calls-sync.wast @@ -1,7 +1,7 @@ ;; This test contains 3 components, $AsyncInner, $SyncMiddle and $AsyncOuter, ;; where there are two instances of $SyncMiddle that import a single instance ;; of $AsyncInner, and $AsyncOuter imports all 3 preceding instances. -;; +;; ;; $AsyncOuter.run asynchronously calls $SyncMiddle.sync-func twice concurrently ;; in each instance (4 total calls), hitting the synchronous backpressure case ;; in 2 of the 4 calls. @@ -19,7 +19,7 @@ (memory 1) (global $blocked (mut i32) (i32.const 1)) - (global $counter (mut i32) (i32.const 3)) + (global $counter (mut i32) (i32.const 2)) ;; 'blocking-call' cooperatively "spin-waits" until $blocked is 0. (func $blocking-call (export "blocking-call") (result i32) @@ -136,24 +136,24 @@ ;; (on $AsyncInner.blocking-call). because 'sync-func1/2' are in different instances, ;; both calls will reach the STARTED state. (local.set $ret (call $sync-func1 (i32.const 8))) - (if (i32.ne (i32.const 0x31 (; STARTED=1 | (subtask=3 << 4) ;)) (local.get $ret)) + (if (i32.ne (i32.const 0x21 (; STARTED=1 | (subtask=2 << 4) ;)) (local.get $ret)) (then unreachable)) - (call $waitable.join (i32.const 3) (global.get $ws)) + (call $waitable.join (i32.const 2) (global.get $ws)) (local.set $ret (call $sync-func2 (i32.const 12))) - (if (i32.ne (i32.const 0x41 (; STARTED=1 | (subtask=4 << 4) ;)) (local.get $ret)) + (if (i32.ne (i32.const 0x31 (; STARTED=1 | (subtask=3 << 4) ;)) (local.get $ret)) (then unreachable)) - (call $waitable.join (i32.const 4) (global.get $ws)) + (call $waitable.join (i32.const 3) (global.get $ws)) ;; now start another pair of 'sync-func1/2' calls, both of which should see auto ;; backpressure and get stuck in the STARTING state. (local.set $ret (call $sync-func1 (i32.const 16))) - (if (i32.ne (i32.const 0x50 (; STARTING=0 | (subtask=5 << 4) ;)) (local.get $ret)) + (if (i32.ne (i32.const 0x40 (; STARTING=0 | (subtask=4 << 4) ;)) (local.get $ret)) (then unreachable)) - (call $waitable.join (i32.const 5) (global.get $ws)) + (call $waitable.join (i32.const 4) (global.get $ws)) (local.set $ret (call $sync-func2 (i32.const 20))) - (if (i32.ne (i32.const 0x60 (; STARTING=0 | (subtask=6 << 4) ;)) (local.get $ret)) + (if (i32.ne (i32.const 0x50 (; STARTING=0 | (subtask=5 << 4) ;)) (local.get $ret)) (then unreachable)) - (call $waitable.join (i32.const 6) (global.get $ws)) + (call $waitable.join (i32.const 5) (global.get $ws)) ;; unblock all the tasks and start waiting to complete (call $unblock) @@ -167,21 +167,21 @@ (then unreachable)) ;; if we receive a SUBTASK STARTED event, it should only be for the 3rd or - ;; 4th subtask (at indices 5/6, resp), so keep waiting for completion + ;; 4th subtask (at indices 4/5, resp), so keep waiting for completion (if (i32.eq (local.get $payload) (i32.const 1 (; STARTED ;))) (then (if (i32.and - (i32.ne (local.get $index) (i32.const 5)) - (i32.ne (local.get $index) (i32.const 6))) + (i32.ne (local.get $index) (i32.const 4)) + (i32.ne (local.get $index) (i32.const 5))) (then unreachable)) (return (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))) )) ;; when we receive a SUBTASK RETURNED event, check the return value is equal to the - ;; subtask index (which we've ensured by having $AsyncInner.$counter start at 3, the - ;; first subtask index. The address of the return buffer is the index-1*4. + ;; subtask index (which we've ensured by having $AsyncInner.$counter start at 2, the + ;; first subtask index. The address of the return buffer is the index*4. (if (i32.ne (local.get $payload) (i32.const 2 (; RETURNED ;))) (then unreachable)) - (if (i32.ne (local.get $index) (i32.load (i32.mul (i32.sub (local.get $index) (i32.const 1)) (i32.const 4)))) + (if (i32.ne (local.get $index) (i32.load (i32.mul (local.get $index) (i32.const 4)))) (then unreachable)) ;; decrement $remain and exit if 0 diff --git a/test/async/cancel-stream.wast b/test/async/cancel-stream.wast index 602a536a..336b5acb 100644 --- a/test/async/cancel-stream.wast +++ b/test/async/cancel-stream.wast @@ -116,7 +116,7 @@ ;; call 'start-stream' to get the stream we'll be working with (local.set $sr (call $start-stream)) - (if (i32.ne (i32.const 2) (local.get $sr)) + (if (i32.ne (i32.const 1) (local.get $sr)) (then unreachable)) ;; start read that will block @@ -155,7 +155,7 @@ ;; get a new $sr (local.set $sr (call $start-stream)) - (if (i32.ne (i32.const 2) (local.get $sr)) + (if (i32.ne (i32.const 1) (local.get $sr)) (then unreachable)) ;; start outstanding write in $C, read 4 of it, then call back into $C diff --git a/test/async/drop-stream.wast b/test/async/drop-stream.wast index da7ab8f9..bf7212f2 100644 --- a/test/async/drop-stream.wast +++ b/test/async/drop-stream.wast @@ -89,7 +89,7 @@ ;; call 'start-stream' to get the stream we'll be working with (local.set $sr (call $start-stream)) - (if (i32.ne (i32.const 2) (local.get $sr)) + (if (i32.ne (i32.const 1) (local.get $sr)) (then unreachable)) ;; start a blocking read @@ -111,7 +111,7 @@ ;; call 'start-stream' to get the stream we'll be working with (local.set $sr (call $start-stream)) - (if (i32.ne (i32.const 2) (local.get $sr)) + (if (i32.ne (i32.const 1) (local.get $sr)) (then unreachable)) ;; start a blocking write and partially read from it diff --git a/test/async/drop-waitable-set.wast b/test/async/drop-waitable-set.wast index ce46bfd6..23fff15b 100644 --- a/test/async/drop-waitable-set.wast +++ b/test/async/drop-waitable-set.wast @@ -11,7 +11,7 @@ (global $ws (mut i32) (i32.const 0)) (func $start (global.set $ws (call $waitable-set.new))) (start $start) - + (func $wait-on-set (export "wait-on-set") (result i32) ;; wait on $ws (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4))) @@ -59,7 +59,7 @@ ;; start an async call to 'wait-on-set' which blocks, waiting on a ;; waitable-set. (local.set $ret (call $wait-on-set)) - (if (i32.ne (i32.const 0x21) (local.get $ret)) + (if (i32.ne (i32.const 0x11) (local.get $ret)) (then unreachable)) ;; this call will try to drop the same waitable-set, which should trap. diff --git a/test/async/empty-wait.wast b/test/async/empty-wait.wast index f8c743ef..8b4d789f 100644 --- a/test/async/empty-wait.wast +++ b/test/async/empty-wait.wast @@ -53,10 +53,10 @@ ;; create a future that will be used to unblock 'blocker', storing r/w ends in $futr/$futw (local.set $ret64 (call $future.new)) (global.set $futr (i32.wrap_i64 (local.get $ret64))) - (if (i32.ne (i32.const 4) (global.get $futr)) + (if (i32.ne (i32.const 2) (global.get $futr)) (then unreachable)) (local.set $futw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) - (if (i32.ne (i32.const 5) (local.get $futw)) + (if (i32.ne (i32.const 3) (local.get $futw)) (then unreachable)) ;; perform a future.read which will block, and add this future to the waitable-set @@ -144,7 +144,7 @@ (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf))) (then unreachable)) (local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4))) - (if (i32.ne (i32.const 3) (local.get $subtask)) + (if (i32.ne (i32.const 2) (local.get $subtask)) (then unreachable)) ;; call 'unblocker' to unblock 'blocker'; it should complete eagerly diff --git a/test/async/futures-must-write.wast b/test/async/futures-must-write.wast index 38744be1..ce2446b3 100644 --- a/test/async/futures-must-write.wast +++ b/test/async/futures-must-write.wast @@ -71,7 +71,7 @@ ;; call 'start-future' to get the future we'll be working with (local $fr i32) (local.set $fr (call $start-future)) - (if (i32.ne (i32.const 2) (local.get $fr)) + (if (i32.ne (i32.const 1) (local.get $fr)) (then unreachable)) ;; ok to immediately drop the readable end @@ -84,7 +84,7 @@ ;; call 'start-future' to get the future we'll be working with (local $fr i32) (local.set $fr (call $start-future)) - (if (i32.ne (i32.const 2) (local.get $fr)) + (if (i32.ne (i32.const 1) (local.get $fr)) (then unreachable)) ;; boom diff --git a/test/async/partial-stream-copies.wast b/test/async/partial-stream-copies.wast index d25dd977..d70ece2e 100644 --- a/test/async/partial-stream-copies.wast +++ b/test/async/partial-stream-copies.wast @@ -35,16 +35,16 @@ ;; check the incoming readable stream end (global.set $insr (local.get 0)) - (if (i32.ne (i32.const 3) (global.get $insr)) + (if (i32.ne (i32.const 2) (global.get $insr)) (then unreachable)) ;; create a new stream r/w pair $outsr/$outsw (local.set $ret64 (call $stream.new)) (local.set $outsr (i32.wrap_i64 (local.get $ret64))) - (if (i32.ne (i32.const 4) (local.get $outsr)) + (if (i32.ne (i32.const 3) (local.get $outsr)) (then unreachable)) (global.set $outsw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) - (if (i32.ne (i32.const 5) (global.get $outsw)) + (if (i32.ne (i32.const 4) (global.get $outsw)) (then unreachable)) ;; start async read on $insr which will block @@ -153,10 +153,10 @@ ;; create a new stream r/w pair $insr/$insw (local.set $ret64 (call $stream.new)) (local.set $insr (i32.wrap_i64 (local.get $ret64))) - (if (i32.ne (i32.const 2) (local.get $insr)) + (if (i32.ne (i32.const 1) (local.get $insr)) (then unreachable)) (local.set $insw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) - (if (i32.ne (i32.const 3) (local.get $insw)) + (if (i32.ne (i32.const 2) (local.get $insw)) (then unreachable)) ;; call 'transform' which will return a readable stream $outsr eagerly @@ -165,7 +165,7 @@ (if (i32.ne (i32.const 2 (; RETURNED=2 | (0<<4) ;)) (local.get $ret)) (then unreachable)) (local.set $outsr (i32.load (local.get $retp))) - (if (i32.ne (i32.const 2) (local.get $outsr)) + (if (i32.ne (i32.const 1) (local.get $outsr)) (then unreachable)) ;; multiple write calls succeed until 12-byte buffer is filled @@ -183,7 +183,7 @@ (local.set $ret (call $stream.write (local.get $insw) (i32.const 16) (i32.const 12))) (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret)) (then unreachable)) - + ;; wait for transform to read our write and drop all the streams (local.set $ws (call $waitable-set.new)) (call $waitable.join (local.get $insw) (local.get $ws)) diff --git a/test/async/passing-resources.wast b/test/async/passing-resources.wast index 91d70e9d..d8a7c501 100644 --- a/test/async/passing-resources.wast +++ b/test/async/passing-resources.wast @@ -121,7 +121,7 @@ ;; get the readable end of a stream which has a pending write (local.set $rs (call $start-stream)) - (if (i32.ne (local.get $rs) (i32.const 2)) + (if (i32.ne (local.get $rs) (i32.const 1)) (then unreachable)) ;; read only 1 (of the 2 pending) elements, which won't block @@ -143,7 +143,7 @@ ;; drop the stream and then let $C run and assert stuff (call $stream.drop-readable (local.get $rs)) (call $cancel-write) - + (i32.const 42) ) ) @@ -173,4 +173,4 @@ (func (export "fail-accessing-res1") (alias export $producer "fail-accessing-res1")) ) (assert_return (invoke "run") (u32.const 42)) -(assert_trap (invoke "fail-accessing-res1") "index is not a resource") +(assert_trap (invoke "fail-accessing-res1") "unknown handle index 3") diff --git a/test/resources/multiple-resources.wast b/test/resources/multiple-resources.wast index 9a242752..77549ad4 100644 --- a/test/resources/multiple-resources.wast +++ b/test/resources/multiple-resources.wast @@ -107,16 +107,16 @@ ;; create 4 resources (local.set $h1 (call $make-R1)) - (if (i32.ne (i32.const 2) (local.get $h1)) + (if (i32.ne (i32.const 1) (local.get $h1)) (then unreachable)) (local.set $h2 (call $make-R2)) - (if (i32.ne (i32.const 3) (local.get $h2)) + (if (i32.ne (i32.const 2) (local.get $h2)) (then unreachable)) (local.set $h3 (call $make-R1)) - (if (i32.ne (i32.const 4) (local.get $h3)) + (if (i32.ne (i32.const 3) (local.get $h3)) (then unreachable)) (local.set $h4 (call $make-R2)) - (if (i32.ne (i32.const 5) (local.get $h4)) + (if (i32.ne (i32.const 4) (local.get $h4)) (then unreachable)) (if (i32.ne (i32.const 4) (call $num-live)) (then unreachable)) diff --git a/test/wasmtime/resources.wast b/test/wasmtime/resources.wast index 21846eb3..28e68ad7 100644 --- a/test/wasmtime/resources.wast +++ b/test/wasmtime/resources.wast @@ -14,7 +14,7 @@ (local $r i32) (local.set $r (call $new (i32.const 100))) - (if (i32.ne (local.get $r) (i32.const 2)) (then (unreachable))) + (if (i32.ne (local.get $r) (i32.const 1)) (then (unreachable))) (if (i32.ne (call $rep (local.get $r)) (i32.const 100)) (then (unreachable))) (call $drop (local.get $r)) @@ -95,13 +95,13 @@ ;; resources assigned sequentially (local.set $r1 (call $new (i32.const 100))) - (if (i32.ne (local.get $r1) (i32.const 2)) (then (unreachable))) + (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) (local.set $r2 (call $new (i32.const 200))) - (if (i32.ne (local.get $r2) (i32.const 3)) (then (unreachable))) + (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) (local.set $r3 (call $new (i32.const 300))) - (if (i32.ne (local.get $r3) (i32.const 4)) (then (unreachable))) + (if (i32.ne (local.get $r3) (i32.const 3)) (then (unreachable))) ;; representations all look good (if (i32.ne (call $rep (local.get $r1)) (i32.const 100)) (then (unreachable))) @@ -113,7 +113,7 @@ (local.set $r2 (call $new (i32.const 400))) ;; should have reused index 3 - (if (i32.ne (local.get $r2) (i32.const 3)) (then (unreachable))) + (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) ;; representations all look good (if (i32.ne (call $rep (local.get $r1)) (i32.const 100)) (then (unreachable))) @@ -135,13 +135,13 @@ (if (i32.ne (call $rep (local.get $r3)) (i32.const 700)) (then (unreachable))) ;; indices should be lifo - (if (i32.ne (local.get $r1) (i32.const 4)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 3)) (then (unreachable))) - (if (i32.ne (local.get $r3) (i32.const 2)) (then (unreachable))) + (if (i32.ne (local.get $r1) (i32.const 3)) (then (unreachable))) + (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) + (if (i32.ne (local.get $r3) (i32.const 1)) (then (unreachable))) ;; bump one more time (local.set $r4 (call $new (i32.const 800))) - (if (i32.ne (local.get $r4) (i32.const 5)) (then (unreachable))) + (if (i32.ne (local.get $r4) (i32.const 4)) (then (unreachable))) ;; deallocate everything (call $drop (local.get $r1)) @@ -241,13 +241,13 @@ (local.set $r2 (call $ctor (i32.const 200))) ;; assert r1/r2 are sequential - (if (i32.ne (local.get $r1) (i32.const 2)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 3)) (then (unreachable))) + (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) + (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) ;; reallocate r1 and it should be reassigned the same index (call $drop (local.get $r1)) (local.set $r1 (call $ctor (i32.const 300))) - (if (i32.ne (local.get $r1) (i32.const 2)) (then (unreachable))) + (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) ;; internal values should match (call $assert (local.get $r1) (i32.const 300)) @@ -443,7 +443,7 @@ (import "" "ctor" (func $ctor (param i32) (result i32))) (func $start - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 2)) (then (unreachable))) + (if (i32.ne (call $ctor (i32.const 100)) (i32.const 1)) (then (unreachable))) ) (start $start) ) @@ -476,7 +476,7 @@ (func (export "f") (canon lift (core func $i "f"))) ) -(assert_trap (invoke "f") "index 1 is not a resource") +(assert_trap (invoke "f") "unknown handle index 1") ;; Each instantiation of a component generates a unique resource type, so ;; allocating in one component and deallocating in another should fail. @@ -492,10 +492,10 @@ (import "" "drop" (func $drop (param i32))) (func (export "alloc") - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 2)) (then (unreachable))) + (if (i32.ne (call $ctor (i32.const 100)) (i32.const 1)) (then (unreachable))) ) (func (export "dealloc") - (call $drop (i32.const 2)) + (call $drop (i32.const 1)) ) ) (core instance $i (instantiate $m @@ -552,10 +552,10 @@ (import "" "drop" (func $drop (param i32))) (func (export "alloc") - (if (i32.ne (call $ctor (i32.const 100)) (i32.const 2)) (then (unreachable))) + (if (i32.ne (call $ctor (i32.const 100)) (i32.const 1)) (then (unreachable))) ) (func (export "dealloc") - (call $drop (i32.const 2)) + (call $drop (i32.const 1)) ) ) (core instance $i (instantiate $m @@ -617,12 +617,12 @@ (call $drop2 (call $new2 (i32.const 104))) ;; should be referencing the same namespace - (if (i32.ne (call $new1 (i32.const 105)) (i32.const 2)) (then (unreachable))) - (if (i32.ne (call $new2 (i32.const 105)) (i32.const 3)) (then (unreachable))) + (if (i32.ne (call $new1 (i32.const 105)) (i32.const 1)) (then (unreachable))) + (if (i32.ne (call $new2 (i32.const 105)) (i32.const 2)) (then (unreachable))) ;; use different drops out of order - (call $drop2 (i32.const 2)) - (call $drop1 (i32.const 3)) + (call $drop2 (i32.const 1)) + (call $drop1 (i32.const 2)) ) (start $start) @@ -702,8 +702,8 @@ ;; indexes start at 2 and while they have distinct types they should be ;; within the same table. - (if (i32.ne (local.get $r1) (i32.const 2)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 3)) (then (unreachable))) + (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) + (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) ;; nothing should be dropped yet (if (i32.ne (call $drops) (i32.const 0)) (then (unreachable))) @@ -867,7 +867,7 @@ ;; table should be empty at this point, so a fresh allocation should get ;; index 2 - (if (i32.ne (call $ctor (i32.const 600)) (i32.const 2)) (then (unreachable))) + (if (i32.ne (call $ctor (i32.const 600)) (i32.const 1)) (then (unreachable))) ) (start $start) @@ -1025,8 +1025,8 @@ (local.set $r1 (call $ctor (i32.const 100))) (local.set $r2 (call $ctor (i32.const 200))) - (if (i32.ne (local.get $r1) (i32.const 2)) (then (unreachable))) - (if (i32.ne (local.get $r2) (i32.const 3)) (then (unreachable))) + (if (i32.ne (local.get $r1) (i32.const 1)) (then (unreachable))) + (if (i32.ne (local.get $r2) (i32.const 2)) (then (unreachable))) (call $assert-borrow (local.get $r2) (i32.const 200)) (call $assert-borrow (local.get $r1) (i32.const 100)) @@ -1086,6 +1086,6 @@ ) (component instance $C1 $C) -(assert_trap (invoke "drop-r1-as-r2") "handle index 2 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") +(assert_trap (invoke "drop-r1-as-r2") "handle index 1 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") (component instance $C1 $C) -(assert_trap (invoke "return-r1-as-r2") "handle index 2 used with the wrong type, expected guest-defined resource but found a different guest-defined resource") +(assert_trap (invoke "return-r1-as-r2") "handle index 1 used with the wrong type, expected guest-defined resource but found a different guest-defined resource")