From 40e541bfc33e4591cfe43fb4f5ca86c36c8edcd4 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 1 Feb 2021 14:25:42 -0800 Subject: [PATCH] test suite: cap-std-sync test environment does not support fdflags sync --- .../tests/wasm_tests/runtime/cap_std_sync.rs | 3 ++ .../wasi-tests/src/bin/path_filestat.rs | 42 ++++++++++++++++--- crates/test-programs/wasi-tests/src/config.rs | 6 +++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs b/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs index 343385bd27..f969218b07 100644 --- a/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs +++ b/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs @@ -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); diff --git a/crates/test-programs/wasi-tests/src/bin/path_filestat.rs b/crates/test-programs/wasi-tests/src/bin/path_filestat.rs index cb55e07b77..ec3719d1d8 100644 --- a/crates/test-programs/wasi-tests/src/bin/path_filestat.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_filestat.rs @@ -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"); diff --git a/crates/test-programs/wasi-tests/src/config.rs b/crates/test-programs/wasi-tests/src/config.rs index 383c817370..8bb77e6aee 100644 --- a/crates/test-programs/wasi-tests/src/config.rs +++ b/crates/test-programs/wasi-tests/src/config.rs @@ -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 + } }