Skip to content

Commit 3508d13

Browse files
authored
Update tests for coop threading (#570)
1 parent d13caa4 commit 3508d13

File tree

9 files changed

+36
-36
lines changed

9 files changed

+36
-36
lines changed

test/async/async-calls-sync.wast

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
(memory 1)
2121
(global $blocked (mut i32) (i32.const 1))
22-
(global $counter (mut i32) (i32.const 2))
22+
(global $counter (mut i32) (i32.const 3))
2323

2424
;; 'blocking-call' cooperatively "spin-waits" until $blocked is 0.
2525
(func $blocking-call (export "blocking-call") (result i32)
@@ -135,24 +135,24 @@
135135
;; (on $AsyncInner.blocking-call). because 'sync-func1/2' are in different instances,
136136
;; both calls will reach the STARTED state.
137137
(local.set $ret (call $sync-func1 (i32.const 8)))
138-
(if (i32.ne (i32.const 0x21 (; STARTED=1 | (subtask=2 << 4) ;)) (local.get $ret))
139-
(then unreachable))
140-
(call $waitable.join (i32.const 2) (global.get $ws))
141-
(local.set $ret (call $sync-func2 (i32.const 12)))
142138
(if (i32.ne (i32.const 0x31 (; STARTED=1 | (subtask=3 << 4) ;)) (local.get $ret))
143139
(then unreachable))
144140
(call $waitable.join (i32.const 3) (global.get $ws))
141+
(local.set $ret (call $sync-func2 (i32.const 12)))
142+
(if (i32.ne (i32.const 0x41 (; STARTED=1 | (subtask=4 << 4) ;)) (local.get $ret))
143+
(then unreachable))
144+
(call $waitable.join (i32.const 4) (global.get $ws))
145145

146146
;; now start another pair of 'sync-func1/2' calls, both of which should see auto
147147
;; backpressure and get stuck in the STARTING state.
148148
(local.set $ret (call $sync-func1 (i32.const 16)))
149-
(if (i32.ne (i32.const 0x40 (; STARTING=0 | (subtask=4 << 4) ;)) (local.get $ret))
150-
(then unreachable))
151-
(call $waitable.join (i32.const 4) (global.get $ws))
152-
(local.set $ret (call $sync-func2 (i32.const 20)))
153149
(if (i32.ne (i32.const 0x50 (; STARTING=0 | (subtask=5 << 4) ;)) (local.get $ret))
154150
(then unreachable))
155151
(call $waitable.join (i32.const 5) (global.get $ws))
152+
(local.set $ret (call $sync-func2 (i32.const 20)))
153+
(if (i32.ne (i32.const 0x60 (; STARTING=0 | (subtask=6 << 4) ;)) (local.get $ret))
154+
(then unreachable))
155+
(call $waitable.join (i32.const 6) (global.get $ws))
156156

157157
;; this POLL should return that nothing is ready
158158
(i32.or (i32.const 3 (; POLL ;)) (i32.shl (global.get $ws) (i32.const 4)))
@@ -175,21 +175,21 @@
175175
(then unreachable))
176176

177177
;; if we receive a SUBTASK STARTED event, it should only be for the 3rd or
178-
;; 4th subtask (at indices 4/5, resp), so keep waiting for completion
178+
;; 4th subtask (at indices 5/6, resp), so keep waiting for completion
179179
(if (i32.eq (local.get $payload) (i32.const 1 (; STARTED ;))) (then
180180
(if (i32.and
181-
(i32.ne (local.get $index) (i32.const 4))
182-
(i32.ne (local.get $index) (i32.const 5)))
181+
(i32.ne (local.get $index) (i32.const 5))
182+
(i32.ne (local.get $index) (i32.const 6)))
183183
(then unreachable))
184184
(return (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4))))
185185
))
186186

