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,54 +1,33 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi_old::wasi_unstable; use wasi_tests::open_scratch_directory_new;
use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
use wasi_tests::wasi_wrappers::wasi_path_open;
unsafe fn test_dangling_fd(dir_fd: wasi_unstable::Fd) { unsafe fn test_dangling_fd(dir_fd: wasi::Fd) {
// Create a file, open it, delete it without closing the handle, // Create a file, open it, delete it without closing the handle,
// and then try creating it again // and then try creating it again
create_file(dir_fd, "file"); let fd = wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).unwrap();
let mut file_fd = wasi_unstable::Fd::max_value() - 1; wasi::fd_close(fd).unwrap();
let mut status = wasi_path_open(dir_fd, 0, "file", 0, 0, 0, 0, &mut file_fd); let file_fd = wasi::path_open(dir_fd, 0, "file", 0, 0, 0, 0).expect("failed to open");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file",
);
assert_gt!( assert_gt!(
file_fd, file_fd,
libc::STDERR_FILENO as wasi_unstable::Fd, libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check", "file descriptor range check",
); );
cleanup_file(dir_fd, "file"); wasi::path_unlink_file(dir_fd, "file").expect("failed to unlink");
create_file(dir_fd, "file"); let fd = wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).unwrap();
wasi::fd_close(fd).unwrap();
// Now, repeat the same process but for a directory // Now, repeat the same process but for a directory
create_dir(dir_fd, "subdir"); wasi::path_create_directory(dir_fd, "subdir").expect("failed to create dir");
let mut subdir_fd = wasi_unstable::Fd::max_value() - 1; let subdir_fd = wasi::path_open(dir_fd, 0, "subdir", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
status = wasi_path_open( .expect("failed to open dir");
dir_fd,
0,
"subdir",
wasi_unstable::O_DIRECTORY,
0,
0,
0,
&mut subdir_fd,
);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a directory",
);
assert_gt!( assert_gt!(
file_fd, subdir_fd,
libc::STDERR_FILENO as wasi_unstable::Fd, libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check", "file descriptor range check",
); );
cleanup_dir(dir_fd, "subdir"); wasi::path_remove_directory(dir_fd, "subdir").expect("failed to remove dir 2");
create_dir(dir_fd, "subdir"); wasi::path_create_directory(dir_fd, "subdir").expect("failed to create dir 2");
} }
fn main() { fn main() {
@@ -62,7 +41,7 @@ fn main() {
}; };
// Open scratch directory // 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, Ok(dir_fd) => dir_fd,
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);

View File

@@ -1,41 +1,25 @@
use std::{env, process}; use std::{env, process};
use wasi_old::wasi_unstable; use wasi_tests::open_scratch_directory_new;
use wasi_tests::open_scratch_directory;
use wasi_tests::utils::cleanup_file;
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink};
unsafe fn test_dangling_symlink(dir_fd: wasi_unstable::Fd) { unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {
// First create a dangling symlink. // First create a dangling symlink.
assert!( assert!(
wasi_path_symlink("target", dir_fd, "symlink").is_ok(), wasi::path_symlink("target", dir_fd, "symlink").is_ok(),
"creating a symlink" "creating a symlink"
); );
// Try to open it as a directory with O_NOFOLLOW. // Try to open it as a directory with O_NOFOLLOW.
let mut file_fd: wasi_unstable::Fd = wasi_unstable::Fd::max_value() - 1; let status = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
let status = wasi_path_open( .err()
dir_fd, .expect("failed to open symlink");
0,
"symlink",
wasi_unstable::O_DIRECTORY,
0,
0,
0,
&mut file_fd,
);
assert_eq!( assert_eq!(
status, status.raw_error(),
wasi_unstable::raw::__WASI_ELOOP, wasi::ERRNO_LOOP,
"opening a dangling symlink as a directory", "opening a dangling symlink as a directory",
); );
assert_eq!(
file_fd,
wasi_unstable::Fd::max_value(),
"failed open should set the file descriptor to -1",
);
// Clean up. // Clean up.
cleanup_file(dir_fd, "symlink"); wasi::path_unlink_file(dir_fd, "symlink").expect("failed to remove file");
} }
fn main() { fn main() {
@@ -49,7 +33,7 @@ fn main() {
}; };
// Open scratch directory // 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, Ok(dir_fd) => dir_fd,
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);

View File

