Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test case ut_lind_fs_mmap_zerolen #70

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/tests/fs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,21 @@ pub mod fs_tests {
//making it valid for any mapping.
let flags: i32 = O_TRUNC | O_CREAT | O_RDWR;
let filepath = "/mmapTestFile1";
// Unlink the file if it already exists
let _ = cage.unlink_syscall(filepath);
let fd = cage.open_syscall(filepath, flags, S_IRWXA);
//Writing into that file's first 9 bytes.
assert_eq!(cage.write_syscall(fd, str2cbuf("Test text"), 9), 9);

//Checking if passing 0 as `len` to `mmap_syscall()`
//correctly results in 'The value of len is 0` error.
assert_eq!(
cage.mmap_syscall(0 as *mut u8, 0, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0),
-(Errno::EINVAL as i32)
);

let mmap_result = cage.mmap_syscall(0 as *mut u8, 0, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
assert_eq!(mmap_result, -1, "Expected mmap to fail with -1 due to zero length");
// Fetch the errno and check that it is `EINVAL` (Invalid argument)
let errno = get_errno();
assert_eq!(errno, libc::EINVAL, "Expected errno to be EINVAL for zero-length mmap");
// Clean up and finalize
assert_eq!(cage.unlink_syscall(filepath), 0);
assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS);
lindrustfinalize();
}
Expand Down
Loading