Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi/tests/all/p3/mod.rs
3130 views
1
use crate::store::{Ctx, MyWasiCtx};
2
use std::path::Path;
3
use test_programs_artifacts::*;
4
use wasmtime::component::{Component, Linker};
5
use wasmtime::{Result, error::Context as _, format_err};
6
use wasmtime_wasi::p3::bindings::Command;
7
8
async fn run(path: &str) -> Result<()> {
9
run_allow_blocking_current_thread(path, false).await
10
}
11
12
async fn run_allow_blocking_current_thread(
13
path: &str,
14
allow_blocking_current_thread: bool,
15
) -> Result<()> {
16
let path = Path::new(path);
17
let name = path.file_stem().unwrap().to_str().unwrap();
18
let engine = test_programs_artifacts::engine(|config| {
19
config.wasm_component_model_async(true);
20
});
21
let mut linker = Linker::new(&engine);
22
// TODO: Remove once test components are not built for `wasm32-wasip1`
23
wasmtime_wasi::p2::add_to_linker_async(&mut linker)
24
.context("failed to link `wasi:[email protected]`")?;
25
wasmtime_wasi::p3::add_to_linker(&mut linker).context("failed to link `wasi:[email protected]`")?;
26
27
let (mut store, _td) = Ctx::new(&engine, name, |builder| MyWasiCtx {
28
wasi: builder
29
.allow_blocking_current_thread(allow_blocking_current_thread)
30
.build(),
31
table: Default::default(),
32
})?;
33
let component = Component::from_file(&engine, path)?;
34
let command = Command::instantiate_async(&mut store, &component, &linker)
35
.await
36
.context("failed to instantiate `wasi:cli/command`")?;
37
store
38
.run_concurrent(async move |store| command.wasi_cli_run().call_run(store).await)
39
.await
40
.context("failed to call `wasi:cli/run#run`")?
41
.context("guest trapped")?
42
.0
43
.map_err(|()| format_err!("`wasi:cli/run#run` failed"))
44
}
45
46
foreach_p3!(assert_test_exists);
47
48
#[test_log::test(tokio::test(flavor = "multi_thread"))]
49
async fn p3_cli() -> wasmtime::Result<()> {
50
run(P3_CLI_COMPONENT).await
51
}
52
53
#[test_log::test(tokio::test(flavor = "multi_thread"))]
54
async fn p3_clocks_sleep() -> wasmtime::Result<()> {
55
run(P3_CLOCKS_SLEEP_COMPONENT).await
56
}
57
58
#[test_log::test(tokio::test(flavor = "multi_thread"))]
59
async fn p3_filesystem_file_read_write() -> wasmtime::Result<()> {
60
run(P3_FILESYSTEM_FILE_READ_WRITE_COMPONENT).await
61
}
62
63
#[test_log::test(tokio::test(flavor = "multi_thread"))]
64
async fn p3_filesystem_file_read_write_blocking() -> wasmtime::Result<()> {
65
run_allow_blocking_current_thread(P3_FILESYSTEM_FILE_READ_WRITE_COMPONENT, true).await
66
}
67
68
#[test_log::test(tokio::test(flavor = "multi_thread"))]
69
async fn p3_random_imports() -> wasmtime::Result<()> {
70
run(P3_RANDOM_IMPORTS_COMPONENT).await
71
}
72
73
#[test_log::test(tokio::test(flavor = "multi_thread"))]
74
async fn p3_sockets_ip_name_lookup() -> wasmtime::Result<()> {
75
run(P3_SOCKETS_IP_NAME_LOOKUP_COMPONENT).await
76
}
77
78
#[test_log::test(tokio::test(flavor = "multi_thread"))]
79
async fn p3_sockets_tcp_bind() -> wasmtime::Result<()> {
80
run(P3_SOCKETS_TCP_BIND_COMPONENT).await
81
}
82
83
#[test_log::test(tokio::test(flavor = "multi_thread"))]
84
async fn p3_sockets_tcp_connect() -> wasmtime::Result<()> {
85
run(P3_SOCKETS_TCP_CONNECT_COMPONENT).await
86
}
87
88
#[test_log::test(tokio::test(flavor = "multi_thread"))]
89
async fn p3_sockets_tcp_listen() -> wasmtime::Result<()> {
90
run(P3_SOCKETS_TCP_LISTEN_COMPONENT).await
91
}
92
93
#[test_log::test(tokio::test(flavor = "multi_thread"))]
94
async fn p3_sockets_tcp_sample_application() -> wasmtime::Result<()> {
95
run(P3_SOCKETS_TCP_SAMPLE_APPLICATION_COMPONENT).await
96
}
97
98
#[test_log::test(tokio::test(flavor = "multi_thread"))]
99
async fn p3_sockets_tcp_sockopts() -> wasmtime::Result<()> {
100
run(P3_SOCKETS_TCP_SOCKOPTS_COMPONENT).await
101
}
102
103
#[test_log::test(tokio::test(flavor = "multi_thread"))]
104
async fn p3_sockets_tcp_states() -> wasmtime::Result<()> {
105
run(P3_SOCKETS_TCP_STATES_COMPONENT).await
106
}
107
108
#[test_log::test(tokio::test(flavor = "multi_thread"))]
109
async fn p3_sockets_tcp_streams() -> wasmtime::Result<()> {
110
run(P3_SOCKETS_TCP_STREAMS_COMPONENT).await
111
}
112
113
#[test_log::test(tokio::test(flavor = "multi_thread"))]
114
async fn p3_sockets_udp_bind() -> wasmtime::Result<()> {
115
run(P3_SOCKETS_UDP_BIND_COMPONENT).await
116
}
117
118
#[test_log::test(tokio::test(flavor = "multi_thread"))]
119
async fn p3_sockets_udp_connect() -> wasmtime::Result<()> {
120
run(P3_SOCKETS_UDP_CONNECT_COMPONENT).await
121
}
122
123
#[test_log::test(tokio::test(flavor = "multi_thread"))]
124
async fn p3_sockets_udp_receive() -> wasmtime::Result<()> {
125
run(P3_SOCKETS_UDP_RECEIVE_COMPONENT).await
126
}
127
128
#[test_log::test(tokio::test(flavor = "multi_thread"))]
129
async fn p3_sockets_udp_sample_application() -> wasmtime::Result<()> {
130
run(P3_SOCKETS_UDP_SAMPLE_APPLICATION_COMPONENT).await
131
}
132
133
#[test_log::test(tokio::test(flavor = "multi_thread"))]
134
async fn p3_sockets_udp_send() -> wasmtime::Result<()> {
135
run(P3_SOCKETS_UDP_SEND_COMPONENT).await
136
}
137
138
#[test_log::test(tokio::test(flavor = "multi_thread"))]
139
async fn p3_sockets_udp_sockopts() -> wasmtime::Result<()> {
140
run(P3_SOCKETS_UDP_SOCKOPTS_COMPONENT).await
141
}
142
143
#[test_log::test(tokio::test(flavor = "multi_thread"))]
144
async fn p3_sockets_udp_states() -> wasmtime::Result<()> {
145
run(P3_SOCKETS_UDP_STATES_COMPONENT).await
146
}
147
148
#[test_log::test(tokio::test(flavor = "multi_thread"))]
149
async fn p3_readdir() -> wasmtime::Result<()> {
150
run(P3_READDIR_COMPONENT).await
151
}
152
153
#[test_log::test(tokio::test(flavor = "multi_thread"))]
154
async fn p3_readdir_blocking() -> wasmtime::Result<()> {
155
run_allow_blocking_current_thread(P3_READDIR_COMPONENT, true).await
156
}
157
158
#[test_log::test(tokio::test(flavor = "multi_thread"))]
159
async fn p3_file_write() -> wasmtime::Result<()> {
160
run(P3_FILE_WRITE_COMPONENT).await
161
}
162
163
#[test_log::test(tokio::test(flavor = "multi_thread"))]
164
async fn p3_file_write_blocking() -> wasmtime::Result<()> {
165
run_allow_blocking_current_thread(P3_FILE_WRITE_COMPONENT, true).await
166
}
167
168
#[expect(
169
dead_code,
170
reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"
171
)]
172
fn p3_cli_hello_stdout() {}
173
174
#[expect(
175
dead_code,
176
reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"
177
)]
178
fn p3_cli_hello_stdout_post_return() {}
179
180
#[expect(
181
dead_code,
182
reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"
183
)]
184
fn p3_cli_much_stdout() {}
185
186
#[expect(
187
dead_code,
188
reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"
189
)]
190
fn p3_cli_serve_hello_world() {}
191
192
#[expect(
193
dead_code,
194
reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"
195
)]
196
fn p3_cli_serve_sleep() {}
197
198