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

[WIP] Add test for rootfs propagation with mock mount #347

Conversation

tiqwab
Copy link
Contributor

@tiqwab tiqwab commented Sep 30, 2021

This is a follow-up pull request to add unit tests for functions implemented in #309.

This pull request calls mount system call through Syscall trait to mock it in unit tests. Although we can use fork and then execute real mount system call in child process, I feel checking mount arguments is simple and enough in this case.

@utam0k @yihuaf
What do you think about the idea of using mock for these tests?

@yihuaf
Copy link
Collaborator

yihuaf commented Sep 30, 2021

Haven't looked the entire PR yet. I think to test the readonly_path and mask_path individually, we should fork and use namespaces. mock only shows the command is being called, but testing the actual assumption we make.

Edit: My knee jerk reaction is to test these functions with fork, new mount namespace, and the actual mount calls. How hard is it to write the actual test with fork? You may have to use serial test in these cases.

@tiqwab
Copy link
Contributor Author

tiqwab commented Sep 30, 2021

I actually wrote a draft for the test of rootfs::make_parent_mount_private function with the actual mount system call in tiqwab@4e49290. Is it similar to what you think?

I just focused on writing unit tests for rootfs::make_parent_mount_private and rootfs::adjust_root_mount_propagation and in that case I thought checking mount args is simpler and enough. However I understand the benefit of using the actual mount call and we might had better to use it considering other test cases in rootfs.

@tiqwab
Copy link
Contributor Author

tiqwab commented Sep 30, 2021

and I realized that there is a similar work in #340, so we might had better to close this and leave it for @tommady.

@tommady
Copy link
Collaborator

tommady commented Sep 30, 2021

and I realized that there is a similar work in #340, so we might had better to close this and leave it for @tommady.

ya thank you and please allow me to copy some of your masterwork there 🙇🏻

@yihuaf
Copy link
Collaborator

yihuaf commented Sep 30, 2021

I actually wrote a draft for the test of rootfs::make_parent_mount_private function with the actual mount system call in tiqwab@4e49290. Is it similar to what you think?

I just focused on writing unit tests for rootfs::make_parent_mount_private and rootfs::adjust_root_mount_propagation and in that case I thought checking mount args is simpler and enough. However I understand the benefit of using the actual mount call and we might had better to use it considering other test cases in rootfs.

Yes, this is what I had in mind as well. A few minor points:

  1. Let's use fork instead of clone, or we should implement clone properly. Rust memory management has some weird issue with regarding to stack vs. heap allocation for stack. We used to use clone but discovered issue in rust. So fork is much safer since you trust the kernel code to copy all the memory correctly. If clone prove to be better suited than fork, I would bring back the old implementation for a clone wrapper. See Refactor clone(2) child stack creation. #167 for reference.

  2. We can now use ipc-channel to pass richer results from child process back to parent process. See Implemented util function to test in child process #345 for reference.

@yihuaf
Copy link
Collaborator

yihuaf commented Sep 30, 2021

and I realized that there is a similar work in #340, so we might had better to close this and leave it for @tommady.

@tommady Are you able to incorporate this change? Since the title of #340 is vague, can I ask what is the scope of the PR? Let us know what you plan to keep from this PR for #340. In general, please keep the PR as small as reasonably possible. This will be much easier for review and coordinate.

@tommady
Copy link
Collaborator

tommady commented Oct 1, 2021

@tommady Are you able to incorporate this change? Since the title of #340 is vague, can I ask what is the scope of the PR? Let us know what you plan to keep from this PR for #340. In general, please keep the PR as small as reasonably possible. This will be much easier for review and coordinate.

hi @yihuaf the goal of PR #340 is trying to increase the testing coverage of rootfs.rs file only.

so the plain is that

  1. won't modify the existing working flow or logic
  2. only try to mock the system calls
  3. try to increase the coverage as much as possible

is that acceptable to you? thanks

@yihuaf
Copy link
Collaborator

yihuaf commented Oct 17, 2021

Looks like @tommady already incorporated this PR into other PRs. Closing this for now. Please reopen if I made a mistake.

@yihuaf yihuaf closed this Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants