use super::*;
#[test]
fn dispatch_mmio_read_unmapped_returns_0xff() {
let com1 = PiMutex::new(console::Serial::new(console::COM1_BASE));
let com2 = PiMutex::new(console::Serial::new(console::COM2_BASE));
let mut buf = [0u8; 4];
dispatch_mmio_read(
&com1, &com2, None, None, None, 0x10_0000, &mut buf,
);
assert_eq!(
buf,
[0xff, 0xff, 0xff, 0xff],
"Unmapped MMIO read must fill the data buffer with 0xFF"
);
}
#[test]
fn dispatch_mmio_read_serial_does_not_fill_0xff() {
let com1 = PiMutex::new(console::Serial::new(console::COM1_BASE));
let com2 = PiMutex::new(console::Serial::new(console::COM2_BASE));
let mut buf = [0xAAu8; 1];
dispatch_mmio_read(
&com1,
&com2,
None,
None,
None,
kvm::SERIAL_MMIO_BASE + 5,
&mut buf,
);
assert_ne!(
buf[0], 0xFF,
"Serial MMIO read must invoke the COM1 LSR path, not the \
unmapped 0xFF fallback"
);
}
#[test]
fn classify_exit_aarch64_mmio_write_serial_is_continue() {
let com1 = PiMutex::new(console::Serial::new(console::COM1_BASE));
let com2 = PiMutex::new(console::Serial::new(console::COM2_BASE));
let data = [b'Q'];
let mut exit = VcpuExit::MmioWrite(kvm::SERIAL_MMIO_BASE, &data);
let action = classify_exit(&com1, &com2, None, None, None, None, &mut exit);
assert!(
matches!(action, Some(ExitAction::Continue)),
"aarch64 MmioWrite to serial must classify as Continue"
);
assert!(
com1.lock().output().contains('Q'),
"Serial MMIO write must land the byte in COM1 output"
);
}
#[test]
fn classify_exit_aarch64_mmio_read_unmapped_returns_0xff() {
let com1 = PiMutex::new(console::Serial::new(console::COM1_BASE));
let com2 = PiMutex::new(console::Serial::new(console::COM2_BASE));
let mut buf = [0u8; 4];
let mut exit = VcpuExit::MmioRead(0x10_0000, &mut buf);
let action = classify_exit(&com1, &com2, None, None, None, None, &mut exit);
assert!(
matches!(action, Some(ExitAction::Continue)),
"Unmapped aarch64 MMIO read must classify as Continue"
);
assert_eq!(
buf,
[0xff, 0xff, 0xff, 0xff],
"Unmapped aarch64 MMIO read must fill with 0xFF"
);
}