|
14 | 14 | (func (param $expected i32) (param $timeout i64) (result i32) |
15 | 15 | (struct.wait $t 2 (ref.null $t) (global.get $wq) (local.get $expected) (local.get $timeout)) |
16 | 16 | ) |
17 | | - ) "struct index out of bounds" |
| 17 | + ) "out of bounds struct.wait field" |
18 | 18 | ) |
19 | 19 |
|
20 | 20 | (assert_invalid |
|
25 | 25 | (func (param $expected i32) (param $timeout i64) (result i32) |
26 | 26 | (struct.wait $t 0 (global.get $g) (global.get $wq) (i64.const 0) (local.get $timeout)) |
27 | 27 | ) |
28 | | - ) "struct.wait expected must be an i32" |
| 28 | + ) "struct.wait expected value must match the field immediate" |
| 29 | +) |
| 30 | + |
| 31 | +(assert_invalid |
| 32 | + (module |
| 33 | + (type $t (shared (struct (field f32)))) |
| 34 | + (global $g (ref $t) (struct.new $t (f32.const 0))) |
| 35 | + (global $wq (ref (shared waitqueue)) (waitqueue.new)) |
| 36 | + (func (param $expected f32) (param $timeout i64) (result i32) |
| 37 | + (struct.wait $t 0 (global.get $g) (global.get $wq) (local.get $expected) (local.get $timeout)) |
| 38 | + ) |
| 39 | + ) "struct.wait control word field must be i32, i64 or a subtype of (ref null (shared eq))" |
| 40 | +) |
| 41 | + |
| 42 | +(assert_invalid |
| 43 | + (module |
| 44 | + (type $t (shared (struct (field i8)))) |
| 45 | + (global $g (ref $t) (struct.new $t (i32.const 0))) |
| 46 | + (global $wq (ref (shared waitqueue)) (waitqueue.new)) |
| 47 | + (func (param $expected i32) (param $timeout i64) (result i32) |
| 48 | + (struct.wait $t 0 (global.get $g) (global.get $wq) (local.get $expected) (local.get $timeout)) |
| 49 | + ) |
| 50 | + ) "struct.wait field must not be packed" |
29 | 51 | ) |
30 | 52 |
|
31 | 53 | (assert_invalid |
|
41 | 63 |
|
42 | 64 | (assert_invalid |
43 | 65 | (module |
44 | | - (type $t (shared (struct (field i32)))) |
45 | | - (global $wq (ref (shared waitqueue)) (waitqueue.new)) |
46 | 66 | (func (param $count i32) (result i32) |
47 | 67 | (waitqueue.notify (ref.null waitqueue) (local.get $count)) |
48 | 68 | ) |
|
74 | 94 | ) |
75 | 95 | ) |
76 | 96 |
|
| 97 | +;; i32 control word |
77 | 98 | (module |
78 | 99 | (type $t (shared (struct (field (mut i32))))) |
79 | 100 |
|
|
119 | 140 | (assert_trap (invoke "struct.wait" (i32.const 0) (i64.const 0)) "null ref") |
120 | 141 | (assert_trap (invoke "waitqueue.notify" (i32.const 0)) "null ref") |
121 | 142 |
|
| 143 | +;; i64 control word |
| 144 | +(module |
| 145 | + (type $t (shared (struct (field (mut i64))))) |
| 146 | + |
| 147 | + (global $g (mut (ref null $t)) (struct.new $t (i64.const 0))) |
| 148 | + (global $wq (mut (ref (shared waitqueue))) (waitqueue.new)) |
| 149 | + |
| 150 | + (func (export "struct.wait") (param $expected i64) (param $timeout i64) (result i32) |
| 151 | + (struct.wait $t 0 (global.get $g) (global.get $wq) (local.get $expected) (local.get $timeout)) |
| 152 | + ) |
| 153 | + |
| 154 | + (func (export "struct.set") (param $val i64) |
| 155 | + (struct.set $t 0 (global.get $g) (local.get $val)) |
| 156 | + ) |
| 157 | + |
| 158 | + (func (export "struct.get") (result i64) |
| 159 | + (struct.get $t 0 (global.get $g)) |
| 160 | + ) |
| 161 | +) |
| 162 | + |
| 163 | +(invoke "struct.set" (i64.const 42)) |
| 164 | +(assert_return (invoke "struct.get") (i64.const 42)) |
| 165 | +(assert_return (invoke "struct.wait" (i64.const 0) (i64.const 100)) (i32.const 1)) |
| 166 | +(assert_return (invoke "struct.wait" (i64.const 42) (i64.const 0)) (i32.const 2)) |
| 167 | + |
| 168 | +;; (ref null (shared eq)) control word |
| 169 | +(module |
| 170 | + (type $control (shared (struct))) |
| 171 | + |
| 172 | + (type $t (shared (struct |
| 173 | + (field (mut (ref null (shared eq)))) |
| 174 | + ))) |
| 175 | + |
| 176 | + (global $control1 (ref $control) (struct.new $control)) |
| 177 | + (global $control2 (ref $control) (struct.new $control)) |
| 178 | + |
| 179 | + (global $g (mut (ref null $t)) (struct.new $t |
| 180 | + (global.get $control1) |
| 181 | + )) |
| 182 | + |
| 183 | + (global $wq (mut (ref null (shared waitqueue))) (waitqueue.new)) |
| 184 | + |
| 185 | + (func (export "wait_control1") (result i32) |
| 186 | + (struct.wait $t 0 (global.get $g) (global.get $wq) (global.get $control1) (i64.const 0)) |
| 187 | + ) |
| 188 | + |
| 189 | + (func (export "wait_control2") (result i32) |
| 190 | + (struct.wait $t 0 (global.get $g) (global.get $wq) (global.get $control2) (i64.const 0)) |
| 191 | + ) |
| 192 | + |
| 193 | + (func (export "wait_null") (result i32) |
| 194 | + (struct.wait $t 0 (global.get $g) (global.get $wq) (ref.null (shared eq)) (i64.const 0)) |
| 195 | + ) |
| 196 | + |
| 197 | + (func (export "set_control_to_null") |
| 198 | + (struct.set $t 0 (global.get $g) (ref.null (shared eq))) |
| 199 | + ) |
| 200 | +) |
| 201 | + |
| 202 | +;; $control1 is the control word, wait 0ns and return 2. |
| 203 | +(assert_return (invoke "wait_control1") (i32.const 2)) |
| 204 | +;; $control2 is not the control work, don't wait and return 1. |
| 205 | +(assert_return (invoke "wait_control2") (i32.const 1)) |
| 206 | +;; ditto for null. |
| 207 | +(assert_return (invoke "wait_null") (i32.const 1)) |
| 208 | + |
| 209 | +(invoke "set_control_to_null") |
| 210 | + |
| 211 | +;; null is now the control word. |
| 212 | +(assert_return (invoke "wait_null") (i32.const 2)) |
| 213 | +(assert_return (invoke "wait_control1") (i32.const 1)) |
| 214 | + |
122 | 215 | ;; Binary format test for waitqueue and nowaitqueue. |
123 | 216 | (module binary |
124 | 217 | "\00asm\01\00\00\00" ;; Wasm header |
|
0 commit comments