| 1 |
;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-async,cm-threading,cm-error-context |
| 2 |
|
| 3 |
;; context.{get,set} 1 |
| 4 |
(component |
| 5 |
(core func $get1 (canon context.get i32 1)) |
| 6 |
(core func $set1 (canon context.set i32 1)) |
| 7 |
|
| 8 |
(core module $m |
| 9 |
(import "" "get1" (func (result i32))) |
| 10 |
(import "" "set1" (func (param i32))) |
| 11 |
) |
| 12 |
(core instance (instantiate $m |
| 13 |
(with "" (instance |
| 14 |
(export "get1" (func $get1)) |
| 15 |
(export "set1" (func $set1)) |
| 16 |
)) |
| 17 |
)) |
| 18 |
) |
| 19 |
|
| 20 |
(assert_invalid |
| 21 |
(component |
| 22 |
(core func (canon context.get i32 2))) |
| 23 |
"immediate must be zero or one: 2") |
| 24 |
(assert_invalid |
| 25 |
(component |
| 26 |
(core func (canon context.set i32 2))) |
| 27 |
"immediate must be zero or one: 2") |
| 28 |
(assert_invalid |
| 29 |
(component |
| 30 |
(core func (canon context.get i32 100))) |
| 31 |
"immediate must be zero or one: 100") |
| 32 |
(assert_invalid |
| 33 |
(component |
| 34 |
(core func (canon context.set i32 100))) |
| 35 |
"immediate must be zero or one: 100") |
| 36 |
|
| 37 |
(assert_invalid |
| 38 |
(component |
| 39 |
(core module $m (import "" "" (func (param i32) (result i32)))) |
| 40 |
(core func $f (canon context.get i32 1)) |
| 41 |
(core instance $i (instantiate $m (with "" (instance (export "" (func $f)))))) |
| 42 |
) |
| 43 |
"found: (func (result i32))") |
| 44 |
(assert_invalid |
| 45 |
(component |
| 46 |
(core module $m (import "" "" (func (param i32) (result i32)))) |
| 47 |
(core func $f (canon context.set i32 1)) |
| 48 |
(core instance $i (instantiate $m (with "" (instance (export "" (func $f)))))) |
| 49 |
) |
| 50 |
"found: (func (param i32))") |
| 51 |
|
| 52 |
;; thread.new_indirect |
| 53 |
(component |
| 54 |
(core type $start (func (param $context i32))) |
| 55 |
(core module $libc (table (export "start-table") 1 (ref null func))) |
| 56 |
(core instance $libc (instantiate $libc)) |
| 57 |
(core func $new_indirect (canon thread.new_indirect $start (table $libc "start-table"))) |
| 58 |
) |
| 59 |
|
| 60 |
(component |
| 61 |
(core type $start (func (param $context i32))) |
| 62 |
(core module $libc (table (export "start-table") 1 (ref null func))) |
| 63 |
(core instance $libc (instantiate $libc)) |
| 64 |
(core func $new_indirect (canon thread.new_indirect $start (table $libc "start-table"))) |
| 65 |
|
| 66 |
(core module $m |
| 67 |
(type $new_indirect_ty (func (param i32) (param i32) (result i32))) |
| 68 |
(import "" "thread.new_indirect" (func (type $new_indirect_ty))) |
| 69 |
) |
| 70 |
|
| 71 |
(core instance (instantiate $m |
| 72 |
(with "" (instance |
| 73 |
(export "thread.new_indirect" (func $new_indirect)) |
| 74 |
)) |
| 75 |
)) |
| 76 |
) |
| 77 |
|
| 78 |
(assert_invalid |
| 79 |
(component |
| 80 |
(core type $start (func (param i32))) |
| 81 |
;; Refer to a non-existent table type (i.e., 0); validation |
| 82 |
;; for `thread.new_indirect` happens first. |
| 83 |
(core func $new_indirect (canon thread.new_indirect $start (table 0))) |
| 84 |
) |
| 85 |
"unknown table 0: table index out of bounds" |
| 86 |
) |
| 87 |
|
| 88 |
(assert_invalid |
| 89 |
(component |
| 90 |
(core type $start (func)) |
| 91 |
(core module $libc (table (export "start-table") 1 (ref null func))) |
| 92 |
(core instance $libc (instantiate $libc)) |
| 93 |
(core func $new_indirect (canon thread.new_indirect $start (table $libc "start-table"))) |
| 94 |
) |
| 95 |
"start function must take a single `i32` argument" |
| 96 |
) |
| 97 |
|
| 98 |
;; thead.index |
| 99 |
(component |
| 100 |
(core module $m |
| 101 |
(import "" "thread.index" (func $thread.index (result i32))) |
| 102 |
) |
| 103 |
(core func $thread.index (canon thread.index)) |
| 104 |
(core instance $i (instantiate $m (with "" (instance (export "thread.index" (func $thread.index)))))) |
| 105 |
) |
| 106 |
|
| 107 |
;; thread.index; incorrect type |
| 108 |
(assert_invalid |
| 109 |
(component |
| 110 |
(core module $m |
| 111 |
(import "" "thread.index" (func $thread.index (param i32) (result i32))) |
| 112 |
) |
| 113 |
(core func $thread.index (canon thread.index)) |
| 114 |
(core instance $i (instantiate $m (with "" (instance (export "thread.index" (func $thread.index)))))) |
| 115 |
) |
| 116 |
"type mismatch for export `thread.index` of module instantiation argument ``" |
| 117 |
) |
| 118 |
|
| 119 |
;; thread.switch-to |
| 120 |
(component |
| 121 |
(core module $m |
| 122 |
(import "" "thread.switch-to" (func $thread.switch-to (param i32) (result i32))) |
| 123 |
) |
| 124 |
(core func $thread.switch-to (canon thread.switch-to cancellable)) |
| 125 |
(core instance $i (instantiate $m (with "" (instance (export "thread.switch-to" (func $thread.switch-to)))))) |
| 126 |
) |
| 127 |
|
| 128 |
;; thread.switch-to; incorrect type |
| 129 |
(assert_invalid |
| 130 |
(component |
| 131 |
(core module $m |
| 132 |
(import "" "thread.switch-to" (func $thread.switch-to (param i32))) |
| 133 |
) |
| 134 |
(core func $thread.switch-to (canon thread.switch-to cancellable)) |
| 135 |
(core instance $i (instantiate $m (with "" (instance (export "thread.switch-to" (func $thread.switch-to)))))) |
| 136 |
) |
| 137 |
"type mismatch for export `thread.switch-to` of module instantiation argument ``" |
| 138 |
) |
| 139 |
|
| 140 |
;; different forms of canonical intrinsics |
| 141 |
|
| 142 |
(component |
| 143 |
(core module $m |
| 144 |
(table (export "start-table") 1 (ref null func)) |
| 145 |
) |
| 146 |
(core instance $i (instantiate $m)) |
| 147 |
(alias core export $i "start-table" (core table $start-table)) |
| 148 |
|
| 149 |
(core func (canon context.get i32 1)) |
| 150 |
(canon context.get i32 1 (core func)) |
| 151 |
(core func (canon context.set i32 1)) |
| 152 |
(canon context.set i32 1 (core func)) |
| 153 |
|
| 154 |
(core type $start (func (param i32))) |
| 155 |
(core func (canon thread.new_indirect $start (table $start-table))) |
| 156 |
(canon thread.new_indirect $start (table $start-table) (core func)) |
| 157 |
(core func (canon thread.switch-to)) |
| 158 |
(canon thread.switch-to (core func)) |
| 159 |
(core func (canon thread.switch-to cancellable)) |
| 160 |
(canon thread.switch-to cancellable (core func)) |
| 161 |
(core func (canon thread.suspend)) |
| 162 |
(canon thread.suspend (core func)) |
| 163 |
(core func (canon thread.suspend cancellable)) |
| 164 |
(canon thread.suspend cancellable (core func)) |
| 165 |
(core func (canon thread.resume-later)) |
| 166 |
(canon thread.resume-later (core func)) |
| 167 |
(core func (canon thread.yield-to)) |
| 168 |
(canon thread.yield-to (core func)) |
| 169 |
(core func (canon thread.yield-to cancellable)) |
| 170 |
(canon thread.yield-to cancellable (core func)) |
| 171 |
) |
| 172 |
|
| 173 |
(component |
| 174 |
(canon task.return (result (stream u8)) (core func)) |
| 175 |
) |