mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Eliminate use of assert!((...).is_ok())
Asserting on .is_ok()/.is_err() leads to hard to debug failures (as if the test fails, it will only say "assertion failed: false". We replace these with `.unwrap()`, which also prints the exact error variant that was unexpectedly encountered (we can to this these days thanks to efforts to implement Display and Debug for our error types). If the assert!((...).is_ok()) was followed by an .unwrap() anyway, we just drop the assert. Inspired by and quoted from @roypat. Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
@@ -3148,8 +3148,8 @@ mod tests {
|
||||
}
|
||||
);
|
||||
|
||||
assert!(CpusConfig::parse("boot=8,topology=2:2:1").is_err());
|
||||
assert!(CpusConfig::parse("boot=8,topology=2:2:1:x").is_err());
|
||||
CpusConfig::parse("boot=8,topology=2:2:1").unwrap_err();
|
||||
CpusConfig::parse("boot=8,topology=2:2:1:x").unwrap_err();
|
||||
assert_eq!(
|
||||
CpusConfig::parse("boot=1,kvm_hyperv=on")?,
|
||||
CpusConfig {
|
||||
@@ -3560,9 +3560,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_fs() -> Result<()> {
|
||||
// "tag" and "socket" must be supplied
|
||||
assert!(FsConfig::parse("").is_err());
|
||||
assert!(FsConfig::parse("tag=mytag").is_err());
|
||||
assert!(FsConfig::parse("socket=/tmp/sock").is_err());
|
||||
FsConfig::parse("").unwrap_err();
|
||||
FsConfig::parse("tag=mytag").unwrap_err();
|
||||
FsConfig::parse("socket=/tmp/sock").unwrap_err();
|
||||
assert_eq!(FsConfig::parse("tag=mytag,socket=/tmp/sock")?, fs_fixture());
|
||||
assert_eq!(
|
||||
FsConfig::parse("tag=mytag,socket=/tmp/sock,num_queues=4,queue_size=1024")?,
|
||||
@@ -3590,8 +3590,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_pmem_parsing() -> Result<()> {
|
||||
// Must always give a file and size
|
||||
assert!(PmemConfig::parse("").is_err());
|
||||
assert!(PmemConfig::parse("size=128M").is_err());
|
||||
PmemConfig::parse("").unwrap_err();
|
||||
PmemConfig::parse("size=128M").unwrap_err();
|
||||
assert_eq!(
|
||||
PmemConfig::parse("file=/tmp/pmem,size=128M")?,
|
||||
pmem_fixture()
|
||||
@@ -3617,8 +3617,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_console_parsing() -> Result<()> {
|
||||
assert!(ConsoleConfig::parse("").is_err());
|
||||
assert!(ConsoleConfig::parse("badmode").is_err());
|
||||
ConsoleConfig::parse("").unwrap_err();
|
||||
ConsoleConfig::parse("badmode").unwrap_err();
|
||||
assert_eq!(
|
||||
ConsoleConfig::parse("off")?,
|
||||
ConsoleConfig {
|
||||
@@ -3707,7 +3707,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_device_parsing() -> Result<()> {
|
||||
// Device must have a path provided
|
||||
assert!(DeviceConfig::parse("").is_err());
|
||||
DeviceConfig::parse("").unwrap_err();
|
||||
assert_eq!(
|
||||
DeviceConfig::parse("path=/path/to/device")?,
|
||||
device_fixture()
|
||||
@@ -3746,7 +3746,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vdpa_parsing() -> Result<()> {
|
||||
// path is required
|
||||
assert!(VdpaConfig::parse("").is_err());
|
||||
VdpaConfig::parse("").unwrap_err();
|
||||
assert_eq!(VdpaConfig::parse("path=/dev/vhost-vdpa")?, vdpa_fixture());
|
||||
assert_eq!(
|
||||
VdpaConfig::parse("path=/dev/vhost-vdpa,num_queues=2,id=my_vdpa")?,
|
||||
@@ -3762,7 +3762,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_tpm_parsing() -> Result<()> {
|
||||
// path is required
|
||||
assert!(TpmConfig::parse("").is_err());
|
||||
TpmConfig::parse("").unwrap_err();
|
||||
assert_eq!(
|
||||
TpmConfig::parse("socket=/var/run/tpm.sock")?,
|
||||
TpmConfig {
|
||||
@@ -3775,7 +3775,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vsock_parsing() -> Result<()> {
|
||||
// socket and cid is required
|
||||
assert!(VsockConfig::parse("").is_err());
|
||||
VsockConfig::parse("").unwrap_err();
|
||||
assert_eq!(
|
||||
VsockConfig::parse("socket=/tmp/sock,cid=3")?,
|
||||
VsockConfig {
|
||||
@@ -3831,7 +3831,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
// Parsing should fail as source_url is a required field
|
||||
assert!(RestoreConfig::parse("prefault=off").is_err());
|
||||
RestoreConfig::parse("prefault=off").unwrap_err();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3909,7 +3909,7 @@ mod tests {
|
||||
},
|
||||
]),
|
||||
};
|
||||
assert!(valid_config.validate(&snapshot_vm_config).is_ok());
|
||||
valid_config.validate(&snapshot_vm_config).unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.net_fds = Some(vec![RestoredNetConfig {
|
||||
@@ -3977,7 +3977,7 @@ mod tests {
|
||||
fds: None,
|
||||
..net_fixture()
|
||||
}]);
|
||||
assert!(another_valid_config.validate(&snapshot_vm_config).is_ok());
|
||||
another_valid_config.validate(&snapshot_vm_config).unwrap();
|
||||
}
|
||||
|
||||
fn platform_fixture() -> PlatformConfig {
|
||||
@@ -4085,12 +4085,12 @@ mod tests {
|
||||
landlock_rules: None,
|
||||
};
|
||||
|
||||
assert!(valid_config.validate().is_ok());
|
||||
valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.serial.mode = ConsoleOutputMode::Tty;
|
||||
invalid_config.console.mode = ConsoleOutputMode::Tty;
|
||||
assert!(valid_config.validate().is_ok());
|
||||
valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.payload = None;
|
||||
@@ -4172,7 +4172,7 @@ mod tests {
|
||||
..disk_fixture()
|
||||
}]);
|
||||
still_valid_config.memory.shared = true;
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.net = Some(vec![NetConfig {
|
||||
@@ -4191,7 +4191,7 @@ mod tests {
|
||||
..net_fixture()
|
||||
}]);
|
||||
still_valid_config.memory.shared = true;
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.net = Some(vec![NetConfig {
|
||||
@@ -4222,16 +4222,16 @@ mod tests {
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.memory.shared = true;
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.memory.hugepages = true;
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.memory.hugepages = true;
|
||||
still_valid_config.memory.hugepage_size = Some(2 << 20);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.memory.hugepages = false;
|
||||
@@ -4251,7 +4251,7 @@ mod tests {
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.platform = Some(platform_fixture());
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.platform = Some(PlatformConfig {
|
||||
@@ -4270,7 +4270,7 @@ mod tests {
|
||||
iommu_segments: Some(vec![1, 2, 3]),
|
||||
..platform_fixture()
|
||||
});
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.platform = Some(PlatformConfig {
|
||||
@@ -4292,7 +4292,7 @@ mod tests {
|
||||
pci_segment: 1,
|
||||
..disk_fixture()
|
||||
}]);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.platform = Some(PlatformConfig {
|
||||
@@ -4304,7 +4304,7 @@ mod tests {
|
||||
pci_segment: 1,
|
||||
..net_fixture()
|
||||
}]);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.platform = Some(PlatformConfig {
|
||||
@@ -4316,7 +4316,7 @@ mod tests {
|
||||
pci_segment: 1,
|
||||
..pmem_fixture()
|
||||
}]);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.platform = Some(PlatformConfig {
|
||||
@@ -4328,7 +4328,7 @@ mod tests {
|
||||
pci_segment: 1,
|
||||
..device_fixture()
|
||||
}]);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut still_valid_config = valid_config.clone();
|
||||
still_valid_config.platform = Some(PlatformConfig {
|
||||
@@ -4342,7 +4342,7 @@ mod tests {
|
||||
iommu: true,
|
||||
pci_segment: 1,
|
||||
});
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.platform = Some(PlatformConfig {
|
||||
@@ -4568,7 +4568,7 @@ mod tests {
|
||||
..device_fixture()
|
||||
},
|
||||
]);
|
||||
assert!(still_valid_config.validate().is_ok());
|
||||
still_valid_config.validate().unwrap();
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.devices = Some(vec![
|
||||
@@ -4581,7 +4581,7 @@ mod tests {
|
||||
..device_fixture()
|
||||
},
|
||||
]);
|
||||
assert!(invalid_config.validate().is_err());
|
||||
invalid_config.validate().unwrap_err();
|
||||
#[cfg(feature = "sev_snp")]
|
||||
{
|
||||
// Payload with empty host data
|
||||
@@ -4596,7 +4596,7 @@ mod tests {
|
||||
#[cfg(feature = "sev_snp")]
|
||||
host_data: Some("".to_string()),
|
||||
});
|
||||
assert!(config_with_no_host_data.validate().is_err());
|
||||
config_with_no_host_data.validate().unwrap_err();
|
||||
|
||||
// Payload with no host data provided
|
||||
let mut valid_config_with_no_host_data = valid_config.clone();
|
||||
@@ -4610,7 +4610,7 @@ mod tests {
|
||||
#[cfg(feature = "sev_snp")]
|
||||
host_data: None,
|
||||
});
|
||||
assert!(valid_config_with_no_host_data.validate().is_ok());
|
||||
valid_config_with_no_host_data.validate().unwrap();
|
||||
|
||||
// Payload with invalid host data length i.e less than 64
|
||||
let mut config_with_invalid_host_data = valid_config.clone();
|
||||
@@ -4626,7 +4626,7 @@ mod tests {
|
||||
"243eb7dc1a21129caa91dcbb794922b933baecb5823a377eb43118867328".to_string(),
|
||||
),
|
||||
});
|
||||
assert!(config_with_invalid_host_data.validate().is_err());
|
||||
config_with_invalid_host_data.validate().unwrap_err();
|
||||
}
|
||||
|
||||
let mut still_valid_config = valid_config;
|
||||
@@ -4643,10 +4643,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_landlock_parsing() -> Result<()> {
|
||||
// should not be empty
|
||||
assert!(LandlockConfig::parse("").is_err());
|
||||
LandlockConfig::parse("").unwrap_err();
|
||||
// access should not be empty
|
||||
assert!(LandlockConfig::parse("path=/dir/path1").is_err());
|
||||
assert!(LandlockConfig::parse("path=/dir/path1,access=rwr").is_err());
|
||||
LandlockConfig::parse("path=/dir/path1").unwrap_err();
|
||||
LandlockConfig::parse("path=/dir/path1,access=rwr").unwrap_err();
|
||||
assert_eq!(
|
||||
LandlockConfig::parse("path=/dir/path1,access=rw")?,
|
||||
LandlockConfig {
|
||||
|
||||
@@ -2817,9 +2817,9 @@ mod tests {
|
||||
fn test_setlint() {
|
||||
let hv = hypervisor::new().unwrap();
|
||||
let vm = hv.create_vm().expect("new VM fd creation failed");
|
||||
assert!(hv.check_required_extensions().is_ok());
|
||||
hv.check_required_extensions().unwrap();
|
||||
// Calling get_lapic will fail if there is no irqchip before hand.
|
||||
assert!(vm.create_irq_chip().is_ok());
|
||||
vm.create_irq_chip().unwrap();
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
let klapic_before: LapicState = vcpu.get_lapic().unwrap();
|
||||
|
||||
@@ -2961,15 +2961,14 @@ mod tests {
|
||||
let vm = hv.create_vm().unwrap();
|
||||
let vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
|
||||
let res = vcpu.setup_regs(0, 0x0, layout::FDT_START.0);
|
||||
// Must fail when vcpu is not initialized yet.
|
||||
assert!(res.is_err());
|
||||
vcpu.setup_regs(0, 0x0, layout::FDT_START.0).unwrap_err();
|
||||
|
||||
let mut kvi: kvm_vcpu_init = kvm_vcpu_init::default();
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
vcpu.vcpu_init(&kvi).unwrap();
|
||||
|
||||
assert!(vcpu.setup_regs(0, 0x0, layout::FDT_START.0).is_ok());
|
||||
vcpu.setup_regs(0, 0x0, layout::FDT_START.0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2981,7 +2980,7 @@ mod tests {
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
|
||||
// Must fail when vcpu is not initialized yet.
|
||||
assert!(vcpu.get_sys_reg(regs::MPIDR_EL1).is_err());
|
||||
vcpu.get_sys_reg(regs::MPIDR_EL1).unwrap_err();
|
||||
|
||||
vcpu.vcpu_init(&kvi).unwrap();
|
||||
assert_eq!(vcpu.get_sys_reg(regs::MPIDR_EL1).unwrap(), 0x80000000);
|
||||
@@ -3005,28 +3004,22 @@ mod tests {
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
|
||||
// Must fail when vcpu is not initialized yet.
|
||||
let res = vcpu.get_regs();
|
||||
assert!(res.is_err());
|
||||
assert_eq!(
|
||||
format!("{}", res.unwrap_err()),
|
||||
format!("{}", vcpu.get_regs().unwrap_err()),
|
||||
"Failed to get aarch64 core register: Exec format error (os error 8)"
|
||||
);
|
||||
|
||||
let mut state = vcpu.create_standard_regs();
|
||||
let res = vcpu.set_regs(&state);
|
||||
assert!(res.is_err());
|
||||
assert_eq!(
|
||||
format!("{}", res.unwrap_err()),
|
||||
format!("{}", vcpu.set_regs(&state).unwrap_err()),
|
||||
"Failed to set aarch64 core register: Exec format error (os error 8)"
|
||||
);
|
||||
|
||||
vcpu.vcpu_init(&kvi).unwrap();
|
||||
let res = vcpu.get_regs();
|
||||
assert!(res.is_ok());
|
||||
state = res.unwrap();
|
||||
state = vcpu.get_regs().unwrap();
|
||||
assert_eq!(state.get_pstate(), 0x3C5);
|
||||
|
||||
assert!(vcpu.set_regs(&state).is_ok());
|
||||
vcpu.set_regs(&state).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -3037,8 +3030,7 @@ mod tests {
|
||||
let mut kvi: kvm_vcpu_init = kvm_vcpu_init::default();
|
||||
vm.get_preferred_target(&mut kvi).unwrap();
|
||||
|
||||
let res = vcpu.get_mp_state();
|
||||
assert!(res.is_ok());
|
||||
assert!(vcpu.set_mp_state(res.unwrap()).is_ok());
|
||||
let state = vcpu.get_mp_state().unwrap();
|
||||
vcpu.set_mp_state(state).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ pub enum LandlockError {
|
||||
// https://docs.rs/landlock/latest/landlock/enum.ABI.html for more info on ABI
|
||||
static ABI: ABI = ABI::V3;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct LandlockAccess {
|
||||
access: BitFlags<AccessFs>,
|
||||
}
|
||||
@@ -150,5 +151,5 @@ fn test_try_from_access() {
|
||||
let landlock_access = LandlockAccess::try_from("w").unwrap();
|
||||
assert!(landlock_access.access == write_access);
|
||||
|
||||
assert!(LandlockAccess::try_from("").is_err());
|
||||
LandlockAccess::try_from("").unwrap_err();
|
||||
}
|
||||
|
||||
@@ -2280,9 +2280,7 @@ mod unit_tests {
|
||||
.devices
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_device(device_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_device(device_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2329,9 +2327,10 @@ mod unit_tests {
|
||||
.user_devices
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_user_device(user_device_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm
|
||||
.vm_add_user_device(user_device_config.clone())
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2377,9 +2376,7 @@ mod unit_tests {
|
||||
.disks
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_disk(disk_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_disk(disk_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2418,9 +2415,7 @@ mod unit_tests {
|
||||
let _ = vmm.vm_create(create_dummy_vm_config());
|
||||
assert!(vmm.vm_config.as_ref().unwrap().lock().unwrap().fs.is_none());
|
||||
|
||||
let result = vmm.vm_add_fs(fs_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_fs(fs_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2466,9 +2461,7 @@ mod unit_tests {
|
||||
.pmem
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_pmem(pmem_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_pmem(pmem_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2517,9 +2510,7 @@ mod unit_tests {
|
||||
.net
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_net(net_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_net(net_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2565,9 +2556,7 @@ mod unit_tests {
|
||||
.vdpa
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_vdpa(vdpa_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_vdpa(vdpa_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
@@ -2613,9 +2602,7 @@ mod unit_tests {
|
||||
.vsock
|
||||
.is_none());
|
||||
|
||||
let result = vmm.vm_add_vsock(vsock_config.clone());
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_none());
|
||||
assert!(vmm.vm_add_vsock(vsock_config.clone()).unwrap().is_none());
|
||||
assert_eq!(
|
||||
vmm.vm_config
|
||||
.as_ref()
|
||||
|
||||
@@ -2850,43 +2850,43 @@ mod tests {
|
||||
match state {
|
||||
VmState::Created => {
|
||||
// Check the transitions from Created
|
||||
assert!(state.valid_transition(VmState::Created).is_err());
|
||||
assert!(state.valid_transition(VmState::Running).is_ok());
|
||||
assert!(state.valid_transition(VmState::Shutdown).is_ok());
|
||||
assert!(state.valid_transition(VmState::Paused).is_ok());
|
||||
assert!(state.valid_transition(VmState::BreakPoint).is_ok());
|
||||
state.valid_transition(VmState::Created).unwrap_err();
|
||||
state.valid_transition(VmState::Running).unwrap();
|
||||
state.valid_transition(VmState::Shutdown).unwrap();
|
||||
state.valid_transition(VmState::Paused).unwrap();
|
||||
state.valid_transition(VmState::BreakPoint).unwrap();
|
||||
}
|
||||
VmState::Running => {
|
||||
// Check the transitions from Running
|
||||
assert!(state.valid_transition(VmState::Created).is_err());
|
||||
assert!(state.valid_transition(VmState::Running).is_err());
|
||||
assert!(state.valid_transition(VmState::Shutdown).is_ok());
|
||||
assert!(state.valid_transition(VmState::Paused).is_ok());
|
||||
assert!(state.valid_transition(VmState::BreakPoint).is_ok());
|
||||
state.valid_transition(VmState::Created).unwrap_err();
|
||||
state.valid_transition(VmState::Running).unwrap_err();
|
||||
state.valid_transition(VmState::Shutdown).unwrap();
|
||||
state.valid_transition(VmState::Paused).unwrap();
|
||||
state.valid_transition(VmState::BreakPoint).unwrap();
|
||||
}
|
||||
VmState::Shutdown => {
|
||||
// Check the transitions from Shutdown
|
||||
assert!(state.valid_transition(VmState::Created).is_err());
|
||||
assert!(state.valid_transition(VmState::Running).is_ok());
|
||||
assert!(state.valid_transition(VmState::Shutdown).is_err());
|
||||
assert!(state.valid_transition(VmState::Paused).is_err());
|
||||
assert!(state.valid_transition(VmState::BreakPoint).is_err());
|
||||
state.valid_transition(VmState::Created).unwrap_err();
|
||||
state.valid_transition(VmState::Running).unwrap();
|
||||
state.valid_transition(VmState::Shutdown).unwrap_err();
|
||||
state.valid_transition(VmState::Paused).unwrap_err();
|
||||
state.valid_transition(VmState::BreakPoint).unwrap_err();
|
||||
}
|
||||
VmState::Paused => {
|
||||
// Check the transitions from Paused
|
||||
assert!(state.valid_transition(VmState::Created).is_err());
|
||||
assert!(state.valid_transition(VmState::Running).is_ok());
|
||||
assert!(state.valid_transition(VmState::Shutdown).is_ok());
|
||||
assert!(state.valid_transition(VmState::Paused).is_err());
|
||||
assert!(state.valid_transition(VmState::BreakPoint).is_err());
|
||||
state.valid_transition(VmState::Created).unwrap_err();
|
||||
state.valid_transition(VmState::Running).unwrap();
|
||||
state.valid_transition(VmState::Shutdown).unwrap();
|
||||
state.valid_transition(VmState::Paused).unwrap_err();
|
||||
state.valid_transition(VmState::BreakPoint).unwrap_err();
|
||||
}
|
||||
VmState::BreakPoint => {
|
||||
// Check the transitions from Breakpoint
|
||||
assert!(state.valid_transition(VmState::Created).is_ok());
|
||||
assert!(state.valid_transition(VmState::Running).is_ok());
|
||||
assert!(state.valid_transition(VmState::Shutdown).is_err());
|
||||
assert!(state.valid_transition(VmState::Paused).is_err());
|
||||
assert!(state.valid_transition(VmState::BreakPoint).is_err());
|
||||
state.valid_transition(VmState::Created).unwrap();
|
||||
state.valid_transition(VmState::Running).unwrap();
|
||||
state.valid_transition(VmState::Shutdown).unwrap_err();
|
||||
state.valid_transition(VmState::Paused).unwrap_err();
|
||||
state.valid_transition(VmState::BreakPoint).unwrap_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3169,7 +3169,7 @@ mod tests {
|
||||
let gic = vm
|
||||
.create_vgic(Gic::create_default_config(1))
|
||||
.expect("Cannot create gic");
|
||||
assert!(create_fdt(
|
||||
create_fdt(
|
||||
&mem,
|
||||
"console=tty0",
|
||||
vec![0],
|
||||
@@ -3182,7 +3182,7 @@ mod tests {
|
||||
None,
|
||||
true,
|
||||
)
|
||||
.is_ok())
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user