Skip to content

Commit

Permalink
riscv: add more mstatus field tests
Browse files Browse the repository at this point in the history
Adds more unit test cases for `Mstatus` field accessors.
  • Loading branch information
rmsyn committed Dec 3, 2024
1 parent e0fd5c4 commit afa0ada
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use CSR helper macros to define `mimpid` register
- Use CSR helper macros to define `misa` register
- Use CSR helper macros to define `mip` register
- Use CSR helper macros to define `mstatus` register

## [v0.12.1] - 2024-10-20

Expand Down
41 changes: 35 additions & 6 deletions riscv/src/register/mstatus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,40 @@ mod test {
#[test]
fn test_mpp() {
let mut mstatus = Mstatus { bits: 0 };
mstatus.set_mpp(MPP::User);
assert_eq!(mstatus.mpp(), MPP::User);
mstatus.set_mpp(MPP::Machine);
assert_eq!(mstatus.mpp(), MPP::Machine);
mstatus.set_mpp(MPP::Supervisor);
assert_eq!(mstatus.mpp(), MPP::Supervisor);

test_csr_field!(mstatus, mpp: MPP::User);
test_csr_field!(mstatus, mpp: MPP::Machine);
test_csr_field!(mstatus, mpp: MPP::Supervisor);

test_csr_field!(mstatus, spp: SPP::User);
test_csr_field!(mstatus, spp: SPP::Supervisor);

test_csr_field!(mstatus, fs: FS::Off);
test_csr_field!(mstatus, fs: FS::Initial);
test_csr_field!(mstatus, fs: FS::Clean);
test_csr_field!(mstatus, fs: FS::Dirty);

test_csr_field!(mstatus, vs: VS::Off);
test_csr_field!(mstatus, vs: VS::Initial);
test_csr_field!(mstatus, vs: VS::Clean);
test_csr_field!(mstatus, vs: VS::Dirty);

test_csr_field!(mstatus, xs: XS::AllOff);
test_csr_field!(mstatus, xs: XS::NoneDirtyOrClean);
test_csr_field!(mstatus, xs: XS::NoneDirtySomeClean);
test_csr_field!(mstatus, xs: XS::SomeDirty);

test_csr_field!(mstatus, sie);
test_csr_field!(mstatus, mie);
test_csr_field!(mstatus, spie);
test_csr_field!(mstatus, ube);
test_csr_field!(mstatus, mpie);
test_csr_field!(mstatus, mprv);
test_csr_field!(mstatus, sum);
test_csr_field!(mstatus, mxr);
test_csr_field!(mstatus, tvm);
test_csr_field!(mstatus, tw);
test_csr_field!(mstatus, tsr);
test_csr_field!(mstatus, sd);
}
}

0 comments on commit afa0ada

Please sign in to comment.