Update some more wasi test programs to 0.9.0

Largely the same as the previous update!
This commit is contained in:
Alex Crichton
2019-12-12 15:19:40 -08:00
committed by Jakub Konka
parent 054b79427e
commit d641e6e7b0
6 changed files with 109 additions and 262 deletions

View File

@@ -1,100 +1,64 @@
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::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open};
use wasi_tests::open_scratch_directory_new;
unsafe fn test_fd_filestat_set(dir_fd: wasi_unstable::Fd) {
unsafe fn test_fd_filestat_set(dir_fd: wasi::Fd) {
// Create a file in the scratch directory.
let mut file_fd = wasi_unstable::Fd::max_value() - 1;
let status = wasi_path_open(
let file_fd = wasi::path_open(
dir_fd,
0,
"file",
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 file_fd,
);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file"
);
).expect("failed to create file");
assert_gt!(
file_fd,
libc::STDERR_FILENO as wasi_unstable::Fd,
libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check",
);
// Check file size
let mut stat = wasi_unstable::FileStat {
st_dev: 0,
st_ino: 0,
st_filetype: 0,
st_nlink: 0,
st_size: 0,
st_atim: 0,
st_mtim: 0,
st_ctim: 0,
};
let status = wasi_fd_filestat_get(file_fd, &mut stat);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"reading file stats"
);
assert_eq!(stat.st_size, 0, "file size should be 0");
let stat = wasi::fd_filestat_get(file_fd).expect("failed filestat");
assert_eq!(stat.size, 0, "file size should be 0");
// Check fd_filestat_set_size
assert!(
wasi_unstable::fd_filestat_set_size(file_fd, 100).is_ok(),
wasi::fd_filestat_set_size(file_fd, 100).is_ok(),
"fd_filestat_set_size"
);
let status = wasi_fd_filestat_get(file_fd, &mut stat);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"reading file stats after fd_filestat_set_size"
);
assert_eq!(stat.st_size, 100, "file size should be 100");
let stat = wasi::fd_filestat_get(file_fd).expect("failed filestat 2");
assert_eq!(stat.size, 100, "file size should be 100");
// Check fd_filestat_set_times
let old_atim = stat.st_atim;
let new_mtim = stat.st_mtim - 100;
let old_atim = stat.atim;
let new_mtim = stat.mtim - 100;
assert!(
wasi_unstable::fd_filestat_set_times(
wasi::fd_filestat_set_times(
file_fd,
new_mtim,
new_mtim,
wasi_unstable::FILESTAT_SET_MTIM,
wasi::FSTFLAGS_MTIM,
)
.is_ok(),
"fd_filestat_set_times"
);
let status = wasi_fd_filestat_get(file_fd, &mut stat);
let stat = wasi::fd_filestat_get(file_fd).expect("failed filestat 3");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"reading file stats after fd_filestat_set_times"
);
assert_eq!(
stat.st_size, 100,
stat.size, 100,
"file size should remain unchanged at 100"
);
assert_eq!(stat.st_mtim, new_mtim, "mtim should change");
assert_eq!(stat.st_atim, old_atim, "atim should not change");
assert_eq!(stat.mtim, new_mtim, "mtim should change");
assert_eq!(stat.atim, old_atim, "atim should not change");
// let status = wasi_fd_filestat_set_times(file_fd, new_mtim, new_mtim, wasi_unstable::FILESTAT_SET_MTIM | wasi_unstable::FILESTAT_SET_MTIM_NOW);
// assert_eq!(status, wasi_unstable::EINVAL, "ATIM & ATIM_NOW can't both be set");
// let status = wasi_fd_filestat_set_times(file_fd, new_mtim, new_mtim, wasi::FILESTAT_SET_MTIM | wasi::FILESTAT_SET_MTIM_NOW);
// assert_eq!(status, wasi::EINVAL, "ATIM & ATIM_NOW can't both be set");
close_fd(file_fd);
cleanup_file(dir_fd, "file");
wasi::fd_close(file_fd).expect("failed to close fd");
wasi::path_unlink_file(dir_fd, "file").expect("failed to remove dir");
}
fn main() {
let mut args = env::args();
@@ -107,7 +71,7 @@ fn main() {
};
// Open scratch directory
let dir_fd = match open_scratch_directory(&arg) {
let dir_fd = match open_scratch_directory_new(&arg) {
Ok(dir_fd) => dir_fd,
Err(err) => {
eprintln!("{}", err);