Skip to content

Commit 6876503

Browse files
committed
add Component Model async ABI tests
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd separately.
1 parent fa70f02 commit 6876503

File tree

94 files changed

+10353
-192
lines changed

Some content is hidden

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

94 files changed

+10353
-192
lines changed

Cargo.lock

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ members = [
156156
"crates/bench-api",
157157
"crates/c-api/artifact",
158158
"crates/environ/fuzz",
159+
"crates/misc/component-async-tests",
159160
"crates/test-programs",
160161
"crates/wasi-preview1-component-adapter",
161162
"crates/wasi-preview1-component-adapter/verify",
@@ -304,6 +305,7 @@ test-programs-artifacts = { path = 'crates/test-programs/artifacts' }
304305
wasmtime-test-util = { path = "crates/test-util" }
305306
byte-array-literals = { path = "crates/wasi-preview1-component-adapter/byte-array-literals" }
306307
pulley-interpreter-fuzz = { path = 'pulley/fuzz' }
308+
component-async-tests = { path = "crates/misc/component-async-tests" }
307309

308310
# Bytecode Alliance maintained dependencies:
309311
# ---------------------------

ci/miri-provenance-test.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
set -ex
99

1010
compile() {
11-
cargo run --no-default-features --features compile,pulley,wat,gc-drc,component-model \
11+
cargo run --no-default-features --features compile,pulley,wat,gc-drc,component-model,component-model-async \
1212
compile --target pulley64 $1 \
1313
-o ${1%.wat}.cwasm \
1414
-O memory-reservation=$((1 << 20)) \
1515
-O memory-guard-size=0 \
1616
-O signals-based-traps=n \
17-
-W function-references
17+
-W function-references,component-model-async,component-model-async-stackful,component-model-async-builtins,component-model-error-context
1818
}
1919

2020
compile ./tests/all/pulley_provenance_test.wat
2121
compile ./tests/all/pulley_provenance_test_component.wat
22+
compile ./tests/all/pulley_provenance_test_async_component.wat
2223

2324
MIRIFLAGS="$MIRIFLAGS -Zmiri-disable-isolation -Zmiri-permissive-provenance" \
2425
cargo miri test --test all -- \
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "component-async-tests"
3+
authors = ["The Wasmtime Project Developers"]
4+
license = "Apache-2.0 WITH LLVM-exception"
5+
version = "0.0.0"
6+
edition.workspace = true
7+
rust-version.workspace = true
8+
publish = false
9+
10+
[lints]
11+
workspace = true
12+
13+
[dependencies]
14+
anyhow = { workspace = true }
15+
futures = { workspace = true }
16+
env_logger = { workspace = true }
17+
tempfile = { workspace = true }
18+
tokio = { workspace = true, features = [
19+
"fs",
20+
"process",
21+
"macros",
22+
"rt-multi-thread",
23+
"time",
24+
] }
25+
wasm-compose = { workspace = true }
26+
wasmparser = { workspace = true }
27+
wasmtime = { workspace = true, features = [
28+
"default",
29+
"pulley",
30+
"cranelift",
31+
"component-model-async",
32+
] }
33+
wasmtime-wasi = { workspace = true }
34+
35+
[dev-dependencies]
36+
test-programs-artifacts = { workspace = true }
37+
bytes = { workspace = true }
38+
once_cell = { version = "1.12.0" }
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use anyhow::Result;
2+
use wasmtime::component::Resource;
3+
use wasmtime_wasi::p2::IoView;
4+
5+
use super::Ctx;
6+
7+
pub mod bindings {
8+
wasmtime::component::bindgen!({
9+
path: "wit",
10+
world: "borrowing-host",
11+
trappable_imports: true,
12+
concurrent_imports: true,
13+
concurrent_exports: true,
14+
async: {
15+
only_imports: []
16+
},
17+
with: {
18+
"local:local/borrowing-types/x": super::MyX,
19+
}
20+
});
21+
}
22+
23+
/// Used as the borrowing type (`local:local/borrowing-types/x`)
24+
pub struct MyX;
25+
26+
impl bindings::local::local::borrowing_types::HostX for &mut Ctx {
27+
fn new(&mut self) -> Result<Resource<MyX>> {
28+
Ok(IoView::table(self).push(MyX)?)
29+
}
30+
31+
fn foo(&mut self, x: Resource<MyX>) -> Result<()> {
32+
_ = IoView::table(self).get(&x)?;
33+
Ok(())
34+
}
35+
36+
fn drop(&mut self, x: Resource<MyX>) -> Result<()> {
37+
IoView::table(self).delete(x)?;
38+
Ok(())
39+
}
40+
}
41+
42+
impl bindings::local::local::borrowing_types::Host for &mut Ctx {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub mod bindings {
2+
wasmtime::component::bindgen!({
3+
path: "wit",
4+
world: "closed-streams",
5+
concurrent_imports: true,
6+
concurrent_exports: true,
7+
async: {
8+
only_imports: [
9+
"local:local/closed#read-stream",
10+
"local:local/closed#read-future",
11+
]
12+
},
13+
});
14+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![expect(clippy::allow_attributes_without_reason)]
2+
3+
use std::sync::{Arc, Mutex};
4+
use std::task::Waker;
5+
6+
use wasmtime::component::{HasData, ResourceTable};
7+
use wasmtime_wasi::p2::{IoView, WasiCtx, WasiView};
8+
9+
pub mod borrowing_host;
10+
pub mod closed_streams;
11+
pub mod resource_stream;
12+
pub mod round_trip;
13+
pub mod round_trip_direct;
14+
pub mod round_trip_many;
15+
pub mod sleep;
16+
pub mod transmit;
17+
pub mod util;
18+
pub mod yield_host;
19+
20+
/// Host implementation, usable primarily by tests
21+
pub struct Ctx {
22+
pub wasi: WasiCtx,
23+
pub table: ResourceTable,
24+
pub wakers: Arc<Mutex<Option<Vec<Waker>>>>,
25+
pub continue_: bool,
26+
}
27+
28+
impl IoView for Ctx {
29+
fn table(&mut self) -> &mut ResourceTable {
30+
&mut self.table
31+
}
32+
}
33+
34+
impl WasiView for Ctx {
35+
fn ctx(&mut self) -> &mut WasiCtx {
36+
&mut self.wasi
37+
}
38+
}
39+
40+
impl HasData for Ctx {
41+
type Data<'a> = &'a mut Self;
42+
}

0 commit comments

Comments
 (0)