Skip to content

Commit

Permalink
riscv: add mtvec unit-tests
Browse files Browse the repository at this point in the history
Adds basic unit-tests for the `mtvec` CSR.
  • Loading branch information
rmsyn committed Dec 21, 2024
1 parent d801d09 commit 6d6b793
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use CSR helper macros to define `mip` register
- Use CSR helper macros to define `mstatus` register
- Use CSR helper macros to define `mstatush` register
- Use CSR helper macros to define `mtvec` register

## [v0.12.1] - 2024-10-20

Expand Down
20 changes: 20 additions & 0 deletions riscv/src/register/mtvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ impl Mtvec {
self.bits = (address & !TRAP_MASK) | (self.bits & TRAP_MASK);
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_mtvec() {
let mut m = Mtvec::from_bits(0);

(1..=usize::BITS)
.map(|r| (((1u128 << r) - 1) as usize))
.for_each(|address| {
m.set_address(address);
assert_eq!(m.address(), address & !TRAP_MASK);
});

test_csr_field!(m, trap_mode: TrapMode::Direct);
test_csr_field!(m, trap_mode: TrapMode::Vectored);
}
}

0 comments on commit 6d6b793

Please sign in to comment.