-
Notifications
You must be signed in to change notification settings - Fork 423
Refactor libc pipe tests to use utility functions for error handling and data operations #4768
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
base: master
Are you sure you want to change the base?
Refactor libc pipe tests to use utility functions for error handling and data operations #4768
Conversation
…and data operations
|
Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two. |
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.
Thanks a lot! This looks great.
However, there are some read calls here you did not convert because we did not have the right helpers for that. I think we should explore adding more helpers so that we don't need to do a second pass over all the tests later.
| let mut buf4: [u8; 5] = [0; 5]; | ||
| let res = unsafe { libc::read(fds[0], buf4.as_mut_ptr().cast(), buf4.len() as libc::size_t) }; | ||
| assert!(res > 0 && res <= 3); |
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.
We should think about a way to also cover this case without having to directly invoke read (or read_all below).
I am imagining functions like this:
/// Fill `dest` by repeatedly reading from `fd`. Error if not enough bytes could be read.
fn read_all_into_slice(fd: libc::c_int, dest: &mut [u8]) -> Result<(), libc::ssize_t>;
/// Read up to `dest.len()` many bytes from `fd`. Returns a pair of the part of `dest` that has been
/// read into, and the tail that was left untouched.
fn read_into_slice(fd: libc::c_int, dest: &mut [u8]) -> Result<(&mut [u8], &mut [u8]), libc::ssize_t>;Can you add such functions to tests/utils/libc.rs and use them here?
(Please let me know if this is too much, then I can take over for this part.)
| let data = b"abcde"; | ||
| write_all_from_slice(fds[1], data).unwrap(); |
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.
| let data = b"abcde"; | |
| write_all_from_slice(fds[1], data).unwrap(); | |
| write_all_from_slice(fds[1], b"abcde").unwrap(); |
Generally, if data is only used exactly once, then just inline it. This occurs some more times below.
|
Reminder, once the PR becomes ready for a review, use |
|
|
||
| #[path = "../../utils/libc.rs"] | ||
| mod libc_utils; | ||
| use libc_utils::{errno_check, errno_result, read_all_into_array, write_all_from_slice}; |
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.
| use libc_utils::{errno_check, errno_result, read_all_into_array, write_all_from_slice}; | |
| use libc_utils::*; |
Related to #4725