devices: add comments to unit test
This presents some comments to describe the root cause
of error scenarios in unit test.
@@ -197,17 +197,24 @@ mod tests {
fn bus_insert() {
let mut bus = Bus::new();
let dummy = Arc::new(Mutex::new(DummyDevice));
+ // Insert len should not be 0.
assert!(bus.insert(dummy.clone(), 0x10, 0).is_err());
assert!(bus.insert(dummy.clone(), 0x10, 0x10).is_ok());
let result = bus.insert(dummy.clone(), 0x0f, 0x10);
+ // This overlaps the address space of the existing bus device at 0x10.
assert!(result.is_err());
assert_eq!(format!("{:?}", result), "Err(Overlap)");
+ // This overlaps the address space of the existing bus device at 0x10.
assert!(bus.insert(dummy.clone(), 0x10, 0x10).is_err());
+ // This overlaps the address space of the existing bus device at 0x10.
assert!(bus.insert(dummy.clone(), 0x10, 0x15).is_err());
+ // This overlaps the address space of the existing bus device at 0x10.
assert!(bus.insert(dummy.clone(), 0x12, 0x15).is_err());
+ // This overlaps the address space of the existing bus device at 0x10.
assert!(bus.insert(dummy.clone(), 0x12, 0x01).is_err());
+ // This overlaps the address space of the existing bus device at 0x10.
assert!(bus.insert(dummy.clone(), 0x0, 0x20).is_err());
assert!(bus.insert(dummy.clone(), 0x20, 0x05).is_ok());
assert!(bus.insert(dummy.clone(), 0x25, 0x05).is_ok());
