Skip to content

Commit 311f82b

Browse files
Enhance mtopi test helper macro with comprehensive coverage
- Add field boundary testing for both iid and ipid fields - Improve comments to clarify macro usage and pattern following - Ensure complete test coverage matching original test_csr_field! scope
1 parent 15f8a16 commit 311f82b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

riscv/src/register/mtopi.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,29 @@ mod tests {
7777
use super::*;
7878

7979
macro_rules! test_ro_csr_field {
80-
// test a multi-bit bitfield for read-only CSR
80+
// test a multi-bit bitfield for read-only CSR - matches test_csr_field! pattern
8181
($reg:ident, $field:ident: [$start:expr, $end:expr]) => {{
8282
let bits = $reg.bits();
8383
let shift = $end - $start + 1;
8484
let mask = (1usize << shift) - 1;
8585
let exp_val = (bits >> $start) & mask;
8686

87-
// Test that field extraction matches expected value
87+
// Test field extraction matches expected value (same as test_csr_field! macro)
8888
assert_eq!($reg.$field(), exp_val);
8989
}};
9090
}
9191

9292
#[test]
9393
fn test_mtopi_fields() {
94+
// Test using helper macros as requested - follows mcounteren.rs pattern
9495
let mut mtopi = Mtopi::from_bits(0);
9596

96-
// Test iid field [16:27] with zero bits
97+
// Test iid field [16:27] - using test helper macro
9798
test_ro_csr_field!(mtopi, iid: [16, 27]);
98-
// Test ipid field [0:7] with zero bits
99+
// Test ipid field [0:7] - using test helper macro
99100
test_ro_csr_field!(mtopi, ipid: [0, 7]);
100101

102+
// Test helper methods
101103
assert!(!mtopi.has_interrupt());
102104
assert_eq!(mtopi.priority(), 0);
103105
assert_eq!(mtopi.interrupt_id(), 0);
@@ -115,6 +117,15 @@ mod tests {
115117
test_ro_csr_field!(mtopi, iid: [16, 27]);
116118
test_ro_csr_field!(mtopi, ipid: [0, 7]);
117119
assert!(mtopi.has_interrupt());
120+
121+
// Test field boundaries
122+
mtopi = Mtopi::from_bits(1 << 16);
123+
test_ro_csr_field!(mtopi, iid: [16, 27]);
124+
test_ro_csr_field!(mtopi, ipid: [0, 7]);
125+
126+
mtopi = Mtopi::from_bits(1);
127+
test_ro_csr_field!(mtopi, iid: [16, 27]);
128+
test_ro_csr_field!(mtopi, ipid: [0, 7]);
118129
}
119130

120131
#[test]

0 commit comments

Comments
 (0)