Skip to content

Commit 5fc8d77

Browse files
committed
tests: add mtinst unit tests
Adds basic unit tests for the `mtinst` CSR.
1 parent 0d87639 commit 5fc8d77

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Write utilities for `mcycle`, `minstret`
1414
- Add `senvcfg` CSR
1515
- Add `scontext` CSR
16+
- Add `mtinst` CSR
1617

1718
### Changed
1819

riscv/src/register/mtinst.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,28 @@ read_write_csr_field! {
6464

6565
set!(0x34a);
6666
clear!(0x34a);
67+
68+
#[cfg(test)]
69+
mod tests {
70+
use super::*;
71+
72+
#[test]
73+
fn test_mtinst() {
74+
(1..=usize::BITS)
75+
.map(|r| ((1u128 << r) - 1) as usize)
76+
.for_each(|bits| {
77+
let reset = 0;
78+
let mut mtinst = Mtinst::from_bits(bits);
79+
80+
test_csr_field!(mtinst, opcode: [0, 6], reset);
81+
test_csr_field!(mtinst, rd: [7, 11], reset);
82+
test_csr_field!(mtinst, funct3: [12, 14], reset);
83+
test_csr_field!(mtinst, address_offset: [15, 19], reset);
84+
test_csr_field!(mtinst, rs2: [20, 24], reset);
85+
test_csr_field!(mtinst, rl);
86+
test_csr_field!(mtinst, aq);
87+
test_csr_field!(mtinst, funct5: [27, 31], reset);
88+
test_csr_field!(mtinst, funct7: [25, 31], reset);
89+
});
90+
}
91+
}

0 commit comments

Comments
 (0)