From 8fad75f264023d78e5da23bb50395bf518b06ce5 Mon Sep 17 00:00:00 2001 From: rmsyn Date: Sun, 27 Oct 2024 20:36:54 +0000 Subject: [PATCH] riscv: add medeleg unit tests Adds basic unit tests for the `medeleg` register. --- riscv/src/register/medeleg.rs | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/riscv/src/register/medeleg.rs b/riscv/src/register/medeleg.rs index d119791d..a23c28b4 100644 --- a/riscv/src/register/medeleg.rs +++ b/riscv/src/register/medeleg.rs @@ -126,3 +126,41 @@ set_clear_csr!( set_clear_csr!( /// Store/AMO Page Fault Delegate , set_store_page_fault, clear_store_page_fault, 1 << 15); + +#[cfg(test)] +mod tests { + use super::*; + + macro_rules! test_field { + ($reg:ident, $field:ident) => {{ + $crate::paste! { + assert!(!$reg.$field()); + + $reg.[](true); + assert!($reg.$field()); + + $reg.[](false); + assert!(!$reg.$field()); + } + }}; + } + + #[test] + fn test_medeleg() { + let mut m = Medeleg::from_bits(0); + + test_field!(m, instruction_misaligned); + test_field!(m, instruction_fault); + test_field!(m, illegal_instruction); + test_field!(m, breakpoint); + test_field!(m, load_misaligned); + test_field!(m, load_fault); + test_field!(m, store_misaligned); + test_field!(m, store_fault); + test_field!(m, user_env_call); + test_field!(m, supervisor_env_call); + test_field!(m, instruction_page_fault); + test_field!(m, load_page_fault); + test_field!(m, store_page_fault); + } +}