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>
This commit is contained in:
elforeign committed 2026-11-24 00:54:07 -06:00
1 parent 69812d97c0
commit cf2d0cfb0b
2 files changed
+84 -8

No files matched your search

+57 -8
View File
@@ -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<String> = 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<usize> = 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::<usize>(), 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<u8> {
words.iter().flat_map(|word| word.to_le_bytes()).collect()
+27
View File
@@ -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::<Vec<_>>()
.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};