Skip to content

Commit

Permalink
Add .cleanup suffix for files created in tests so the're automaticall…
Browse files Browse the repository at this point in the history
…y cleaned up by the test runner
  • Loading branch information
loganek committed Dec 8, 2022
1 parent 769a7da commit 7b60184
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 11 additions & 9 deletions tests/rust/src/bin/dangling_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ unsafe fn test_dangling_fd(dir_fd: wasi::Fd) {
if TESTCONFIG.support_dangling_filesystem() {
// Create a file, open it, delete it without closing the handle,
// and then try creating it again
let fd = wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).unwrap();
let fd = wasi::path_open(dir_fd, 0, "file.cleanup", wasi::OFLAGS_CREAT, 0, 0, 0).unwrap();
wasi::fd_close(fd).unwrap();
let file_fd = wasi::path_open(dir_fd, 0, "file", 0, 0, 0, 0).expect("failed to open");
let file_fd =
wasi::path_open(dir_fd, 0, "file.cleanup", 0, 0, 0, 0).expect("failed to open");
assert!(
file_fd > libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check",
);
wasi::path_unlink_file(dir_fd, "file").expect("failed to unlink");
let fd = wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).unwrap();
wasi::path_unlink_file(dir_fd, "file.cleanup").expect("failed to unlink");
let fd = wasi::path_open(dir_fd, 0, "file.cleanup", 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");
wasi::path_create_directory(dir_fd, "subdir.cleanup").expect("failed to create dir");
let subdir_fd =
wasi::path_open(dir_fd, 0, "subdir.cleanup", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect("failed to open dir");
assert!(
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");
wasi::path_remove_directory(dir_fd, "subdir.cleanup").expect("failed to remove dir 2");
wasi::path_create_directory(dir_fd, "subdir.cleanup").expect("failed to create dir 2");
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/rust/src/bin/dangling_symlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use wasi_tests::{assert_errno, open_scratch_directory, TESTCONFIG};
unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {
if TESTCONFIG.support_dangling_filesystem() {
// First create a dangling symlink.
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink");
wasi::path_symlink("target", dir_fd, "symlink.cleanup").expect("creating a symlink");

// Try to open it as a directory with O_NOFOLLOW.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
wasi::path_open(dir_fd, 0, "symlink.cleanup", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a dangling symlink as a directory")
.raw_error(),
wasi::ERRNO_NOTDIR,
Expand All @@ -17,14 +17,14 @@ unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {

// Try to open it as a file with O_NOFOLLOW.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
wasi::path_open(dir_fd, 0, "symlink.cleanup", 0, 0, 0, 0)
.expect_err("opening a dangling symlink as a file")
.raw_error(),
wasi::ERRNO_LOOP
);

// Clean up.
wasi::path_unlink_file(dir_fd, "symlink").expect("failed to remove file");
wasi::path_unlink_file(dir_fd, "symlink.cleanup").expect("failed to remove file");
}
}

Expand Down

0 comments on commit 7b60184

Please sign in to comment.