From 34ad8df1698856882521a847a8a56a84fd31d53d Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 28 Jan 2021 12:58:41 -0800 Subject: [PATCH] dangling directories are a windows thing --- crates/test-programs/TEST_FAILURES | 28 +++++-------------- .../test-programs/tests/wasm_tests/runtime.rs | 3 +- .../wasi-tests/src/bin/dangling_fd.rs | 26 +++++++++-------- .../bin/remove_directory_trailing_slashes.rs | 2 -- crates/test-programs/wasi-tests/src/config.rs | 6 ++++ 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/crates/test-programs/TEST_FAILURES b/crates/test-programs/TEST_FAILURES index 2ae868ad65..920b559199 100644 --- a/crates/test-programs/TEST_FAILURES +++ b/crates/test-programs/TEST_FAILURES @@ -14,10 +14,6 @@ * fd_readdir - DirEntry metadata ino panics on windows: https://github.com/bytecodealliance/cap-std/issues/142 -* file_allocate - - call to fd_allocate(10,10) reduces size from 100 to 20 - - fix upstream: fd_allocate is impossible on windows, so dont even try - - the test should be modified to accept this fd_allocate always failing on windows. * nofollow_errors - I loosened up some errno acceptance but windows requires rmdir to delete a symlink to a directory, rather than unlink_file @@ -25,10 +21,6 @@ * symlink_create - narrowed down the symlink delete issue that only shows up on linux - dan is doing the upstream fix rn -* path_rename - - permission denied on windows to rename a dir to an existing empty dir -* path_link - - passes everything except dangling symlinks * fd_flags_set - same metadata panic as fd_readdir * path_filestat @@ -41,17 +33,11 @@ - on windows, opening a directory with a trailing slash fails. * path_rename_file_trailing_slashes - same incorrect behavior as linux -* path_symlink_trailing_slashes - - dangling symlinks are not supported, different errnos in four spots + + +* dangling_fd +* dangling_symlink +* path_rename_trailing_slashes * remove_directory_trailing_slashes - - different errno in one case -* unlink_file_trailing_slashes - - different errnos in three spots - - -# Test Divergences - -* fd_allocate supported or not -* dangling symlinks supported or not -* errno: windows or linux mode? - +* symlink_filestat +* symlink_loop diff --git a/crates/test-programs/tests/wasm_tests/runtime.rs b/crates/test-programs/tests/wasm_tests/runtime.rs index 2c3a6e3b3d..8308363d4c 100644 --- a/crates/test-programs/tests/wasm_tests/runtime.rs +++ b/crates/test-programs/tests/wasm_tests/runtime.rs @@ -34,7 +34,8 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any .env("ERRNO_MODE_WINDOWS", "1")? .env("NO_DANGLING_SYMLINKS", "1")? .env("NO_FD_ALLOCATE", "1")? - .env("NO_RENAME_DIR_TO_EMPTY_DIR", "1")?; + .env("NO_RENAME_DIR_TO_EMPTY_DIR", "1")? + .env("NO_DANGLING_DIRECTORY", "1")?; } #[cfg(unix)] { diff --git a/crates/test-programs/wasi-tests/src/bin/dangling_fd.rs b/crates/test-programs/wasi-tests/src/bin/dangling_fd.rs index e63ecbc8d7..c97e2dcc16 100644 --- a/crates/test-programs/wasi-tests/src/bin/dangling_fd.rs +++ b/crates/test-programs/wasi-tests/src/bin/dangling_fd.rs @@ -1,6 +1,6 @@ use more_asserts::assert_gt; use std::{env, process}; -use wasi_tests::open_scratch_directory; +use wasi_tests::{open_scratch_directory, TESTCONFIG}; unsafe fn test_dangling_fd(dir_fd: wasi::Fd) { // Create a file, open it, delete it without closing the handle, @@ -17,17 +17,19 @@ unsafe fn test_dangling_fd(dir_fd: wasi::Fd) { 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 - wasi::path_create_directory(dir_fd, "subdir").expect("failed to create dir"); - let subdir_fd = wasi::path_open(dir_fd, 0, "subdir", wasi::OFLAGS_DIRECTORY, 0, 0, 0) - .expect("failed to open dir"); - assert_gt!( - subdir_fd, - libc::STDERR_FILENO as wasi::Fd, - "file descriptor range check", - ); - wasi::path_remove_directory(dir_fd, "subdir").expect("failed to remove dir 2"); - wasi::path_create_directory(dir_fd, "subdir").expect("failed to create dir 2"); + if TESTCONFIG.support_dangling_directory() { + // Now, repeat the same process but for a directory + wasi::path_create_directory(dir_fd, "subdir").expect("failed to create dir"); + let subdir_fd = wasi::path_open(dir_fd, 0, "subdir", wasi::OFLAGS_DIRECTORY, 0, 0, 0) + .expect("failed to open dir"); + assert_gt!( + subdir_fd, + libc::STDERR_FILENO as wasi::Fd, + "file descriptor range check", + ); + wasi::path_remove_directory(dir_fd, "subdir").expect("failed to remove dir 2"); + wasi::path_create_directory(dir_fd, "subdir").expect("failed to create dir 2"); + } } fn main() { diff --git a/crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs b/crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs index 654c899262..e3805a96ec 100644 --- a/crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs +++ b/crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs @@ -11,11 +11,9 @@ unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi::Fd) { wasi::path_create_directory(dir_fd, "dir").expect("creating a directory"); - /* XXX disabled: this fails presently on windows and linux // Test that removing it with a trailing slash succeeds. wasi::path_remove_directory(dir_fd, "dir/") .expect("remove_directory with a trailing slash on a directory should succeed"); - */ // Create a temporary file. create_file(dir_fd, "file"); diff --git a/crates/test-programs/wasi-tests/src/config.rs b/crates/test-programs/wasi-tests/src/config.rs index 132ac8dcb5..383c817370 100644 --- a/crates/test-programs/wasi-tests/src/config.rs +++ b/crates/test-programs/wasi-tests/src/config.rs @@ -3,6 +3,7 @@ pub struct TestConfig { no_dangling_symlinks: bool, no_fd_allocate: bool, no_rename_dir_to_empty_dir: bool, + no_dangling_directory: bool, } enum ErrnoMode { @@ -23,11 +24,13 @@ impl TestConfig { let no_dangling_symlinks = std::env::var("NO_DANGLING_SYMLINKS").is_ok(); 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(); TestConfig { errno_mode, no_dangling_symlinks, no_fd_allocate, no_rename_dir_to_empty_dir, + no_dangling_directory, } } pub fn errno_expect_unix(&self) -> bool { @@ -51,4 +54,7 @@ impl TestConfig { pub fn support_rename_dir_to_empty_dir(&self) -> bool { !self.no_rename_dir_to_empty_dir } + pub fn support_dangling_directory(&self) -> bool { + !self.no_dangling_directory + } }