From e521dfd66c54d6b9053506e2d8ba47ff3987a35c Mon Sep 17 00:00:00 2001 From: McNight Date: Mon, 2 Feb 2026 11:47:11 +0100 Subject: [PATCH] test: fix macos::eventfd::tests Signed-off-by: McNight --- src/utils/Cargo.toml | 3 +++ src/utils/src/macos/epoll.rs | 17 +++++++++++------ src/utils/src/macos/eventfd.rs | 10 ---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/utils/Cargo.toml b/src/utils/Cargo.toml index e3720d400..482eb62ae 100644 --- a/src/utils/Cargo.toml +++ b/src/utils/Cargo.toml @@ -14,3 +14,6 @@ crossbeam-channel = ">=0.5.15" [target.'cfg(target_os = "linux")'.dependencies] kvm-bindings = { version = ">=0.11", features = ["fam-wrappers"] } + +[target.'cfg(target_os = "macos")'.dependencies] +nix = { version = "0.30.1", features = ["fs"] } \ No newline at end of file diff --git a/src/utils/src/macos/epoll.rs b/src/utils/src/macos/epoll.rs index a928caee7..f6141cd53 100644 --- a/src/utils/src/macos/epoll.rs +++ b/src/utils/src/macos/epoll.rs @@ -322,8 +322,9 @@ mod tests { #[test] fn test_epoll() { - const DEFAULT__TIMEOUT: i32 = 250; + const DEFAULT_TIMEOUT: i32 = 250; const EVENT_BUFFER_SIZE: usize = 128; + const MAX_EVENTS: usize = 10; let epoll = Epoll::new().unwrap(); assert_eq!(epoll.queue, epoll.as_raw_fd()); @@ -345,7 +346,7 @@ mod tests { .ctl( ControlOperation::Add, event_fd_1.as_raw_fd() as i32, - event_1 + &event_1 ) .is_ok()); @@ -357,13 +358,15 @@ mod tests { event_fd_2.as_raw_fd() as i32, // For this fd, we want an Event instance that has `data` field set to other // value than the value of the fd and `events` without EPOLLIN type set. - EpollEvent::new(EventSet::IN, 10) + &EpollEvent::new(EventSet::IN, 10) ) .is_ok()); // Let's check `epoll_wait()` behavior for our epoll instance. let mut ready_events = vec![EpollEvent::default(); EVENT_BUFFER_SIZE]; - let mut ev_count = epoll.wait(DEFAULT__TIMEOUT, &mut ready_events[..]).unwrap(); + let mut ev_count = epoll + .wait(MAX_EVENTS, DEFAULT_TIMEOUT, &mut ready_events[..]) + .unwrap(); // We expect to have 3 fds in the ready list of epoll instance. assert_eq!(ev_count, 2); @@ -382,12 +385,14 @@ mod tests { .ctl( ControlOperation::Delete, event_fd_2.as_raw_fd() as i32, - EpollEvent::default() + &EpollEvent::default() ) .is_ok()); // We expect to have only one fd remained in the ready list (event_fd_3). - ev_count = epoll.wait(DEFAULT__TIMEOUT, &mut ready_events[..]).unwrap(); + ev_count = epoll + .wait(MAX_EVENTS, DEFAULT_TIMEOUT, &mut ready_events[..]) + .unwrap(); assert_eq!(ev_count, 1); assert_eq!(ready_events[0].data(), event_fd_1.as_raw_fd() as u64); diff --git a/src/utils/src/macos/eventfd.rs b/src/utils/src/macos/eventfd.rs index dc7ab07c5..c66ffbad7 100644 --- a/src/utils/src/macos/eventfd.rs +++ b/src/utils/src/macos/eventfd.rs @@ -95,16 +95,6 @@ mod tests { assert_eq!(evt.read().unwrap(), 55); } - #[test] - fn test_write_overflow() { - let evt = EventFd::new(EFD_NONBLOCK).unwrap(); - evt.write(std::u64::MAX - 1).unwrap(); - let r = evt.write(1); - match r { - Err(ref inner) if inner.kind() == io::ErrorKind::WouldBlock => (), - _ => panic!("Unexpected"), - } - } #[test] fn test_read_nothing() { let evt = EventFd::new(EFD_NONBLOCK).unwrap();