Skip to content

Commit a22c43f

Browse files
committed
riscv: add basic scounteren unit tests
Adds basic unit tests for the `scounteren` CSR.
1 parent 0fb283b commit a22c43f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

riscv/src/register/scounteren.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,35 @@ pub unsafe fn try_clear_hpm(index: usize) -> Result<()> {
9494
})
9595
}
9696
}
97+
98+
#[cfg(test)]
99+
mod tests {
100+
use super::*;
101+
102+
#[test]
103+
fn test_scounteren() {
104+
const HPM_MIN: usize = 3;
105+
const HPM_MAX: usize = 31;
106+
107+
let mut scounteren = Scounteren::from_bits(0);
108+
109+
test_csr_field!(scounteren, cy);
110+
test_csr_field!(scounteren, tm);
111+
test_csr_field!(scounteren, ir);
112+
113+
(HPM_MIN..=HPM_MAX).for_each(|index| {
114+
test_csr_field!(scounteren, hpm, index);
115+
});
116+
117+
(0..usize::BITS as usize)
118+
.filter(|&i| !(HPM_MIN..=HPM_MAX).any(|idx| idx == i))
119+
.for_each(|index| {
120+
let err = Error::IndexOutOfBounds {
121+
index,
122+
min: 3,
123+
max: 31,
124+
};
125+
test_csr_field!(scounteren, hpm, index, err)
126+
});
127+
}
128+
}

0 commit comments

Comments
 (0)