Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi/tests/all/p3/mod.rs
1693 views
1
use crate::store::{Ctx, MyWasiCtx};
2
use anyhow::{Context as _, anyhow};
3
use std::path::Path;
4
use test_programs_artifacts::*;
5
use wasmtime::Result;
6
use wasmtime::component::{Component, Linker};
7
use wasmtime_wasi::p3::bindings::Command;
8
9
async fn run(path: &str) -> Result<()> {
10
run_allow_blocking_current_thread(path, false).await
11
}
12
13
async fn run_allow_blocking_current_thread(
14
path: &str,
15
allow_blocking_current_thread: bool,
16
) -> Result<()> {
17
let path = Path::new(path);
18
let name = path.file_stem().unwrap().to_str().unwrap();
19
let engine = test_programs_artifacts::engine(|config| {
20
config.async_support(true);
21
config.wasm_component_model_async(true);
22
});
23
let mut linker = Linker::new(&engine);
24
// TODO: Remove once test components are not built for `wasm32-wasip1`
25
wasmtime_wasi::p2::add_to_linker_async(&mut linker)
26
.context("failed to link `wasi:[email protected]`")?;
27
wasmtime_wasi::p3::add_to_linker(&mut linker).context("failed to link `wasi:[email protected]`")?;
28
29
let (mut store, _td) = Ctx::new(&engine, name, |builder| MyWasiCtx {
30
wasi: builder
31
.allow_blocking_current_thread(allow_blocking_current_thread)
32
.build(),
33
table: Default::default(),
34
})?;
35
let component = Component::from_file(&engine, path)?;
36
let instance = linker.instantiate_async(&mut store, &component).await?;
37
let command =
38
Command::new(&mut store, &instance).context("failed to instantiate `wasi:cli/command`")?;
39
instance
40
.run_concurrent(&mut store, async move |store| {
41
command.wasi_cli_run().call_run(store).await
42
})
43
.await
44
.context("failed to call `wasi:cli/run#run`")?
45
.context("guest trapped")?
46
.map_err(|()| anyhow!("`wasi:cli/run#run` failed"))
47
}
48
49
foreach_p3!(assert_test_exists);
50
51
#[test_log::test(tokio::test(flavor = "multi_thread"))]
52
async fn p3_cli() -> anyhow::Result<()> {
53
run(P3_CLI_COMPONENT).await
54
}
55
56
#[test_log::test(tokio::test(flavor = "multi_thread"))]
57
async fn p3_clocks_sleep() -> anyhow::Result<()> {
58
run(P3_CLOCKS_SLEEP_COMPONENT).await
59
}
60
61
#[test_log::test(tokio::test(flavor = "multi_thread"))]
62
async fn p3_filesystem_file_read_write() -> anyhow::Result<()> {
63
run(P3_FILESYSTEM_FILE_READ_WRITE_COMPONENT).await
64
}
65
66
#[test_log::test(tokio::test(flavor = "multi_thread"))]
67
async fn p3_filesystem_file_read_write_blocking() -> anyhow::Result<()> {
68
run_allow_blocking_current_thread(P3_FILESYSTEM_FILE_READ_WRITE_COMPONENT, true).await
69
}
70
71
#[test_log::test(tokio::test(flavor = "multi_thread"))]
72
async fn p3_random_imports() -> anyhow::Result<()> {
73
run(P3_RANDOM_IMPORTS_COMPONENT).await
74
}
75
76
#[test_log::test(tokio::test(flavor = "multi_thread"))]
77
async fn p3_sockets_ip_name_lookup() -> anyhow::Result<()> {
78
run(P3_SOCKETS_IP_NAME_LOOKUP_COMPONENT).await
79
}
80
81
#[test_log::test(tokio::test(flavor = "multi_thread"))]
82
async fn p3_sockets_tcp_bind() -> anyhow::Result<()> {
83
run(P3_SOCKETS_TCP_BIND_COMPONENT).await
84
}
85
86
#[test_log::test(tokio::test(flavor = "multi_thread"))]
87
async fn p3_sockets_tcp_connect() -> anyhow::Result<()> {
88
run(P3_SOCKETS_TCP_CONNECT_COMPONENT).await
89
}
90
91
#[test_log::test(tokio::test(flavor = "multi_thread"))]
92
async fn p3_sockets_tcp_sample_application() -> anyhow::Result<()> {
93
run(P3_SOCKETS_TCP_SAMPLE_APPLICATION_COMPONENT).await
94
}
95
96
#[test_log::test(tokio::test(flavor = "multi_thread"))]
97
async fn p3_sockets_tcp_sockopts() -> anyhow::Result<()> {
98
run(P3_SOCKETS_TCP_SOCKOPTS_COMPONENT).await
99
}
100
101
#[test_log::test(tokio::test(flavor = "multi_thread"))]
102
async fn p3_sockets_tcp_states() -> anyhow::Result<()> {
103
run(P3_SOCKETS_TCP_STATES_COMPONENT).await
104
}
105
106
#[test_log::test(tokio::test(flavor = "multi_thread"))]
107
async fn p3_sockets_tcp_streams() -> anyhow::Result<()> {
108
run(P3_SOCKETS_TCP_STREAMS_COMPONENT).await
109
}
110
111
#[test_log::test(tokio::test(flavor = "multi_thread"))]
112
async fn p3_sockets_udp_bind() -> anyhow::Result<()> {
113
run(P3_SOCKETS_UDP_BIND_COMPONENT).await
114
}
115
116
#[test_log::test(tokio::test(flavor = "multi_thread"))]
117
async fn p3_sockets_udp_connect() -> anyhow::Result<()> {
118
run(P3_SOCKETS_UDP_CONNECT_COMPONENT).await
119
}
120
121
#[test_log::test(tokio::test(flavor = "multi_thread"))]
122
async fn p3_sockets_udp_sample_application() -> anyhow::Result<()> {
123
run(P3_SOCKETS_UDP_SAMPLE_APPLICATION_COMPONENT).await
124
}
125
126
#[test_log::test(tokio::test(flavor = "multi_thread"))]
127
async fn p3_sockets_udp_sockopts() -> anyhow::Result<()> {
128
run(P3_SOCKETS_UDP_SOCKOPTS_COMPONENT).await
129
}
130
131
#[test_log::test(tokio::test(flavor = "multi_thread"))]
132
async fn p3_sockets_udp_states() -> anyhow::Result<()> {
133
run(P3_SOCKETS_UDP_STATES_COMPONENT).await
134
}
135
136
#[test_log::test(tokio::test(flavor = "multi_thread"))]
137
async fn p3_readdir() -> anyhow::Result<()> {
138
run(P3_READDIR_COMPONENT).await
139
}
140
141
#[test_log::test(tokio::test(flavor = "multi_thread"))]
142
async fn p3_readdir_blocking() -> anyhow::Result<()> {
143
run_allow_blocking_current_thread(P3_READDIR_COMPONENT, true).await
144
}
145
146