Skip to content

Commit 0a83351

Browse files
dianpopaacatangiu
authored andcommitted
vmm: fix test_epoll_stdin_event
This unit tests makes sure that calling epoll_ctl_add on STDIN_FILENO succeeds. However, if the unit tests are run through ssh without a pseudo terminal, adding STDIN_FILENO would return EPERM. Adjust unit test to not panic in case of EPERM. Signed-off-by: Diana Popa <[email protected]>
1 parent 9537189 commit 0a83351

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

vmm/src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,15 +2621,21 @@ mod tests {
26212621
#[test]
26222622
fn test_epoll_stdin_event() {
26232623
let mut epoll_context = EpollContext::new().unwrap();
2624-
epoll_context.enable_stdin_event();
2625-
assert_eq!(
2626-
epoll_context.dispatch_table[epoll_context.stdin_index as usize].unwrap(),
2627-
EpollDispatch::Stdin
2628-
);
2629-
// This should trigger a warn!. When logger will not be a global var we will be able to test
2630-
// it.
2631-
epoll_context.enable_stdin_event();
26322624

2625+
// If this unit test is run without a terminal attached (i.e ssh without pseudo terminal,
2626+
// request, jailer with `--daemonize` flag on) EPOLL_CTL_ADD would return EPERM
2627+
// on STDIN_FILENO. So, we are using `isatty` to check whether STDIN_FILENO refers
2628+
// to a terminal. If it does not, we are no longer asserting against
2629+
// `epoll_context.dispatch_table[epoll_context.stdin_index as usize]` holding any value.
2630+
if unsafe { libc::isatty(libc::STDIN_FILENO as i32) } == 1 {
2631+
epoll_context.enable_stdin_event();
2632+
assert_eq!(
2633+
epoll_context.dispatch_table[epoll_context.stdin_index as usize].unwrap(),
2634+
EpollDispatch::Stdin
2635+
);
2636+
}
2637+
2638+
epoll_context.enable_stdin_event();
26332639
epoll_context.disable_stdin_event();
26342640
assert!(epoll_context.dispatch_table[epoll_context.stdin_index as usize].is_none());
26352641
}

0 commit comments

Comments
 (0)