//! Rung 3 under `cargo test`: the 51 streams of sn76489-python's `validation/closed_box.py`, //! on each of the four parts (`tests/closed_box/*.txt`, written by //! scripts/export_closed_box.py), replayed through this core. Each trace must have the SHA-256 //! of sn76489-python's trace of the same script (`tests/closed_box/traces.sha256`, written by //! scripts/lockstep_ref.py under PyPy at the pin). scripts/rung3.sh compares the traces //! themselves when the reference is fetched. #[path = "../examples/common/trace.rs"] mod trace; use sha2::{Digest, Sha256}; #[test] fn closed_box_streams_match_the_reference_traces() { let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/closed_box"); let hashes = std::fs::read_to_string(dir.join("traces.sha256")).unwrap(); let (mut same, mut differ) = (0, vec![]); for line in hashes.lines() { let (hash, name) = line.split_once(" ").unwrap(); let script = dir.join(name.replace(".trace", ".txt")); let ours = trace::trace(&std::fs::read_to_string(&script).unwrap()); let digest: String = Sha256::digest(ours.as_bytes()) .iter() .map(|b| format!("{b:02x}")) .collect(); if digest == hash { same += 1; } else { differ.push(name.to_string()); } } println!( "{same} of {} closed-box traces identical", same + differ.len() ); assert!(differ.is_empty(), "differ: {differ:?}"); assert_eq!(same, 204); }