Skip to content

Commit 6d6b793

Browse files
committed
riscv: add mtvec unit-tests
Adds basic unit-tests for the `mtvec` CSR.
1 parent d801d09 commit 6d6b793

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2727
- Use CSR helper macros to define `mip` register
2828
- Use CSR helper macros to define `mstatus` register
2929
- Use CSR helper macros to define `mstatush` register
30+
- Use CSR helper macros to define `mtvec` register
3031

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

riscv/src/register/mtvec.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@ impl Mtvec {
4242
self.bits = (address & !TRAP_MASK) | (self.bits & TRAP_MASK);
4343
}
4444
}
45+
46+
#[cfg(test)]
47+
mod tests {
48+
use super::*;
49+
50+
#[test]
51+
fn test_mtvec() {
52+
let mut m = Mtvec::from_bits(0);
53+
54+
(1..=usize::BITS)
55+
.map(|r| (((1u128 << r) - 1) as usize))
56+
.for_each(|address| {
57+
m.set_address(address);
58+
assert_eq!(m.address(), address & !TRAP_MASK);
59+
});
60+
61+
test_csr_field!(m, trap_mode: TrapMode::Direct);
62+
test_csr_field!(m, trap_mode: TrapMode::Vectored);
63+
}
64+
}

0 commit comments

Comments
 (0)