Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi/tests/all/p1.rs
1692 views
1
use crate::store::Ctx;
2
use anyhow::Result;
3
use std::path::Path;
4
use test_programs_artifacts::*;
5
use wasmtime::{Linker, Module};
6
use wasmtime_wasi::p1::{WasiP1Ctx, add_to_linker_async};
7
8
async fn run(path: &str, inherit_stdio: bool) -> Result<()> {
9
let path = Path::new(path);
10
let name = path.file_stem().unwrap().to_str().unwrap();
11
let engine = test_programs_artifacts::engine(|config| {
12
config.async_support(true);
13
});
14
let mut linker = Linker::<Ctx<WasiP1Ctx>>::new(&engine);
15
add_to_linker_async(&mut linker, |t| &mut t.wasi)?;
16
17
let module = Module::from_file(&engine, path)?;
18
let (mut store, _td) = Ctx::new(&engine, name, |builder| {
19
if inherit_stdio {
20
builder.inherit_stdio();
21
}
22
builder.build_p1()
23
})?;
24
let instance = linker.instantiate_async(&mut store, &module).await?;
25
let start = instance.get_typed_func::<(), ()>(&mut store, "_start")?;
26
start.call_async(&mut store, ()).await?;
27
Ok(())
28
}
29
30
foreach_preview1!(assert_test_exists);
31
32
// Below here is mechanical: there should be one test for every binary in
33
// wasi-tests.
34
#[test_log::test(tokio::test(flavor = "multi_thread"))]
35
async fn preview1_big_random_buf() {
36
run(PREVIEW1_BIG_RANDOM_BUF, false).await.unwrap()
37
}
38
#[test_log::test(tokio::test(flavor = "multi_thread"))]
39
async fn preview1_clock_time_get() {
40
run(PREVIEW1_CLOCK_TIME_GET, false).await.unwrap()
41
}
42
#[test_log::test(tokio::test(flavor = "multi_thread"))]
43
async fn preview1_close_preopen() {
44
run(PREVIEW1_CLOSE_PREOPEN, false).await.unwrap()
45
}
46
#[test_log::test(tokio::test(flavor = "multi_thread"))]
47
async fn preview1_dangling_fd() {
48
run(PREVIEW1_DANGLING_FD, false).await.unwrap()
49
}
50
#[test_log::test(tokio::test(flavor = "multi_thread"))]
51
async fn preview1_dangling_symlink() {
52
run(PREVIEW1_DANGLING_SYMLINK, false).await.unwrap()
53
}
54
#[test_log::test(tokio::test(flavor = "multi_thread"))]
55
async fn preview1_directory_seek() {
56
run(PREVIEW1_DIRECTORY_SEEK, false).await.unwrap()
57
}
58
#[test_log::test(tokio::test(flavor = "multi_thread"))]
59
async fn preview1_dir_fd_op_failures() {
60
run(PREVIEW1_DIR_FD_OP_FAILURES, false).await.unwrap()
61
}
62
#[test_log::test(tokio::test(flavor = "multi_thread"))]
63
async fn preview1_fd_advise() {
64
run(PREVIEW1_FD_ADVISE, false).await.unwrap()
65
}
66
#[test_log::test(tokio::test(flavor = "multi_thread"))]
67
async fn preview1_fd_filestat_get() {
68
run(PREVIEW1_FD_FILESTAT_GET, false).await.unwrap()
69
}
70
#[test_log::test(tokio::test(flavor = "multi_thread"))]
71
async fn preview1_fd_filestat_set() {
72
run(PREVIEW1_FD_FILESTAT_SET, false).await.unwrap()
73
}
74
#[test_log::test(tokio::test(flavor = "multi_thread"))]
75
async fn preview1_fd_flags_set() {
76
run(PREVIEW1_FD_FLAGS_SET, false).await.unwrap()
77
}
78
#[test_log::test(tokio::test(flavor = "multi_thread"))]
79
async fn preview1_fd_readdir() {
80
run(PREVIEW1_FD_READDIR, false).await.unwrap()
81
}
82
#[test_log::test(tokio::test(flavor = "multi_thread"))]
83
async fn preview1_file_allocate() {
84
run(PREVIEW1_FILE_ALLOCATE, false).await.unwrap()
85
}
86
#[test_log::test(tokio::test(flavor = "multi_thread"))]
87
async fn preview1_file_pread_pwrite() {
88
run(PREVIEW1_FILE_PREAD_PWRITE, false).await.unwrap()
89
}
90
#[test_log::test(tokio::test(flavor = "multi_thread"))]
91
async fn preview1_file_read_write() {
92
run(PREVIEW1_FILE_READ_WRITE, false).await.unwrap()
93
}
94
#[test_log::test(tokio::test(flavor = "multi_thread"))]
95
async fn preview1_file_seek_tell() {
96
run(PREVIEW1_FILE_SEEK_TELL, false).await.unwrap()
97
}
98
#[test_log::test(tokio::test(flavor = "multi_thread"))]
99
async fn preview1_file_truncation() {
100
run(PREVIEW1_FILE_TRUNCATION, false).await.unwrap()
101
}
102
#[test_log::test(tokio::test(flavor = "multi_thread"))]
103
async fn preview1_file_unbuffered_write() {
104
run(PREVIEW1_FILE_UNBUFFERED_WRITE, false).await.unwrap()
105
}
106
#[test_log::test(tokio::test(flavor = "multi_thread"))]
107
async fn preview1_interesting_paths() {
108
run(PREVIEW1_INTERESTING_PATHS, true).await.unwrap()
109
}
110
#[test_log::test(tokio::test(flavor = "multi_thread"))]
111
async fn preview1_regular_file_isatty() {
112
run(PREVIEW1_REGULAR_FILE_ISATTY, false).await.unwrap()
113
}
114
#[test_log::test(tokio::test(flavor = "multi_thread"))]
115
async fn preview1_nofollow_errors() {
116
run(PREVIEW1_NOFOLLOW_ERRORS, false).await.unwrap()
117
}
118
#[test_log::test(tokio::test(flavor = "multi_thread"))]
119
async fn preview1_overwrite_preopen() {
120
run(PREVIEW1_OVERWRITE_PREOPEN, false).await.unwrap()
121
}
122
#[test_log::test(tokio::test(flavor = "multi_thread"))]
123
async fn preview1_path_exists() {
124
run(PREVIEW1_PATH_EXISTS, false).await.unwrap()
125
}
126
#[test_log::test(tokio::test(flavor = "multi_thread"))]
127
async fn preview1_path_filestat() {
128
run(PREVIEW1_PATH_FILESTAT, false).await.unwrap()
129
}
130
#[test_log::test(tokio::test(flavor = "multi_thread"))]
131
async fn preview1_path_link() {
132
run(PREVIEW1_PATH_LINK, false).await.unwrap()
133
}
134
#[test_log::test(tokio::test(flavor = "multi_thread"))]
135
async fn preview1_path_open_create_existing() {
136
run(PREVIEW1_PATH_OPEN_CREATE_EXISTING, false)
137
.await
138
.unwrap()
139
}
140
#[test_log::test(tokio::test(flavor = "multi_thread"))]
141
async fn preview1_path_open_read_write() {
142
run(PREVIEW1_PATH_OPEN_READ_WRITE, false).await.unwrap()
143
}
144
#[test_log::test(tokio::test(flavor = "multi_thread"))]
145
async fn preview1_path_open_dirfd_not_dir() {
146
run(PREVIEW1_PATH_OPEN_DIRFD_NOT_DIR, false).await.unwrap()
147
}
148
#[test_log::test(tokio::test(flavor = "multi_thread"))]
149
async fn preview1_path_open_missing() {
150
run(PREVIEW1_PATH_OPEN_MISSING, false).await.unwrap()
151
}
152
#[test_log::test(tokio::test(flavor = "multi_thread"))]
153
async fn preview1_path_open_nonblock() {
154
run(PREVIEW1_PATH_OPEN_NONBLOCK, false).await.unwrap()
155
}
156
#[test_log::test(tokio::test(flavor = "multi_thread"))]
157
async fn preview1_path_rename_dir_trailing_slashes() {
158
run(PREVIEW1_PATH_RENAME_DIR_TRAILING_SLASHES, false)
159
.await
160
.unwrap()
161
}
162
#[test_log::test(tokio::test(flavor = "multi_thread"))]
163
async fn preview1_path_rename() {
164
run(PREVIEW1_PATH_RENAME, false).await.unwrap()
165
}
166
#[test_log::test(tokio::test(flavor = "multi_thread"))]
167
async fn preview1_path_symlink_trailing_slashes() {
168
run(PREVIEW1_PATH_SYMLINK_TRAILING_SLASHES, false)
169
.await
170
.unwrap()
171
}
172
#[test_log::test(tokio::test(flavor = "multi_thread"))]
173
async fn preview1_poll_oneoff_files() {
174
run(PREVIEW1_POLL_ONEOFF_FILES, false).await.unwrap()
175
}
176
177
#[test_log::test(tokio::test(flavor = "multi_thread"))]
178
async fn preview1_poll_oneoff_stdio() {
179
run(PREVIEW1_POLL_ONEOFF_STDIO, true).await.unwrap()
180
}
181
#[test_log::test(tokio::test(flavor = "multi_thread"))]
182
async fn preview1_readlink() {
183
run(PREVIEW1_READLINK, false).await.unwrap()
184
}
185
#[test_log::test(tokio::test(flavor = "multi_thread"))]
186
async fn preview1_remove_directory() {
187
run(PREVIEW1_REMOVE_DIRECTORY, false).await.unwrap()
188
}
189
#[test_log::test(tokio::test(flavor = "multi_thread"))]
190
async fn preview1_remove_nonempty_directory() {
191
run(PREVIEW1_REMOVE_NONEMPTY_DIRECTORY, false)
192
.await
193
.unwrap()
194
}
195
#[test_log::test(tokio::test(flavor = "multi_thread"))]
196
async fn preview1_renumber() {
197
run(PREVIEW1_RENUMBER, false).await.unwrap()
198
}
199
#[test_log::test(tokio::test(flavor = "multi_thread"))]
200
async fn preview1_sched_yield() {
201
run(PREVIEW1_SCHED_YIELD, false).await.unwrap()
202
}
203
#[test_log::test(tokio::test(flavor = "multi_thread"))]
204
async fn preview1_stdio() {
205
run(PREVIEW1_STDIO, false).await.unwrap()
206
}
207
#[test_log::test(tokio::test(flavor = "multi_thread"))]
208
async fn preview1_stdio_isatty() {
209
// If the test process is setup such that stdio is a terminal:
210
if test_programs_artifacts::stdio_is_terminal() {
211
// Inherit stdio, test asserts each is not tty:
212
run(PREVIEW1_STDIO_ISATTY, true).await.unwrap()
213
}
214
}
215
#[test_log::test(tokio::test(flavor = "multi_thread"))]
216
async fn preview1_stdio_not_isatty() {
217
// Don't inherit stdio, test asserts each is not tty:
218
run(PREVIEW1_STDIO_NOT_ISATTY, false).await.unwrap()
219
}
220
#[test_log::test(tokio::test(flavor = "multi_thread"))]
221
async fn preview1_symlink_create() {
222
run(PREVIEW1_SYMLINK_CREATE, false).await.unwrap()
223
}
224
#[test_log::test(tokio::test(flavor = "multi_thread"))]
225
async fn preview1_symlink_filestat() {
226
run(PREVIEW1_SYMLINK_FILESTAT, false).await.unwrap()
227
}
228
#[test_log::test(tokio::test(flavor = "multi_thread"))]
229
async fn preview1_symlink_loop() {
230
run(PREVIEW1_SYMLINK_LOOP, false).await.unwrap()
231
}
232
#[test_log::test(tokio::test(flavor = "multi_thread"))]
233
async fn preview1_unlink_file_trailing_slashes() {
234
run(PREVIEW1_UNLINK_FILE_TRAILING_SLASHES, false)
235
.await
236
.unwrap()
237
}
238
#[test_log::test(tokio::test(flavor = "multi_thread"))]
239
async fn preview1_path_open_preopen() {
240
run(PREVIEW1_PATH_OPEN_PREOPEN, false).await.unwrap()
241
}
242
#[test_log::test(tokio::test(flavor = "multi_thread"))]
243
async fn preview1_unicode_output() {
244
run(PREVIEW1_UNICODE_OUTPUT, true).await.unwrap()
245
}
246
#[test_log::test(tokio::test(flavor = "multi_thread"))]
247
async fn preview1_file_write() {
248
run(PREVIEW1_FILE_WRITE, true).await.unwrap()
249
}
250
#[test_log::test(tokio::test(flavor = "multi_thread"))]
251
async fn preview1_path_open_lots() {
252
run(PREVIEW1_PATH_OPEN_LOTS, true).await.unwrap()
253
}
254
255