Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi/tests/all/p2/async_.rs
3129 views
1
use crate::store::{Ctx, MyWasiCtx};
2
use std::path::Path;
3
use test_programs_artifacts::*;
4
use wasmtime::Result;
5
use wasmtime::component::{Component, Linker};
6
use wasmtime_wasi::p2::add_to_linker_async;
7
use wasmtime_wasi::p2::bindings::Command;
8
9
async fn run(path: &str, inherit_stdio: bool) -> Result<()> {
10
let path = Path::new(path);
11
let name = path.file_stem().unwrap().to_str().unwrap();
12
let engine = test_programs_artifacts::engine(|_config| {});
13
let mut linker = Linker::new(&engine);
14
add_to_linker_async(&mut linker)?;
15
16
let (mut store, _td) = Ctx::new(&engine, name, |builder| {
17
if inherit_stdio {
18
builder.inherit_stdio();
19
}
20
MyWasiCtx {
21
wasi: builder.build(),
22
table: Default::default(),
23
}
24
})?;
25
let component = Component::from_file(&engine, path)?;
26
let command = Command::instantiate_async(&mut store, &component, &linker).await?;
27
command
28
.wasi_cli_run()
29
.call_run(&mut store)
30
.await?
31
.map_err(|()| wasmtime::format_err!("run returned a failure"))
32
}
33
34
foreach_p1!(assert_test_exists);
35
foreach_p2!(assert_test_exists);
36
37
// Below here is mechanical: there should be one test for every binary in
38
// wasi-tests.
39
#[test_log::test(tokio::test(flavor = "multi_thread"))]
40
async fn p1_big_random_buf() {
41
run(P1_BIG_RANDOM_BUF_COMPONENT, false).await.unwrap()
42
}
43
#[test_log::test(tokio::test(flavor = "multi_thread"))]
44
async fn p1_clock_time_get() {
45
run(P1_CLOCK_TIME_GET_COMPONENT, false).await.unwrap()
46
}
47
#[test_log::test(tokio::test(flavor = "multi_thread"))]
48
async fn p1_close_preopen() {
49
run(P1_CLOSE_PREOPEN_COMPONENT, false).await.unwrap()
50
}
51
#[test_log::test(tokio::test(flavor = "multi_thread"))]
52
async fn p1_dangling_fd() {
53
run(P1_DANGLING_FD_COMPONENT, false).await.unwrap()
54
}
55
#[test_log::test(tokio::test(flavor = "multi_thread"))]
56
async fn p1_dangling_symlink() {
57
run(P1_DANGLING_SYMLINK_COMPONENT, false).await.unwrap()
58
}
59
#[test_log::test(tokio::test(flavor = "multi_thread"))]
60
async fn p1_directory_seek() {
61
run(P1_DIRECTORY_SEEK_COMPONENT, false).await.unwrap()
62
}
63
#[test_log::test(tokio::test(flavor = "multi_thread"))]
64
async fn p1_dir_fd_op_failures() {
65
run(P1_DIR_FD_OP_FAILURES_COMPONENT, false).await.unwrap()
66
}
67
#[test_log::test(tokio::test(flavor = "multi_thread"))]
68
async fn p1_fd_advise() {
69
run(P1_FD_ADVISE_COMPONENT, false).await.unwrap()
70
}
71
#[test_log::test(tokio::test(flavor = "multi_thread"))]
72
async fn p1_fd_filestat_get() {
73
run(P1_FD_FILESTAT_GET_COMPONENT, false).await.unwrap()
74
}
75
#[test_log::test(tokio::test(flavor = "multi_thread"))]
76
async fn p1_fd_filestat_set() {
77
run(P1_FD_FILESTAT_SET_COMPONENT, false).await.unwrap()
78
}
79
#[test_log::test(tokio::test(flavor = "multi_thread"))]
80
async fn p1_fd_flags_set() {
81
run(P1_FD_FLAGS_SET_COMPONENT, false).await.unwrap()
82
}
83
#[test_log::test(tokio::test(flavor = "multi_thread"))]
84
async fn p1_fd_readdir() {
85
run(P1_FD_READDIR_COMPONENT, false).await.unwrap()
86
}
87
#[test_log::test(tokio::test(flavor = "multi_thread"))]
88
async fn p1_file_allocate() {
89
run(P1_FILE_ALLOCATE_COMPONENT, false).await.unwrap()
90
}
91
#[test_log::test(tokio::test(flavor = "multi_thread"))]
92
async fn p1_file_pread_pwrite() {
93
run(P1_FILE_PREAD_PWRITE_COMPONENT, false).await.unwrap()
94
}
95
#[test_log::test(tokio::test(flavor = "multi_thread"))]
96
async fn p1_file_read_write() {
97
run(P1_FILE_READ_WRITE_COMPONENT, false).await.unwrap()
98
}
99
#[test_log::test(tokio::test(flavor = "multi_thread"))]
100
async fn p1_file_seek_tell() {
101
run(P1_FILE_SEEK_TELL_COMPONENT, false).await.unwrap()
102
}
103
#[test_log::test(tokio::test(flavor = "multi_thread"))]
104
async fn p1_file_truncation() {
105
run(P1_FILE_TRUNCATION_COMPONENT, false).await.unwrap()
106
}
107
#[test_log::test(tokio::test(flavor = "multi_thread"))]
108
async fn p1_file_unbuffered_write() {
109
run(P1_FILE_UNBUFFERED_WRITE_COMPONENT, false)
110
.await
111
.unwrap()
112
}
113
#[test_log::test(tokio::test(flavor = "multi_thread"))]
114
async fn p1_interesting_paths() {
115
run(P1_INTERESTING_PATHS_COMPONENT, true).await.unwrap()
116
}
117
#[test_log::test(tokio::test(flavor = "multi_thread"))]
118
async fn p1_regular_file_isatty() {
119
run(P1_REGULAR_FILE_ISATTY_COMPONENT, false).await.unwrap()
120
}
121
#[test_log::test(tokio::test(flavor = "multi_thread"))]
122
async fn p1_nofollow_errors() {
123
run(P1_NOFOLLOW_ERRORS_COMPONENT, false).await.unwrap()
124
}
125
#[test_log::test(tokio::test(flavor = "multi_thread"))]
126
async fn p1_overwrite_preopen() {
127
run(P1_OVERWRITE_PREOPEN_COMPONENT, false).await.unwrap()
128
}
129
#[test_log::test(tokio::test(flavor = "multi_thread"))]
130
async fn p1_path_exists() {
131
run(P1_PATH_EXISTS_COMPONENT, false).await.unwrap()
132
}
133
#[test_log::test(tokio::test(flavor = "multi_thread"))]
134
async fn p1_path_filestat() {
135
run(P1_PATH_FILESTAT_COMPONENT, false).await.unwrap()
136
}
137
#[test_log::test(tokio::test(flavor = "multi_thread"))]
138
async fn p1_path_link() {
139
run(P1_PATH_LINK_COMPONENT, false).await.unwrap()
140
}
141
#[test_log::test(tokio::test(flavor = "multi_thread"))]
142
async fn p1_path_open_create_existing() {
143
run(P1_PATH_OPEN_CREATE_EXISTING_COMPONENT, false)
144
.await
145
.unwrap()
146
}
147
#[test_log::test(tokio::test(flavor = "multi_thread"))]
148
async fn p1_path_open_read_write() {
149
run(P1_PATH_OPEN_READ_WRITE_COMPONENT, false).await.unwrap()
150
}
151
#[test_log::test(tokio::test(flavor = "multi_thread"))]
152
async fn p1_path_open_dirfd_not_dir() {
153
run(P1_PATH_OPEN_DIRFD_NOT_DIR_COMPONENT, false)
154
.await
155
.unwrap()
156
}
157
#[test_log::test(tokio::test(flavor = "multi_thread"))]
158
async fn p1_path_open_missing() {
159
run(P1_PATH_OPEN_MISSING_COMPONENT, false).await.unwrap()
160
}
161
#[test_log::test(tokio::test(flavor = "multi_thread"))]
162
async fn p1_path_open_nonblock() {
163
run(P1_PATH_OPEN_NONBLOCK_COMPONENT, false).await.unwrap()
164
}
165
#[test_log::test(tokio::test(flavor = "multi_thread"))]
166
async fn p1_path_rename_dir_trailing_slashes() {
167
run(P1_PATH_RENAME_DIR_TRAILING_SLASHES_COMPONENT, false)
168
.await
169
.unwrap()
170
}
171
#[test_log::test(tokio::test(flavor = "multi_thread"))]
172
async fn p1_path_rename() {
173
run(P1_PATH_RENAME_COMPONENT, false).await.unwrap()
174
}
175
#[test_log::test(tokio::test(flavor = "multi_thread"))]
176
async fn p1_path_symlink_trailing_slashes() {
177
run(P1_PATH_SYMLINK_TRAILING_SLASHES_COMPONENT, false)
178
.await
179
.unwrap()
180
}
181
#[test_log::test(tokio::test(flavor = "multi_thread"))]
182
async fn p1_poll_oneoff_files() {
183
run(P1_POLL_ONEOFF_FILES_COMPONENT, false).await.unwrap()
184
}
185
186
#[test_log::test(tokio::test(flavor = "multi_thread"))]
187
async fn p1_poll_oneoff_stdio() {
188
run(P1_POLL_ONEOFF_STDIO_COMPONENT, true).await.unwrap()
189
}
190
#[test_log::test(tokio::test(flavor = "multi_thread"))]
191
async fn p1_readlink() {
192
run(P1_READLINK_COMPONENT, false).await.unwrap()
193
}
194
#[test_log::test(tokio::test(flavor = "multi_thread"))]
195
async fn p1_remove_directory() {
196
run(P1_REMOVE_DIRECTORY_COMPONENT, false).await.unwrap()
197
}
198
#[test_log::test(tokio::test(flavor = "multi_thread"))]
199
async fn p1_remove_nonempty_directory() {
200
run(P1_REMOVE_NONEMPTY_DIRECTORY_COMPONENT, false)
201
.await
202
.unwrap()
203
}
204
#[test_log::test(tokio::test(flavor = "multi_thread"))]
205
async fn p1_renumber() {
206
run(P1_RENUMBER_COMPONENT, false).await.unwrap()
207
}
208
#[test_log::test(tokio::test(flavor = "multi_thread"))]
209
async fn p1_sched_yield() {
210
run(P1_SCHED_YIELD_COMPONENT, false).await.unwrap()
211
}
212
#[test_log::test(tokio::test(flavor = "multi_thread"))]
213
async fn p1_stdio() {
214
run(P1_STDIO_COMPONENT, false).await.unwrap()
215
}
216
#[test_log::test(tokio::test(flavor = "multi_thread"))]
217
async fn p1_stdio_isatty() {
218
// If the test process is setup such that stdio is a terminal:
219
if test_programs_artifacts::stdio_is_terminal() {
220
// Inherit stdio, test asserts each is not tty:
221
run(P1_STDIO_ISATTY_COMPONENT, true).await.unwrap()
222
}
223
}
224
#[test_log::test(tokio::test(flavor = "multi_thread"))]
225
async fn p1_stdio_not_isatty() {
226
// Don't inherit stdio, test asserts each is not tty:
227
run(P1_STDIO_NOT_ISATTY_COMPONENT, false).await.unwrap()
228
}
229
#[test_log::test(tokio::test(flavor = "multi_thread"))]
230
async fn p1_symlink_create() {
231
run(P1_SYMLINK_CREATE_COMPONENT, false).await.unwrap()
232
}
233
#[test_log::test(tokio::test(flavor = "multi_thread"))]
234
async fn p1_symlink_filestat() {
235
run(P1_SYMLINK_FILESTAT_COMPONENT, false).await.unwrap()
236
}
237
#[test_log::test(tokio::test(flavor = "multi_thread"))]
238
async fn p1_symlink_loop() {
239
run(P1_SYMLINK_LOOP_COMPONENT, false).await.unwrap()
240
}
241
#[test_log::test(tokio::test(flavor = "multi_thread"))]
242
async fn p1_unlink_file_trailing_slashes() {
243
run(P1_UNLINK_FILE_TRAILING_SLASHES_COMPONENT, false)
244
.await
245
.unwrap()
246
}
247
#[test_log::test(tokio::test(flavor = "multi_thread"))]
248
async fn p1_path_open_preopen() {
249
run(P1_PATH_OPEN_PREOPEN_COMPONENT, false).await.unwrap()
250
}
251
#[test_log::test(tokio::test(flavor = "multi_thread"))]
252
async fn p1_unicode_output() {
253
run(P1_UNICODE_OUTPUT_COMPONENT, true).await.unwrap()
254
}
255
#[test_log::test(tokio::test(flavor = "multi_thread"))]
256
async fn p1_file_write() {
257
run(P1_FILE_WRITE_COMPONENT, false).await.unwrap()
258
}
259
#[test_log::test(tokio::test(flavor = "multi_thread"))]
260
async fn p1_path_open_lots() {
261
run(P1_PATH_OPEN_LOTS_COMPONENT, false).await.unwrap()
262
}
263
264
#[test_log::test(tokio::test(flavor = "multi_thread"))]
265
async fn p2_sleep() {
266
run(P2_SLEEP_COMPONENT, false).await.unwrap()
267
}
268
#[test_log::test(tokio::test(flavor = "multi_thread"))]
269
async fn p2_random() {
270
run(P2_RANDOM_COMPONENT, false).await.unwrap()
271
}
272
#[test_log::test(tokio::test(flavor = "multi_thread"))]
273
async fn p2_ip_name_lookup() {
274
run(P2_IP_NAME_LOOKUP_COMPONENT, false).await.unwrap()
275
}
276
#[test_log::test(tokio::test(flavor = "multi_thread"))]
277
async fn p2_tcp_sockopts() {
278
run(P2_TCP_SOCKOPTS_COMPONENT, false).await.unwrap()
279
}
280
#[test_log::test(tokio::test(flavor = "multi_thread"))]
281
async fn p2_tcp_sample_application() {
282
run(P2_TCP_SAMPLE_APPLICATION_COMPONENT, false)
283
.await
284
.unwrap()
285
}
286
#[test_log::test(tokio::test(flavor = "multi_thread"))]
287
async fn p2_tcp_states() {
288
run(P2_TCP_STATES_COMPONENT, false).await.unwrap()
289
}
290
#[test_log::test(tokio::test(flavor = "multi_thread"))]
291
async fn p2_tcp_streams() {
292
run(P2_TCP_STREAMS_COMPONENT, false).await.unwrap()
293
}
294
#[test_log::test(tokio::test(flavor = "multi_thread"))]
295
async fn p2_tcp_bind() {
296
run(P2_TCP_BIND_COMPONENT, false).await.unwrap()
297
}
298
#[test_log::test(tokio::test(flavor = "multi_thread"))]
299
async fn p2_tcp_connect() {
300
run(P2_TCP_CONNECT_COMPONENT, false).await.unwrap()
301
}
302
#[test_log::test(tokio::test(flavor = "multi_thread"))]
303
async fn p2_tcp_listen() {
304
run(P2_TCP_LISTEN_COMPONENT, false).await.unwrap()
305
}
306
#[test_log::test(tokio::test(flavor = "multi_thread"))]
307
async fn p2_udp_sockopts() {
308
run(P2_UDP_SOCKOPTS_COMPONENT, false).await.unwrap()
309
}
310
#[test_log::test(tokio::test(flavor = "multi_thread"))]
311
async fn p2_udp_sample_application() {
312
run(P2_UDP_SAMPLE_APPLICATION_COMPONENT, false)
313
.await
314
.unwrap()
315
}
316
#[test_log::test(tokio::test(flavor = "multi_thread"))]
317
async fn p2_udp_states() {
318
run(P2_UDP_STATES_COMPONENT, false).await.unwrap()
319
}
320
#[test_log::test(tokio::test(flavor = "multi_thread"))]
321
async fn p2_udp_bind() {
322
run(P2_UDP_BIND_COMPONENT, false).await.unwrap()
323
}
324
#[test_log::test(tokio::test(flavor = "multi_thread"))]
325
async fn p2_udp_connect() {
326
run(P2_UDP_CONNECT_COMPONENT, false).await.unwrap()
327
}
328
#[test_log::test(tokio::test(flavor = "multi_thread"))]
329
async fn p2_stream_pollable_correct() {
330
run(P2_STREAM_POLLABLE_CORRECT_COMPONENT, false)
331
.await
332
.unwrap()
333
}
334
#[test_log::test(tokio::test(flavor = "multi_thread"))]
335
async fn p2_stream_pollable_traps() {
336
let e = run(P2_STREAM_POLLABLE_TRAPS_COMPONENT, false)
337
.await
338
.unwrap_err();
339
assert_eq!(
340
format!("{}", e.source().expect("trap source")),
341
"resource has children"
342
)
343
}
344
#[test_log::test(tokio::test(flavor = "multi_thread"))]
345
async fn p2_pollable_correct() {
346
run(P2_POLLABLE_CORRECT_COMPONENT, false).await.unwrap()
347
}
348
#[test_log::test(tokio::test(flavor = "multi_thread"))]
349
async fn p2_pollable_traps() {
350
let e = run(P2_POLLABLE_TRAPS_COMPONENT, false).await.unwrap_err();
351
assert_eq!(
352
format!("{}", e.source().expect("trap source")),
353
"empty poll list"
354
)
355
}
356
#[test_log::test(tokio::test(flavor = "multi_thread"))]
357
async fn p2_adapter_badfd() {
358
run(P2_ADAPTER_BADFD_COMPONENT, false).await.unwrap()
359
}
360
#[test_log::test(tokio::test(flavor = "multi_thread"))]
361
async fn p2_file_read_write() {
362
run(P2_FILE_READ_WRITE_COMPONENT, false).await.unwrap()
363
}
364
#[expect(
365
dead_code,
366
reason = "tested in the wasi-cli crate, satisfying foreach_api! macro"
367
)]
368
fn p1_cli_much_stdout() {}
369
370