//! The resumable runner against z80-bench's loop: ZEXALL's first million //! instructions in slices give the same totals as one slice, and inline_files //! turns the manifest's file segment into data. use std::fs; use std::path::Path; use z80_wasm::runner::Runner; fn zexall() -> Option<(String, Vec)> { let root = Path::new(env!("CARGO_MANIFEST_DIR")); let manifest = fs::read_to_string(root.join("conformance/zex/zexall.json")).unwrap(); let com = fs::read(root.join("external/zexall.com")).ok()?; Some((manifest, com)) } #[test] fn slices_and_one_run_agree() { let Some((manifest, com)) = zexall() else { eprintln!("external/zexall.com not fetched; skipping"); return; }; let files = |name: &str| (name == "zexall.com").then(|| com.clone()); let mut whole = Runner::new(&manifest, files).unwrap(); let one = whole.run(1_000_000); let mut sliced = Runner::new(&manifest, files).unwrap(); let mut output = Vec::new(); let mut last = None; for _ in 0..10 { let p = sliced.run(100_000); output.extend(p.output.clone()); last = Some(p); } let last = last.unwrap(); assert_eq!(last.instructions, 1_000_000); assert_eq!(last.instructions, one.instructions); assert_eq!(last.t_states, one.t_states); assert_eq!(output, one.output); assert!(last.stopped.is_none()); assert!(String::from_utf8_lossy(&one.output).contains("Z80 instruction exerciser")); } #[test] fn a_missing_file_is_an_error() { let manifest = r#"{"version":1,"name":"x","host":"cpm-minimal","memory":[{"address":256,"file":"nope.com"}],"initial":{"pc":256},"stop":{"max_steps":10}}"#; let error = Runner::new(manifest, |_| None).err().unwrap(); assert!(error.contains("nope.com"), "{error}"); }