Skip to content

Commit 04b95cb

Browse files
committed
tests: add mtval2 unit tests
Adds basic unit tests for the `mtval2` CSR.
1 parent 6c33cce commit 04b95cb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

riscv/src/register/mtval2.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,22 @@ impl Mtval2 {
2121
self.bits() << Self::GUEST_PAGE_SHIFT
2222
}
2323
}
24+
25+
#[cfg(test)]
26+
mod tests {
27+
use super::*;
28+
29+
#[test]
30+
fn test_mtval2() {
31+
(1..=usize::BITS)
32+
.map(|r| ((1u128 << r) - 1) as usize)
33+
.for_each(|bits| {
34+
let mtval2 = Mtval2::from_bits(bits);
35+
assert_eq!(mtval2.bits(), bits);
36+
assert_eq!(
37+
mtval2.guest_fault_address(),
38+
bits << Mtval2::GUEST_PAGE_SHIFT
39+
);
40+
});
41+
}
42+
}

0 commit comments

Comments
 (0)