A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Run `*.wast` tests from component-model repo (#11677)
Alex Crichton38b408c3aacf
diff --git a/.gitmodules b/.gitmodulesindex e1fa8b72c6..09f95a1a02 100644--- a/.gitmodules+++ b/.gitmodules@@ -8,3 +8,6 @@path = tests/wasi_testsuite/wasi-commonurl = https://github.com/WebAssembly/wasi-testsuite.gitbranch = prod/testsuite-base+[submodule "tests/component-model"]+ path = tests/component-model+ url = https://github.com/WebAssembly/component-modeldiff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rsindex 45d899e608..7a98f9f443 100644--- a/crates/test-util/src/wast.rs+++ b/crates/test-util/src/wast.rs@@ -32,12 +32,30 @@ pub mod limits {/// of the wasmtime repository.pub fn find_tests(root: &Path) -> Result<Vec<WastTest>> {let mut tests = Vec::new();- add_tests(&mut tests, &root.join("tests/spec_testsuite"), false)?;- add_tests(&mut tests, &root.join("tests/misc_testsuite"), true)?;+ add_tests(+ &mut tests,+ &root.join("tests/spec_testsuite"),+ &FindConfig::Infer(spec_test_config),+ )?;+ add_tests(+ &mut tests,+ &root.join("tests/misc_testsuite"),+ &FindConfig::InTest,+ )?;+ add_tests(+ &mut tests,+ &root.join("tests/component-model/test"),+ &FindConfig::Infer(component_test_config),+ )?;Ok(tests)}-fn add_tests(tests: &mut Vec<WastTest>, path: &Path, has_config: bool) -> Result<()> {+enum FindConfig {+ InTest,+ Infer(fn(&Path) -> TestConfig),+}++fn add_tests(tests: &mut Vec<WastTest>, path: &Path, config: &FindConfig) -> Result<()> {for entry in path.read_dir().context("failed to read directory")? {let entry = entry.context("failed to read directory entry")?;let path = entry.path();@@ -46,7 +64,7 @@ fn add_tests(tests: &mut Vec<WastTest>, path: &Path, has_config: bool) -> Result.context("failed to get file type")?.is_dir(){- add_tests(tests, &path, has_config).context("failed to read sub-directory")?;+ add_tests(tests, &path, config).context("failed to read sub-directory")?;continue;}@@ -56,11 +74,10 @@ fn add_tests(tests: &mut Vec<WastTest>, path: &Path, has_config: bool) -> Resultlet contents =fs::read_to_string(&path).with_context(|| format!("failed to read test: {path:?}"))?;- let config = if has_config {- parse_test_config(&contents, ";;!")- .with_context(|| format!("failed to parse test configuration: {path:?}"))?- } else {- spec_test_config(&path)+ let config = match config {+ FindConfig::InTest => parse_test_config(&contents, ";;!")+ .with_context(|| format!("failed to parse test configuration: {path:?}"))?,+ FindConfig::Infer(f) => f(&path),};tests.push(WastTest {path,@@ -139,6 +156,22 @@ fn spec_test_config(test: &Path) -> TestConfig {ret}+fn component_test_config(test: &Path) -> TestConfig {+ let mut ret = TestConfig::default();+ ret.spec_test = Some(true);+ ret.reference_types = Some(true);+ ret.multi_memory = Some(true);++ if let Some(parent) = test.parent() {+ if parent.ends_with("async") {+ ret.component_model_async = Some(true);+ ret.component_model_async_builtins = Some(true);+ }+ }++ ret+}+/// Parse test configuration from the specified test, comments starting with/// `;;!`.pub fn parse_test_config<T>(wat: &str, comment: &'static str) -> Result<T>@@ -302,7 +335,7 @@ impl Compiler {}Compiler::Winch => {- let unsupported_base = config.gc()+ if config.gc()|| config.tail_call()|| config.function_references()|| config.gc()@@ -311,20 +344,19 @@ impl Compiler {|| config.exceptions()|| config.legacy_exceptions()|| config.stack_switching()- || config.legacy_exceptions();-- if cfg!(target_arch = "x86_64") {- return unsupported_base;+ || config.legacy_exceptions()+ || config.component_model_async()+ {+ return true;}if cfg!(target_arch = "aarch64") {- return unsupported_base- || config.wide_arithmetic()+ return config.wide_arithmetic()|| (config.simd() && !config.spec_test())|| config.threads();}- true+ !cfg!(target_arch = "x86_64")}Compiler::CraneliftPulley => {@@ -634,6 +666,17 @@ impl WastTest {}}+ let failing_component_model_tests = [+ // FIXME(#11676)+ "component-model/test/values/trap-in-post-return.wast",+ ];+ if failing_component_model_tests+ .iter()+ .any(|part| self.path.ends_with(part))+ {+ return true;+ }+false}}diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rsindex 843743f7d6..e1cc9f2fda 100644--- a/crates/wasmtime/src/config.rs+++ b/crates/wasmtime/src/config.rs@@ -2130,7 +2130,8 @@ impl Config {| WasmFeatures::GC_TYPES| WasmFeatures::EXCEPTIONS| WasmFeatures::LEGACY_EXCEPTIONS- | WasmFeatures::STACK_SWITCHING;+ | WasmFeatures::STACK_SWITCHING+ | WasmFeatures::CM_ASYNC;match self.compiler_target().architecture {target_lexicon::Architecture::Aarch64(_) => {unsupported |= WasmFeatures::THREADS;diff --git a/tests/component-model b/tests/component-modelnew file mode 160000index 0000000000..3870cbe964--- /dev/null+++ b/tests/component-model@@ -0,0 +1 @@+Subproject commit 3870cbe964d8bc84777c182a883a9da00f6ea2cbdiff --git a/tests/misc_testsuite/component-model-async/cancel-stream.wast b/tests/misc_testsuite/component-model-async/cancel-stream.wastdeleted file mode 100644index 39fe37eb4d..0000000000--- a/tests/misc_testsuite/component-model-async/cancel-stream.wast+++ /dev/null@@ -1,208 +0,0 @@-;;! component_model_async = true--;; This test contains two components $C and $D that test cancelling reads-;; and writes in the presence and absence of partial reads/writes.-;;-;; $C exports a function 'start-stream' that creates and holds onto a writable-;; stream in the global $sw as well as various operations that operate on $sw.-;; $D calls $C.start-stream to get the readable end and then drives the test.-;;-;; (Copied from-;; https://github.com/WebAssembly/component-model/blob/add-tests/test/concurrency/cancel-stream.wast)-(component- (component $C- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $CM- (import "" "mem" (memory 1))- (import "" "task.return" (func $task.return (param i32)))- (import "" "stream.new" (func $stream.new (result i64)))- (import "" "stream.write" (func $stream.write (param i32 i32 i32) (result i32)))- (import "" "stream.cancel-write" (func $stream.cancel-write (param i32) (result i32)))- (import "" "stream.drop-writable" (func $stream.drop-writable (param i32)))-- (global $sw (mut i32) (i32.const 0))-- (func $start-stream (export "start-stream") (result i32)- ;; create a new stream, return the readable end to the caller- (local $ret64 i64)- (local.set $ret64 (call $stream.new))- (global.set $sw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32))))- (i32.wrap_i64 (local.get $ret64))- )-- (func $write4 (export "write4")- ;; write 6 bytes into the stream, expecting to rendezvous with a stream.read- (local $ret i32)- (i32.store (i32.const 8) (i32.const 0xabcd))- (local.set $ret (call $stream.write (global.get $sw) (i32.const 8) (i32.const 4)))- (if (i32.ne (i32.const 0x40 (; COMPLETED=0 | (4<<4) ;)) (local.get $ret))- (then unreachable))- )-- (func $write4-and-drop (export "write4-and-drop")- (call $write4)- (call $stream.drop-writable (global.get $sw))- )-- (func $start-blocking-write (export "start-blocking-write")- (local $ret i32)-- ;; prepare the write buffer- (i64.store (i32.const 8) (i64.const 0x123456789abcdef))-- ;; start one blocking write and immediately cancel it- (local.set $ret (call $stream.write (global.get $sw) (i32.const 8) (i32.const 8)))- (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret))- (then unreachable))- (local.set $ret (call $stream.cancel-write (global.get $sw)))- (if (i32.ne (i32.const 0x2 (; CANCELLED ;)) (local.get $ret))- (then unreachable))-- ;; start a second blockign write and leave it pending- (local.set $ret (call $stream.write (global.get $sw) (i32.const 8) (i32.const 8)))- (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret))- (then unreachable))- )-- (func $cancel-after-read4 (export "cancel-after-read4")- (local $ret i32)- (local.set $ret (call $stream.cancel-write (global.get $sw)))- (if (i32.ne (i32.const 0x42 (; CANCELLED=2 | (4<<4) ;)) (local.get $ret))- (then unreachable))- )- )- (type $ST (stream u8))- (canon task.return (result u32) (core func $task.return))- (canon stream.new $ST (core func $stream.new))- (canon stream.write $ST async (memory $memory "mem") (core func $stream.write))- (canon stream.cancel-write $ST (core func $stream.cancel-write))- (canon stream.drop-writable $ST (core func $stream.drop-writable))- (core instance $cm (instantiate $CM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "task.return" (func $task.return))- (export "stream.new" (func $stream.new))- (export "stream.write" (func $stream.write))- (export "stream.cancel-write" (func $stream.cancel-write))- (export "stream.drop-writable" (func $stream.drop-writable))- ))))- (func (export "start-stream") (result (stream u8)) (canon lift (core func $cm "start-stream")))- (func (export "write4") (canon lift (core func $cm "write4")))- (func (export "write4-and-drop") (canon lift (core func $cm "write4-and-drop")))- (func (export "start-blocking-write") (canon lift (core func $cm "start-blocking-write")))- (func (export "cancel-after-read4") (canon lift (core func $cm "cancel-after-read4")))- )-- (component $D- (import "c" (instance $c- (export "start-stream" (func (result (stream u8))))- (export "write4" (func))- (export "write4-and-drop" (func))- (export "start-blocking-write" (func))- (export "cancel-after-read4" (func))- ))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $DM- (import "" "mem" (memory 1))- (import "" "stream.read" (func $stream.read (param i32 i32 i32) (result i32)))- (import "" "stream.cancel-read" (func $stream.cancel-read (param i32) (result i32)))- (import "" "stream.drop-readable" (func $stream.drop-readable (param i32)))- (import "" "start-stream" (func $start-stream (result i32)))- (import "" "write4" (func $write4))- (import "" "write4-and-drop" (func $write4-and-drop))- (import "" "start-blocking-write" (func $start-blocking-write))- (import "" "cancel-after-read4" (func $cancel-after-read4))-- (func $run (export "run") (result i32)- (local $ret i32)- (local $sr i32)-- ;; call 'start-stream' to get the stream we'll be working with- (local.set $sr (call $start-stream))- (if (i32.ne (i32.const 1) (local.get $sr))- (then unreachable))-- ;; start read that will block- (local.set $ret (call $stream.read (local.get $sr) (i32.const 8) (i32.const 100)))- (if (i32.ne (i32.const -1 (; BLOCKED;)) (local.get $ret))- (then unreachable))-- ;; cancelling it will finish without anything having been written- (local.set $ret (call $stream.cancel-read (local.get $sr)))- (if (i32.ne (i32.const 0x2 (; CANCELLED ;)) (local.get $ret))- (then unreachable))-- ;; read, block, call $C to write 4 bytes into the buffer,- ;; then cancel, which should show "4+cancelled"- (local.set $ret (call $stream.read (local.get $sr) (i32.const 8) (i32.const 100)))- (if (i32.ne (i32.const -1 (; BLOCKED;)) (local.get $ret))- (then unreachable))- (call $write4)- (local.set $ret (call $stream.cancel-read (local.get $sr)))- (if (i32.ne (i32.const 0x42 (; CANCELLED=2 | (4<<4) ;)) (local.get $ret))- (then unreachable))- (if (i32.ne (i32.const 0xabcd) (i32.load (i32.const 8)))- (then unreachable))-- ;; read, block, call $C to write 4 bytes into the buffer and drop,- ;; then cancel, which should show "4+dropped"- (local.set $ret (call $stream.read (local.get $sr) (i32.const 8) (i32.const 100)))- (if (i32.ne (i32.const -1 (; BLOCKED;)) (local.get $ret))- (then unreachable))- (call $write4-and-drop)- (local.set $ret (call $stream.cancel-read (local.get $sr)))- (if (i32.ne (i32.const 0x41 (; DROPPED=1 | (4<<4) ;)) (local.get $ret))- (then unreachable))- (if (i32.ne (i32.const 0xabcd) (i32.load (i32.const 8)))- (then unreachable))- (call $stream.drop-readable (local.get $sr))-- ;; get a new $sr- (local.set $sr (call $start-stream))- (if (i32.ne (i32.const 1) (local.get $sr))- (then unreachable))-- ;; start outstanding write in $C, read 4 of it, then call back into $C- ;; which will cancel and see 4 written.- (call $start-blocking-write)- (local.set $ret (call $stream.read (local.get $sr) (i32.const 8) (i32.const 4)))- (if (i32.ne (i32.const 0x40 (; COMPLETED=0 | (4<<4) ;)) (local.get $ret))- (then unreachable))- (if (i32.ne (i32.const 0x89abcdef) (i32.load (i32.const 8)))- (then unreachable))- (call $cancel-after-read4)-- ;; return 42 to the top-level assert_return- (i32.const 42)- )- )- (type $ST (stream u8))- (canon stream.read $ST async (memory $memory "mem") (core func $stream.read))- (canon stream.cancel-read $ST (core func $stream.cancel-read))- (canon stream.drop-readable $ST (core func $stream.drop-readable))- (canon lower (func $c "start-stream") (core func $start-stream'))- (canon lower (func $c "write4") (core func $write4'))- (canon lower (func $c "write4-and-drop") (core func $write4-and-drop'))- (canon lower (func $c "start-blocking-write") (core func $start-blocking-write'))- (canon lower (func $c "cancel-after-read4") (core func $cancel-after-read4'))- (core instance $dm (instantiate $DM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "stream.read" (func $stream.read))- (export "stream.cancel-read" (func $stream.cancel-read))- (export "stream.drop-readable" (func $stream.drop-readable))- (export "start-stream" (func $start-stream'))- (export "write4" (func $write4'))- (export "write4-and-drop" (func $write4-and-drop'))- (export "start-blocking-write" (func $start-blocking-write'))- (export "cancel-after-read4" (func $cancel-after-read4'))- ))))- (func (export "run") (result u32) (canon lift (core func $dm "run")))- )-- (instance $c (instantiate $C))- (instance $d (instantiate $D (with "c" (instance $c))))- (func (export "run") (alias export $d "run"))-)-(assert_return (invoke "run") (u32.const 42))diff --git a/tests/misc_testsuite/component-model-async/cancel-subtask.wast b/tests/misc_testsuite/component-model-async/cancel-subtask.wastdeleted file mode 100644index 88b0689be6..0000000000--- a/tests/misc_testsuite/component-model-async/cancel-subtask.wast+++ /dev/null@@ -1,209 +0,0 @@-;;! component_model_async = true-;;! component_model_async_builtins = true-;;! reference_types = true-;;! gc_types = true--;; This test contains two components $C and $D where $D imports and calls $C.-;; $D.run calls $C.f, which blocks on an empty waitable set-;; $D.run then subtask.cancels $C.f, which resumes $C.f which promptly resolves-;; without returning a value.-;;-;; (Copied from-;; https://github.com/WebAssembly/component-model/blob/2c17516179f99accdafb01d8e4affcc0f58184cc/test/async/cancel-subtask.wast)-(component- (component $C- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $CM- (import "" "mem" (memory 1))- (import "" "task.cancel" (func $task.cancel))- (import "" "future.read" (func $future.read (param i32 i32) (result i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))-- ;; $ws is waited on by 'f'- (global $ws (mut i32) (i32.const 0))- (func $start (global.set $ws (call $waitable-set.new)))- (start $start)-- (func $f (export "f") (result i32)- ;; wait on $ws which is currently empty, expected to get cancelled- (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))- )- (func $f_cb (export "f_cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)- ;; confirm that we've received a cancellation request- (if (i32.ne (local.get $event_code) (i32.const 6 (; TASK_CANCELLED ;)))- (then unreachable))- (if (i32.ne (local.get $index) (i32.const 0))- (then unreachable))- (if (i32.ne (local.get $payload) (i32.const 0))- (then unreachable))-- ;; finish without returning a value- (call $task.cancel)- (i32.const 0 (; EXIT ;))- )-- (func $g (export "g") (param $futr i32) (result i32)- (local $ret i32)- (local $event_code i32)-- ;; perform a future.read which will block, waiting for the caller to write- (local.set $ret (call $future.read (local.get $futr) (i32.const 0xdeadbeef)))- (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret))- (then unreachable))- (call $waitable.join (local.get $futr) (global.get $ws))-- ;; wait on $ws synchronously, don't expect cancellation- (local.set $event_code (call $waitable-set.wait (global.get $ws) (i32.const 0)))- (if (i32.ne (i32.const 4 (; FUTURE_READ ;)) (local.get $event_code))- (then unreachable))-- ;; finish returning a value- (i32.const 42)- )- )- (type $FT (future))- (canon task.cancel (core func $task.cancel))- (canon future.read $FT async (memory $memory "mem") (core func $future.read))- (canon waitable.join (core func $waitable.join))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (core instance $cm (instantiate $CM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "task.cancel" (func $task.cancel))- (export "future.read" (func $future.read))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- ))))- (func (export "f") (result u32) (canon lift- (core func $cm "f")- async (callback (func $cm "f_cb"))- ))- (func (export "g") (param "fut" $FT) (result u32) (canon lift- (core func $cm "g")- ))- )-- (component $D- (type $FT (future))- (import "f" (func $f (result u32)))- (import "g" (func $g (param "fut" $FT) (result u32)))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $DM- (import "" "mem" (memory 1))- (import "" "subtask.cancel" (func $subtask.cancel (param i32) (result i32)))- (import "" "subtask.drop" (func $subtask.drop (param i32)))- (import "" "future.new" (func $future.new (result i64)))- (import "" "future.write" (func $future.write (param i32 i32) (result i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "f" (func $f (param i32) (result i32)))- (import "" "g" (func $g (param i32 i32) (result i32)))-- (func $run (export "run") (result i32)- (local $ret i32) (local $ret64 i64)- (local $retp i32) (local $retp1 i32) (local $retp2 i32)- (local $subtask i32)- (local $event_code i32)- (local $futr i32) (local $futw i32)- (local $ws i32)-- ;; call 'f'; it should block- (local.set $retp (i32.const 4))- (i32.store (local.get $retp) (i32.const 0xbad0bad0))- (local.set $ret (call $f (local.get $retp)))- (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))- (then unreachable))- (local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4)))-- ;; cancel 'f'; it should complete without blocking- (local.set $ret (call $subtask.cancel (local.get $subtask)))- (if (i32.ne (i32.const 4 (; CANCELLED_BEFORE_RETURNED ;)) (local.get $ret))- (then unreachable))-- ;; The $retp memory shouldn't have changed- (if (i32.ne (i32.load (local.get $retp)) (i32.const 0xbad0bad0))- (then unreachable))-- (call $subtask.drop (local.get $subtask))-- ;; create future that g will wait on- (local.set $ret64 (call $future.new))- (local.set $futr (i32.wrap_i64 (local.get $ret64)))- (local.set $futw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32))))-- ;; call 'g'; it should block- (local.set $retp1 (i32.const 4))- (local.set $retp2 (i32.const 8))- (i32.store (local.get $retp1) (i32.const 0xbad0bad0))- (i32.store (local.get $retp2) (i32.const 0xbad0bad0))- (local.set $ret (call $g (local.get $futr) (local.get $retp1)))- (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))- (then unreachable))- (local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4)))-- ;; cancel 'g'; it should block- (local.set $ret (call $subtask.cancel (local.get $subtask)))- (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret))- (then unreachable))-- ;; future.write, unblocking 'g'- (local.set $ret (call $future.write (local.get $futw) (i32.const 0xdeadbeef)))- (if (i32.ne (i32.const 0 (; COMPLETED ;)) (local.get $ret))- (then unreachable))-- ;; wait to see 'g' finish and check its return value- (local.set $ws (call $waitable-set.new))- (call $waitable.join (local.get $subtask) (local.get $ws))- (local.set $event_code (call $waitable-set.wait (local.get $ws) (local.get $retp2)))- (if (i32.ne (i32.const 1 (; SUBTASK ;)) (local.get $event_code))- (then unreachable))- (if (i32.ne (local.get $subtask) (i32.load (local.get $retp2)))- (then unreachable))- (if (i32.ne (i32.const 2 (; RETURNED=2 | (0<<4) ;)) (i32.load offset=4 (local.get $retp2)))- (then unreachable))- (if (i32.ne (i32.const 42) (i32.load (local.get $retp1)))- (then unreachable))-- ;; return to the top-level assert_return- (i32.const 42)- )- )- (canon subtask.cancel async (core func $subtask.cancel))- (canon subtask.drop (core func $subtask.drop))- (canon future.new $FT (core func $future.new))- (canon future.write $FT async (memory $memory "mem") (core func $future.write))- (canon waitable.join (core func $waitable.join))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (canon lower (func $f) async (memory $memory "mem") (core func $f'))- (canon lower (func $g) async (memory $memory "mem") (core func $g'))- (core instance $dm (instantiate $DM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "subtask.cancel" (func $subtask.cancel))- (export "subtask.drop" (func $subtask.drop))- (export "future.new" (func $future.new))- (export "future.write" (func $future.write))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "f" (func $f'))- (export "g" (func $g'))- ))))- (func (export "run") (result u32) (canon lift (core func $dm "run")))- )-- (instance $c (instantiate $C))- (instance $d (instantiate $D- (with "f" (func $c "f"))- (with "g" (func $c "g"))- ))- (func (export "run") (alias export $d "run"))-)-(assert_return (invoke "run") (u32.const 42))diff --git a/tests/misc_testsuite/component-model-async/deadlock.wast b/tests/misc_testsuite/component-model-async/deadlock.wastdeleted file mode 100644index 9071058acc..0000000000--- a/tests/misc_testsuite/component-model-async/deadlock.wast+++ /dev/null@@ -1,85 +0,0 @@-;;! component_model_async = true-;;! reference_types = true-;;! gc_types = true-;;! multi_memory = true--;; This test defines components $C and $D where $D imports and calls $C-;; $C.f waits on an empty waitable set-;; $D.g calls $C.f and then waits for it to finish, which fails due to deadlock-;;-;; (Copied from-;; https://github.com/WebAssembly/component-model/blob/89dcdd7b52989c60e03386ea7f1e216d89e854c5/test/async/deadlock.wast)-(component definition $Tester- (component $C- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $CM- (import "" "mem" (memory 1))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))-- (func (export "f") (result i32)- ;; wait on a new empty waitable set- (local $ws i32)- (local.set $ws (call $waitable-set.new))- (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (local.get $ws) (i32.const 4)))- )- (func (export "cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)- unreachable- )- )- (canon waitable-set.new (core func $waitable-set.new))- (core instance $cm (instantiate $CM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "waitable-set.new" (func $waitable-set.new))- ))))- (func (export "f") (result u32) (canon lift- (core func $cm "f")- async (memory $memory "mem") (callback (func $cm "cb"))- ))- )-- (component $D- (import "f" (func $f (result u32)))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $DM- (import "" "mem" (memory 1))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "f" (func $f (param i32) (result i32)))-- (func (export "g") (result i32)- (local $ws i32) (local $ret i32) (local $subtaski i32)- (local.set $ret (call $f (i32.const 0)))- (local.set $subtaski (i32.shr_u (local.get $ret) (i32.const 4)))- (local.set $ws (call $waitable-set.new))- (call $waitable.join (local.get $subtaski) (local.get $ws))- (call $waitable-set.wait (local.get $ws) (i32.const 0))- unreachable- )- )- (canon waitable.join (core func $waitable.join))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (canon lower (func $f) async (memory $memory "mem") (core func $f'))- (core instance $dm (instantiate $DM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "f" (func $f'))- ))))- (func (export "f") (result u32) (canon lift (core func $dm "g")))- )-- (instance $c (instantiate $C))- (instance $d (instantiate $D (with "f" (func $c "f"))))- (func (export "f") (alias export $d "f"))-)-(component instance $i1 $Tester)-(assert_trap (invoke "f") "wasm trap: deadlock detected: event loop cannot make further progress")-;; Run it once more to test https://github.com/bytecodealliance/wasip3-prototyping/issues/209-(component instance $i2 $Tester)-(assert_trap (invoke "f") "wasm trap: deadlock detected: event loop cannot make further progress")diff --git a/tests/misc_testsuite/component-model-async/drop-subtask.wast b/tests/misc_testsuite/component-model-async/drop-subtask.wastdeleted file mode 100644index 3fb3d099f7..0000000000--- a/tests/misc_testsuite/component-model-async/drop-subtask.wast+++ /dev/null@@ -1,147 +0,0 @@-;;! component_model_async = true-;;! reference_types = true-;;! gc_types = true--;; This test contains two components: $Looper and $Caller.-;; $Caller starts an async subtask for $Looper.loop and then drops these-;; subtasks in both allowed and disallowed cases, testing for success and-;; traps.-;;-;; (Copied from-;; https://github.com/WebAssembly/component-model/blob/add-tests/test/concurrency/drop-subtask.wast)-(component- (component $Looper- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $CoreLooper- (import "" "mem" (memory 1))- (import "" "task.return" (func $task.return))-- (global $done (mut i32) (i32.const 0))-- (func $loop (export "loop") (result i32)- (i32.const 1 (; YIELD ;))- )- (func $loop_cb (export "loop_cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)- ;; confirm that we've received a cancellation request- (if (i32.ne (local.get $event_code) (i32.const 0 (; NONE ;)))- (then unreachable))- (if (i32.ne (local.get $index) (i32.const 0))- (then unreachable))- (if (i32.ne (local.get $payload) (i32.const 0))- (then unreachable))-- (if (i32.eqz (global.get $done))- (then (return (i32.const 1 (; YIELD ;)))))- (call $task.return)- (i32.const 0 (; EXIT ;))- )-- (func $return (export "return")- (global.set $done (i32.const 1))- )- )- (canon task.return (core func $task.return))- (core instance $core_looper (instantiate $CoreLooper (with "" (instance- (export "mem" (memory $memory "mem"))- (export "task.return" (func $task.return))- ))))- (func (export "loop") (canon lift- (core func $core_looper "loop")- async (callback (func $core_looper "loop_cb"))- ))- (func (export "return") (canon lift- (core func $core_looper "return")- ))- )-- (component $Caller- (import "looper" (instance $looper- (export "loop" (func))- (export "return" (func))- ))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $CoreCaller- (import "" "mem" (memory 1))- (import "" "subtask.drop" (func $subtask.drop (param i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "loop" (func $loop (result i32)))- (import "" "return" (func $return))-- (func $drop-after-return (export "drop-after-return") (result i32)- (local $ret i32) (local $ws i32) (local $subtask i32)-- ;; start 'loop'- (local.set $ret (call $loop))- (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))- (then unreachable))- (local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4)))-- ;; tell 'loop' to stop- (call $return)-- ;; wait for 'loop' to run and return- (local.set $ws (call $waitable-set.new))- (call $waitable.join (local.get $subtask) (local.get $ws))- (local.set $ret (call $waitable-set.wait (local.get $ws) (i32.const 0)))- (if (i32.ne (i32.const 1 (; SUBTASK ;)) (local.get $ret))- (then unreachable))- (if (i32.ne (local.get $subtask) (i32.load (i32.const 0)))- (then unreachable))- (if (i32.ne (i32.const 2 (; RETURNED ;)) (i32.load (i32.const 4)))- (then unreachable))-- ;; ok to drop- (call $subtask.drop (local.get $subtask))- (i32.const 42)- )-- (func $drop-before-return (export "drop-before-return") (result i32)- (local $ret i32) (local $subtask i32)-- ;; start 'loop'- (local.set $ret (call $loop (i32.const 0xdead) (i32.const 0xbeef)))- (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))- (then unreachable))- (local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4)))-- ;; this should trap- (call $subtask.drop (local.get $subtask))- unreachable- )- )- (canon subtask.drop (core func $subtask.drop))- (canon waitable.join (core func $waitable.join))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (canon lower (func $looper "loop") async (memory $memory "mem") (core func $loop'))- (canon lower (func $looper "return") (memory $memory "mem") (core func $return'))- (core instance $core_caller (instantiate $CoreCaller (with "" (instance- (export "mem" (memory $memory "mem"))- (export "subtask.drop" (func $subtask.drop))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "loop" (func $loop'))- (export "return" (func $return'))- ))))- (func (export "drop-after-return") (result u32) (canon lift- (core func $core_caller "drop-after-return")- ))- (func (export "drop-before-return") (result u32) (canon lift- (core func $core_caller "drop-before-return")- ))- )-- (instance $looper (instantiate $Looper))- (instance $caller1 (instantiate $Caller (with "looper" (instance $looper))))- (instance $caller2 (instantiate $Caller (with "looper" (instance $looper))))- (func (export "drop-after-return") (alias export $caller1 "drop-after-return"))- (func (export "drop-before-return") (alias export $caller2 "drop-before-return"))-)-(assert_return (invoke "drop-after-return") (u32.const 42))-(assert_trap (invoke "drop-before-return") "cannot drop a subtask which has not yet resolved")diff --git a/tests/misc_testsuite/component-model-async/drop-waitable-set.wast b/tests/misc_testsuite/component-model-async/drop-waitable-set.wastdeleted file mode 100644index ea78cb30f0..0000000000--- a/tests/misc_testsuite/component-model-async/drop-waitable-set.wast+++ /dev/null@@ -1,90 +0,0 @@-;;! component_model_async = true-;;! reference_types = true-;;! gc_types = true--;; This test contains two components $C and $D-;; $D.run drives the test and first calls $C.wait-on-set, which waits on-;; a waitable-set. Then $D.run calls $C.drop-while-waiting which attempts-;; to drop the same waitable-set, which should trap.-;;-;; (Copied from-;; https://github.com/WebAssembly/component-model/blob/add-tests/test/concurrency/drop-waitable-set.wast)-(component- (component $C- (core module $Core- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.drop" (func $waitable-set.drop (param i32)))-- (global $ws (mut i32) (i32.const 0))- (func $start (global.set $ws (call $waitable-set.new)))- (start $start)-- (func $wait-on-set (export "wait-on-set") (result i32)- ;; wait on $ws- (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))- )- (func $drop-while-waiting (export "drop-while-waiting") (result i32)- (call $waitable-set.drop (global.get $ws))- unreachable- )- (func $unreachable-cb (export "unreachable-cb") (param i32 i32 i32) (result i32)- unreachable- )- )- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.drop (core func $waitable-set.drop))- (core instance $core (instantiate $Core (with "" (instance- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.drop" (func $waitable-set.drop))- ))))- (func (export "wait-on-set") (canon lift- (core func $core "wait-on-set")- async (callback (func $core "unreachable-cb"))- ))- (func (export "drop-while-waiting") (canon lift- (core func $core "drop-while-waiting")- async (callback (func $core "unreachable-cb"))- ))- )-- (component $D- (import "c" (instance $c- (export "wait-on-set" (func))- (export "drop-while-waiting" (func))- ))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $Core- (import "" "mem" (memory 1))- (import "" "wait-on-set" (func $wait-on-set (result i32)))- (import "" "drop-while-waiting" (func $drop-while-waiting))- (func $run (export "run") (result i32)- (local $ret i32)-- ;; start an async call to 'wait-on-set' which blocks, waiting on a- ;; waitable-set.- (local.set $ret (call $wait-on-set))- (if (i32.ne (i32.const 0x11) (local.get $ret))- (then unreachable))-- ;; this call will try to drop the same waitable-set, which should trap.- (call $drop-while-waiting)- unreachable- )- )- (canon lower (func $c "wait-on-set") async (memory $memory "mem") (core func $wait-on-set'))- (canon lower (func $c "drop-while-waiting") (core func $drop-while-waiting'))- (core instance $core (instantiate $Core (with "" (instance- (export "mem" (memory $memory "mem"))- (export "wait-on-set" (func $wait-on-set'))- (export "drop-while-waiting" (func $drop-while-waiting'))- ))))- (func (export "run") (result u32) (canon lift (core func $core "run")))- )-- (instance $c (instantiate $C))- (instance $d (instantiate $D (with "c" (instance $c))))- (func (export "run") (alias export $d "run"))-)-(assert_trap (invoke "run") "cannot drop waitable set with waiters")diff --git a/tests/misc_testsuite/component-model-async/empty-wait.wast b/tests/misc_testsuite/component-model-async/empty-wait.wastdeleted file mode 100644index a8364d58bf..0000000000--- a/tests/misc_testsuite/component-model-async/empty-wait.wast+++ /dev/null@@ -1,209 +0,0 @@-;;! component_model_async = true-;;! reference_types = true-;;! gc_types = true--;; This test has two components $C and $D, where $D imports and calls $C-;; $C exports two functions: 'blocker' and 'unblocker'-;; 'blocker' blocks on an empty waitable set-;; 'unblocker' wakes blocker by adding a resolved future to blocker's waitable set-;; $D calls 'blocker' then 'unblocker', then waits for 'blocker' to finish-;;-;; (Copied from-;; https://github.com/WebAssembly/component-model/blob/add-tests/test/concurrency/empty-wait.wast)-(component- (component $C- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $CM- (import "" "mem" (memory 1))- (import "" "task.return" (func $task.return (param i32)))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "future.new" (func $future.new (result i64)))- (import "" "future.read" (func $future.read (param i32 i32) (result i32)))- (import "" "future.write" (func $future.write (param i32 i32) (result i32)))- (import "" "future.drop-readable" (func $future.drop-readable (param i32)))- (import "" "future.drop-writable" (func $future.drop-writable (param i32)))-- ;; $ws is waited on by 'blocker' and added to by 'unblocker'- (global $ws (mut i32) (i32.const 0))- (func $start (global.set $ws (call $waitable-set.new)))- (start $start)-- ;; 'unblocker' initializes $futr with the readable end of a resolved future- (global $futr (mut i32) (i32.const 0))-- (func $blocker (export "blocker") (result i32)- ;; wait on $ws which is currently empty; 'unblocker' will wake us up- (i32.or (i32.const 2 (; WAIT ;)) (i32.shl (global.get $ws) (i32.const 4)))- )- (func $blocker_cb (export "blocker_cb") (param $event_code i32) (param $index i32) (param $payload i32) (result i32)- ;; assert that we were in fact woken by 'unblocker' adding $futr to $ws- (if (i32.ne (i32.const 4 (; FUTURE_READ ;)) (local.get $event_code))- (then unreachable))- (if (i32.ne (global.get $futr) (local.get $index))- (then unreachable))- (if (i32.ne (i32.const 0) (local.get $payload))- (then unreachable))-- (call $future.drop-readable (global.get $futr))-- ;; return 42 to $D.run- (call $task.return (i32.const 42))- (i32.const 0)- )-- (func $unblocker (export "unblocker") (result i32)- (local $ret i32) (local $ret64 i64)- (local $futw i32)-- ;; create a future that will be used to unblock 'blocker', storing r/w ends in $futr/$futw- (local.set $ret64 (call $future.new))- (global.set $futr (i32.wrap_i64 (local.get $ret64)))- (if (i32.ne (i32.const 2) (global.get $futr))- (then unreachable))- (local.set $futw (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32))))- (if (i32.ne (i32.const 3) (local.get $futw))- (then unreachable))-- ;; perform a future.read which will block, and add this future to the waitable-set- ;; being waited on by 'blocker'- (local.set $ret (call $future.read (global.get $futr) (i32.const 0)))- (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret))- (then unreachable))- (call $waitable.join (global.get $futr) (global.get $ws))-- ;; perform a future.write which will rendezvous with the write and complete- (local.set $ret (call $future.write (local.get $futw) (i32.const 0)))- (if (i32.ne (i32.const 0) (local.get $ret))- (then unreachable))-- (call $future.drop-writable (local.get $futw))-- ;; return 43 to $D.run- (call $task.return (i32.const 43))- (i32.const 0)- )- (func $unblocker_cb (export "unblocker_cb") (param i32 i32 i32) (result i32)- ;; 'unblocker' doesn't block- unreachable- )- )- (type $FT (future))- (canon task.return (result u32) (core func $task.return))- (canon waitable.join (core func $waitable.join))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (canon future.new $FT (core func $future.new))- (canon future.read $FT async (core func $future.read))- (canon future.write $FT async (core func $future.write))- (canon future.drop-readable $FT (core func $future.drop-readable))- (canon future.drop-writable $FT (core func $future.drop-writable))- (core instance $cm (instantiate $CM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "task.return" (func $task.return))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "future.new" (func $future.new))- (export "future.read" (func $future.read))- (export "future.write" (func $future.write))- (export "future.drop-readable" (func $future.drop-readable))- (export "future.drop-writable" (func $future.drop-writable))- ))))- (func (export "blocker") (result u32) (canon lift- (core func $cm "blocker")- async (callback (func $cm "blocker_cb"))- ))- (func (export "unblocker") (result u32) (canon lift- (core func $cm "unblocker")- async (callback (func $cm "unblocker_cb"))- ))- )-- (component $D- (import "c" (instance $c- (export "blocker" (func (result u32)))- (export "unblocker" (func (result u32)))- ))-- (core module $Memory (memory (export "mem") 1))- (core instance $memory (instantiate $Memory))- (core module $DM- (import "" "mem" (memory 1))- (import "" "waitable.join" (func $waitable.join (param i32 i32)))- (import "" "waitable-set.new" (func $waitable-set.new (result i32)))- (import "" "waitable-set.wait" (func $waitable-set.wait (param i32 i32) (result i32)))- (import "" "subtask.drop" (func $subtask.drop (param i32)))- (import "" "blocker" (func $blocker (param i32) (result i32)))- (import "" "unblocker" (func $unblocker (param i32) (result i32)))-- (global $ws (mut i32) (i32.const 0))- (func $start (global.set $ws (call $waitable-set.new)))- (start $start)-- (func $run (export "run") (result i32)- (local $ret i32) (local $retp1 i32) (local $retp2 i32)- (local $subtask i32)- (local $event_code i32)-- ;; call 'blocker'; it should block- (local.set $retp1 (i32.const 4))- (local.set $ret (call $blocker (local.get $retp1)))- (if (i32.ne (i32.const 1 (; STARTED ;)) (i32.and (local.get $ret) (i32.const 0xf)))- (then unreachable))- (local.set $subtask (i32.shr_u (local.get $ret) (i32.const 4)))- (if (i32.ne (i32.const 2) (local.get $subtask))- (then unreachable))-- ;; call 'unblocker' to unblock 'blocker'; it should complete eagerly- (local.set $retp2 (i32.const 8))- (local.set $ret (call $unblocker (local.get $retp2)))- (if (i32.ne (i32.const 2 (; RETURNED ;)) (local.get $ret))- (then unreachable))- (if (i32.ne (i32.const 43) (i32.load (local.get $retp2)))- (then unreachable))-- ;; wait for 'blocker' to be scheduled, run, and return- (call $waitable.join (local.get $subtask) (global.get $ws))- (local.set $retp2 (i32.const 8))- (local.set $event_code (call $waitable-set.wait (global.get $ws) (local.get $retp2)))- (if (i32.ne (i32.const 1 (; SUBTASK ;)) (local.get $event_code))- (then unreachable))- (if (i32.ne (local.get $subtask) (i32.load (local.get $retp2)))- (then unreachable))- (if (i32.ne (i32.const 2 (; RETURNED ;)) (i32.load offset=4 (local.get $retp2)))- (then unreachable))- (if (i32.ne (i32.const 42) (i32.load (local.get $retp1)))- (then unreachable))-- (call $subtask.drop (local.get $subtask))-- ;; return 44 to the top-level test harness- (i32.const 44)- )- )- (canon waitable.join (core func $waitable.join))- (canon waitable-set.new (core func $waitable-set.new))- (canon waitable-set.wait (memory $memory "mem") (core func $waitable-set.wait))- (canon subtask.drop (core func $subtask.drop))- (canon lower (func $c "blocker") async (memory $memory "mem") (core func $blocker'))- (canon lower (func $c "unblocker") async (memory $memory "mem") (core func $unblocker'))- (core instance $dm (instantiate $DM (with "" (instance- (export "mem" (memory $memory "mem"))- (export "waitable.join" (func $waitable.join))- (export "waitable-set.new" (func $waitable-set.new))- (export "waitable-set.wait" (func $waitable-set.wait))- (export "subtask.drop" (func $subtask.drop))- (export "blocker" (func $blocker'))- (export "unblocker" (func $unblocker'))- ))))- (func (export "run") (result u32) (canon lift (core func $dm "run")))- )-- (instance $c (instantiate $C))- (instance $d (instantiate $D (with "c" (instance $c))))- (func (export "run") (alias export $d "run"))-)-(assert_return (invoke "run") (u32.const 44))