Skip to content

Commit

Permalink
fix: test case ut_lind_fs_pwrite_to_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lind committed Oct 22, 2024
1 parent 1e4fe90 commit 3f5c746
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/tests/fs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4153,14 +4153,22 @@ pub mod fs_tests {
// supported.
let path = "/test_dir";
assert_eq!(cage.mkdir_syscall(path, S_IRWXA), 0);
let fd = cage.open_syscall(path, O_WRONLY, S_IRWXA);
// Open the directory with O_RDONLY
let fd = cage.open_syscall(path, O_RDONLY, S_IRWXA);
assert!(fd >= 0, "Failed to open directory: invalid file descriptor");

let write_data = "hello";
// Attempt to pwrite to the directory, expecting EBADF.
let result = cage.pwrite_syscall(fd, write_data.as_ptr(), write_data.len(), 0);
// Expect EBADF (Bad file descriptor) as directories cannot be written to.
assert_eq!(
cage.pwrite_syscall(fd, write_data.as_ptr(), write_data.len(), 0),
-(Errno::EISDIR as i32)
result,
-(Errno::EBADF as i32),
"Expected EBADF error when attempting to write to a directory"
);

// Clean up
assert_eq!(cage.rmdir_syscall(path), 0);
assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS);
lindrustfinalize();
}
Expand Down

0 comments on commit 3f5c746

Please sign in to comment.