Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
17 changes: 11 additions & 6 deletions src/utils/src/macos/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -345,7 +346,7 @@ mod tests {
.ctl(
ControlOperation::Add,
event_fd_1.as_raw_fd() as i32,
event_1
&event_1
)
.is_ok());

Expand All @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions src/utils/src/macos/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading