Update WASI tests to use wasi crate v0.9.0 (#743)
This commit updates _all_ WASI test programs to use the latest version of the `wasi` crate (`v0.9.0`). While at it, it also unifies asserting error conditions across all test programs.
This commit is contained in:
@@ -1,39 +1,28 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{close_fd, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::{
|
||||
wasi_path_open, wasi_path_remove_directory, wasi_path_unlink_file,
|
||||
};
|
||||
use wasi_tests::{create_file, open_scratch_directory};
|
||||
|
||||
unsafe fn test_interesting_paths(dir_fd: wasi_unstable::Fd, arg: &str) {
|
||||
unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
|
||||
// Create a directory in the scratch directory.
|
||||
create_dir(dir_fd, "dir");
|
||||
wasi::path_create_directory(dir_fd, "dir").expect("creating dir");
|
||||
|
||||
// Create a directory in the directory we just created.
|
||||
create_dir(dir_fd, "dir/nested");
|
||||
wasi::path_create_directory(dir_fd, "dir/nested").expect("creating a nested dir");
|
||||
|
||||
// Create a file in the nested directory.
|
||||
create_file(dir_fd, "dir/nested/file");
|
||||
|
||||
// Now open it with an absolute path.
|
||||
let mut file_fd: wasi_unstable::Fd = wasi_unstable::Fd::max_value() - 1;
|
||||
let mut status = wasi_path_open(dir_fd, 0, "/dir/nested/file", 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ENOTCAPABLE,
|
||||
"opening a file with an absolute path"
|
||||
);
|
||||
assert_eq!(
|
||||
file_fd,
|
||||
wasi_unstable::Fd::max_value(),
|
||||
"failed open should set the file descriptor to -1",
|
||||
wasi::path_open(dir_fd, 0, "/dir/nested/file", 0, 0, 0, 0)
|
||||
.expect_err("opening a file with an absolute path")
|
||||
.raw_error(),
|
||||
wasi::ERRNO_NOTCAPABLE,
|
||||
"errno should be ERRNO_NOTCAPABLE"
|
||||
);
|
||||
|
||||
// Now open it with a path containing "..".
|
||||
status = wasi_path_open(
|
||||
let mut file_fd = wasi::path_open(
|
||||
dir_fd,
|
||||
0,
|
||||
"dir/.//nested/../../dir/nested/../nested///./file",
|
||||
@@ -41,112 +30,77 @@ unsafe fn test_interesting_paths(dir_fd: wasi_unstable::Fd, arg: &str) {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&mut file_fd,
|
||||
);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"opening a file with \"..\" in the path"
|
||||
);
|
||||
)
|
||||
.expect("opening a file with \"..\" in the path");
|
||||
assert_gt!(
|
||||
file_fd,
|
||||
libc::STDERR_FILENO as wasi_unstable::Fd,
|
||||
libc::STDERR_FILENO as wasi::Fd,
|
||||
"file descriptor range check",
|
||||
);
|
||||
close_fd(file_fd);
|
||||
wasi::fd_close(file_fd).expect("closing a file");
|
||||
|
||||
// Now open it with a trailing NUL.
|
||||
status = wasi_path_open(dir_fd, 0, "dir/nested/file\0", 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_EILSEQ,
|
||||
"opening a file with a trailing NUL"
|
||||
);
|
||||
assert_eq!(
|
||||
file_fd,
|
||||
wasi_unstable::Fd::max_value(),
|
||||
"failed open should set the file descriptor to -1",
|
||||
wasi::path_open(dir_fd, 0, "dir/nested/file\0", 0, 0, 0, 0)
|
||||
.expect_err("opening a file with a trailing NUL")
|
||||
.raw_error(),
|
||||
wasi::ERRNO_ILSEQ,
|
||||
"errno should be ERRNO_ILSEQ",
|
||||
);
|
||||
|
||||
// Now open it with a trailing slash.
|
||||
status = wasi_path_open(dir_fd, 0, "dir/nested/file/", 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ENOTDIR,
|
||||
"opening a file with a trailing slash"
|
||||
);
|
||||
assert_eq!(
|
||||
file_fd,
|
||||
wasi_unstable::Fd::max_value(),
|
||||
"failed open should set the file descriptor to -1",
|
||||
wasi::path_open(dir_fd, 0, "dir/nested/file/", 0, 0, 0, 0)
|
||||
.expect_err("opening a file with a trailing slash should fail")
|
||||
.raw_error(),
|
||||
wasi::ERRNO_NOTDIR,
|
||||
"errno should be ERRNO_NOTDIR",
|
||||
);
|
||||
|
||||
// Now open it with trailing slashes.
|
||||
status = wasi_path_open(dir_fd, 0, "dir/nested/file///", 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ENOTDIR,
|
||||
"opening a file with trailing slashes"
|
||||
);
|
||||
assert_eq!(
|
||||
file_fd,
|
||||
wasi_unstable::Fd::max_value(),
|
||||
"failed open should set the file descriptor to -1",
|
||||
wasi::path_open(dir_fd, 0, "dir/nested/file///", 0, 0, 0, 0)
|
||||
.expect_err("opening a file with trailing slashes should fail")
|
||||
.raw_error(),
|
||||
wasi::ERRNO_NOTDIR,
|
||||
"errno should be ERRNO_NOTDIR",
|
||||
);
|
||||
|
||||
// Now open the directory with a trailing slash.
|
||||
status = wasi_path_open(dir_fd, 0, "dir/nested/", 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"opening a directory with a trailing slash"
|
||||
);
|
||||
file_fd = wasi::path_open(dir_fd, 0, "dir/nested/", 0, 0, 0, 0)
|
||||
.expect("opening a directory with a trailing slash");
|
||||
assert_gt!(
|
||||
file_fd,
|
||||
libc::STDERR_FILENO as wasi_unstable::Fd,
|
||||
libc::STDERR_FILENO as wasi::Fd,
|
||||
"file descriptor range check",
|
||||
);
|
||||
close_fd(file_fd);
|
||||
wasi::fd_close(file_fd).expect("closing a file");
|
||||
|
||||
// Now open the directory with trailing slashes.
|
||||
status = wasi_path_open(dir_fd, 0, "dir/nested///", 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"opening a directory with trailing slashes"
|
||||
);
|
||||
file_fd = wasi::path_open(dir_fd, 0, "dir/nested///", 0, 0, 0, 0)
|
||||
.expect("opening a directory with trailing slashes");
|
||||
assert_gt!(
|
||||
file_fd,
|
||||
libc::STDERR_FILENO as wasi_unstable::Fd,
|
||||
libc::STDERR_FILENO as wasi::Fd,
|
||||
"file descriptor range check",
|
||||
);
|
||||
close_fd(file_fd);
|
||||
wasi::fd_close(file_fd).expect("closing a file");
|
||||
|
||||
// Now open it with a path containing too many ".."s.
|
||||
let bad_path = format!("dir/nested/../../../{}/dir/nested/file", arg);
|
||||
status = wasi_path_open(dir_fd, 0, &bad_path, 0, 0, 0, 0, &mut file_fd);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ENOTCAPABLE,
|
||||
"opening a file with too many \"..\"s in the path"
|
||||
);
|
||||
assert_eq!(
|
||||
file_fd,
|
||||
wasi_unstable::Fd::max_value(),
|
||||
"failed open should set the file descriptor to -1",
|
||||
);
|
||||
assert!(
|
||||
wasi_path_unlink_file(dir_fd, "dir/nested/file").is_ok(),
|
||||
"unlink_file on a symlink should succeed"
|
||||
);
|
||||
assert!(
|
||||
wasi_path_remove_directory(dir_fd, "dir/nested").is_ok(),
|
||||
"remove_directory on a directory should succeed"
|
||||
);
|
||||
assert!(
|
||||
wasi_path_remove_directory(dir_fd, "dir").is_ok(),
|
||||
"remove_directory on a directory should succeed"
|
||||
wasi::path_open(dir_fd, 0, &bad_path, 0, 0, 0, 0)
|
||||
.expect_err("opening a file with too many \"..\"s in the path should fail")
|
||||
.raw_error(),
|
||||
wasi::ERRNO_NOTCAPABLE,
|
||||
"errno should be ERRNO_NOTCAPABLE",
|
||||
);
|
||||
wasi::path_unlink_file(dir_fd, "dir/nested/file")
|
||||
.expect("unlink_file on a symlink should succeed");
|
||||
wasi::path_remove_directory(dir_fd, "dir/nested")
|
||||
.expect("remove_directory on a directory should succeed");
|
||||
wasi::path_remove_directory(dir_fd, "dir")
|
||||
.expect("remove_directory on a directory should succeed");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user