]>
Witch of Git - jade-mouse/blob - toolchain/src/cpu/test.rs
2 use crate::inst
::{Inst
, Reg
, Half
};
3 use proptest
::prelude
::*;
5 fn cpu() -> impl Strategy
<Value
= Cpu
> {
9 prop
::collection
::vec(any
::<u8>(), 0..1024),
11 .prop_map(|(pc
, reg
, memory
)| Cpu
{
14 reg
: RegFile
{ values
: reg
},
19 fn reg() -> impl Strategy
<Value
= Reg
> {
20 (0..4).prop_map(|r
| match r
{
31 fn run_move(mut cpu
in cpu(), dst
in reg(), src
in reg()) {
32 let inst
= Inst
::Move(dst
, src
);
33 let val
= cpu
.reg(src
);
35 prop_assert_eq
!(val
, cpu
.reg(src
));
36 prop_assert_eq
!(val
, cpu
.reg(dst
));
40 fn run_jalr(mut cpu
in cpu(), r
in reg()) {
41 let inst
= Inst
::Jalr(r
);
42 let dest
= cpu
.reg(r
);
45 prop_assert_eq
!(pc0
, cpu
.reg(r
));
46 prop_assert_eq
!(dest
, cpu
.pc
);
50 fn run_imm_lohi(mut cpu
in cpu(), r
in reg(), val
: u16) {
51 let [b0
, b1
] = val
.to_le_bytes();
52 cpu
.run_inst(&Inst
::LdImm(Half
::Low
, r
, b0
));
53 cpu
.run_inst(&Inst
::LdImm(Half
::High
, r
, b1
));
54 prop_assert_eq
!(val
, cpu
.reg(r
));