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:
Ruoqing He
2024-09-30 19:07:39 +00:00
committed by Rob Bradford
parent 83bcf2a1ff
commit 297236a7c0
25 changed files with 244 additions and 281 deletions

View File

@@ -491,7 +491,7 @@ mod tests {
let hv = crate::new().unwrap();
let vm = hv.create_vm().unwrap();
assert!(KvmGicV3Its::new(&*vm, create_test_vgic_config()).is_ok());
KvmGicV3Its::new(&*vm, create_test_vgic_config()).unwrap();
}
#[test]
@@ -501,13 +501,10 @@ mod tests {
let _ = vm.create_vcpu(0, None).unwrap();
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
let res = get_dist_regs(&gic.device);
assert!(res.is_ok());
let state = res.unwrap();
let state = get_dist_regs(&gic.device).unwrap();
assert_eq!(state.len(), 568);
let res = set_dist_regs(&gic.device, &state);
assert!(res.is_ok());
set_dist_regs(&gic.device, &state).unwrap();
}
#[test]
@@ -518,13 +515,11 @@ mod tests {
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
let gicr_typer = vec![123];
let res = get_redist_regs(&gic.device, &gicr_typer);
assert!(res.is_ok());
let state = res.unwrap();
let state = get_redist_regs(&gic.device, &gicr_typer).unwrap();
println!("{}", state.len());
assert!(state.len() == 24);
assert!(set_redist_regs(&gic.device, &gicr_typer, &state).is_ok());
set_redist_regs(&gic.device, &gicr_typer, &state).unwrap();
}
#[test]
@@ -535,13 +530,11 @@ mod tests {
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
let gicr_typer = vec![123];
let res = get_icc_regs(&gic.device, &gicr_typer);
assert!(res.is_ok());
let state = res.unwrap();
let state = get_icc_regs(&gic.device, &gicr_typer).unwrap();
println!("{}", state.len());
assert!(state.len() == 9);
assert!(set_icc_regs(&gic.device, &gicr_typer, &state).is_ok());
set_icc_regs(&gic.device, &gicr_typer, &state).unwrap();
}
#[test]
@@ -553,6 +546,6 @@ mod tests {
.create_vgic(create_test_vgic_config())
.expect("Cannot create gic");
assert!(gic.lock().unwrap().save_data_tables().is_ok());
gic.lock().unwrap().save_data_tables().unwrap();
}
}