@@ -1,68 +1,46 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, mem, process}; use std::{env, process};
use wasi_old::wasi_unstable; use wasi_tests::open_scratch_directory_new;
use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, close_fd, create_dir};
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_fd_seek, wasi_path_open};
unsafe fn test_directory_seek(dir_fd: wasi_unstable::Fd) { unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
// Create a directory in the scratch directory. // Create a directory in the scratch directory.
create_dir(dir_fd, "dir"); wasi::path_create_directory(dir_fd, "dir").expect("failed to make directory");
// Open the directory and attempt to request rights for seeking. // Open the directory and attempt to request rights for seeking.
let mut fd: wasi_unstable::Fd = wasi_unstable::Fd::max_value() - 1; let fd = wasi::path_open(dir_fd, 0, "dir", 0, wasi::RIGHTS_FD_SEEK, 0, 0)
let mut status = wasi_path_open( .expect("failed to open file");
dir_fd,
0,
"dir",
0,
wasi_unstable::RIGHT_FD_SEEK,
0,
0,
&mut fd,
);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file"
);
assert_gt!( assert_gt!(
fd, fd,
libc::STDERR_FILENO as wasi_unstable::Fd, libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check", "file descriptor range check",
); );
// Attempt to seek. // Attempt to seek.
let mut newoffset = 1; let status = wasi::fd_seek(fd, 0, wasi::WHENCE_CUR)
status = wasi_fd_seek(fd, 0, wasi_unstable::WHENCE_CUR, &mut newoffset); .err()
.expect("failed to seek");
assert_eq!( assert_eq!(
status, status.raw_error(),
wasi_unstable::raw::__WASI_ENOTCAPABLE, wasi::ERRNO_NOTCAPABLE,
"seek on a directory" "seek on a directory"
); );
// Check if we obtained the right to seek. // Check if we obtained the right to seek.
let mut fdstat: wasi_unstable::FdStat = mem::zeroed(); let fdstat = wasi::fd_fdstat_get(fd).expect("failed to fdstat");
status = wasi_fd_fdstat_get(fd, &mut fdstat);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"calling fd_fdstat on a directory"
);
assert_eq!( assert_eq!(
fdstat.fs_filetype, fdstat.fs_filetype,
wasi_unstable::FILETYPE_DIRECTORY, wasi::FILETYPE_DIRECTORY,
"expected the scratch directory to be a directory", "expected the scratch directory to be a directory",
); );
assert_eq!( assert_eq!(
(fdstat.fs_rights_base & wasi_unstable::RIGHT_FD_SEEK), (fdstat.fs_rights_base & wasi::RIGHTS_FD_SEEK),
0, 0,
"directory has the seek right", "directory has the seek right",
); );
// Clean up. // Clean up.
close_fd(fd); wasi::fd_close(fd).expect("failed to close fd");
cleanup_dir(dir_fd, "dir"); wasi::path_remove_directory(dir_fd, "dir").expect("failed to remove dir");
} }
fn main() { fn main() {
@@ -76,7 +54,7 @@ fn main() {
}; };
// Open scratch directory // 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, Ok(dir_fd) => dir_fd,
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);

View File

@@ -1,78 +1,44 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi_old::wasi_unstable; use wasi_tests::open_scratch_directory_new;
use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{wasi_fd_advise, wasi_fd_filestat_get, wasi_path_open};
unsafe fn test_fd_advise(dir_fd: wasi_unstable::Fd) { unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
// Create a file in the scratch directory. // Create a file in the scratch directory.
let mut file_fd = wasi_unstable::Fd::max_value() - 1; let file_fd = wasi::path_open(
let status = wasi_path_open(
dir_fd, dir_fd,
0, 0,
"file", "file",
wasi_unstable::O_CREAT, wasi::OFLAGS_CREAT,
wasi_unstable::RIGHT_FD_READ | wasi_unstable::RIGHT_FD_WRITE, wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0, 0,
0, 0,
&mut file_fd, )
); .expect("failed to open file");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file"
);
assert_gt!( assert_gt!(
file_fd, file_fd,
libc::STDERR_FILENO as wasi_unstable::Fd, libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check", "file descriptor range check",
); );
// Check file size // Check file size
let mut stat = wasi_unstable::FileStat { let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat");
st_dev: 0, assert_eq!(stat.size, 0, "file size should be 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");
// Allocate some size // Allocate some size
assert!( assert!(
wasi_unstable::fd_allocate(file_fd, 0, 100).is_ok(), wasi::fd_allocate(file_fd, 0, 100).is_ok(),
"allocating size" "allocating size"
); );
let status = wasi_fd_filestat_get(file_fd, &mut stat); let stat = wasi::fd_filestat_get(file_fd).expect("failed to fdstat 2");
assert_eq!( assert_eq!(stat.size, 100, "file size should be 100");
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"reading file stats after initial allocation"
);
assert_eq!(stat.st_size, 100, "file size should be 100");
// Advise the kernel // Advise the kernel
let status = wasi_fd_advise(file_fd, 10, 50, wasi_unstable::ADVICE_NORMAL); wasi::fd_advise(file_fd, 10, 50, wasi::ADVICE_NORMAL).expect("failed advise");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"advising the kernel"
);
close_fd(file_fd); wasi::fd_close(file_fd).expect("failed to close");
cleanup_file(dir_fd, "file"); wasi::path_unlink_file(dir_fd, "file").expect("failed to unlink");
} }
fn main() { fn main() {
let mut args = env::args(); let mut args = env::args();
@@ -85,7 +51,7 @@ fn main() {
}; };
// Open scratch directory // 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, Ok(dir_fd) => dir_fd,
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);

