Skip to content

Commit

Permalink
Debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Sep 24, 2024
1 parent 30b23d4 commit d9150b0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/event/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ fn test_select_with_maxfd_sockets() {
}
setrlimit(Resource::Nofile, rlimit).unwrap();

dbg!("hello");
// Renumber the fds to the maximum possible values.
let great_fd = unsafe { libc::dup2(reader.as_raw_fd(), fd_limit as RawFd - 1) };
let reader = unsafe { OwnedFd::from_raw_fd(great_fd) };
let great_fd = unsafe { libc::dup2(writer.as_raw_fd(), fd_limit as RawFd - 2) };
let writer = unsafe { OwnedFd::from_raw_fd(great_fd) };
dbg!("hello");

let nfds = max(reader.as_raw_fd(), writer.as_raw_fd()) + 1;

Expand All @@ -311,6 +313,7 @@ fn test_select_with_maxfd_sockets() {
// `select` should say there's nothing ready to be read from the pipe.
let mut readfds = vec![FdSetElement::default(); fd_set_num_elements(2, nfds as RawFd)];
fd_set_insert(&mut readfds, reader.as_raw_fd());
dbg!("hello");
let num = retry_on_intr(|| unsafe {
select(
nfds,
Expand All @@ -324,16 +327,19 @@ fn test_select_with_maxfd_sockets() {
)
})
.unwrap();
dbg!("hello");
assert_eq!(num, 0);
assert!(!fd_set_contains(&readfds, reader.as_raw_fd()));
assert_eq!(fd_set_bound(&readfds), 0);

dbg!("hello");
// Write a byte to the pipe.
assert_eq!(
retry_on_intr(|| send(&writer, b"a", SendFlags::empty())).unwrap(),
1
);

dbg!("hello");
// `select` should now say there's data to be read.
let mut readfds = vec![FdSetElement::default(); fd_set_num_elements(2, nfds as RawFd)];
fd_set_insert(&mut readfds, reader.as_raw_fd());
Expand All @@ -346,6 +352,7 @@ fn test_select_with_maxfd_sockets() {
assert!(!fd_set_contains(&readfds, reader.as_raw_fd()));
assert_eq!(fd_set_bound(&readfds), 0);

dbg!("hello");
// Read the byte from the pipe.
let mut buf = [b'\0'];
assert_eq!(
Expand All @@ -372,6 +379,7 @@ fn test_select_with_maxfd_sockets() {
assert_eq!(num, 0);
assert!(!fd_set_contains(&readfds, reader.as_raw_fd()));
assert_eq!(fd_set_bound(&readfds), 0);
dbg!("hello");

setrlimit(Resource::Nofile, orig_rlimit).unwrap();
}
Expand Down

0 comments on commit d9150b0

Please sign in to comment.