// SPDX-License-Identifier: MIT //! The trace and beam watch on a synthetic BIOS, and the import boundaries //! (a5200-python's tests/test_debug.py and tests/test_boundaries.py, transcribed; the PyPy //! attribute guard has no Rust counterpart). mod common; use a5200::debug::{trace_jsonl, BeamWatch}; use common::fake_board; use serde_json::Value; #[test] fn trace_lines_carry_bus_events() { // STA $D40A (WSYNC) ; JMP $F800 let mut cpu = fake_board(&[0x8D, 0x0A, 0xD4, 0x4C, 0x00, 0xF8], None); let mut out = Vec::new(); trace_jsonl(&mut cpu, &mut out, 4).unwrap(); let text = String::from_utf8(out).unwrap(); let lines: Vec = text .lines() .map(|l| serde_json::from_str(l).unwrap()) .collect(); assert_eq!(lines.len(), 4); let kinds: Vec = lines .iter() .flat_map(|line| line["bus"].as_array().unwrap().iter()) .map(|event| event[1].as_str().unwrap().to_string()) .collect(); assert!(kinds.iter().any(|k| k == "R") && kinds.iter().any(|k| k == "W")); assert!(cpu.bus.bus_observers.is_empty()); } #[test] fn beam_and_register_watch() { let mut cpu = fake_board(&[0x8D, 0x18, 0xC0, 0x4C, 0x00, 0xF8], None); // STA COLPF2 let mut watch = BeamWatch::new(&mut cpu); assert!(watch.run_to_beam(&mut cpu, 100, 50, 10_000_000)); assert_eq!(cpu.bus.antic.vcount, 100); watch.watch_register("gtia", 0x18); let hit = watch.run_to_register_write(&mut cpu, 10_000_000); assert!(hit.is_some_and(|h| (h.0, h.1) == ("gtia", 0x18))); } fn uses(path: &str) -> Vec { let text = std::fs::read_to_string(format!("{}/{path}", env!("CARGO_MANIFEST_DIR"))).unwrap(); text.lines() .filter(|l| l.trim_start().starts_with("use ")) .map(|l| l.trim().to_string()) .collect() } #[test] fn antic_and_gtia_import_nothing_from_the_board() { for chip in ["src/antic.rs", "src/gtia.rs"] { for line in uses(chip) { assert!(!line.contains("crate::"), "{chip}: {line}"); } } } #[test] fn cartridge_package_does_not_import_the_board() { for file in [ "src/cartridge/mod.rs", "src/cartridge/mappings.rs", "src/cartridge/walk.rs", ] { for line in uses(file) { assert!( !line.contains("crate::") && !line.contains("super::"), "{file}: {line}" ); } } }