From 0f1961458149dab80a3784b841a3292d0b3b3b12 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 3 Jan 2025 16:54:35 -0700 Subject: [PATCH] add tests/misc_testsuite/component-model-async/*.wast 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 --- Cargo.toml | 2 +- crates/misc/component-test-util/src/lib.rs | 3 + crates/wast-util/src/lib.rs | 1 + crates/wast/Cargo.toml | 1 + crates/wast/src/spectest.rs | 3 + .../component-model-async/error-context.wast | 35 ++++++++ .../component-model-async/futures.wast | 90 +++++++++++++++++++ .../component-model-async/lift.wast | 26 ++++++ .../component-model-async/lower.wast | 13 +++ .../component-model-async/streams.wast | 90 +++++++++++++++++++ .../component-model-async/task-builtins.wast | 60 +++++++++++++ tests/wast.rs | 1 + 12 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 tests/misc_testsuite/component-model-async/error-context.wast create mode 100644 tests/misc_testsuite/component-model-async/futures.wast create mode 100644 tests/misc_testsuite/component-model-async/lift.wast create mode 100644 tests/misc_testsuite/component-model-async/lower.wast create mode 100644 tests/misc_testsuite/component-model-async/streams.wast create mode 100644 tests/misc_testsuite/component-model-async/task-builtins.wast diff --git a/Cargo.toml b/Cargo.toml index ddb5e1554c4d..59a6cc40e022 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/crates/misc/component-test-util/src/lib.rs b/crates/misc/component-test-util/src/lib.rs index d2804990b855..a04ed65bb312 100644 --- a/crates/misc/component-test-util/src/lib.rs +++ b/crates/misc/component-test-util/src/lib.rs @@ -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, @@ -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); @@ -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); } diff --git a/crates/wast-util/src/lib.rs b/crates/wast-util/src/lib.rs index f8e15777a481..4253635b729c 100644 --- a/crates/wast-util/src/lib.rs +++ b/crates/wast-util/src/lib.rs @@ -185,6 +185,7 @@ macro_rules! foreach_config_option { hogs_memory nan_canonicalization component_model_more_flags + component_model_async simd gc_types } diff --git a/crates/wast/Cargo.toml b/crates/wast/Cargo.toml index 599cfae1cdd1..fa143250736e 100644 --- a/crates/wast/Cargo.toml +++ b/crates/wast/Cargo.toml @@ -21,3 +21,4 @@ log = { workspace = true } [features] component-model = ['wasmtime/component-model'] +component-model-async = ['wasmtime/component-model-async'] diff --git a/crates/wast/src/spectest.rs b/crates/wast/src/spectest.rs index 924bf66d1c40..e9b1ec7575ae 100644 --- a/crates/wast/src/spectest.rs +++ b/crates/wast/src/spectest.rs @@ -94,6 +94,9 @@ pub fn link_component_spectest(linker: &mut component::Linker) -> 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,)))?; diff --git a/tests/misc_testsuite/component-model-async/error-context.wast b/tests/misc_testsuite/component-model-async/error-context.wast new file mode 100644 index 000000000000..e564416a5109 --- /dev/null +++ b/tests/misc_testsuite/component-model-async/error-context.wast @@ -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)))))) +) diff --git a/tests/misc_testsuite/component-model-async/futures.wast b/tests/misc_testsuite/component-model-async/futures.wast new file mode 100644 index 000000000000..f1e4d4d5b940 --- /dev/null +++ b/tests/misc_testsuite/component-model-async/futures.wast @@ -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)))))) +) diff --git a/tests/misc_testsuite/component-model-async/lift.wast b/tests/misc_testsuite/component-model-async/lift.wast new file mode 100644 index 000000000000..f90c65672c96 --- /dev/null +++ b/tests/misc_testsuite/component-model-async/lift.wast @@ -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"))) + ) +) diff --git a/tests/misc_testsuite/component-model-async/lower.wast b/tests/misc_testsuite/component-model-async/lower.wast new file mode 100644 index 000000000000..bcb4862fc8b4 --- /dev/null +++ b/tests/misc_testsuite/component-model-async/lower.wast @@ -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)))))) +) diff --git a/tests/misc_testsuite/component-model-async/streams.wast b/tests/misc_testsuite/component-model-async/streams.wast new file mode 100644 index 000000000000..790ddec7e5f8 --- /dev/null +++ b/tests/misc_testsuite/component-model-async/streams.wast @@ -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)))))) +) diff --git a/tests/misc_testsuite/component-model-async/task-builtins.wast b/tests/misc_testsuite/component-model-async/task-builtins.wast new file mode 100644 index 000000000000..a5f9ca0f468e --- /dev/null +++ b/tests/misc_testsuite/component-model-async/task-builtins.wast @@ -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)))))) +) diff --git a/tests/wast.rs b/tests/wast.rs index fc062c39fc45..1cd6441aa3a7 100644 --- a/tests/wast.rs +++ b/tests/wast.rs @@ -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);