pvmfw: Call patch() in patch test
This CL adds missing patch() call in device_info_patch() test.
The test was unexpectidly passed because of equality check between
expected and actual properties where mistakenly done by zip().
zip() combines two iterators, but ends cleanly when any iterator is
over. So it can't be used to assert whether two iterators have the
same content.
Bug: 277993056
Test: atest libpvmfw.device_assignment.test, launch protected VM
Change-Id: I93b17a87c75b5494a6bd8387a1418afb98206208
diff --git a/pvmfw/src/device_assignment.rs b/pvmfw/src/device_assignment.rs
index 7eae09f..a92b418 100644
--- a/pvmfw/src/device_assignment.rs
+++ b/pvmfw/src/device_assignment.rs
@@ -401,17 +401,28 @@
unsafe {
platform_dt.apply_overlay(vm_dtbo.as_mut()).unwrap();
}
+ device_info.patch(platform_dt).unwrap();
- let rng_node = platform_dt.node(cstr!("/rng")).unwrap().unwrap();
- let expected: Vec<(&CStr, Vec<u8>)> = vec![
- (cstr!("android,rng,ignore-gctrl-reset"), Vec::<u8>::new()),
- (cstr!("compatible"), b"android,rng\0".to_vec()),
- (cstr!("reg"), into_fdt_prop(vec![0x0, 0x9, 0x0, 0xFF])),
- (cstr!("interrupts"), into_fdt_prop(vec![0x0, 0xF, 0x4])),
+ type FdtResult<T> = libfdt::Result<T>;
+ let expected: Vec<(FdtResult<&CStr>, FdtResult<Vec<u8>>)> = vec![
+ (Ok(cstr!("android,rng,ignore-gctrl-reset")), Ok(Vec::new())),
+ (Ok(cstr!("compatible")), Ok(Vec::from(*b"android,rng\0"))),
+ (Ok(cstr!("interrupts")), Ok(into_fdt_prop(vec![0x0, 0xF, 0x4]))),
+ (Ok(cstr!("reg")), Ok(into_fdt_prop(vec![0x0, 0x9, 0x0, 0xFF]))),
];
- for (prop, (prop_name, prop_value)) in rng_node.properties().unwrap().zip(expected) {
- assert_eq!((prop.name(), prop.value()), (Ok(prop_name), Ok(prop_value.as_slice())));
- }
+ let rng_node = platform_dt.node(cstr!("/rng")).unwrap().unwrap();
+ let mut properties: Vec<_> = rng_node
+ .properties()
+ .unwrap()
+ .map(|prop| (prop.name(), prop.value().map(|x| x.into())))
+ .collect();
+ properties.sort_by(|a, b| {
+ let lhs = a.0.unwrap_or_default();
+ let rhs = b.0.unwrap_or_default();
+ lhs.partial_cmp(rhs).unwrap()
+ });
+
+ assert_eq!(properties, expected);
}
}