Skip to content

Commit 366d4f9

Browse files
wainersmandreeaflorescu
authored andcommitted
system: Add test_open_with_cloexec test
Added tests for Kvm::open_with_cloexec(). Signed-off-by: Wainer dos Santos Moschetta <[email protected]>
1 parent 6e965fb commit 366d4f9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/ioctls/system.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ mod tests {
495495
use super::*;
496496
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
497497
use kvm_bindings::KVM_MAX_CPUID_ENTRIES;
498+
use libc::{fcntl, FD_CLOEXEC, F_GETFD};
498499
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
499500
use vmm_sys_util::fam::FamStruct;
500501

@@ -503,6 +504,16 @@ mod tests {
503504
Kvm::new().unwrap();
504505
}
505506

507+
#[test]
508+
fn test_open_with_cloexec() {
509+
let fd = Kvm::open_with_cloexec(false).unwrap();
510+
let flags = unsafe { fcntl(fd, F_GETFD, 0) };
511+
assert_eq!(flags & FD_CLOEXEC, 0);
512+
let fd = Kvm::open_with_cloexec(true).unwrap();
513+
let flags = unsafe { fcntl(fd, F_GETFD, 0) };
514+
assert_eq!(flags & FD_CLOEXEC, FD_CLOEXEC);
515+
}
516+
506517
#[test]
507518
fn test_kvm_api_version() {
508519
let kvm = Kvm::new().unwrap();

0 commit comments

Comments
 (0)