187187
;; when we receive a SUBTASK RETURNED event, check the return value is equal to the
188-
;; subtask index (which we've ensured by having $AsyncInner.$counter start at 2, the
189-
;; first subtask index. The address of the return buffer is the index*4.
188+
;; subtask index (which we've ensured by having $AsyncInner.$counter start at 3, the
189+
;; first subtask index. The address of the return buffer is the index-1*4.
190190
(if (i32.ne (local.get $payload) (i32.const 2 (; RETURNED ;)))
191191
(then unreachable))
192-
(if (i32.ne (local.get $index) (i32.load (i32.mul (local.get $index) (i32.const 4))))
192+
(if (i32.ne (local.get $index) (i32.load (i32.mul (i32.sub (local.get $index) (i32.const 1)) (i32.const 4))))
193193
(then unreachable))
194194

195195
;; decrement $remain and exit if 0

test/async/cancel-stream.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117
;; call 'start-stream' to get the stream we'll be working with
118118
(local.set $sr (call $start-stream))
119-
(if (i32.ne (i32.const 1) (local.get $sr))
119+
(if (i32.ne (i32.const 2) (local.get $sr))
120120
(then unreachable))
121121

122122
;; start read that will block
@@ -155,7 +155,7 @@
155155

156156
;; get a new $sr
157157
(local.set $sr (call $start-stream))
158-
(if (i32.ne (i32.const 1) (local.get $sr))
158+
(if (i32.ne (i32.const 2) (local.get $sr))
159159
(then unreachable))
160160

161161
;; start outstanding write in $C, read 4 of it, then call back into $C

test/async/drop-stream.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
;; call 'start-stream' to get the stream we'll be working with
9191
(local.set $sr (call $start-stream))
92-
(if (i32.ne (i32.const 1) (local.get $sr))
92+
(if (i32.ne (i32.const 2) (local.get $sr))
9393
(then unreachable))
9494

9595
;; start a blocking read
@@ -111,7 +111,7 @@
111111

112112
;; call 'start-stream' to get the stream we'll be working with
113113
(local.set $sr (call $start-stream))
114-
(if (i32.ne (i32.const 1) (local.get $sr))
114+
(if (i32.ne (i32.const 2) (local.get $sr))
115115
(then unreachable))
116116

117117
;; start a blocking write and partially read from it

test/async/drop-waitable-set.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
;; start an async call to 'wait-on-set' which blocks, waiting on a
6060
;; waitable-set.
6161
(local.set $ret (call $wait-on-set))
62-
(if (i32.ne (i32.const 0x11) (local.get $ret))
62+
(if (i32.ne (i32.const 0x21) (local.get $ret))
6363
(then unreachable))
6464

6565
;; this call will try to drop the same waitable-set, which should trap.

test/async/empty-wait.wast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
;; create a future that will be used to unblock 'blocker', storing r/w ends in $futr/$futw
5454
(local.set $ret64 (call $future.new))
5555
(global.set $futr (i32.wrap_i64 (local.get $ret64)))
56-
(if (i32.ne (i32.const 2) (global.get $futr))
56+
(if (i32.ne (i32.const 4) (global.get $futr))
5757
(then unreachable))
5858
(local.set $futw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32))))
59-
(if (i32.ne (i32.const 3) (local.get $futw))
59+
(if (i32.ne (i32.const 5) (local.get $futw))
6060
(then unreachable))
6161

6262
;; perform a future.read which will block, and add this future to the waitable-set
@@ -144,7 +144,7 @@
144144
(if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))
145145
(then unreachable))
146146
(local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4)))
147-
(if (i32.ne (i32.const 2 (; RETURNED=2 | (0<<4) ;)) (local.get $subtask))
147+
(if (i32.ne (i32.const 3) (local.get $subtask))
148148
(then unreachable))
149149

150150
;; call 'unblocker' to unblock 'blocker'; it should complete eagerly

test/async/futures-must-write.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
;; call 'start-future' to get the future we'll be working with
7272
(local $fr i32)
7373
(local.set $fr (call $start-future))
74-
(if (i32.ne (i32.const 1) (local.get $fr))
74+
(if (i32.ne (i32.const 2) (local.get $fr))
7575
(then unreachable))
7676

7777
;; ok to immediately drop the readable end
@@ -84,7 +84,7 @@
8484
;; call 'start-future' to get the future we'll be working with
8585
(local $fr i32)
8686
(local.set $fr (call $start-future))
87-
(if (i32.ne (i32.const 1) (local.get $fr))
87+
(if (i32.ne (i32.const 2) (local.get $fr))
8888
(then unreachable))
8989

9090
;; boom

test/async/partial-stream-copies.wast

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535

3636
;; check the incoming readable stream end
3737
(global.set $insr (local.get 0))
38-
(if (i32.ne (i32.const 2) (global.get $insr))
38+
(if (i32.ne (i32.const 3) (global.get $insr))
3939
(then unreachable))
4040

4141
;; create a new stream r/w pair $outsr/$outsw
4242
(local.set $ret64 (call $stream.new))
4343
(local.set $outsr (i32.wrap_i64 (local.get $ret64)))
44-
(if (i32.ne (i32.const 3) (local.get $outsr))
44+
(if (i32.ne (i32.const 4) (local.get $outsr))
4545
(then unreachable))
4646
(global.set $outsw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32))))
47-
(if (i32.ne (i32.const 4) (global.get $outsw))
47+
(if (i32.ne (i32.const 5) (global.get $outsw))
4848
(then unreachable))
4949

5050
;; start async read on $insr which will block
@@ -153,10 +153,10 @@
153153
;; create a new stream r/w pair $insr/$insw
154154
(local.set $ret64 (call $stream.new))
155155
(local.set $insr (i32.wrap_i64 (local.get $ret64)))
156-
(if (i32.ne (i32.const 1) (local.get $insr))
156+
(if (i32.ne (i32.const 2) (local.get $insr))
157157
(then unreachable))
158158
(local.set $insw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32))))
159-
(if (i32.ne (i32.const 2) (local.get $insw))
159+
(if (i32.ne (i32.const 3) (local.get $insw))
160160
(then unreachable))
161161

162162
;; call 'transform' which will return a readable stream $outsr eagerly
@@ -165,7 +165,7 @@
165165
(if (i32.ne (i32.const 2 (; RETURNED=2 | (0<<4) ;)) (local.get $ret))
166166
(then unreachable))
167167
(local.set $outsr (i32.load (local.get $retp)))
168-
(if (i32.ne (i32.const 1) (local.get $outsr))
168+
(if (i32.ne (i32.const 2) (local.get $outsr))
169169
(then unreachable))
170170

171171
;; multiple write calls succeed until 12-byte buffer is filled

test/async/passing-resources.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
;; get the readable end of a stream which has a pending write
123123
(local.set $rs (call $start-stream))
124-
(if (i32.ne (local.get $rs) (i32.const 1))
124+
(if (i32.ne (local.get $rs) (i32.const 2))
125125
(then unreachable))
126126

127127
;; read only 1 (of the 2 pending) elements, which won't block

test/resources/multiple-resources.wast

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@
107107

108108
;; create 4 resources
109109
(local.set $h1 (call $make-R1))
110-
(if (i32.ne (i32.const 1) (local.get $h1))
110+
(if (i32.ne (i32.const 2) (local.get $h1))
111111
(then unreachable))
112112
(local.set $h2 (call $make-R2))
113-
(if (i32.ne (i32.const 2) (local.get $h2))
113+
(if (i32.ne (i32.const 3) (local.get $h2))
114114
(then unreachable))
115115
(local.set $h3 (call $make-R1))
116-
(if (i32.ne (i32.const 3) (local.get $h3))
116+
(if (i32.ne (i32.const 4) (local.get $h3))
117117
(then unreachable))
118118
(local.set $h4 (call $make-R2))
119-
(if (i32.ne (i32.const 4) (local.get $h4))
119+
(if (i32.ne (i32.const 5) (local.get $h4))
120120
(then unreachable))
121121
(if (i32.ne (i32.const 4) (call $num-live))
122122
(then unreachable))

0 commit comments

Comments
 (0)