Skip to content

Commit

Permalink
mshv-ioctls: unit tests for synthetic state components
Browse files Browse the repository at this point in the history
Add unit tests for the get/set APIs of the synthetic
state components.

Signed-off-by: Muminul Islam <[email protected]>
  • Loading branch information
russell-islam committed Mar 29, 2024
1 parent f8c9f9e commit 3d221d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mshv-ioctls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
52 changes: 52 additions & 0 deletions mshv-ioctls/src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 3d221d3

Please sign in to comment.