Chirp/tests/chip8_test_suite.rs

100 lines
2.7 KiB
Rust
Raw Normal View History

2023-03-28 02:31:54 +00:00
//! These are a series of interpreter tests using Timendus's incredible test suite
pub use chirp::*;
2023-03-28 02:31:54 +00:00
fn setup_environment() -> (CPU, Bus) {
let mut cpu = CPU::default();
cpu.flags = ControlFlags {
debug: true,
pause: false,
monotonic: Some(8),
..Default::default()
};
(
cpu,
bus! {
// Load the charset into ROM
Charset [0x0050..0x00A0] = include_bytes!("../src/mem/charset.bin"),
// Load the ROM file into RAM
2023-04-02 19:45:32 +00:00
Program [0x0200..0x1000] = include_bytes!("../chip8-test-suite/bin/chip8-test-suite.ch8"),
// Create a screen, and fill it with garbage data
Screen [0x0F00..0x1000] = include_bytes!("chip8_test_suite.rs"),
2023-03-28 02:31:54 +00:00
},
)
}
struct SuiteTest {
program: &'static [u8],
screen: &'static [u8],
}
fn run_screentest(test: SuiteTest, mut cpu: CPU, mut bus: Bus) {
// Load the test program
bus = bus.load_region(Program, test.program);
// The test suite always initiates a keypause on test completion
while !cpu.flags.keypause {
cpu.multistep(&mut bus, 8).unwrap();
2023-03-28 02:31:54 +00:00
}
// Compare the screen to the reference screen buffer
bus.print_screen().unwrap();
bus! {crate::bus::Region::Screen [0..256] = test.screen}
.print_screen()
.unwrap();
assert_eq!(bus.get_region(Screen).unwrap(), test.screen);
}
#[test]
fn splash_screen() {
2023-04-02 19:45:32 +00:00
let (cpu, bus) = setup_environment();
2023-03-28 02:31:54 +00:00
run_screentest(
SuiteTest {
program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"),
screen: include_bytes!("screens/chip8-test-suite/splash.bin"),
},
2023-04-02 19:45:32 +00:00
cpu,
bus,
2023-03-28 02:31:54 +00:00
)
}
#[test]
fn ibm_logo() {
let (cpu, mut bus) = setup_environment();
bus.write(0x1ffu16, 1u8);
2023-03-28 02:31:54 +00:00
run_screentest(
SuiteTest {
program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"),
screen: include_bytes!("screens/chip8-test-suite/IBM.bin"),
},
cpu,
bus,
2023-03-28 02:31:54 +00:00
)
}
#[test]
fn flags_test() {
let (cpu, mut bus) = setup_environment();
bus.write(0x1ffu16, 3u8);
2023-03-28 02:31:54 +00:00
run_screentest(
SuiteTest {
program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"),
screen: include_bytes!("screens/chip8-test-suite/flags.bin"),
},
cpu,
bus,
2023-03-28 02:31:54 +00:00
)
}
#[test]
fn quirks_test() {
let (cpu, mut bus) = setup_environment();
bus.write(0x1feu16, 0x0104u16);
2023-03-28 02:31:54 +00:00
run_screentest(
SuiteTest {
program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"),
screen: include_bytes!("screens/chip8-test-suite/quirks.bin"),
},
cpu,
bus,
2023-03-28 02:31:54 +00:00
)
}