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 <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2020-10-26 18:02:11 -07:00 committed by Commit Bot
parent 0c47e9441e
commit 336a9ef925

View file

@ -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]);
}
}