-
Notifications
You must be signed in to change notification settings - Fork 10
Added tests for mkdir_syscall #255
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall logic makes sense to me, lgtm so approved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Can you add a test for doing mkdir through a symlink?
Great starter! i think we can bundle the comments update for the syscall in this PR itself. |
Added the test for the same. |
src/tests/fs_tests.rs
Outdated
// Create a directory which will be referred to as originaldir | ||
let fd = cage.open_syscall("/originaldir", O_CREAT | O_EXCL | O_WRONLY, S_IRWXA); | ||
assert_eq!(cage.write_syscall(fd, str2cbuf("hi"), 2), 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a file, not a directory, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a file, not a directory, right?
Sorry, my bad...I just rechecked the other references for this function call and it creates a file, not a directory. Updated the changes.
src/safeposix/syscalls/fs_calls.rs
Outdated
{ | ||
parentdir | ||
.filename_to_inode_dict | ||
.insert(filename, newinodenum); | ||
parentdir.linkcount += 1; | ||
parentdir.ctime = time; | ||
parentdir.mtime = time; | ||
// Here, update the ctime and mtime for the parent directory as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man pages for this call contain the update to the timestamps as well - https://docs.oracle.com/cd/E86824_01/html/E54765/mkdir-2.html
assert_eq!(cage.mkdir_syscall("/parentdir/dir", S_IRWXA), 0); | ||
|
||
// Get the stat data for the child directory and check for inode link count to be 3 initially | ||
let mut statdata2 = StatData::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this test to verify the "link count" when a new directory is created.
src/safeposix/syscalls/fs_calls.rs
Outdated
@@ -187,6 +187,8 @@ impl Cage { | |||
if path.len() == 0 { | |||
return syscall_error(Errno::ENOENT, "mkdir", "given path was null"); | |||
} | |||
|
|||
// Get the absolute path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done to get the absolute path from the root directory of Lind so that we can trace the entire path and check for errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, please explain why we need to do this to check for errors in the code comment.
I can tell you're getting the absolute path from the code, but don't know why you are getting it until you tell me...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, will update the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. I like the tests particularly. A few comments could be improved, but it mostly looks ready.
A brief intro and info about the arguments, Flags being used, purpose and return types above the function signature will make the documentation whole. you can refer to the man pages to add this, potentially also include any limitations and unsupported features we have today as a Note. other than that, everything looks good! |
Done, added relevant information before the system call and added more context inside the function call for better understanding. Couldn't find any limitations / unsupported features for now, but will update it once I find in future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
Fixes # (issue)
The following changes include the tests for the "mkdir" file system call under RustPosix.
The tests were added to cover all the possible scenarios that might happen when calling the file system_call
mkdir_syscall
.Type of change
How Has This Been Tested?
Inorder to run the tests, we need to run
cargo test --lib
command inside thesafeposix-rust
directory.All the tests are present under this directory:
lind_project/src/safeposix-rust/src/tests/fs_tests.rs
ut_lind_fs_mkdir_empty_directory()
ut_lind_fs_mkdir_nonexisting_directory()
ut_lind_fs_mkdir_existing_directory()
ut_lind_fs_mkdir_invalid_modebits()
ut_lind_fs_mkdir_success()
ut_lind_fs_mkdir_using_symlink()
Checklist: