// SPDX-License-Identifier: MIT //! The test programs natively in the harness: the reference's rungs 2 and 3. //! //! programs SPCTEST_DIR CPUTEST_DIR //! //! Rung 2 is the reference's `tests/test_spctest.py`: gilyon's three spctest //! programs (`spc_tests0.bin`-`2`, cut from the ROM by the reference's //! scripts/build_referees.py) under `run_spctest`, which plays the S-CPU side of //! the port protocol: every test from 0 to $557 in order, none failing. Rung 3 //! is its `tests/test_cpu_tests.py`: PeterLemon's seven CPU tests, raw and as //! snapshots, under `run_cpu_test`: every sub-test writes $0n, none $8n. //! //! One line per run, in the form `scripts/reference_programs.py` prints from the //! reference; the rung compares the two outputs. Exit status 1 if any fails. use std::path::Path; use spc700::harness::{run_cpu_test, run_spctest}; const TESTS: u32 = 1368; // $558: tests.txt holds Test 0000 to Test 0557, numbered in hex const SUBTESTS: [(&str, u8); 7] = [ ("ADC", 26), ("AND", 28), ("DEC", 14), ("EOR", 26), ("INC", 14), ("ORA", 28), ("SBC", 26), ]; fn main() { let args: Vec = std::env::args().skip(1).collect(); if args.len() != 2 { eprintln!("usage: programs SPCTEST_DIR CPUTEST_DIR"); std::process::exit(2); } let (spctest, cputest) = (Path::new(&args[0]), Path::new(&args[1])); let programs: Vec> = (0..3) .map(|n| std::fs::read(spctest.join(format!("spc_tests{n}.bin"))).expect("spctest program")) .collect(); let report = run_spctest(&programs, 400_000_000); let mut ok = report.failure.is_none() && report.programs == 3 && report.tests.iter().copied().eq(0..TESTS); println!( "spctest: {} programs, {} tests (last {}), {} cycles, {} instructions, failure {}: {}", report.programs, report.tests.len(), report .tests .last() .map_or("none".into(), |t| format!("{t:04X}")), report.cycles, report.instructions, report.failure.map_or("none".into(), |f| format!("{f:?}")), if ok { "pass" } else { "FAIL" } ); for (name, subtests) in SUBTESTS { for form in ["raw", "snapshot"] { let path = if form == "raw" { cputest.join(name).join(format!("SPC700{name}.spc")) } else { cputest.join(format!("SPC700{name}.spc")) }; let program = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); let report = run_cpu_test(&program, 400_000_000); let pass = report.reason == "self-branch" && report.failures().is_empty() && report.passes() == (1..=subtests).collect::>(); let codes: Vec = report.codes.iter().map(|c| format!("{c:02X}")).collect(); println!( "SPC700{name} {form}: {} after {} cycles, {} instructions; codes {}: {}", report.reason, report.cycles, report.instructions, codes.join(" "), if pass { "pass" } else { "FAIL" } ); ok &= pass; } } std::process::exit(if ok { 0 } else { 1 }); }