test suite: cap-std-sync test environment does not support fdflags sync

This commit is contained in:
Pat Hickey
2021-02-01 14:25:42 -08:00
parent cde252c59b
commit 40e541bfc3
3 changed files with 45 additions and 6 deletions

View File

@@ -42,6 +42,9 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
builder = builder.env("ERRNO_MODE_UNIX", "1")?;
}
// cap-std-sync does not yet support the sync family of fdflags
builder = builder.env("NO_FDFLAGS_SYNC_SUPPORT", "1")?;
let wasi = wasmtime_wasi::Wasi::new(&store, builder.build()?);
let mut linker = Linker::new(&store);

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt;
use std::{env, process};
use wasi_tests::{assert_errno, open_scratch_directory};
use wasi_tests::{assert_errno, open_scratch_directory, TESTCONFIG};
unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
let mut fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get");
@@ -10,6 +10,12 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
"the scratch directory should have RIGHT_PATH_FILESTAT_GET as base right",
);
let fdflags = if TESTCONFIG.support_fdflags_sync() {
wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC
} else {
wasi::FDFLAGS_APPEND
};
// Create a file in the scratch directory.
let file_fd = wasi::path_open(
dir_fd,
@@ -19,7 +25,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET,
0,
// Pass some flags for later retrieval
wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC,
fdflags,
)
.expect("opening a file");
assert_gt!(
@@ -39,11 +45,35 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
0,
"files shouldn't have rights for path_* syscalls even if manually given",
);
assert_ne!(
fdstat.fs_flags & (wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC),
0,
"file should have the same flags used to create the file"
assert_eq!(
fdstat.fs_flags & wasi::FDFLAGS_APPEND,
wasi::FDFLAGS_APPEND,
"file should have the APPEND fdflag used to create the file"
);
if TESTCONFIG.support_fdflags_sync() {
assert_eq!(
fdstat.fs_flags & wasi::FDFLAGS_SYNC,
wasi::FDFLAGS_SYNC,
"file should have the SYNC fdflag used to create the file"
);
}
if !TESTCONFIG.support_fdflags_sync() {
assert_errno!(
wasi::path_open(
dir_fd,
0,
"file",
0,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET,
0,
wasi::FDFLAGS_SYNC,
)
.expect_err("FDFLAGS_SYNC not supported by platform")
.raw_error(),
wasi::ERRNO_NOTSUP
);
}
// Check file size
let file_stat = wasi::path_filestat_get(dir_fd, 0, "file").expect("reading file stats");

View File

@@ -4,6 +4,7 @@ pub struct TestConfig {
no_fd_allocate: bool,
no_rename_dir_to_empty_dir: bool,
no_dangling_directory: bool,
no_fdflags_sync_support: bool,
}
enum ErrnoMode {
@@ -25,12 +26,14 @@ impl TestConfig {
let no_fd_allocate = std::env::var("NO_FD_ALLOCATE").is_ok();
let no_rename_dir_to_empty_dir = std::env::var("NO_RENAME_DIR_TO_EMPTY_DIR").is_ok();
let no_dangling_directory = std::env::var("NO_DANGLING_DIRECTORY").is_ok();
let no_fdflags_sync_support = std::env::var("NO_FDFLAGS_SYNC_SUPPORT").is_ok();
TestConfig {
errno_mode,
no_dangling_symlinks,
no_fd_allocate,
no_rename_dir_to_empty_dir,
no_dangling_directory,
no_fdflags_sync_support,
}
}
pub fn errno_expect_unix(&self) -> bool {
@@ -57,4 +60,7 @@ impl TestConfig {
pub fn support_dangling_directory(&self) -> bool {
!self.no_dangling_directory
}
pub fn support_fdflags_sync(&self) -> bool {
!self.no_fdflags_sync_support
}
}