From cf2d0cfb0bebf47c32821ac7e1b89dfd2505a86d Mon Sep 17 00:00:00 2001 From: elforeign <324243036+elforeign@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:54:07 -0600 Subject: [PATCH] isa, shaders: test that coverage totals and documented counts match FORMS At 5450612 the generated table held 1,460 forms while the docs and PR said 1,465; 1493dcf added the five literal-only forms the LLVM oracle found, so the table, xenora shaders coverage (text and JSON) and docs now agree on 1,465 across 21 families. Nothing checked that they stay in step. Test the JSON and text totals and per-family sum against FORMS and SEMANTIC_FORMS, and the counts stated in docs/research/rdna2.md and CHANGELOG.md against FORMS.len(). The branch inspection fix for #183 is the previous commit 9640269. Fixes #183, fixes #184 Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> --- crates/cli/src/shaders.rs | 65 ++++++++++++++++++++++++++++++++++----- crates/isa/tests/meta.rs | 27 ++++++++++++++++ 2 files changed, 84 insertions(+), 8 deletions(-) diff --git a/crates/cli/src/shaders.rs b/crates/cli/src/shaders.rs index e2f2c6c..dfe6bb1 100644 --- a/crates/cli/src/shaders.rs +++ b/crates/cli/src/shaders.rs @@ -34,12 +34,19 @@ fn semantic(family: EncodingFamily) -> usize { /// with their length; "semantic" forms decode into executable instructions. /// Reference, Metal and native GPU evidence per form stays in docs/status.toml. fn coverage(json: bool) -> ExitCode { + print!("{}", coverage_report(json)); + ExitCode::SUCCESS +} + +fn coverage_report(json: bool) -> String { + use std::fmt::Write as _; let rows: Vec<_> = meta::inventory() .into_iter() .map(|(family, discovered)| (family, discovered, semantic(family))) .collect(); let total: usize = rows.iter().map(|row| row.1).sum(); let supported: usize = rows.iter().map(|row| row.2).sum(); + let mut out = String::new(); if json { let families: Vec = rows .iter() @@ -50,20 +57,31 @@ fn coverage(json: bool) -> ExitCode { ) }) .collect(); - println!( + writeln!( + out, "{{\"architecture\":\"gfx1030\",\"source_sha256\":\"{}\",\"discovered\":{total},\"semantic\":{supported},\"families\":[{}]}}", meta::SOURCE_SHA256, families.join(",") - ); + ) + .unwrap(); } else { - println!("{:<10} {:>10} {:>9}", "family", "discovered", "semantic"); + writeln!( + out, + "{:<10} {:>10} {:>9}", + "family", "discovered", "semantic" + ) + .unwrap(); for (family, discovered, semantic) in &rows { - println!("{:<10} {discovered:>10} {semantic:>9}", family.name()); + writeln!(out, "{:<10} {discovered:>10} {semantic:>9}", family.name()).unwrap(); } - println!("{:<10} {total:>10} {supported:>9}", "total"); - println!("Semantic forms decode for the operand subsets in docs/status.toml only."); + writeln!(out, "{:<10} {total:>10} {supported:>9}", "total").unwrap(); + writeln!( + out, + "Semantic forms decode for the operand subsets in docs/status.toml only." + ) + .unwrap(); } - ExitCode::SUCCESS + out } fn inspect(path: &str) -> ExitCode { @@ -156,7 +174,38 @@ fn listing(bytes: &[u8]) -> Listing { #[cfg(test)] mod tests { - use super::listing; + use super::{coverage_report, listing}; + use xenora_decoder::SEMANTIC_FORMS; + use xenora_isa::meta::{EncodingFamily, FORMS}; + + #[test] + fn coverage_totals_match_the_generated_table() { + let json = coverage_report(true); + let totals = format!( + "\"discovered\":{},\"semantic\":{},\"families\":[", + FORMS.len(), + SEMANTIC_FORMS.len() + ); + assert!(json.contains(&totals), "{json}"); + let families: Vec = json + .split("{\"family\":") + .skip(1) + .map(|row| { + let count = row.split("\"discovered\":").nth(1).unwrap(); + count[..count.find(',').unwrap()].parse().unwrap() + }) + .collect(); + assert_eq!(families.len(), EncodingFamily::ALL.len()); + assert_eq!(families.iter().sum::(), FORMS.len()); + let text = coverage_report(false); + let total = format!( + "{:<10} {:>10} {:>9}\n", + "total", + FORMS.len(), + SEMANTIC_FORMS.len() + ); + assert!(text.contains(&total), "{text}"); + } fn program(words: &[u32]) -> Vec { words.iter().flat_map(|word| word.to_le_bytes()).collect() diff --git a/crates/isa/tests/meta.rs b/crates/isa/tests/meta.rs index 6989782..0c70237 100644 --- a/crates/isa/tests/meta.rs +++ b/crates/isa/tests/meta.rs @@ -154,6 +154,33 @@ fn every_form_identifies_as_itself() { assert_eq!(total, FORMS.len()); } +#[test] +fn documented_form_counts_match_the_generated_table() { + let count = FORMS.len(); + let count = format!("{},{:03}", count / 1000, count % 1000); + let families = EncodingFamily::ALL.len(); + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + for (file, claim) in [ + ( + "docs/research/rdna2.md", + format!("{count} forms in {families} encoding families"), + ), + ( + "CHANGELOG.md", + format!("{count} base forms across {families} encoding families"), + ), + ] { + let text = fs::read_to_string(root.join(file)).unwrap(); + assert!( + text.split_whitespace() + .collect::>() + .join(" ") + .contains(&claim), + "{file} must state \"{claim}\"" + ); + } +} + #[test] fn first_word_opcode_table_agrees_with_full_metadata() { use xenora_isa::{BUFFER_LOAD_DWORD, S_ENDPGM, V_ADD_F32, V_ADD_NC_U32, V_MOV_B32};