mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vmm: Add unit test for 'VmConfig::preserved_fds'
Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
e3d2917d5f
commit
4baf85857a
@ -2168,6 +2168,8 @@ impl Drop for VmConfig {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use net_util::MacAddr;
|
||||
use std::fs::File;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
#[test]
|
||||
fn test_cpu_parsing() -> Result<()> {
|
||||
@ -3184,7 +3186,7 @@ mod tests {
|
||||
]);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
|
||||
let mut invalid_config = valid_config;
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.devices = Some(vec![
|
||||
DeviceConfig {
|
||||
path: "/device1".into(),
|
||||
@ -3196,5 +3198,16 @@ mod tests {
|
||||
},
|
||||
]);
|
||||
assert!(invalid_config.validate().is_err());
|
||||
|
||||
let mut still_valid_config = valid_config;
|
||||
// SAFETY: Safe as the file was just opened
|
||||
let fd1 = unsafe { libc::dup(File::open("/dev/null").unwrap().as_raw_fd()) };
|
||||
// SAFETY: Safe as the file was just opened
|
||||
let fd2 = unsafe { libc::dup(File::open("/dev/null").unwrap().as_raw_fd()) };
|
||||
// SAFETY: safe as both FDs are valid
|
||||
unsafe {
|
||||
still_valid_config.add_preserved_fds(vec![fd1, fd2]);
|
||||
}
|
||||
let _still_valid_config = still_valid_config.clone();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user