From cc0f7bcbed2f5ed36570bc61c5ed76fe8fce267d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Sun, 30 Jun 2024 22:20:12 +0100 Subject: [PATCH 01/13] Create rom tests --- .gitmodules | 3 ++ fpt/src/debug_interface.rs | 22 +++++++++++++ fpt/src/debugger.rs | 34 +++++++++++++++++++- fpt/src/lib.rs | 3 +- fpt/src/lr35902.rs | 22 +++++++++++++ fpt/src/timer.rs | 7 ---- fpt/tests/rom_test.rs | 58 ++++++++++++++++++++++++++++++++++ third_party/mooneye-test-suite | 1 + 8 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 .gitmodules create mode 100644 fpt/tests/rom_test.rs create mode 160000 third_party/mooneye-test-suite diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cbe4f99 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/mooneye-test-suite"] + path = third_party/mooneye-test-suite + url = git@github.com:Gekkio/mooneye-test-suite.git diff --git a/fpt/src/debug_interface.rs b/fpt/src/debug_interface.rs index fb4a4e0..2b9997e 100644 --- a/fpt/src/debug_interface.rs +++ b/fpt/src/debug_interface.rs @@ -27,12 +27,25 @@ impl Watchpoint { } } +#[derive(Clone, Copy, PartialEq, Debug)] +pub struct Instrpoint { + pub opcode: u16, + pub triggered: bool, +} + +impl Instrpoint { + pub fn new(opcode: u16, triggered: bool) -> Self { + Self { opcode, triggered } + } +} + #[derive(Debug)] pub enum DebugCmd { Pause, Continue, Breakpoint(u16), Watchpoint(u16), + Instrpoint(u16), Load(String), ListBreakpoints, ListWatchpoints, @@ -43,10 +56,12 @@ pub enum DebugEvent { Continue, RegisterBreakpoint(u16), RegisterWatchpoint(u16), + RegisterInstrpoint(u16), ListBreakpoints(Vec), ListWatchpoints(Vec), Breakpoint(u16), Watchpoint(u16, u16), + Instrpoint(u16), } impl fmt::Display for DebugEvent { @@ -60,6 +75,9 @@ impl fmt::Display for DebugEvent { DebugEvent::RegisterWatchpoint(addr) => { writeln!(f, "Register watchpoint at address {:#04X}", addr) } + DebugEvent::RegisterInstrpoint(opcode) => { + writeln!(f, "Register instrpoint with opcode {:#04X}", opcode) + } DebugEvent::ListBreakpoints(breakpoints) => { writeln!(f, "breakpoints:")?; for (i, breakpoint) in breakpoints.iter().enumerate() { @@ -86,6 +104,10 @@ impl fmt::Display for DebugEvent { )?; Ok(()) } + DebugEvent::Instrpoint(opcode) => { + writeln!(f, "Hit instrpoint at {:#06X}", opcode)?; + Ok(()) + } } } } diff --git a/fpt/src/debugger.rs b/fpt/src/debugger.rs index 2cfce50..5741a04 100644 --- a/fpt/src/debugger.rs +++ b/fpt/src/debugger.rs @@ -1,11 +1,12 @@ use std::collections::VecDeque; -use crate::debug_interface::{Breakpoint, DebugCmd, DebugEvent, Watchpoint}; +use crate::debug_interface::{Breakpoint, DebugCmd, DebugEvent, Instrpoint, Watchpoint}; #[derive(Clone, PartialEq)] pub struct Debugger { breakpoints: Vec, watchpoints: Vec, + instrpoints: Vec, pub paused: bool, dbg_events: VecDeque, } @@ -21,6 +22,7 @@ impl Debugger { Self { breakpoints: Vec::new(), watchpoints: Vec::new(), + instrpoints: Vec::new(), paused: false, dbg_events: VecDeque::new(), } @@ -47,6 +49,13 @@ impl Debugger { self.watchpoints.push(Watchpoint { addr: *addr }); Some(DebugEvent::RegisterWatchpoint(*addr)) } + DebugCmd::Instrpoint(instruction) => { + self.instrpoints.push(Instrpoint { + opcode: *instruction, + triggered: false, + }); + Some(DebugEvent::RegisterInstrpoint(instruction.clone())) + } DebugCmd::ListBreakpoints => { Some(DebugEvent::ListBreakpoints(self.breakpoints.clone())) } @@ -57,6 +66,29 @@ impl Debugger { } } + pub fn match_instrpoint(&mut self, opcode: u16) -> bool { + let instrpoint = self.instrpoints.iter_mut().find(|i| i.opcode == opcode); + let is_instrpoint = instrpoint.is_some(); + + let triggered = false; + + if instrpoint.is_some() { + let instrpoint = instrpoint.unwrap(); + if instrpoint.triggered { + instrpoint.triggered = false; + } else { + instrpoint.triggered = true; + self.paused = true; + } + } + + if self.paused { + self.dbg_events.push_back(DebugEvent::Instrpoint(opcode)); + } + + is_instrpoint && !triggered + } + pub fn match_breakpoint(&mut self, pc: u16) -> bool { let breakpoint = self.breakpoints.iter_mut().find(|b| b.pc == pc); diff --git a/fpt/src/lib.rs b/fpt/src/lib.rs index a9652cc..978fb08 100644 --- a/fpt/src/lib.rs +++ b/fpt/src/lib.rs @@ -4,8 +4,7 @@ use std::collections::VecDeque; -use debug_interface::DebugEvent; -pub use debug_interface::{DebugCmd, DebugInterface}; +pub use debug_interface::{DebugCmd, DebugEvent, DebugInterface}; use lr35902::LR35902; use memory::{Bus, Buttons}; use ppu::{Frame, Ppu, DOTS_IN_ONE_FRAME}; diff --git a/fpt/src/lr35902.rs b/fpt/src/lr35902.rs index 7811eb4..071c3fc 100644 --- a/fpt/src/lr35902.rs +++ b/fpt/src/lr35902.rs @@ -27,6 +27,8 @@ pub struct LR35902 { branch_taken: bool, bus: Bus, debugger: Debugger, + previous_pc: u16, + pc_counter: u16, } impl Default for LR35902 { @@ -77,6 +79,8 @@ impl LR35902 { bus: memory, // Debugging debugger: Debugger::new(), + previous_pc: 0, + pc_counter: 0, } } @@ -633,6 +637,21 @@ impl LR35902 { // Run instructions /// Run one t-cycle - from actual crystal @ 4 or 8 MHz (double speed mode) pub fn t_cycle(&mut self) { + static mut PREVIOUS_PC: u16 = 0; + static mut PC_COUNTER: u16 = 0; + // test roms get stuck in the same pc when finished + unsafe { + if PREVIOUS_PC != self.pc() { + PREVIOUS_PC = self.pc(); + PC_COUNTER = 0; + } else { + PC_COUNTER += 1; + if PC_COUNTER == 100 { + std::process::exit(0); + } + } + } + let inst = self.decode(); self.set_inst_cycle_count(self.inst_cycle_count() + 1); // Only actually mutate CPU state on the last t-cycle of the instruction @@ -643,6 +662,9 @@ impl LR35902 { if self.debugger.match_breakpoint(self.pc()) { return; } + if self.debugger.match_instrpoint(inst.opcode) { + return; + } self.execute(inst); if !self.mutated_pc() { self.set_pc(self.pc() + inst.size as u16); diff --git a/fpt/src/timer.rs b/fpt/src/timer.rs index 8b9fd78..5bb590a 100644 --- a/fpt/src/timer.rs +++ b/fpt/src/timer.rs @@ -71,13 +71,6 @@ impl Timer { let tac = self.get_tac(); let tma = self.get_tma(); - if (div + 1) % 4 == 0 { - println!( - "self.div: {}, self.tima: {}, self.tac: {}, self.tma: {}", - div, tima, tac, tma - ); - } - self.sys = self.sys.overflowing_add(1).0; let enable = bw::test_bit8::<2>(tac); diff --git a/fpt/tests/rom_test.rs b/fpt/tests/rom_test.rs new file mode 100644 index 0000000..7cbf239 --- /dev/null +++ b/fpt/tests/rom_test.rs @@ -0,0 +1,58 @@ +use fpt::{DebugCmd, DebugEvent, Gameboy}; + +fn check_registers(gb: &Gameboy) -> bool { + return gb.cpu().b() == 3 + && gb.cpu().c() == 5 + && gb.cpu().d() == 8 + && gb.cpu().e() == 13 + && gb.cpu().h() == 21 + && gb.cpu().l() == 34; +} + +fn rom_test(rom_path: &str, termination_address: u16) { + let mut gb = Gameboy::new(); + gb.simulate_dmg0_bootrom_handoff_state(); + + let rom = std::fs::read(rom_path).unwrap(); + gb.load_rom(&rom); + + gb.debug_cmd(&DebugCmd::Instrpoint(0x40)); + gb.debug_cmd(&DebugCmd::Breakpoint(termination_address)); + + 'outer: loop { + gb.step(); + let debug_events = gb.get_debug_events(); + if !debug_events.is_empty() { + loop { + match debug_events.pop_back().unwrap() { + DebugEvent::Breakpoint(_) => { + println!("breakpoint"); + break 'outer; + } + DebugEvent::Instrpoint(_) => { + println!("instrpoint"); + assert!(check_registers(&gb) == true); + continue 'outer; + } + _ => continue 'outer, + } + } + } + } +} + +#[test] +fn rom_test1() { + rom_test( + "../third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", + 0x4ab4, + ); +} + +#[test] +fn rom_test2() { + rom_test( + "../third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", + 0x4ab4, + ); +} diff --git a/third_party/mooneye-test-suite b/third_party/mooneye-test-suite new file mode 160000 index 0000000..74ae166 --- /dev/null +++ b/third_party/mooneye-test-suite @@ -0,0 +1 @@ +Subproject commit 74ae1664e4cd0201c62edd469044674d7d32daf9 From db0621e9028da03c1424d12197210602ea6f24c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Sun, 7 Jul 2024 20:08:08 +0100 Subject: [PATCH 02/13] Update submodules --- .github/workflows/main.yml | 17 +++++++++++++++++ fpt/src/debugger.rs | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f4e56f..3150022 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Install rgbds + run: > + wget "https://github.com/gbdev/rgbds/releases/download/v0.8.0/rgbds-0.8.0-linux-x86_64.tar.xz" -P rgbds; + cd rgbds; + tar -xvf rgbds-0.8.0-linux-x86_64.tar.xz; + sudo ./install.sh; + - name: Install wla_dx + run: > + git clone "https://github.com/vhelin/wla-dx.git"; + cd wla-dx; + cmake -G "Unix Makefiles" .; + make -j8; + sudo make install; + - name: Build mooneye-test-suite + run: cd third_party/mooneye-test-suite; make; - uses: Swatinem/rust-cache@v2 - name: Version run: rustc --version diff --git a/fpt/src/debugger.rs b/fpt/src/debugger.rs index 5741a04..6efc720 100644 --- a/fpt/src/debugger.rs +++ b/fpt/src/debugger.rs @@ -54,7 +54,7 @@ impl Debugger { opcode: *instruction, triggered: false, }); - Some(DebugEvent::RegisterInstrpoint(instruction.clone())) + Some(DebugEvent::RegisterInstrpoint(*instruction)) } DebugCmd::ListBreakpoints => { Some(DebugEvent::ListBreakpoints(self.breakpoints.clone())) From 4dc91adf51a8d173e655861e8821fb609bfb742b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Sun, 7 Jul 2024 22:25:31 +0100 Subject: [PATCH 03/13] Generate rom tests --- .github/workflows/main.yml | 2 +- Cargo.lock | 25 ++++++++++ fpt/Cargo.toml | 3 ++ fpt/build.rs | 55 +++++++++++++++++++++ fpt/tests/rom_tests.json | 8 +++ fpt/tests/{rom_test.rs => templates/header} | 50 +++++++------------ fpt/tests/templates/test | 7 +++ fpt/tests/test_roms.rs | 2 + 8 files changed, 118 insertions(+), 34 deletions(-) create mode 100644 fpt/build.rs create mode 100644 fpt/tests/rom_tests.json rename fpt/tests/{rom_test.rs => templates/header} (51%) create mode 100644 fpt/tests/templates/test create mode 100644 fpt/tests/test_roms.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3150022..d213cb1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: 'true' + - uses: Swatinem/rust-cache@v2 - name: Install rgbds run: > wget "https://github.com/gbdev/rgbds/releases/download/v0.8.0/rgbds-0.8.0-linux-x86_64.tar.xz" -P rgbds; @@ -33,7 +34,6 @@ jobs: sudo make install; - name: Build mooneye-test-suite run: cd third_party/mooneye-test-suite; make; - - uses: Swatinem/rust-cache@v2 - name: Version run: rustc --version - name: Run rustfmt diff --git a/Cargo.lock b/Cargo.lock index ab248db..68144ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -738,6 +738,8 @@ dependencies = [ "num-traits", "regex", "rstest", + "serde", + "serde_json", ] [[package]] @@ -1069,6 +1071,12 @@ version = "1.70.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "jni" version = "0.21.1" @@ -1683,6 +1691,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "same-file" version = "1.0.6" @@ -1730,6 +1744,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "simd-adler32" version = "0.3.7" diff --git a/fpt/Cargo.toml b/fpt/Cargo.toml index a7023df..bcab6b1 100644 --- a/fpt/Cargo.toml +++ b/fpt/Cargo.toml @@ -10,3 +10,6 @@ num-traits = "0.2" [dev-dependencies] rstest = "0.18" +[build-dependencies] +serde = {version = "1.0", features = ["derive"]} +serde_json = "1.0" diff --git a/fpt/build.rs b/fpt/build.rs new file mode 100644 index 0000000..dc0e7ce --- /dev/null +++ b/fpt/build.rs @@ -0,0 +1,55 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::Path; + +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +struct Suite { + tests: Vec, + name: String, +} + +#[derive(Serialize, Deserialize)] +struct Test { + id: u32, + path: String, + termination_address: String, + enabled: Option, +} + +// build script's entry point +fn main() { + let out_dir = env::var("OUT_DIR").unwrap(); + let destination = dbg!(Path::new(&out_dir).join("tests.rs")); + let mut test_file = File::create(destination).unwrap(); + + write_header(&mut test_file); + write_test(&mut test_file, "tests/rom_tests.json"); +} + +fn write_test(test_file: &mut File, directory: &str) { + let source = dbg!(std::fs::read_to_string(directory).unwrap()); + let suite: Suite = serde_json::from_str(&source).unwrap(); + + for test in suite.tests { + if test.enabled.is_some() && !test.enabled.unwrap() { + continue; + } + let test_name = format!("{}_{}", suite.name, test.id); + + write!( + test_file, + include_str!("./tests/templates/test"), + name = test_name, + path = test.path, + termination_address = test.termination_address, + ) + .unwrap(); + } +} + +fn write_header(test_file: &mut File) { + write!(test_file, include_str!("./tests/templates/header")).unwrap(); +} diff --git a/fpt/tests/rom_tests.json b/fpt/tests/rom_tests.json new file mode 100644 index 0000000..443297c --- /dev/null +++ b/fpt/tests/rom_tests.json @@ -0,0 +1,8 @@ +{ + "name": "rom_tests", + "tests": [ + {"id": 0, "path": "../third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", "termination_address": "0x4ab4"}, + {"id": 1, "path": "../third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", + "termination_address": "0x4ab4"} + ] +} diff --git a/fpt/tests/rom_test.rs b/fpt/tests/templates/header similarity index 51% rename from fpt/tests/rom_test.rs rename to fpt/tests/templates/header index 7cbf239..06fe07c 100644 --- a/fpt/tests/rom_test.rs +++ b/fpt/tests/templates/header @@ -1,15 +1,15 @@ -use fpt::{DebugCmd, DebugEvent, Gameboy}; +use fpt::{{DebugCmd, DebugEvent, Gameboy}}; -fn check_registers(gb: &Gameboy) -> bool { +fn check_registers(gb: &Gameboy) -> bool {{ return gb.cpu().b() == 3 && gb.cpu().c() == 5 && gb.cpu().d() == 8 && gb.cpu().e() == 13 && gb.cpu().h() == 21 && gb.cpu().l() == 34; -} +}} -fn rom_test(rom_path: &str, termination_address: u16) { +fn rom_test(rom_path: &str, termination_address: u16) {{ let mut gb = Gameboy::new(); gb.simulate_dmg0_bootrom_handoff_state(); @@ -19,40 +19,24 @@ fn rom_test(rom_path: &str, termination_address: u16) { gb.debug_cmd(&DebugCmd::Instrpoint(0x40)); gb.debug_cmd(&DebugCmd::Breakpoint(termination_address)); - 'outer: loop { + 'outer: loop {{ gb.step(); let debug_events = gb.get_debug_events(); - if !debug_events.is_empty() { - loop { - match debug_events.pop_back().unwrap() { - DebugEvent::Breakpoint(_) => { + if !debug_events.is_empty() {{ + loop {{ + match debug_events.pop_back().unwrap() {{ + DebugEvent::Breakpoint(_) => {{ println!("breakpoint"); break 'outer; - } - DebugEvent::Instrpoint(_) => { + }} + DebugEvent::Instrpoint(_) => {{ println!("instrpoint"); assert!(check_registers(&gb) == true); continue 'outer; - } + }} _ => continue 'outer, - } - } - } - } -} - -#[test] -fn rom_test1() { - rom_test( - "../third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", - 0x4ab4, - ); -} - -#[test] -fn rom_test2() { - rom_test( - "../third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", - 0x4ab4, - ); -} + }} + }} + }} + }} +}} diff --git a/fpt/tests/templates/test b/fpt/tests/templates/test new file mode 100644 index 0000000..082afb2 --- /dev/null +++ b/fpt/tests/templates/test @@ -0,0 +1,7 @@ +#[test] +fn {name}() {{ + rom_test( + "{path}", + {termination_address}, + ); +}} diff --git a/fpt/tests/test_roms.rs b/fpt/tests/test_roms.rs new file mode 100644 index 0000000..1429652 --- /dev/null +++ b/fpt/tests/test_roms.rs @@ -0,0 +1,2 @@ +// include tests generated by `build.rs`, one test per directory in tests/data +include!(concat!(env!("OUT_DIR"), "/tests.rs")); From 9880f13ae29428d9f7ed701a31d2f9c1ef4309d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Sun, 7 Jul 2024 22:39:42 +0100 Subject: [PATCH 04/13] Add all timer test roms --- fpt/tests/rom_tests.json | 75 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/fpt/tests/rom_tests.json b/fpt/tests/rom_tests.json index 443297c..22ab73d 100644 --- a/fpt/tests/rom_tests.json +++ b/fpt/tests/rom_tests.json @@ -1,8 +1,71 @@ { - "name": "rom_tests", - "tests": [ - {"id": 0, "path": "../third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", "termination_address": "0x4ab4"}, - {"id": 1, "path": "../third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", - "termination_address": "0x4ab4"} - ] + "name":"rom_tests", + "tests":[ + { + "id":0, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", + "termination_address":"0x4ab4" + }, + { + "id":1, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", + "termination_address":"0x4ab4" + }, + { + "id":2, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/div_write.gb", + "termination_address":"0x4ab4" + }, + { + "id":3, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/rapid_toggle.gb", + "termination_address":"0x4ab4", + "enabled":false + }, + { + "id":4, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim00_div_trigger.gb", + "termination_address":"0x4ab4" + }, + { + "id":5, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim01_div_trigger.gb", + "termination_address":"0x4ab4" + }, + { + "id":6, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim10_div_trigger.gb", + "termination_address":"0x4ab4" + }, + { + "id":7, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim10.gb", + "termination_address":"0x4ab4" + }, + { + "id":8, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim11_div_trigger.gb", + "termination_address":"0x4ab4" + }, + { + "id":9, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim11.gb", + "termination_address":"0x4ab4" + }, + { + "id":10, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tima_reload.gb", + "termination_address":"0x4ab4" + }, + { + "id":11, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tima_write_reloading.gb", + "termination_address":"0x4ab4" + }, + { + "id":12, + "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tma_write_reloading.gb", + "termination_address":"0x4ab4" + } + ] } From 4ec92d02394a2488dbe987080918c2e39e5fc546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Sun, 7 Jul 2024 23:00:32 +0100 Subject: [PATCH 05/13] Add missing mooneye test roms --- fpt/tests/rom_tests.json | 251 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+) diff --git a/fpt/tests/rom_tests.json b/fpt/tests/rom_tests.json index 22ab73d..32ea3ee 100644 --- a/fpt/tests/rom_tests.json +++ b/fpt/tests/rom_tests.json @@ -66,6 +66,257 @@ "id":12, "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tma_write_reloading.gb", "termination_address":"0x4ab4" + }, + { + "id":13, + "path":"../third_party/mooneye-test-suite/build/acceptance/bits/mem_oam.gb", + "termination_address":"0x4ab4" + }, + { + "id":14, + "path":"../third_party/mooneye-test-suite/build/acceptance/bits/reg_f.gb", + "termination_address":"0x4ab4" + }, + { + "id":15, + "path":"../third_party/mooneye-test-suite/build/acceptance/bits/unused_hwio-GS.gb", + "termination_address":"0x4ab4", + "enabled":false + }, + { + "id":16, + "path":"../third_party/mooneye-test-suite/build/acceptance/instr/daa.gb", + "termination_address":"0x4ab4", + "enabled":false + }, + { + "id":17, + "path":"../third_party/mooneye-test-suite/build/acceptance/interrupts/ie_push.gb", + "termination_address":"0x4ab4", + "enabled":false + }, + { + "id":18, + "path":"../third_party/mooneye-test-suite/build/acceptance/add_sp_e_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":19, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div2-S.gb", + "termination_address":"0x4ab4" + }, + { + "id":20, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div-dmg0.gb", + "termination_address":"0x4ab4" + }, + { + "id":21, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div-dmgABCmgb.gb", + "termination_address":"0x4ab4" + }, + { + "id":22, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div-S.gb", + "termination_address":"0x4ab4" + }, + { + "id":23, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmg0.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":24, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmgABCmgb.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":25, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_hwio-S.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":26, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-dmg0.gb", + "termination_address":"0x4ab4" + }, + { + "id":27, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-dmgABC.gb", + "termination_address":"0x4ab4" + }, + { + "id":28, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-mgb.gb", + "termination_address":"0x4ab4" + }, + { + "id":29, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb2.gb", + "termination_address":"0x4ab4" + }, + { + "id":30, + "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb.gb", + "termination_address":"0x4ab4" + }, + { + "id":31, + "path":"../third_party/mooneye-test-suite/build/acceptance/call_cc_timing2.gb", + "termination_address":"0x4ab4" + }, + { + "id":32, + "path":"../third_party/mooneye-test-suite/build/acceptance/call_cc_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":34, + "path":"../third_party/mooneye-test-suite/build/acceptance/call_timing2.gb", + "termination_address":"0x4ab4" + }, + { + "id":35, + "path":"../third_party/mooneye-test-suite/build/acceptance/call_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":36, + "path":"../third_party/mooneye-test-suite/build/acceptance/di_timing-GS.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":37, + "path":"../third_party/mooneye-test-suite/build/acceptance/div_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":38, + "path":"../third_party/mooneye-test-suite/build/acceptance/ei_sequence.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":39, + "path":"../third_party/mooneye-test-suite/build/acceptance/ei_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":40, + "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime0_ei.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":41, + "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime0_nointr_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":42, + "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing2-GS.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":43, + "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":44, + "path":"../third_party/mooneye-test-suite/build/acceptance/if_ie_registers.gb", + "termination_address":"0x4ab4" + }, + { + "id":45, + "path":"../third_party/mooneye-test-suite/build/acceptance/intr_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":46, + "path":"../third_party/mooneye-test-suite/build/acceptance/jp_cc_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":47, + "path":"../third_party/mooneye-test-suite/build/acceptance/jp_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":48, + "path":"../third_party/mooneye-test-suite/build/acceptance/ld_hl_sp_e_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":49, + "path":"../third_party/mooneye-test-suite/build/acceptance/oam_dma_restart.gb", + "termination_address":"0x4ab4" + }, + { + "id":50, + "path":"../third_party/mooneye-test-suite/build/acceptance/oam_dma_start.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":51, + "path":"../third_party/mooneye-test-suite/build/acceptance/oam_dma_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":52, + "path":"../third_party/mooneye-test-suite/build/acceptance/pop_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":53, + "path":"../third_party/mooneye-test-suite/build/acceptance/push_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":54, + "path":"../third_party/mooneye-test-suite/build/acceptance/rapid_di_ei.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":55, + "path":"../third_party/mooneye-test-suite/build/acceptance/ret_cc_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":56, + "path":"../third_party/mooneye-test-suite/build/acceptance/reti_intr_timing.gb", + "termination_address":"0x4ab4", + "enabled": false + }, + { + "id":57, + "path":"../third_party/mooneye-test-suite/build/acceptance/reti_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":58, + "path":"../third_party/mooneye-test-suite/build/acceptance/ret_timing.gb", + "termination_address":"0x4ab4" + }, + { + "id":59, + "path":"../third_party/mooneye-test-suite/build/acceptance/rst_timing.gb", + "termination_address":"0x4ab4" } ] } From d9efcb370bef09a20098a2bdfa12cf7d0e5f3688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Mon, 8 Jul 2024 21:25:26 +0100 Subject: [PATCH 06/13] Fetch prebuilt mooneye test roms --- .github/workflows/main.yml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d213cb1..a4f9598 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,21 +19,12 @@ jobs: with: submodules: 'true' - uses: Swatinem/rust-cache@v2 - - name: Install rgbds - run: > - wget "https://github.com/gbdev/rgbds/releases/download/v0.8.0/rgbds-0.8.0-linux-x86_64.tar.xz" -P rgbds; - cd rgbds; - tar -xvf rgbds-0.8.0-linux-x86_64.tar.xz; - sudo ./install.sh; - - name: Install wla_dx + - name: Fetch mooneye-test-suite run: > - git clone "https://github.com/vhelin/wla-dx.git"; - cd wla-dx; - cmake -G "Unix Makefiles" .; - make -j8; - sudo make install; - - name: Build mooneye-test-suite - run: cd third_party/mooneye-test-suite; make; + wget https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz; + tar -xvf mts-20240127-1204-74ae166.tar.xz; + mkdir -p third_party/mooneye-test-suite; + mv mts-20240127-1204-74ae166 third_party/mooneye-test-suite/build; - name: Version run: rustc --version - name: Run rustfmt From 214183681f4a3134bb11bf4bc15b7f2f31d24c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Mon, 8 Jul 2024 22:21:01 +0100 Subject: [PATCH 07/13] Fetch test roms from build.rs --- .github/workflows/main.yml | 6 -- .gitmodules | 3 - fpt/build.rs | 31 +++++++-- fpt/tests/rom_tests.json | 118 ++++++++++++++++----------------- third_party/mooneye-test-suite | 1 - 5 files changed, 86 insertions(+), 73 deletions(-) delete mode 160000 third_party/mooneye-test-suite diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a4f9598..36eb311 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,12 +19,6 @@ jobs: with: submodules: 'true' - uses: Swatinem/rust-cache@v2 - - name: Fetch mooneye-test-suite - run: > - wget https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz; - tar -xvf mts-20240127-1204-74ae166.tar.xz; - mkdir -p third_party/mooneye-test-suite; - mv mts-20240127-1204-74ae166 third_party/mooneye-test-suite/build; - name: Version run: rustc --version - name: Run rustfmt diff --git a/.gitmodules b/.gitmodules index cbe4f99..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "third_party/mooneye-test-suite"] - path = third_party/mooneye-test-suite - url = git@github.com:Gekkio/mooneye-test-suite.git diff --git a/fpt/build.rs b/fpt/build.rs index dc0e7ce..5911dc4 100644 --- a/fpt/build.rs +++ b/fpt/build.rs @@ -2,6 +2,7 @@ use std::env; use std::fs::File; use std::io::Write; use std::path::Path; +use std::process::Command; use serde::{Deserialize, Serialize}; @@ -19,10 +20,9 @@ struct Test { enabled: Option, } -// build script's entry point -fn main() { +fn generate_rom_tests() { let out_dir = env::var("OUT_DIR").unwrap(); - let destination = dbg!(Path::new(&out_dir).join("tests.rs")); + let destination = Path::new(&out_dir).join("tests.rs"); let mut test_file = File::create(destination).unwrap(); write_header(&mut test_file); @@ -30,7 +30,7 @@ fn main() { } fn write_test(test_file: &mut File, directory: &str) { - let source = dbg!(std::fs::read_to_string(directory).unwrap()); + let source = std::fs::read_to_string(directory).unwrap(); let suite: Suite = serde_json::from_str(&source).unwrap(); for test in suite.tests { @@ -53,3 +53,26 @@ fn write_test(test_file: &mut File, directory: &str) { fn write_header(test_file: &mut File) { write!(test_file, include_str!("./tests/templates/header")).unwrap(); } + +fn run_cmd(cmd: &str) -> String { + let output = Command::new("sh") + .arg("-c") + .arg(cmd) + .output() + .expect("failed to execute process"); + + String::from_utf8(output.stdout).expect("Failed to convert output to string") +} + +fn fetch_mooneye_test_roms() { + run_cmd("wget https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz"); + run_cmd("tar -xvf mts-20240127-1204-74ae166.tar.xz"); + run_cmd("mkdir -p third_party/mooneye-test-suite"); + run_cmd("mv mts-20240127-1204-74ae166 third_party/mooneye-test-suite/build"); + run_cmd("tree ."); +} + +fn main() { + generate_rom_tests(); + fetch_mooneye_test_roms(); +} diff --git a/fpt/tests/rom_tests.json b/fpt/tests/rom_tests.json index 32ea3ee..5020182 100644 --- a/fpt/tests/rom_tests.json +++ b/fpt/tests/rom_tests.json @@ -3,319 +3,319 @@ "tests":[ { "id":0, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", "termination_address":"0x4ab4" }, { "id":1, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", "termination_address":"0x4ab4" }, { "id":2, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/div_write.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/div_write.gb", "termination_address":"0x4ab4" }, { "id":3, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/rapid_toggle.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/rapid_toggle.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":4, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim00_div_trigger.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim00_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":5, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim01_div_trigger.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim01_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":6, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim10_div_trigger.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim10_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":7, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim10.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim10.gb", "termination_address":"0x4ab4" }, { "id":8, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim11_div_trigger.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim11_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":9, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tim11.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim11.gb", "termination_address":"0x4ab4" }, { "id":10, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tima_reload.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tima_reload.gb", "termination_address":"0x4ab4" }, { "id":11, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tima_write_reloading.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tima_write_reloading.gb", "termination_address":"0x4ab4" }, { "id":12, - "path":"../third_party/mooneye-test-suite/build/acceptance/timer/tma_write_reloading.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/timer/tma_write_reloading.gb", "termination_address":"0x4ab4" }, { "id":13, - "path":"../third_party/mooneye-test-suite/build/acceptance/bits/mem_oam.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/bits/mem_oam.gb", "termination_address":"0x4ab4" }, { "id":14, - "path":"../third_party/mooneye-test-suite/build/acceptance/bits/reg_f.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/bits/reg_f.gb", "termination_address":"0x4ab4" }, { "id":15, - "path":"../third_party/mooneye-test-suite/build/acceptance/bits/unused_hwio-GS.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/bits/unused_hwio-GS.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":16, - "path":"../third_party/mooneye-test-suite/build/acceptance/instr/daa.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/instr/daa.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":17, - "path":"../third_party/mooneye-test-suite/build/acceptance/interrupts/ie_push.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/interrupts/ie_push.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":18, - "path":"../third_party/mooneye-test-suite/build/acceptance/add_sp_e_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/add_sp_e_timing.gb", "termination_address":"0x4ab4" }, { "id":19, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div2-S.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_div2-S.gb", "termination_address":"0x4ab4" }, { "id":20, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div-dmg0.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_div-dmg0.gb", "termination_address":"0x4ab4" }, { "id":21, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div-dmgABCmgb.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_div-dmgABCmgb.gb", "termination_address":"0x4ab4" }, { "id":22, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_div-S.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_div-S.gb", "termination_address":"0x4ab4" }, { "id":23, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmg0.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmg0.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":24, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmgABCmgb.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmgABCmgb.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":25, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_hwio-S.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_hwio-S.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":26, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-dmg0.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-dmg0.gb", "termination_address":"0x4ab4" }, { "id":27, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-dmgABC.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-dmgABC.gb", "termination_address":"0x4ab4" }, { "id":28, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-mgb.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-mgb.gb", "termination_address":"0x4ab4" }, { "id":29, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb2.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb2.gb", "termination_address":"0x4ab4" }, { "id":30, - "path":"../third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb.gb", "termination_address":"0x4ab4" }, { "id":31, - "path":"../third_party/mooneye-test-suite/build/acceptance/call_cc_timing2.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/call_cc_timing2.gb", "termination_address":"0x4ab4" }, { "id":32, - "path":"../third_party/mooneye-test-suite/build/acceptance/call_cc_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/call_cc_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":34, - "path":"../third_party/mooneye-test-suite/build/acceptance/call_timing2.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/call_timing2.gb", "termination_address":"0x4ab4" }, { "id":35, - "path":"../third_party/mooneye-test-suite/build/acceptance/call_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/call_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":36, - "path":"../third_party/mooneye-test-suite/build/acceptance/di_timing-GS.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/di_timing-GS.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":37, - "path":"../third_party/mooneye-test-suite/build/acceptance/div_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/div_timing.gb", "termination_address":"0x4ab4" }, { "id":38, - "path":"../third_party/mooneye-test-suite/build/acceptance/ei_sequence.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/ei_sequence.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":39, - "path":"../third_party/mooneye-test-suite/build/acceptance/ei_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/ei_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":40, - "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime0_ei.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime0_ei.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":41, - "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime0_nointr_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime0_nointr_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":42, - "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing2-GS.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing2-GS.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":43, - "path":"../third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":44, - "path":"../third_party/mooneye-test-suite/build/acceptance/if_ie_registers.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/if_ie_registers.gb", "termination_address":"0x4ab4" }, { "id":45, - "path":"../third_party/mooneye-test-suite/build/acceptance/intr_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/intr_timing.gb", "termination_address":"0x4ab4" }, { "id":46, - "path":"../third_party/mooneye-test-suite/build/acceptance/jp_cc_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/jp_cc_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":47, - "path":"../third_party/mooneye-test-suite/build/acceptance/jp_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/jp_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":48, - "path":"../third_party/mooneye-test-suite/build/acceptance/ld_hl_sp_e_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/ld_hl_sp_e_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":49, - "path":"../third_party/mooneye-test-suite/build/acceptance/oam_dma_restart.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/oam_dma_restart.gb", "termination_address":"0x4ab4" }, { "id":50, - "path":"../third_party/mooneye-test-suite/build/acceptance/oam_dma_start.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/oam_dma_start.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":51, - "path":"../third_party/mooneye-test-suite/build/acceptance/oam_dma_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/oam_dma_timing.gb", "termination_address":"0x4ab4" }, { "id":52, - "path":"../third_party/mooneye-test-suite/build/acceptance/pop_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/pop_timing.gb", "termination_address":"0x4ab4" }, { "id":53, - "path":"../third_party/mooneye-test-suite/build/acceptance/push_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/push_timing.gb", "termination_address":"0x4ab4" }, { "id":54, - "path":"../third_party/mooneye-test-suite/build/acceptance/rapid_di_ei.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/rapid_di_ei.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":55, - "path":"../third_party/mooneye-test-suite/build/acceptance/ret_cc_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/ret_cc_timing.gb", "termination_address":"0x4ab4" }, { "id":56, - "path":"../third_party/mooneye-test-suite/build/acceptance/reti_intr_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/reti_intr_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":57, - "path":"../third_party/mooneye-test-suite/build/acceptance/reti_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/reti_timing.gb", "termination_address":"0x4ab4" }, { "id":58, - "path":"../third_party/mooneye-test-suite/build/acceptance/ret_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/ret_timing.gb", "termination_address":"0x4ab4" }, { "id":59, - "path":"../third_party/mooneye-test-suite/build/acceptance/rst_timing.gb", + "path":"third_party/mooneye-test-suite/build/acceptance/rst_timing.gb", "termination_address":"0x4ab4" } ] diff --git a/third_party/mooneye-test-suite b/third_party/mooneye-test-suite deleted file mode 160000 index 74ae166..0000000 --- a/third_party/mooneye-test-suite +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 74ae1664e4cd0201c62edd469044674d7d32daf9 From b73ac99db7d68be742a62d764595811e0bceef8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Tue, 9 Jul 2024 22:34:04 +0100 Subject: [PATCH 08/13] Download mooneye test roms to target/ --- .github/workflows/main.yml | 2 +- fpt/build.rs | 10 ++-- fpt/tests/rom_tests.json | 118 ++++++++++++++++++------------------- fpt/tests/templates/test | 2 +- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36eb311..9b39bda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,6 +24,6 @@ jobs: - name: Run rustfmt run: cargo fmt --check - name: Unit tests - run: cargo test -- --nocapture + run: cargo test -- --ignored --nocapture - name : Clippy run: cargo clippy --all-features diff --git a/fpt/build.rs b/fpt/build.rs index 5911dc4..4e76a54 100644 --- a/fpt/build.rs +++ b/fpt/build.rs @@ -65,11 +65,11 @@ fn run_cmd(cmd: &str) -> String { } fn fetch_mooneye_test_roms() { - run_cmd("wget https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz"); - run_cmd("tar -xvf mts-20240127-1204-74ae166.tar.xz"); - run_cmd("mkdir -p third_party/mooneye-test-suite"); - run_cmd("mv mts-20240127-1204-74ae166 third_party/mooneye-test-suite/build"); - run_cmd("tree ."); + println!("cargo:rerun-if-changed=build.rs"); + run_cmd("wget -P ../target/tmp https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz"); + run_cmd("mkdir -p ../target/test_roms"); + run_cmd("tar -xvf ../target/tmp/mts-20240127-1204-74ae166.tar.xz -C ../target/test_roms"); + run_cmd("mv ../target/test_roms/mts-20240127-1204-74ae166 ../target/test_roms/mooneye"); } fn main() { diff --git a/fpt/tests/rom_tests.json b/fpt/tests/rom_tests.json index 5020182..e7a95df 100644 --- a/fpt/tests/rom_tests.json +++ b/fpt/tests/rom_tests.json @@ -3,319 +3,319 @@ "tests":[ { "id":0, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim00.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim00.gb", "termination_address":"0x4ab4" }, { "id":1, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim01.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim01.gb", "termination_address":"0x4ab4" }, { "id":2, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/div_write.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/div_write.gb", "termination_address":"0x4ab4" }, { "id":3, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/rapid_toggle.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/rapid_toggle.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":4, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim00_div_trigger.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim00_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":5, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim01_div_trigger.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim01_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":6, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim10_div_trigger.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim10_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":7, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim10.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim10.gb", "termination_address":"0x4ab4" }, { "id":8, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim11_div_trigger.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim11_div_trigger.gb", "termination_address":"0x4ab4" }, { "id":9, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tim11.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tim11.gb", "termination_address":"0x4ab4" }, { "id":10, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tima_reload.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tima_reload.gb", "termination_address":"0x4ab4" }, { "id":11, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tima_write_reloading.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tima_write_reloading.gb", "termination_address":"0x4ab4" }, { "id":12, - "path":"third_party/mooneye-test-suite/build/acceptance/timer/tma_write_reloading.gb", + "path":"../target/test_roms/mooneye/acceptance/timer/tma_write_reloading.gb", "termination_address":"0x4ab4" }, { "id":13, - "path":"third_party/mooneye-test-suite/build/acceptance/bits/mem_oam.gb", + "path":"../target/test_roms/mooneye/acceptance/bits/mem_oam.gb", "termination_address":"0x4ab4" }, { "id":14, - "path":"third_party/mooneye-test-suite/build/acceptance/bits/reg_f.gb", + "path":"../target/test_roms/mooneye/acceptance/bits/reg_f.gb", "termination_address":"0x4ab4" }, { "id":15, - "path":"third_party/mooneye-test-suite/build/acceptance/bits/unused_hwio-GS.gb", + "path":"../target/test_roms/mooneye/acceptance/bits/unused_hwio-GS.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":16, - "path":"third_party/mooneye-test-suite/build/acceptance/instr/daa.gb", + "path":"../target/test_roms/mooneye/acceptance/instr/daa.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":17, - "path":"third_party/mooneye-test-suite/build/acceptance/interrupts/ie_push.gb", + "path":"../target/test_roms/mooneye/acceptance/interrupts/ie_push.gb", "termination_address":"0x4ab4", "enabled":false }, { "id":18, - "path":"third_party/mooneye-test-suite/build/acceptance/add_sp_e_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/add_sp_e_timing.gb", "termination_address":"0x4ab4" }, { "id":19, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_div2-S.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_div2-S.gb", "termination_address":"0x4ab4" }, { "id":20, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_div-dmg0.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_div-dmg0.gb", "termination_address":"0x4ab4" }, { "id":21, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_div-dmgABCmgb.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_div-dmgABCmgb.gb", "termination_address":"0x4ab4" }, { "id":22, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_div-S.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_div-S.gb", "termination_address":"0x4ab4" }, { "id":23, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmg0.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_hwio-dmg0.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":24, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_hwio-dmgABCmgb.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_hwio-dmgABCmgb.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":25, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_hwio-S.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_hwio-S.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":26, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-dmg0.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_regs-dmg0.gb", "termination_address":"0x4ab4" }, { "id":27, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-dmgABC.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_regs-dmgABC.gb", "termination_address":"0x4ab4" }, { "id":28, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-mgb.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_regs-mgb.gb", "termination_address":"0x4ab4" }, { "id":29, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb2.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_regs-sgb2.gb", "termination_address":"0x4ab4" }, { "id":30, - "path":"third_party/mooneye-test-suite/build/acceptance/boot_regs-sgb.gb", + "path":"../target/test_roms/mooneye/acceptance/boot_regs-sgb.gb", "termination_address":"0x4ab4" }, { "id":31, - "path":"third_party/mooneye-test-suite/build/acceptance/call_cc_timing2.gb", + "path":"../target/test_roms/mooneye/acceptance/call_cc_timing2.gb", "termination_address":"0x4ab4" }, { "id":32, - "path":"third_party/mooneye-test-suite/build/acceptance/call_cc_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/call_cc_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":34, - "path":"third_party/mooneye-test-suite/build/acceptance/call_timing2.gb", + "path":"../target/test_roms/mooneye/acceptance/call_timing2.gb", "termination_address":"0x4ab4" }, { "id":35, - "path":"third_party/mooneye-test-suite/build/acceptance/call_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/call_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":36, - "path":"third_party/mooneye-test-suite/build/acceptance/di_timing-GS.gb", + "path":"../target/test_roms/mooneye/acceptance/di_timing-GS.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":37, - "path":"third_party/mooneye-test-suite/build/acceptance/div_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/div_timing.gb", "termination_address":"0x4ab4" }, { "id":38, - "path":"third_party/mooneye-test-suite/build/acceptance/ei_sequence.gb", + "path":"../target/test_roms/mooneye/acceptance/ei_sequence.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":39, - "path":"third_party/mooneye-test-suite/build/acceptance/ei_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/ei_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":40, - "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime0_ei.gb", + "path":"../target/test_roms/mooneye/acceptance/halt_ime0_ei.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":41, - "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime0_nointr_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/halt_ime0_nointr_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":42, - "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing2-GS.gb", + "path":"../target/test_roms/mooneye/acceptance/halt_ime1_timing2-GS.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":43, - "path":"third_party/mooneye-test-suite/build/acceptance/halt_ime1_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/halt_ime1_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":44, - "path":"third_party/mooneye-test-suite/build/acceptance/if_ie_registers.gb", + "path":"../target/test_roms/mooneye/acceptance/if_ie_registers.gb", "termination_address":"0x4ab4" }, { "id":45, - "path":"third_party/mooneye-test-suite/build/acceptance/intr_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/intr_timing.gb", "termination_address":"0x4ab4" }, { "id":46, - "path":"third_party/mooneye-test-suite/build/acceptance/jp_cc_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/jp_cc_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":47, - "path":"third_party/mooneye-test-suite/build/acceptance/jp_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/jp_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":48, - "path":"third_party/mooneye-test-suite/build/acceptance/ld_hl_sp_e_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/ld_hl_sp_e_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":49, - "path":"third_party/mooneye-test-suite/build/acceptance/oam_dma_restart.gb", + "path":"../target/test_roms/mooneye/acceptance/oam_dma_restart.gb", "termination_address":"0x4ab4" }, { "id":50, - "path":"third_party/mooneye-test-suite/build/acceptance/oam_dma_start.gb", + "path":"../target/test_roms/mooneye/acceptance/oam_dma_start.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":51, - "path":"third_party/mooneye-test-suite/build/acceptance/oam_dma_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/oam_dma_timing.gb", "termination_address":"0x4ab4" }, { "id":52, - "path":"third_party/mooneye-test-suite/build/acceptance/pop_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/pop_timing.gb", "termination_address":"0x4ab4" }, { "id":53, - "path":"third_party/mooneye-test-suite/build/acceptance/push_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/push_timing.gb", "termination_address":"0x4ab4" }, { "id":54, - "path":"third_party/mooneye-test-suite/build/acceptance/rapid_di_ei.gb", + "path":"../target/test_roms/mooneye/acceptance/rapid_di_ei.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":55, - "path":"third_party/mooneye-test-suite/build/acceptance/ret_cc_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/ret_cc_timing.gb", "termination_address":"0x4ab4" }, { "id":56, - "path":"third_party/mooneye-test-suite/build/acceptance/reti_intr_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/reti_intr_timing.gb", "termination_address":"0x4ab4", "enabled": false }, { "id":57, - "path":"third_party/mooneye-test-suite/build/acceptance/reti_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/reti_timing.gb", "termination_address":"0x4ab4" }, { "id":58, - "path":"third_party/mooneye-test-suite/build/acceptance/ret_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/ret_timing.gb", "termination_address":"0x4ab4" }, { "id":59, - "path":"third_party/mooneye-test-suite/build/acceptance/rst_timing.gb", + "path":"../target/test_roms/mooneye/acceptance/rst_timing.gb", "termination_address":"0x4ab4" } ] diff --git a/fpt/tests/templates/test b/fpt/tests/templates/test index 082afb2..f17cafc 100644 --- a/fpt/tests/templates/test +++ b/fpt/tests/templates/test @@ -1,4 +1,4 @@ -#[test] +#[test] #[ignore] fn {name}() {{ rom_test( "{path}", From 1ca614f7014619f42f772623c4db626fa46497a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Tue, 9 Jul 2024 22:34:43 +0100 Subject: [PATCH 09/13] No more submodules --- .github/workflows/main.yml | 2 -- .gitmodules | 0 2 files changed, 2 deletions(-) delete mode 100644 .gitmodules diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9b39bda..155a3e1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - submodules: 'true' - uses: Swatinem/rust-cache@v2 - name: Version run: rustc --version diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 From 6fcdec860f6484a8f9db8506d8062b74a89533f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Tue, 9 Jul 2024 22:37:19 +0100 Subject: [PATCH 10/13] Remove loop detection exit logic --- fpt/src/lr35902.rs | 19 ------------------- fpt/tests/templates/header | 2 -- 2 files changed, 21 deletions(-) diff --git a/fpt/src/lr35902.rs b/fpt/src/lr35902.rs index 071c3fc..5318cf6 100644 --- a/fpt/src/lr35902.rs +++ b/fpt/src/lr35902.rs @@ -27,8 +27,6 @@ pub struct LR35902 { branch_taken: bool, bus: Bus, debugger: Debugger, - previous_pc: u16, - pc_counter: u16, } impl Default for LR35902 { @@ -79,8 +77,6 @@ impl LR35902 { bus: memory, // Debugging debugger: Debugger::new(), - previous_pc: 0, - pc_counter: 0, } } @@ -637,21 +633,6 @@ impl LR35902 { // Run instructions /// Run one t-cycle - from actual crystal @ 4 or 8 MHz (double speed mode) pub fn t_cycle(&mut self) { - static mut PREVIOUS_PC: u16 = 0; - static mut PC_COUNTER: u16 = 0; - // test roms get stuck in the same pc when finished - unsafe { - if PREVIOUS_PC != self.pc() { - PREVIOUS_PC = self.pc(); - PC_COUNTER = 0; - } else { - PC_COUNTER += 1; - if PC_COUNTER == 100 { - std::process::exit(0); - } - } - } - let inst = self.decode(); self.set_inst_cycle_count(self.inst_cycle_count() + 1); // Only actually mutate CPU state on the last t-cycle of the instruction diff --git a/fpt/tests/templates/header b/fpt/tests/templates/header index 06fe07c..7349446 100644 --- a/fpt/tests/templates/header +++ b/fpt/tests/templates/header @@ -26,11 +26,9 @@ fn rom_test(rom_path: &str, termination_address: u16) {{ loop {{ match debug_events.pop_back().unwrap() {{ DebugEvent::Breakpoint(_) => {{ - println!("breakpoint"); break 'outer; }} DebugEvent::Instrpoint(_) => {{ - println!("instrpoint"); assert!(check_registers(&gb) == true); continue 'outer; }} From b9ceccc2c0d9e823e17a24d5bb71fd5cb02339b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Tue, 9 Jul 2024 22:56:59 +0100 Subject: [PATCH 11/13] Add flag to indicate failing tests --- fpt/build.rs | 7 +++++ fpt/src/lr35902.rs | 2 +- fpt/tests/rom_tests.json | 53 ++++++++++++++++++++++++-------------- fpt/tests/templates/header | 11 ++++++-- fpt/tests/templates/test | 1 + 5 files changed, 51 insertions(+), 23 deletions(-) diff --git a/fpt/build.rs b/fpt/build.rs index 4e76a54..6e355b0 100644 --- a/fpt/build.rs +++ b/fpt/build.rs @@ -17,10 +17,12 @@ struct Test { id: u32, path: String, termination_address: String, + passing: Option, enabled: Option, } fn generate_rom_tests() { + println!("cargo:rerun-if-changed=tests"); let out_dir = env::var("OUT_DIR").unwrap(); let destination = Path::new(&out_dir).join("tests.rs"); let mut test_file = File::create(destination).unwrap(); @@ -45,6 +47,11 @@ fn write_test(test_file: &mut File, directory: &str) { name = test_name, path = test.path, termination_address = test.termination_address, + passing = if test.passing.unwrap_or(true) { + "true" + } else { + "false" + }, ) .unwrap(); } diff --git a/fpt/src/lr35902.rs b/fpt/src/lr35902.rs index 5318cf6..bfd8214 100644 --- a/fpt/src/lr35902.rs +++ b/fpt/src/lr35902.rs @@ -1254,7 +1254,7 @@ impl LR35902 { // HALT // Take care for halt bug: https://gbdev.io/pandocs/halt.html // https://rgbds.gbdev.io/docs/v0.6.1/gbz80.7/#HALT - //todo!("0x76 HALT") + todo!("0x76 HALT") } 0x77 => { // LD (HL),A diff --git a/fpt/tests/rom_tests.json b/fpt/tests/rom_tests.json index e7a95df..32718cb 100644 --- a/fpt/tests/rom_tests.json +++ b/fpt/tests/rom_tests.json @@ -20,7 +20,7 @@ "id":3, "path":"../target/test_roms/mooneye/acceptance/timer/rapid_toggle.gb", "termination_address":"0x4ab4", - "enabled":false + "passing":false }, { "id":4, @@ -81,18 +81,20 @@ "id":15, "path":"../target/test_roms/mooneye/acceptance/bits/unused_hwio-GS.gb", "termination_address":"0x4ab4", - "enabled":false + "passing":false }, { "id":16, "path":"../target/test_roms/mooneye/acceptance/instr/daa.gb", "termination_address":"0x4ab4", + "passing":false, "enabled":false }, { "id":17, "path":"../target/test_roms/mooneye/acceptance/interrupts/ie_push.gb", "termination_address":"0x4ab4", + "passing":false, "enabled":false }, { @@ -124,19 +126,19 @@ "id":23, "path":"../target/test_roms/mooneye/acceptance/boot_hwio-dmg0.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":24, "path":"../target/test_roms/mooneye/acceptance/boot_hwio-dmgABCmgb.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":25, "path":"../target/test_roms/mooneye/acceptance/boot_hwio-S.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":26, @@ -172,7 +174,7 @@ "id":32, "path":"../target/test_roms/mooneye/acceptance/call_cc_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":34, @@ -183,13 +185,14 @@ "id":35, "path":"../target/test_roms/mooneye/acceptance/call_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":36, "path":"../target/test_roms/mooneye/acceptance/di_timing-GS.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":37, @@ -200,37 +203,43 @@ "id":38, "path":"../target/test_roms/mooneye/acceptance/ei_sequence.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":39, "path":"../target/test_roms/mooneye/acceptance/ei_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":40, "path":"../target/test_roms/mooneye/acceptance/halt_ime0_ei.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":41, "path":"../target/test_roms/mooneye/acceptance/halt_ime0_nointr_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":42, "path":"../target/test_roms/mooneye/acceptance/halt_ime1_timing2-GS.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":43, "path":"../target/test_roms/mooneye/acceptance/halt_ime1_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":44, @@ -246,19 +255,20 @@ "id":46, "path":"../target/test_roms/mooneye/acceptance/jp_cc_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":47, "path":"../target/test_roms/mooneye/acceptance/jp_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false }, { "id":48, "path":"../target/test_roms/mooneye/acceptance/ld_hl_sp_e_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":49, @@ -269,7 +279,8 @@ "id":50, "path":"../target/test_roms/mooneye/acceptance/oam_dma_start.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":51, @@ -290,7 +301,8 @@ "id":54, "path":"../target/test_roms/mooneye/acceptance/rapid_di_ei.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":55, @@ -301,7 +313,8 @@ "id":56, "path":"../target/test_roms/mooneye/acceptance/reti_intr_timing.gb", "termination_address":"0x4ab4", - "enabled": false + "passing": false, + "enabled": false }, { "id":57, diff --git a/fpt/tests/templates/header b/fpt/tests/templates/header index 7349446..84bc308 100644 --- a/fpt/tests/templates/header +++ b/fpt/tests/templates/header @@ -9,7 +9,7 @@ fn check_registers(gb: &Gameboy) -> bool {{ && gb.cpu().l() == 34; }} -fn rom_test(rom_path: &str, termination_address: u16) {{ +fn rom_test(rom_path: &str, termination_address: u16, passing: bool) {{ let mut gb = Gameboy::new(); gb.simulate_dmg0_bootrom_handoff_state(); @@ -19,6 +19,7 @@ fn rom_test(rom_path: &str, termination_address: u16) {{ gb.debug_cmd(&DebugCmd::Instrpoint(0x40)); gb.debug_cmd(&DebugCmd::Breakpoint(termination_address)); + let mut success = true; 'outer: loop {{ gb.step(); let debug_events = gb.get_debug_events(); @@ -29,7 +30,11 @@ fn rom_test(rom_path: &str, termination_address: u16) {{ break 'outer; }} DebugEvent::Instrpoint(_) => {{ - assert!(check_registers(&gb) == true); + let check = check_registers(&gb); + success &= check; + if passing {{ + assert!(check == true); + }} continue 'outer; }} _ => continue 'outer, @@ -37,4 +42,6 @@ fn rom_test(rom_path: &str, termination_address: u16) {{ }} }} }} + + assert!(success == passing); }} diff --git a/fpt/tests/templates/test b/fpt/tests/templates/test index f17cafc..5e0890f 100644 --- a/fpt/tests/templates/test +++ b/fpt/tests/templates/test @@ -3,5 +3,6 @@ fn {name}() {{ rom_test( "{path}", {termination_address}, + {passing}, ); }} From 60bf25abc32e91ec353f711ff90345fde953d020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pinheiro?= Date: Tue, 9 Jul 2024 23:54:15 +0100 Subject: [PATCH 12/13] use curl --- fpt/build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fpt/build.rs b/fpt/build.rs index 6e355b0..c81bb4a 100644 --- a/fpt/build.rs +++ b/fpt/build.rs @@ -67,15 +67,18 @@ fn run_cmd(cmd: &str) -> String { .arg(cmd) .output() .expect("failed to execute process"); - + if !output.status.success() { + panic!("Command {} failed with exit code: {}", cmd, output.status); + } String::from_utf8(output.stdout).expect("Failed to convert output to string") } fn fetch_mooneye_test_roms() { println!("cargo:rerun-if-changed=build.rs"); - run_cmd("wget -P ../target/tmp https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz"); + run_cmd("curl -L --create-dirs --output-dir ../target/tmp -O https://gekkio.fi/files/mooneye-test-suite/mts-20240127-1204-74ae166/mts-20240127-1204-74ae166.tar.xz"); run_cmd("mkdir -p ../target/test_roms"); run_cmd("tar -xvf ../target/tmp/mts-20240127-1204-74ae166.tar.xz -C ../target/test_roms"); + run_cmd("rm -rf ../target/test_roms/mooneye"); run_cmd("mv ../target/test_roms/mts-20240127-1204-74ae166 ../target/test_roms/mooneye"); } From 9f185740343c4d5abf6e72c07c7a09049fcd9c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Freitas?= Date: Wed, 10 Jul 2024 18:48:30 +0100 Subject: [PATCH 13/13] Include ignored tests in the ci --- .github/workflows/main.yml | 2 +- README.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 155a3e1..69498e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,6 @@ jobs: - name: Run rustfmt run: cargo fmt --check - name: Unit tests - run: cargo test -- --ignored --nocapture + run: cargo test -- --include-ignored --nocapture - name : Clippy run: cargo clippy --all-features diff --git a/README.md b/README.md index 759a747..2a60ee1 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ RUSTFLAGS='--cfg=web_sys_unstable_apis' trunk serve --release `cargo test` +Run ignored tests: + +`cargo test -- --include-ignored` + ## References ### Opcodes