diff --git a/mshv-ioctls/Cargo.toml b/mshv-ioctls/Cargo.toml index 107bfef3..23ca481f 100644 --- a/mshv-ioctls/Cargo.toml +++ b/mshv-ioctls/Cargo.toml @@ -9,3 +9,6 @@ license = "Apache-2.0 OR BSD-3-Clause" libc = ">=0.2.39" mshv-bindings = {path = "../mshv-bindings", features = ["fam-wrappers"]} vmm-sys-util = ">=0.12.1" + +[dev-dependencies] +random-number = "0.1.6" diff --git a/mshv-ioctls/src/ioctls/vcpu.rs b/mshv-ioctls/src/ioctls/vcpu.rs index 0ba95302..b413447f 100644 --- a/mshv-ioctls/src/ioctls/vcpu.rs +++ b/mshv-ioctls/src/ioctls/vcpu.rs @@ -1158,6 +1158,7 @@ mod tests { // Note this useful idiom: importing names from outer (for mod tests) scope. use super::*; use crate::ioctls::system::Mshv; + use random_number::random; #[test] fn test_set_get_regs() { @@ -1569,4 +1570,55 @@ mod tests { let max_function = res[0]; assert!(max_function >= 1); } + + #[test] + fn test_get_set_synic_timers() { + let hv = Mshv::new().unwrap(); + let vm = hv.create_vm().unwrap(); + let vcpu = vm.create_vcpu(0).unwrap(); + + let in_state: SyntheticTimers = vcpu.get_synic_timers().unwrap(); + vcpu.set_synic_timers(&in_state).unwrap(); + let out_state = vcpu.get_synic_timers().unwrap(); + assert!(in_state == out_state); + } + + #[test] + fn test_get_set_simp() { + let hv = Mshv::new().unwrap(); + let vm = hv.create_vm().unwrap(); + let vcpu = vm.create_vcpu(0).unwrap(); + + let mut in_state: SynicMessagePage = SynicMessagePage::default(); + + for i in 0..4096 { + in_state.buffer[i] = random!(); + } + vcpu.set_synic_message_page(&in_state).unwrap(); + let out_state = vcpu.get_synic_message_page().unwrap(); + assert!(in_state + .buffer + .iter() + .zip(out_state.buffer.iter()) + .all(|(a, b)| a == b)); + } + + #[test] + fn test_get_set_sief() { + let hv = Mshv::new().unwrap(); + let vm = hv.create_vm().unwrap(); + let vcpu = vm.create_vcpu(0).unwrap(); + + let mut in_state: SynicEventFlagsPage = SynicEventFlagsPage::default(); + for i in 0..4096 { + in_state.buffer[i] = random!(); + } + vcpu.set_synic_event_flags_page(&in_state).unwrap(); + let out_state = vcpu.get_synic_event_flags_page().unwrap(); + assert!(in_state + .buffer + .iter() + .zip(out_state.buffer.iter()) + .all(|(a, b)| a == b)); + } }