Skip to content

Commit 1c17a18

Browse files
authored
Prepare some component-model tests for upstreaming (bytecodealliance#2335)
This commit prepares a number of the `component-model/*.wast` tests for upstreaming into the component model repository itself. Namely: * All `value`-related functionality is moved to `values.wast` instead of being spread out. * All components are now either `component definition` or a nested component to work well in Wasmtime (previously everything assumed it could import anything). Tests now pass with `wasmtime wast` and after this I plan on upstreaming these tests to the component model repository itself.
1 parent 7ff0753 commit 1c17a18

112 files changed

Lines changed: 1626 additions & 1440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/cli/component-model/a.wast

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/cli/component-model/adapt.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; RUN: wast --assert default --snapshot tests/snapshots %
22

3-
(component
3+
(component definition
44
(import "log" (func $log (param "msg" string)))
55
(core module $libc
66
(memory (export "memory") 1)

tests/cli/component-model/alias.wast

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-values
1+
;; RUN: wast --assert default --snapshot tests/snapshots %
22

33
(component
4-
(import "i" (instance $i
5-
(export "f1" (func))
6-
(export "f2" (func (param "p1" string)))
7-
))
8-
(export "run" (func $i "f1"))
4+
(component
5+
(import "i" (instance $i
6+
(export "f1" (func))
7+
(export "f2" (func (param "p1" string)))
8+
))
9+
(export "run" (func $i "f1"))
10+
)
911
)
1012

1113
(component
12-
(import "i" (component $c
13-
(export "f1" (func))
14-
(export "f2" (func (param "p1" string)))
15-
))
16-
(instance $i (instantiate $c))
17-
(export "run" (func $i "f1"))
14+
(component
15+
(import "i" (component $c
16+
(export "f1" (func))
17+
(export "f2" (func (param "p1" string)))
18+
))
19+
(instance $i (instantiate $c))
20+
(export "run" (func $i "f1"))
21+
)
1822
)
1923

20-
(component
24+
(component definition
2125
(import "i" (core module $m
2226
(export "f1" (func $f1))
2327
(export "f2" (func $f2 (param i32)))
@@ -29,7 +33,7 @@
2933
(core instance (instantiate $m2 (with "" (instance (export "" (func $i "f1"))))))
3034
)
3135

32-
(component
36+
(component definition
3337
(import "a" (core module $libc
3438
(export "memory" (memory 1))
3539
(export "table" (table 0 funcref))
@@ -62,17 +66,20 @@
6266
)
6367

6468
(component
65-
(import "a" (instance $i
66-
(export "a" (func))
67-
(export "b" (core module))
68-
(export "c" (instance))
69-
))
70-
(export "b" (func $i "a"))
71-
(export "c" (core module $i "b"))
72-
(export "d" (instance $i "c"))
69+
(component
70+
(import "a" (instance $i
71+
(export "a" (func))
72+
(export "b" (core module))
73+
(export "c" (instance))
74+
))
75+
(export "b" (func $i "a"))
76+
(export "c" (core module $i "b"))
77+
(export "d" (instance $i "c"))
78+
)
7379
)
7480

75-
(component
81+
82+
(component definition
7683
(import "a" (core module $libc
7784
(export "memory" (memory 1))
7885
(export "table" (table 0 funcref))
@@ -193,36 +200,35 @@
193200
)
194201

195202
;; multiple projections in alias sugar
196-
(component $a
197-
(import "a" (instance $a
198-
(export "a" (instance
203+
(component
204+
(component $a
205+
(import "a" (instance $a
199206
(export "a" (instance
200207
(export "a" (instance
201-
(export "a" (func))
208+
(export "a" (instance
209+
(export "a" (func))
210+
))
202211
))
203212
))
204213
))
205-
))
206214

207-
(import "b" (component $b (import "a" (func))))
215+
(import "b" (component $b (import "a" (func))))
208216

209-
(instance (instantiate $b
210-
(with "a" (func $a "a" "a" "a" "a"))
211-
))
217+
(instance (instantiate $b
218+
(with "a" (func $a "a" "a" "a" "a"))
219+
))
220+
)
212221
)
213222

214223
;; alias some constructs
215224
(component
216-
(import "a" (instance $foo (export "v" (value s32))))
217-
(export "v" (value $foo "v"))
218-
)
219-
220-
(component
221-
(import "a" (instance $foo (export "v" (component))))
222-
(export "v" (component $foo "v"))
225+
(component
226+
(import "a" (instance $foo (export "v" (component))))
227+
(export "v" (component $foo "v"))
228+
)
223229
)
224230

225-
(component
231+
(component definition
226232
(import "a" (instance $foo (export "v" (core module))))
227233
(export "v" (core module $foo "v"))
228234
)
@@ -244,10 +250,12 @@
244250
(export "v" (core module $target))
245251
)
246252

247-
(component $C
248-
(component $m)
249-
(alias outer $C $m (component $target))
250-
(export "v" (component $target))
253+
(component
254+
(component $C
255+
(component $m)
256+
(alias outer $C $m (component $target))
257+
(export "v" (component $target))
258+
)
251259
)
252260

253261
(assert_invalid
@@ -274,7 +282,7 @@
274282
(component (alias outer 0 0 (component)))
275283
"index out of bounds")
276284

277-
(component
285+
(component definition
278286
(import "a" (instance $i
279287
(export "x" (core module))
280288
))
@@ -283,9 +291,11 @@
283291
)
284292

285293
(component
286-
(import "a" (instance $i
287-
(export "x" (component))
288-
))
289-
;; inline alias injection sugar works for component references
290-
(instance (instantiate (component $i "x")))
294+
(component
295+
(import "a" (instance $i
296+
(export "x" (component))
297+
))
298+
;; inline alias injection sugar works for component references
299+
(instance (instantiate (component $i "x")))
300+
)
291301
)

tests/cli/component-model/big.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; RUN: wast --assert default --snapshot tests/snapshots %
22

3-
(component
3+
(component definition
44
(import "wasi-logging" (instance $logging
55
(export "log" (func (param "msg" string)))
66
))

tests/cli/component-model/export-ascription.wast

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
;; RUN: wast --assert default --snapshot tests/snapshots %
22

33
(component
4-
(import "f" (func $f))
5-
(export "f2" (func $f) (func))
4+
(component
5+
(import "f" (func $f))
6+
(export "f2" (func $f) (func))
7+
)
68
)
79

810
;; subtyping works
911
(component
10-
(import "f" (instance $i (export "f" (func))))
11-
(export "f2" (instance $i) (instance))
12+
(component
13+
(import "f" (instance $i (export "f" (func))))
14+
(export "f2" (instance $i) (instance))
15+
)
1216
)
1317

1418
;; make sure subtyping works in the right direction

tests/cli/component-model/export-introduces-alias.wast

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
;; RUN: wast --assert default --snapshot tests/snapshots %
22

33
(component
4-
(import "x" (func $f))
4+
(component
5+
(import "x" (func $f))
56

6-
(export $g "g" (func $f))
7-
(export $g2 "g2" (func $g))
7+
(export $g "g" (func $f))
8+
(export $g2 "g2" (func $g))
9+
)
810
)
911

1012
(component

tests/cli/component-model/export.wast

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-values
1+
;; RUN: wast --assert default --snapshot tests/snapshots %
22

33
(assert_invalid
44
(component (export "" (instance 0)))
@@ -16,42 +16,33 @@
1616
(component (export "" (func 0)))
1717
"index out of bounds")
1818

19-
(assert_invalid
20-
(component (export "" (value 0)))
21-
"index out of bounds")
22-
2319
(component
24-
(import "a" (instance $i))
25-
(import "b" (core module $m))
26-
(import "c" (component $c))
27-
(import "d" (value $v string))
28-
(import "e" (func $f))
29-
30-
(export "f" (instance $i))
31-
(export "g" (core module $m))
32-
(export "h" (component $c))
33-
(export "i" (value $v))
34-
(export "j" (func $f))
35-
)
36-
37-
(assert_invalid
3820
(component
39-
(import "a" (value $v string))
40-
(export "b" (value $v))
41-
(export "c" (value $v))
21+
(import "a" (instance $i))
22+
(import "b" (core module $m))
23+
(import "c" (component $c))
24+
(import "e" (func $f))
25+
26+
(export "f" (instance $i))
27+
(export "g" (core module $m))
28+
(export "h" (component $c))
29+
(export "j" (func $f))
4230
)
43-
"cannot be used more than once")
44-
31+
)
4532

4633
(component
47-
(import "a" (func))
48-
(export (interface "wasi:http/types@2.0.0") (func 0))
34+
(component
35+
(import "a" (func))
36+
(export (interface "wasi:http/types@2.0.0") (func 0))
37+
)
4938
)
5039

5140
;; import/exports can overlap on ids
5241
(component
53-
(import (interface "wasi:http/types@2.0.0") (func))
54-
(export (interface "wasi:http/types@2.0.0") (func 0))
42+
(component
43+
(import (interface "wasi:http/types@2.0.0") (func))
44+
(export (interface "wasi:http/types@2.0.0") (func 0))
45+
)
5546
)
5647

5748
;; cannot export some types of strings

tests/cli/component-model/func.wast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
;; RUN: wast --assert default --snapshot tests/snapshots %
22

3-
(component
3+
(component definition
44
(import "a" (func (param "foo" string)))
55
(import "b" (func (param "foo" string) (param "bar" s32) (param "baz" u32)))
66
(import "c" (func (result (tuple u8))))
77
)
88

9-
(component
9+
(component definition
1010
(import "a" (func))
1111
(import "b" (func (param "p1" string)))
1212
(import "c" (func (result u32)))
@@ -36,7 +36,7 @@
3636
"canonical option `memory` is required"
3737
)
3838

39-
(component
39+
(component definition
4040
(import "a" (func $log (param "msg" string)))
4141
(core module $libc
4242
(memory (export "memory") 1)

tests/cli/component-model/gc.wast

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,31 @@
135135
(type (sub $t1 (func)))
136136
)
137137
)
138+
139+
;; test components with non-mvp types
140+
(component definition
141+
;; all abstract heap types work
142+
(core type (func (param (ref any))))
143+
(core type (func (param (ref func))))
144+
(core type (func (param (ref extern))))
145+
(core type (func (param (ref exn))))
146+
(core type (func (param (ref noexn))))
147+
(core type (func (param (ref eq))))
148+
(core type (func (param (ref struct))))
149+
(core type (func (param (ref array))))
150+
(core type (func (param (ref nofunc))))
151+
(core type (func (param (ref noextern))))
152+
(core type (func (param (ref none))))
153+
(core type (func (param (ref i31))))
154+
155+
;; some shorthands work
156+
(core type (func (param anyref)))
157+
(core type (func (param eqref)))
158+
159+
;; simd types work
160+
(core type (func (param v128)))
161+
162+
;; types-pointing-to-types works
163+
(core type $t (func))
164+
(core type (func (param (ref $t))))
165+
)

0 commit comments

Comments
 (0)