Skip to content

Commit 832e35f

Browse files
committed
riscv: add basic sstatus unit tests
Adds basic unit tests for the `sstatus` CSR.
1 parent 575f015 commit 832e35f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

riscv/src/register/sstatus.rs

+47
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,50 @@ pub unsafe fn set_fs(fs: FS) {
145145
value |= (fs as usize) << 13;
146146
_write(value);
147147
}
148+
149+
#[cfg(test)]
150+
mod tests {
151+
use super::*;
152+
153+
#[test]
154+
fn test_sstatus() {
155+
let mut sstatus = Sstatus::from_bits(0);
156+
157+
test_csr_field!(sstatus, sie);
158+
test_csr_field!(sstatus, spie);
159+
160+
[SPP::User, SPP::Supervisor].into_iter().for_each(|spp| {
161+
test_csr_field!(sstatus, spp: spp);
162+
});
163+
164+
[FS::Off, FS::Initial, FS::Clean, FS::Dirty]
165+
.into_iter()
166+
.for_each(|fs| {
167+
test_csr_field!(sstatus, fs: fs);
168+
});
169+
170+
[
171+
XS::AllOff,
172+
XS::NoneDirtyOrClean,
173+
XS::NoneDirtySomeClean,
174+
XS::SomeDirty,
175+
]
176+
.into_iter()
177+
.for_each(|xs| {
178+
let sstatus = Sstatus::from_bits(xs.into_usize() << 15);
179+
assert_eq!(sstatus.xs(), xs);
180+
assert_eq!(sstatus.try_xs(), Ok(xs));
181+
});
182+
183+
test_csr_field!(sstatus, sum);
184+
test_csr_field!(sstatus, mxr);
185+
186+
[XLEN::XLEN32, XLEN::XLEN64, XLEN::XLEN128]
187+
.into_iter()
188+
.for_each(|xlen| {
189+
test_csr_field!(sstatus, uxl: xlen);
190+
});
191+
192+
test_csr_field!(sstatus, sd);
193+
}
194+
}

0 commit comments

Comments
 (0)