Skip to content

Commit 541c36f

Browse files
committed
tests: add scontext unit tests
Adds basic unit tests for the `scontext` CSR.
1 parent 7a73715 commit 541c36f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

riscv/src/register/scontext.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,26 @@ read_write_csr_field! {
2727
/// Represents the `data` context number of the `scontext` CSR.
2828
data: [0:31],
2929
}
30+
31+
#[cfg(test)]
32+
mod tests {
33+
use super::*;
34+
35+
#[test]
36+
fn test_scontext() {
37+
#[cfg(target_arch = "riscv32")]
38+
const DATA_BITS: usize = 16;
39+
#[cfg(not(target_arch = "riscv32"))]
40+
const DATA_BITS: usize = 32;
41+
42+
let mut scontext = Scontext::from_bits(0);
43+
44+
(1..=DATA_BITS)
45+
.map(|b| ((1u64 << b) - 1) as usize)
46+
.for_each(|data| {
47+
scontext.set_data(data);
48+
assert_eq!(scontext.data(), data);
49+
assert_eq!(scontext.bits(), data);
50+
});
51+
}
52+
}

0 commit comments

Comments
 (0)