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:
Jakub Konka
2019-12-24 22:04:15 +01:00
committed by Dan Gohman
parent 907e7aac01
commit 51f3ac0c45
37 changed files with 862 additions and 1860 deletions

View File

@@ -1,92 +1,65 @@
use libc;
use more_asserts::assert_gt;
use std::{env, mem, process};
use wasi_old::wasi_unstable;
use std::{env, process};
use wasi_tests::open_scratch_directory;
use wasi_tests::utils::close_fd;
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open};
unsafe fn test_renumber(dir_fd: wasi_unstable::Fd) {
let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd;
unsafe fn test_renumber(dir_fd: wasi::Fd) {
let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd;
assert_gt!(dir_fd, pre_fd, "dir_fd number");
// Create a file in the scratch directory.
let mut fd_from = wasi_unstable::Fd::max_value() - 1;
let mut status = wasi_path_open(
let fd_from = wasi::path_open(
dir_fd,
0,
"file1",
wasi_unstable::O_CREAT,
wasi_unstable::RIGHT_FD_READ | wasi_unstable::RIGHT_FD_WRITE,
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
&mut fd_from,
);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file"
);
)
.expect("opening a file");
assert_gt!(
fd_from,
libc::STDERR_FILENO as wasi_unstable::Fd,
libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check",
);
// Get fd_from fdstat attributes
let mut fdstat_from: wasi_unstable::FdStat = mem::zeroed();
status = wasi_fd_fdstat_get(fd_from, &mut fdstat_from);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"calling fd_fdstat on the open file descriptor"
);
let fdstat_from =
wasi::fd_fdstat_get(fd_from).expect("calling fd_fdstat on the open file descriptor");
// Create another file in the scratch directory.
let mut fd_to = wasi_unstable::Fd::max_value() - 1;
status = wasi_path_open(
let fd_to = wasi::path_open(
dir_fd,
0,
"file2",
wasi_unstable::O_CREAT,
wasi_unstable::RIGHT_FD_READ | wasi_unstable::RIGHT_FD_WRITE,
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
&mut fd_to,
);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file"
);
)
.expect("opening a file");
assert_gt!(
fd_to,
libc::STDERR_FILENO as wasi_unstable::Fd,
libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check",
);
// Renumber fd of file1 into fd of file2
assert!(
wasi_unstable::fd_renumber(fd_from, fd_to).is_ok(),
"renumbering two descriptors",
);
wasi::fd_renumber(fd_from, fd_to).expect("renumbering two descriptors");
// Ensure that fd_from is closed
assert_eq!(
wasi_unstable::fd_close(fd_from),
Err(wasi_unstable::EBADF),
"closing already closed file descriptor"
wasi::fd_close(fd_from)
.expect_err("closing already closed file descriptor")
.raw_error(),
wasi::ERRNO_BADF,
"errno should be ERRNO_BADF"
);
// Ensure that fd_to is still open.
let mut fdstat_to: wasi_unstable::FdStat = mem::zeroed();
status = wasi_fd_fdstat_get(fd_to, &mut fdstat_to);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"calling fd_fdstat on the open file descriptor"
);
let fdstat_to =
wasi::fd_fdstat_get(fd_to).expect("calling fd_fdstat on the open file descriptor");
assert_eq!(
fdstat_from.fs_filetype, fdstat_to.fs_filetype,
"expected fd_to have the same fdstat as fd_from"
@@ -104,7 +77,7 @@ unsafe fn test_renumber(dir_fd: wasi_unstable::Fd) {
"expected fd_to have the same fdstat as fd_from"
);
close_fd(fd_to);
wasi::fd_close(fd_to).expect("closing a file");
}
fn main() {