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