* Reorganize wasi-misc-tests. Move wasi-misc-tests out of wasi-common, to break a dependency cycle; previously, wasmtime-* depended on wasi-common, but wasi-common dev-dependended on wasmtime-*. Now, wasi-common no longer dev-depends on wasmtime-*; instead, the tests are in their own crate which depends on wasi-common and on wasmtime-*. Also, rename wasi-misc-tests to wasi-tests for simplicity. This also removes the "wasm_tests" feature; it's replaced by the "test-programs" feature. * Update the CI script to use the new feature name. * Update the CI script to use the new feature name in one more place. * Change a `write!` to a `writeln!`.
55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use crate::wasi_wrappers::*;
|
|
use more_asserts::assert_gt;
|
|
use wasi::wasi_unstable;
|
|
|
|
pub unsafe fn create_dir(dir_fd: wasi_unstable::Fd, dir_name: &str) {
|
|
assert!(
|
|
wasi_path_create_directory(dir_fd, dir_name).is_ok(),
|
|
"creating a directory"
|
|
);
|
|
}
|
|
|
|
pub unsafe fn cleanup_dir(dir_fd: wasi_unstable::Fd, dir_name: &str) {
|
|
assert!(
|
|
wasi_path_remove_directory(dir_fd, dir_name).is_ok(),
|
|
"remove_directory on an empty directory should succeed"
|
|
);
|
|
}
|
|
|
|
/// Create an empty file with the given name.
|
|
pub unsafe fn create_file(dir_fd: wasi_unstable::Fd, file_name: &str) {
|
|
let mut file_fd = wasi_unstable::Fd::max_value() - 1;
|
|
let status = wasi_path_open(
|
|
dir_fd,
|
|
0,
|
|
file_name,
|
|
wasi_unstable::O_CREAT,
|
|
0,
|
|
0,
|
|
0,
|
|
&mut file_fd,
|
|
);
|
|
assert_eq!(
|
|
status,
|
|
wasi_unstable::raw::__WASI_ESUCCESS,
|
|
"creating a file"
|
|
);
|
|
assert_gt!(
|
|
file_fd,
|
|
libc::STDERR_FILENO as wasi_unstable::Fd,
|
|
"file descriptor range check",
|
|
);
|
|
close_fd(file_fd);
|
|
}
|
|
|
|
pub unsafe fn cleanup_file(dir_fd: wasi_unstable::Fd, file_name: &str) {
|
|
assert!(
|
|
wasi_path_unlink_file(dir_fd, file_name).is_ok(),
|
|
"unlink_file on a symlink should succeed"
|
|
);
|
|
}
|
|
|
|
pub unsafe fn close_fd(fd: wasi_unstable::Fd) {
|
|
assert!(wasi_unstable::fd_close(fd).is_ok(), "closing a file");
|
|
}
|