From 336a9ef925f1882b6a3e3bad72d263ac8b9a2158 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Mon, 26 Oct 2020 18:02:11 -0700 Subject: [PATCH] pl030: Add simple tests This CL justs adds two very simple tests to improve overall test coverage. Not sure what the best practices would be for mocking out the system time, so I have skipped that functionality for now. BUG=b:171750410 TEST=No change in functionality, just an added test. Change-Id: I7a4e99c9d11203c5569ff28d2a5477bf8fd1b3a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2500948 Reviewed-by: Daniel Verkamp Reviewed-by: Zach Reizner Tested-by: kokoro Commit-Queue: Dennis Kempin --- devices/src/pl030.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/devices/src/pl030.rs b/devices/src/pl030.rs index 9db36ebc9f..f5600e5aa5 100644 --- a/devices/src/pl030.rs +++ b/devices/src/pl030.rs @@ -143,3 +143,35 @@ impl BusDevice for Pl030 { data[3] = (reg_content >> 24) as u8; } } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_interrupt_status_register() { + let event = Event::new().unwrap(); + let mut device = Pl030::new(event.try_clone().unwrap()); + let mut register = [0, 0, 0, 0]; + + // set interrupt + device.write(RTCEOI, &[1, 0, 0, 0]); + device.read(RTCSTAT, &mut register); + assert_eq!(register, [1, 0, 0, 0]); + assert_eq!(event.read().unwrap(), 1); + + // clear interrupt + device.write(RTCEOI, &[0, 0, 0, 0]); + device.read(RTCSTAT, &mut register); + assert_eq!(register, [0, 0, 0, 0]); + } + + #[test] + fn test_match_register() { + let mut device = Pl030::new(Event::new().unwrap()); + let mut register = [0, 0, 0, 0]; + + device.write(RTCMR, &[1, 2, 3, 4]); + device.read(RTCMR, &mut register); + assert_eq!(register, [4, 3, 2, 1]); + } +}