From d5cfdc6802ece31d803093710d421701b38de715 Mon Sep 17 00:00:00 2001 From: John Breaux Date: Mon, 27 Mar 2023 21:01:33 -0500 Subject: [PATCH] tests: Move chip8-test-suite to integration tests. --- .gitmodules | 4 +- src/cpu/tests.rs | 70 ------------- {src/cpu/tests => tests}/chip8-test-suite | 0 .../screens/chip8-test-suite.ch8/64.bin | Bin .../screens/chip8-test-suite.ch8/flags.bin | Bin .../screens/chip8-test-suite.ch8/quirks.bin | Bin .../screens/chip8-test-suite.ch8/splash.bin | Bin tests/tests.rs | 92 ++++++++++++++++++ 8 files changed, 94 insertions(+), 72 deletions(-) rename {src/cpu/tests => tests}/chip8-test-suite (100%) rename {src/cpu/tests => tests}/screens/chip8-test-suite.ch8/64.bin (100%) rename {src/cpu/tests => tests}/screens/chip8-test-suite.ch8/flags.bin (100%) rename {src/cpu/tests => tests}/screens/chip8-test-suite.ch8/quirks.bin (100%) rename {src/cpu/tests => tests}/screens/chip8-test-suite.ch8/splash.bin (100%) create mode 100644 tests/tests.rs diff --git a/.gitmodules b/.gitmodules index 800ce73..260ccee 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "src/cpu/tests/chip8-test-suite"] - path = src/cpu/tests/chip8-test-suite +[submodule "tests/chip8-test-suite"] + path = tests/chip8-test-suite url = https://github.com/Timendus/chip8-test-suite.git diff --git a/src/cpu/tests.rs b/src/cpu/tests.rs index 1fde075..a37db83 100644 --- a/src/cpu/tests.rs +++ b/src/cpu/tests.rs @@ -839,73 +839,3 @@ mod io { } } } - -/// These are a series of interpreter tests using Timendus's incredible test suite -/// TODO: These are technically integration tests, and should be moved to src/tests -mod chip8_test_suite { - use super::*; - - 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); - } - // 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() { - let (mut c, b) = setup_environment(); - c.flags.quirks = true.into(); - run_screentest( - SuiteTest { - program: include_bytes!("tests/chip8-test-suite/bin/chip8-test-suite.ch8"), - screen: include_bytes!("tests/screens/chip8-test-suite.ch8/splash.bin"), - }, - c, - b, - ) - } - - #[test] - fn flags_test() { - let (mut c, mut b) = setup_environment(); - c.flags.quirks = true.into(); - b.write(0x1ffu16, 3u8); - run_screentest( - SuiteTest { - program: include_bytes!("tests/chip8-test-suite/bin/chip8-test-suite.ch8"), - screen: include_bytes!("tests/screens/chip8-test-suite.ch8/flags.bin"), - }, - c, - b, - ) - } - - #[test] - fn quirks_test() { - let (mut c, mut b) = setup_environment(); - c.flags.quirks = true.into(); - b.write(0x1feu16, 0x0104u16); - run_screentest( - SuiteTest { - program: include_bytes!("tests/chip8-test-suite/bin/chip8-test-suite.ch8"), - screen: include_bytes!("tests/screens/chip8-test-suite.ch8/quirks.bin"), - }, - c, - b, - ) - } -} diff --git a/src/cpu/tests/chip8-test-suite b/tests/chip8-test-suite similarity index 100% rename from src/cpu/tests/chip8-test-suite rename to tests/chip8-test-suite diff --git a/src/cpu/tests/screens/chip8-test-suite.ch8/64.bin b/tests/screens/chip8-test-suite.ch8/64.bin similarity index 100% rename from src/cpu/tests/screens/chip8-test-suite.ch8/64.bin rename to tests/screens/chip8-test-suite.ch8/64.bin diff --git a/src/cpu/tests/screens/chip8-test-suite.ch8/flags.bin b/tests/screens/chip8-test-suite.ch8/flags.bin similarity index 100% rename from src/cpu/tests/screens/chip8-test-suite.ch8/flags.bin rename to tests/screens/chip8-test-suite.ch8/flags.bin diff --git a/src/cpu/tests/screens/chip8-test-suite.ch8/quirks.bin b/tests/screens/chip8-test-suite.ch8/quirks.bin similarity index 100% rename from src/cpu/tests/screens/chip8-test-suite.ch8/quirks.bin rename to tests/screens/chip8-test-suite.ch8/quirks.bin diff --git a/src/cpu/tests/screens/chip8-test-suite.ch8/splash.bin b/tests/screens/chip8-test-suite.ch8/splash.bin similarity index 100% rename from src/cpu/tests/screens/chip8-test-suite.ch8/splash.bin rename to tests/screens/chip8-test-suite.ch8/splash.bin diff --git a/tests/tests.rs b/tests/tests.rs new file mode 100644 index 0000000..ef1ca87 --- /dev/null +++ b/tests/tests.rs @@ -0,0 +1,92 @@ +pub use chirp::prelude::*; + +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 + Program [0x0200..0x1000] = include_bytes!("../chip-8/BC_test.ch8"), + // Create a screen + Screen [0x0F00..0x1000] = include_bytes!("../chip-8/IBM Logo.ch8"), + }, + ) +} + +/// These are a series of interpreter tests using Timendus's incredible test suite +/// TODO: These are technically integration tests, and should be moved to src/tests +mod chip8_test_suite { + use super::*; + + 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); + } + // 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() { + let (mut c, b) = setup_environment(); + c.flags.quirks = true.into(); + run_screentest( + SuiteTest { + program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"), + screen: include_bytes!("screens/chip8-test-suite.ch8/splash.bin"), + }, + c, + b, + ) + } + + #[test] + fn flags_test() { + let (mut c, mut b) = setup_environment(); + c.flags.quirks = true.into(); + b.write(0x1ffu16, 3u8); + run_screentest( + SuiteTest { + program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"), + screen: include_bytes!("screens/chip8-test-suite.ch8/flags.bin"), + }, + c, + b, + ) + } + + #[test] + fn quirks_test() { + let (mut c, mut b) = setup_environment(); + c.flags.quirks = true.into(); + b.write(0x1feu16, 0x0104u16); + run_screentest( + SuiteTest { + program: include_bytes!("chip8-test-suite/bin/chip8-test-suite.ch8"), + screen: include_bytes!("screens/chip8-test-suite.ch8/quirks.bin"), + }, + c, + b, + ) + } +}