View File

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

View File

@@ -1,15 +1,11 @@
use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{cmp::min, env, mem, process, slice, str}; use std::{cmp::min, env, mem, process, slice, str};
use wasi_old::wasi_unstable; use wasi_tests::open_scratch_directory_new;
use wasi_tests::open_scratch_directory;
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_fd_readdir, wasi_path_open};
const BUF_LEN: usize = 256; const BUF_LEN: usize = 256;
#[derive(Debug)]
struct DirEntry { struct DirEntry {
dirent: wasi_unstable::Dirent, dirent: wasi::Dirent,
name: String, name: String,
} }
@@ -35,7 +31,7 @@ impl<'a> Iterator for ReadDir<'a> {
} }
// Read the data // Read the data
let dirent_ptr = self.buf.as_ptr() as *const wasi_unstable::Dirent; let dirent_ptr = self.buf.as_ptr() as *const wasi::Dirent;
let dirent = dirent_ptr.read_unaligned(); let dirent = dirent_ptr.read_unaligned();
let name_ptr = dirent_ptr.offset(1) as *const u8; let name_ptr = dirent_ptr.offset(1) as *const u8;
// NOTE Linux syscall returns a NULL-terminated name, but WASI doesn't // NOTE Linux syscall returns a NULL-terminated name, but WASI doesn't
@@ -53,30 +49,22 @@ impl<'a> Iterator for ReadDir<'a> {
} }
unsafe fn exec_fd_readdir( unsafe fn exec_fd_readdir(
fd: wasi_unstable::Fd, fd: wasi::Fd,
cookie: wasi_unstable::DirCookie, cookie: wasi::Dircookie,
) -> Vec<DirEntry> { ) -> Vec<DirEntry> {
let mut buf: [u8; BUF_LEN] = [0; BUF_LEN]; let mut buf: [u8; BUF_LEN] = [0; BUF_LEN];
let mut bufused = 0; let bufused = wasi::fd_readdir(fd, buf.as_mut_ptr(), BUF_LEN, cookie).expect("failed fd_readdir");
let status = wasi_fd_readdir(fd, &mut buf, BUF_LEN, cookie, &mut bufused);
assert_eq!(status, wasi_unstable::raw::__WASI_ESUCCESS, "fd_readdir");
let sl = slice::from_raw_parts(buf.as_ptr(), min(BUF_LEN, bufused)); let sl = slice::from_raw_parts(buf.as_ptr(), min(BUF_LEN, bufused));
let dirs: Vec<_> = ReadDir::from_slice(sl).collect(); let dirs: Vec<_> = ReadDir::from_slice(sl).collect();
dirs dirs
} }
unsafe fn test_fd_readdir(dir_fd: wasi_unstable::Fd) { unsafe fn test_fd_readdir(dir_fd: wasi::Fd) {
let mut stat: wasi_unstable::FileStat = mem::zeroed(); let stat = wasi::fd_filestat_get(dir_fd).expect("failed filestat");
let status = wasi_fd_filestat_get(dir_fd, &mut stat);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"reading scratch directory stats"
);
// Check the behavior in an empty directory // Check the behavior in an empty directory
let mut dirs = exec_fd_readdir(dir_fd, wasi_unstable::DIRCOOKIE_START); let mut dirs = exec_fd_readdir(dir_fd, 0);
dirs.sort_by_key(|d| d.name.clone()); dirs.sort_by_key(|d| d.name.clone());
assert_eq!(dirs.len(), 2, "expected two entries in an empty directory"); assert_eq!(dirs.len(), 2, "expected two entries in an empty directory");
let mut dirs = dirs.into_iter(); let mut dirs = dirs.into_iter();
@@ -86,10 +74,10 @@ unsafe fn test_fd_readdir(dir_fd: wasi_unstable::Fd) {
assert_eq!(dir.name, ".", "first name"); assert_eq!(dir.name, ".", "first name");
assert_eq!( assert_eq!(
dir.dirent.d_type, dir.dirent.d_type,
wasi_unstable::FILETYPE_DIRECTORY, wasi::FILETYPE_DIRECTORY,
"first type" "first type"
); );
assert_eq!(dir.dirent.d_ino, stat.st_ino); assert_eq!(dir.dirent.d_ino, stat.ino);
assert_eq!(dir.dirent.d_namlen, 1); assert_eq!(dir.dirent.d_namlen, 1);
// the second entry should be `..` // the second entry should be `..`
@@ -97,7 +85,7 @@ unsafe fn test_fd_readdir(dir_fd: wasi_unstable::Fd) {
assert_eq!(dir.name, "..", "second name"); assert_eq!(dir.name, "..", "second name");
assert_eq!( assert_eq!(
dir.dirent.d_type, dir.dirent.d_type,
wasi_unstable::FILETYPE_DIRECTORY, wasi::FILETYPE_DIRECTORY,
"second type" "second type"
); );
@@ -107,37 +95,25 @@ unsafe fn test_fd_readdir(dir_fd: wasi_unstable::Fd) {
); );
// Add a file and check the behavior // Add a file and check the behavior
let mut file_fd = wasi_unstable::Fd::max_value() - 1; let file_fd = wasi::path_open(
let status = wasi_path_open(
dir_fd, dir_fd,
0, 0,
"file", "file",
wasi_unstable::O_CREAT, wasi::OFLAGS_CREAT,
wasi_unstable::RIGHT_FD_READ | wasi_unstable::RIGHT_FD_WRITE, wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0, 0,
0, 0,
&mut file_fd, ).expect("failed to create file");
);
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"opening a file"
);
assert_gt!( assert_gt!(
file_fd, file_fd,
libc::STDERR_FILENO as wasi_unstable::Fd, libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check", "file descriptor range check",
); );
let status = wasi_fd_filestat_get(file_fd, &mut stat); let stat = wasi::fd_filestat_get(file_fd).expect("failed filestat");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"reading file stats"
);
// Execute another readdir // Execute another readdir
let mut dirs = exec_fd_readdir(dir_fd, wasi_unstable::DIRCOOKIE_START); let mut dirs = exec_fd_readdir(dir_fd, 0);
assert_eq!(dirs.len(), 3, "expected three entries"); assert_eq!(dirs.len(), 3, "expected three entries");
// Save the data about the last entry. We need to do it before sorting. // Save the data about the last entry. We need to do it before sorting.
let lastfile_cookie = dirs[1].dirent.d_next; let lastfile_cookie = dirs[1].dirent.d_next;
@@ -154,10 +130,10 @@ unsafe fn test_fd_readdir(dir_fd: wasi_unstable::Fd) {
assert_eq!(dir.name, "file", "file name doesn't match"); assert_eq!(dir.name, "file", "file name doesn't match");
assert_eq!( assert_eq!(
dir.dirent.d_type, dir.dirent.d_type,
wasi_unstable::FILETYPE_REGULAR_FILE, wasi::FILETYPE_REGULAR_FILE,
"type for the real file" "type for the real file"
); );
assert_eq!(dir.dirent.d_ino, stat.st_ino); assert_eq!(dir.dirent.d_ino, stat.ino);
// check if cookie works as expected // check if cookie works as expected
let dirs = exec_fd_readdir(dir_fd, lastfile_cookie); let dirs = exec_fd_readdir(dir_fd, lastfile_cookie);
@@ -176,7 +152,7 @@ fn main() {
}; };
// Open scratch directory // 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, Ok(dir_fd) => dir_fd,
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);