Skip to content

Commit

Permalink
add tests/misc_testsuite/component-model-async/*.wast
Browse files Browse the repository at this point in the history
These only test instantiation of components which use various async options and
built-ins so far.  Next, I'll happy and sad path tests which actually execute
code.

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Jan 3, 2025
1 parent 8852943 commit 0f19614
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async-trait = { workspace = true }
trait-variant = { workspace = true }
wat = { workspace = true }
rayon = "1.5.0"
wasmtime-wast = { workspace = true, features = ['component-model'] }
wasmtime-wast = { workspace = true, features = ['component-model', 'component-model-async'] }
wasmtime-component-util = { workspace = true }
component-macro-test = { path = "crates/misc/component-macro-test" }
component-test-util = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/misc/component-test-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wasmtime_wast_util::
extended_const,
wide_arithmetic,
component_model_more_flags,
component_model_async,
nan_canonicalization,
simd,

Expand All @@ -192,6 +193,7 @@ pub fn apply_test_config(config: &mut Config, test_config: &wasmtime_wast_util::
let extended_const = extended_const.unwrap_or(false);
let wide_arithmetic = wide_arithmetic.unwrap_or(false);
let component_model_more_flags = component_model_more_flags.unwrap_or(false);
let component_model_async = component_model_async.unwrap_or(false);
let nan_canonicalization = nan_canonicalization.unwrap_or(false);
let relaxed_simd = relaxed_simd.unwrap_or(false);

Expand All @@ -218,5 +220,6 @@ pub fn apply_test_config(config: &mut Config, test_config: &wasmtime_wast_util::
.wasm_extended_const(extended_const)
.wasm_wide_arithmetic(wide_arithmetic)
.wasm_component_model_more_flags(component_model_more_flags)
.wasm_component_model_async(component_model_async)
.cranelift_nan_canonicalization(nan_canonicalization);
}
1 change: 1 addition & 0 deletions crates/wast-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ macro_rules! foreach_config_option {
hogs_memory
nan_canonicalization
component_model_more_flags
component_model_async
simd
gc_types
}
Expand Down
1 change: 1 addition & 0 deletions crates/wast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ log = { workspace = true }

[features]
component-model = ['wasmtime/component-model']
component-model-async = ['wasmtime/component-model-async']
3 changes: 3 additions & 0 deletions crates/wast/src/spectest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub fn link_component_spectest<T>(linker: &mut component::Linker<T>) -> Result<(
use wasmtime::component::{Resource, ResourceType};

let engine = linker.engine().clone();
linker
.root()
.func_wrap("host-echo-u32", |_, v: (u32,)| Ok(v))?;
linker
.root()
.func_wrap("host-return-two", |_, _: ()| Ok((2u32,)))?;
Expand Down
35 changes: 35 additions & 0 deletions tests/misc_testsuite/component-model-async/error-context.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! component_model_async = true

;; error-context.new
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "error-context.new" (func $error-context-new (param i32 i32) (result i32)))
)
(core func $error-context-new (canon error-context.new (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "error-context.new" (func $error-context-new))))))
)

;; error-context.debug-message
(component
(core module $libc
(func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)
(memory (export "memory") 1)
)
(core instance $libc (instantiate $libc))
(core module $m
(import "" "error-context.debug-message" (func $error-context-debug-message (param i32 i32)))
)
(core func $error-context-debug-message (canon error-context.debug-message (memory $libc "memory") (realloc (func $libc "realloc"))))
(core instance $i (instantiate $m (with "" (instance (export "error-context.debug-message" (func $error-context-debug-message))))))
)

;; error-context.drop
(component
(core module $m
(import "" "error-context.drop" (func $error-context-drop (param i32)))
)
(core func $error-context-drop (canon error-context.drop))
(core instance $i (instantiate $m (with "" (instance (export "error-context.drop" (func $error-context-drop))))))
)
90 changes: 90 additions & 0 deletions tests/misc_testsuite/component-model-async/futures.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
;;! component_model_async = true

;; future.new
(component
(core module $m
(import "" "future.new" (func $future-new (result i32)))
)
(type $future-type (future u8))
(core func $future-new (canon future.new $future-type))
(core instance $i (instantiate $m (with "" (instance (export "future.new" (func $future-new))))))
)

;; future.read
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "future.read" (func $future-read (param i32 i32) (result i32)))
)
(type $future-type (future u8))
(core func $future-read (canon future.read $future-type async (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "future.read" (func $future-read))))))
)

;; future.read; with realloc
(component
(core module $libc
(func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)
(memory (export "memory") 1)
)
(core instance $libc (instantiate $libc))
(core module $m
(import "" "future.read" (func $future-read (param i32 i32) (result i32)))
)
(type $future-type (future string))
(core func $future-read (canon future.read $future-type async (memory $libc "memory") (realloc (func $libc "realloc"))))
(core instance $i (instantiate $m (with "" (instance (export "future.read" (func $future-read))))))
)

;; future.write
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "future.write" (func $future-write (param i32 i32) (result i32)))
)
(type $future-type (future u8))
(core func $future-write (canon future.write $future-type async (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "future.write" (func $future-write))))))
)

;; future.cancel-read
(component
(core module $m
(import "" "future.cancel-read" (func $future-cancel-read (param i32) (result i32)))
)
(type $future-type (future u8))
(core func $future-cancel-read (canon future.cancel-read $future-type async))
(core instance $i (instantiate $m (with "" (instance (export "future.cancel-read" (func $future-cancel-read))))))
)

;; future.cancel-write
(component
(core module $m
(import "" "future.cancel-write" (func $future-cancel-write (param i32) (result i32)))
)
(type $future-type (future u8))
(core func $future-cancel-write (canon future.cancel-write $future-type async))
(core instance $i (instantiate $m (with "" (instance (export "future.cancel-write" (func $future-cancel-write))))))
)

;; future.close-readable
(component
(core module $m
(import "" "future.close-readable" (func $future-close-readable (param i32)))
)
(type $future-type (future u8))
(core func $future-close-readable (canon future.close-readable $future-type))
(core instance $i (instantiate $m (with "" (instance (export "future.close-readable" (func $future-close-readable))))))
)

;; future.close-writable
(component
(core module $m
(import "" "future.close-writable" (func $future-close-writable (param i32 i32)))
)
(type $future-type (future u8))
(core func $future-close-writable (canon future.close-writable $future-type))
(core instance $i (instantiate $m (with "" (instance (export "future.close-writable" (func $future-close-writable))))))
)
26 changes: 26 additions & 0 deletions tests/misc_testsuite/component-model-async/lift.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;! component_model_async = true

;; async lift; no callback
(component
(core module $m
(func (export "foo") (param i32) unreachable)
)
(core instance $i (instantiate $m))

(func (export "foo") (param "p1" u32) (result u32)
(canon lift (core func $i "foo") async)
)
)

;; async lift; with callback
(component
(core module $m
(func (export "callback") (param i32 i32 i32 i32) (result i32) unreachable)
(func (export "foo") (param i32) (result i32) unreachable)
)
(core instance $i (instantiate $m))

(func (export "foo") (param "p1" u32) (result u32)
(canon lift (core func $i "foo") async (callback (func $i "callback")))
)
)
13 changes: 13 additions & 0 deletions tests/misc_testsuite/component-model-async/lower.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;;! component_model_async = true

;; async lower
(component
(import "host-echo-u32" (func $foo (param "p1" u32) (result u32)))
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core func $foo (canon lower (func $foo) async (memory $libc "memory")))
(core module $m
(func (import "" "foo") (param i32 i32) (result i32))
)
(core instance $i (instantiate $m (with "" (instance (export "foo" (func $foo))))))
)
90 changes: 90 additions & 0 deletions tests/misc_testsuite/component-model-async/streams.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
;;! component_model_async = true

;; stream.new
(component
(core module $m
(import "" "stream.new" (func $stream-new (result i32)))
)
(type $stream-type (stream u8))
(core func $stream-new (canon stream.new $stream-type))
(core instance $i (instantiate $m (with "" (instance (export "stream.new" (func $stream-new))))))
)

;; stream.read
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "stream.read" (func $stream-read (param i32 i32 i32) (result i32)))
)
(type $stream-type (stream u8))
(core func $stream-read (canon stream.read $stream-type async (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "stream.read" (func $stream-read))))))
)

;; stream.read; with realloc
(component
(core module $libc
(func (export "realloc") (param i32 i32 i32 i32) (result i32) unreachable)
(memory (export "memory") 1)
)
(core instance $libc (instantiate $libc))
(core module $m
(import "" "stream.read" (func $stream-read (param i32 i32 i32) (result i32)))
)
(type $stream-type (stream string))
(core func $stream-read (canon stream.read $stream-type async (memory $libc "memory") (realloc (func $libc "realloc"))))
(core instance $i (instantiate $m (with "" (instance (export "stream.read" (func $stream-read))))))
)

;; stream.write
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "stream.write" (func $stream-write (param i32 i32 i32) (result i32)))
)
(type $stream-type (stream u8))
(core func $stream-write (canon stream.write $stream-type async (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "stream.write" (func $stream-write))))))
)

;; stream.cancel-read
(component
(core module $m
(import "" "stream.cancel-read" (func $stream-cancel-read (param i32) (result i32)))
)
(type $stream-type (stream u8))
(core func $stream-cancel-read (canon stream.cancel-read $stream-type async))
(core instance $i (instantiate $m (with "" (instance (export "stream.cancel-read" (func $stream-cancel-read))))))
)

;; stream.cancel-write
(component
(core module $m
(import "" "stream.cancel-write" (func $stream-cancel-write (param i32) (result i32)))
)
(type $stream-type (stream u8))
(core func $stream-cancel-write (canon stream.cancel-write $stream-type async))
(core instance $i (instantiate $m (with "" (instance (export "stream.cancel-write" (func $stream-cancel-write))))))
)

;; stream.close-readable
(component
(core module $m
(import "" "stream.close-readable" (func $stream-close-readable (param i32)))
)
(type $stream-type (stream u8))
(core func $stream-close-readable (canon stream.close-readable $stream-type))
(core instance $i (instantiate $m (with "" (instance (export "stream.close-readable" (func $stream-close-readable))))))
)

;; stream.close-writable
(component
(core module $m
(import "" "stream.close-writable" (func $stream-close-writable (param i32 i32)))
)
(type $stream-type (stream u8))
(core func $stream-close-writable (canon stream.close-writable $stream-type))
(core instance $i (instantiate $m (with "" (instance (export "stream.close-writable" (func $stream-close-writable))))))
)
60 changes: 60 additions & 0 deletions tests/misc_testsuite/component-model-async/task-builtins.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
;;! component_model_async = true

;; task.backpressure
(component
(core module $m
(import "" "task.backpressure" (func $task-backpressure (param i32)))
)
(core func $task-backpressure (canon task.backpressure))
(core instance $i (instantiate $m (with "" (instance (export "task.backpressure" (func $task-backpressure))))))
)

;; task.return
(component
(core module $m
(import "" "task.return" (func $task-return (param i32)))
)
(core type $task-return-type (func (param i32)))
(core func $task-return (canon task.return $task-return-type))
(core instance $i (instantiate $m (with "" (instance (export "task.return" (func $task-return))))))
)

;; task.wait
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "task.wait" (func $task-wait (param i32) (result i32)))
)
(core func $task-wait (canon task.wait async (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "task.wait" (func $task-wait))))))
)

;; task.poll
(component
(core module $libc (memory (export "memory") 1))
(core instance $libc (instantiate $libc))
(core module $m
(import "" "task.poll" (func $task-poll (param i32) (result i32)))
)
(core func $task-poll (canon task.poll async (memory $libc "memory")))
(core instance $i (instantiate $m (with "" (instance (export "task.poll" (func $task-poll))))))
)

;; task.yield
(component
(core module $m
(import "" "task.yield" (func $task-yield))
)
(core func $task-yield (canon task.yield async))
(core instance $i (instantiate $m (with "" (instance (export "task.yield" (func $task-yield))))))
)

;; subtask.drop
(component
(core module $m
(import "" "subtask.drop" (func $subtask-drop (param i32)))
)
(core func $subtask-drop (canon subtask.drop))
(core instance $i (instantiate $m (with "" (instance (export "subtask.drop" (func $subtask-drop))))))
)
1 change: 1 addition & 0 deletions tests/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn run_wast(test: &WastTest, config: WastConfig) -> anyhow::Result<()> {
};

let mut cfg = Config::new();
cfg.wasm_component_model_async(true);
component_test_util::apply_test_config(&mut cfg, &test_config);
component_test_util::apply_wast_config(&mut cfg, &config);

Expand Down

0 comments on commit 0f19614

Please sign in to comment.