-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
!.gitignore | ||
!*.s | ||
!*.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::{fs::File, io::Read}; | ||
|
||
use rstest::rstest; | ||
use rysk::cpu::Cpu; | ||
|
||
#[rstest] | ||
#[case::addi("tests/addi.bin", &[(31, 6)], &[], &[])] | ||
#[case::csr("tests/csr.bin", &[(5, 1), (6, 2), (7, 3)], &[], &[(256, 4), (261, 5), (321, 6), (768, 1), (773, 2), (833, 3)])] | ||
fn run_test( | ||
#[case] path: &str, | ||
#[case] expected_regs: &[(usize, u64)], | ||
#[case] expected_mem: &[(usize, u8)], | ||
#[case] expected_csr: &[(usize, u64)], | ||
) { | ||
let mut file = File::open(path).expect("did you run 'make test' ?"); | ||
let mut code = Vec::new(); | ||
file.read_to_end(&mut code).unwrap(); | ||
|
||
let mut cpu = Cpu::new(code); | ||
cpu.run().unwrap(); | ||
|
||
cpu.dump_registers(); | ||
cpu.dump_csr(); | ||
|
||
assert_eq!(cpu.regs[0], 0, "zero register is not 0"); | ||
|
||
for (reg, value) in expected_regs { | ||
assert_eq!(cpu.regs[*reg], *value, "register mismatch"); | ||
} | ||
|
||
for (addr, value) in expected_mem { | ||
assert_eq!(cpu.bus.dram.dram[*addr], *value, "memory mismatch"); | ||
} | ||
|
||
for (addr, value) in expected_csr { | ||
assert_eq!(cpu.csrs[*addr], *value, "csrs mismatch"); | ||
} | ||
} |