mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 19:30:43 +00:00
Counts identified, encoding-validated, declared, decoder, IR/MSL, reference and Metal evidence per encoding family, reading evidence only from docs/status.toml so registry requirements never count as results. Unrecognized inputs fail instead of being skipped. --check never writes. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
91 lines
3.9 KiB
Python
91 lines
3.9 KiB
Python
import unittest
|
|
|
|
from audit import semantic_coverage as coverage
|
|
|
|
|
|
class SemanticCoverageTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.identified = {("SOP2", "S_ADD_U32"): 0, ("SOP2", "S_SUB_U32"): 1}
|
|
self.registry = {
|
|
"schema": 1,
|
|
"form": [{
|
|
"family": "SOP2", "name": "S_ADD_U32", "opcode": 0,
|
|
"operands": "scalar", "verify": ["metal", "reference", "llvm_encoding"],
|
|
}],
|
|
"operand_rules": {
|
|
"scalar": {"family": "SOP2", "unsupported": ["two_literals"]},
|
|
},
|
|
}
|
|
|
|
def counts(self, *rows):
|
|
counts, _ = coverage.collect_coverage(
|
|
self.identified, self.registry, {("SOP2", "S_SUB_U32")},
|
|
{"instruction": list(rows)},
|
|
)
|
|
return dict(zip(coverage.COLUMNS, counts["SOP2"]))
|
|
|
|
def test_declared_without_metal_evidence_is_not_metal_verified(self):
|
|
counts = self.counts()
|
|
self.assertEqual(counts["Declared"], 1)
|
|
self.assertEqual(counts["Metal-verified"], 0)
|
|
self.assertEqual(counts["Reference-verified"], 0)
|
|
self.assertEqual(counts["Encoding-validated"], 0)
|
|
|
|
def test_status_evidence_counts_for_handwritten_form(self):
|
|
counts = self.counts({
|
|
"form": "s_sub_u32", "encoding": "SOP2, scalar operands",
|
|
"llvm": "three-way passed", "lowering": "resolved scalar state and SCC",
|
|
"reference": "implemented", "cpu": "fixture verified",
|
|
"gpu": "fixture verified on Apple M5",
|
|
})
|
|
self.assertEqual(counts, {
|
|
"Identified": 2, "Encoding-validated": 1, "Declared": 1,
|
|
"Decoder-supported": 2, "IR": 1, "MSL": 1, "Reference-verified": 1,
|
|
"Metal-verified": 1, "Unsupported operand variants": 1,
|
|
})
|
|
|
|
def test_pending_readback_does_not_count(self):
|
|
counts = self.counts({
|
|
"form": "s_add_u32", "encoding": "SOP2", "lowering": "resolved scalar state and SCC",
|
|
"reference": "implemented", "cpu": "local known-answer test passed",
|
|
"gpu": "local Apple M5 readback passed; acceptance pending",
|
|
})
|
|
self.assertEqual(counts["Metal-verified"], 0)
|
|
self.assertEqual(counts["Reference-verified"], 0)
|
|
self.assertEqual(counts["IR"], 1)
|
|
|
|
def test_stub_or_unrecognized_lowering_fails(self):
|
|
for lowering in ("stub", "MSL placeholder add", "something new"):
|
|
with self.assertRaisesRegex(ValueError, "unrecognized lowering"):
|
|
self.counts({"form": "s_add_u32", "encoding": "SOP2", "lowering": lowering})
|
|
|
|
def test_status_suffix_disambiguates_encoding(self):
|
|
forms = {("VOP2", "V_AND_B32"): 1, ("VOP3", "V_AND_B32"): 2}
|
|
self.assertEqual(coverage.status_form(
|
|
{"form": "v_and_b32_e32", "encoding": "Two VGPR sources"}, forms,
|
|
), ("VOP2", "V_AND_B32"))
|
|
with self.assertRaisesRegex(ValueError, "cannot uniquely map"):
|
|
coverage.status_form(
|
|
{"form": "v_and_b32", "encoding": "Two VGPR sources"}, forms,
|
|
)
|
|
|
|
def test_unknown_status_form_fails(self):
|
|
with self.assertRaisesRegex(ValueError, "cannot uniquely map.*s_typo"):
|
|
self.counts({"form": "s_typo", "encoding": "SOP2"})
|
|
|
|
def test_decoder_parser_rejects_unrecognized_entry(self):
|
|
header = (
|
|
"pub const SEMANTIC_FORMS: [(&str, EncodingFamily); "
|
|
"HANDWRITTEN_FORMS.len() + FORM_IDS.len()] =\n"
|
|
"const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 1] = ["
|
|
)
|
|
self.assertEqual(coverage.parse_decoder(
|
|
f'{header}\n ("S_ADD_U32", EncodingFamily::Sop2),\n];',
|
|
), {("SOP2", "S_ADD_U32")})
|
|
with self.assertRaisesRegex(ValueError, "unrecognized SEMANTIC_FORMS entry"):
|
|
coverage.parse_decoder(f"{header}\n unknown!(),\n];")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|