From 164de9ceaf496d1e69294db53cbed45881d168e1 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:54:44 -0500 Subject: [PATCH 1/2] decomp(savedata): hasChannel in C (asm placeholder removed) (worker d968b5f2) (#1350) --- docs/asm-inventory.md | 5 +- src/system/iplSaveDataManager.cpp | 117 ++++++---------------- tools/decomp-assist/a2c-hasch.attempts.md | 84 ++++++++++++++++ 3 files changed, 118 insertions(+), 88 deletions(-) create mode 100644 tools/decomp-assist/a2c-hasch.attempts.md diff --git a/docs/asm-inventory.md b/docs/asm-inventory.md index 67f1b871..97af1957 100644 --- a/docs/asm-inventory.md +++ b/docs/asm-inventory.md @@ -1,7 +1,7 @@ # Assembly inventory -4.3U, 2026-10-08. 166 functions contain 168 assembly -bodies/blocks: 162 ORIGINAL functions and 4 PLACEHOLDER functions. +4.3U, 2026-10-09. 165 functions contain 167 assembly +bodies/blocks: 162 ORIGINAL functions and 3 PLACEHOLDER functions. Run `python3 tools/check_asm_inventory.py`. Completion requires exit 0, complete coverage and zero placeholders. The checker also rejects stale/duplicate rows, @@ -186,7 +186,6 @@ found. Historical logs absent from this branch have commit IDs and excerpts in | `src/BS2/BS2Start.c` | `__start` | ORIGINAL | Runs before the C stack and ABI registers exist; constructs the initial stack. | | `src/BS2/BS2Start.c` | `__init_registers` | ORIGINAL | Initializes GPRs, r1, r2, and r13 for the C runtime. | | `src/scene/nakamuraTest/gamespy/common/gsPlatformUtil.c` | `GetTicks` | ORIGINAL | Inactive PS2 branch reads the CP0 Count register with mfc0 $9. | -| `src/system/iplSaveDataManager.cpp` | `Manager::hasChannel` | PLACEHOLDER | Title-slot search; best C 71/71 instructions, 12 mask/base register differences, [sol-ph1](../tools/decomp-assist/sol-ph1.attempts.md). | | `src/system/iplSystem.cpp` | `System::warning_run` | PLACEHOLDER | Scene/render calls; best C 98.66477%, 176/176 instructions, 47 saved-register differences, [rx17][rx17]. | | `src/system/rvl_dec.c` | `Rvl_decode` | ORIGINAL | Direct beq decoder entries preserve r3/r4 and LR; lis/ori builds the format signatures. | | `src/system/rvl_dec.c` | `Rvl_decode_szs` | ORIGINAL | Original SZS decoder convention: nofralloc, r0 retains output length, fixed r3..r10/CTR byte-copy pipeline. | diff --git a/src/system/iplSaveDataManager.cpp b/src/system/iplSaveDataManager.cpp index 1f1628e2..56d1eac8 100644 --- a/src/system/iplSaveDataManager.cpp +++ b/src/system/iplSaveDataManager.cpp @@ -15,9 +15,6 @@ #include "config.h" -extern "C" void _savegpr_22(); -extern "C" void _restgpr_22(); - namespace ipl { // clang-format off #define DISK_CHANNEL CHANNEL_INFO(channel::PRIMARY_TYPE_DISK, channel::SECONARY_TYPE_SYSTEM, SCENE_DISK_CHANNEL, 0) @@ -136,90 +133,40 @@ namespace ipl { return file->isFinished(); } - asm ESTitleId Manager::hasChannel(register ESTitleId titleId, register int* outIndex, register int* outPage) const { - nofralloc - stwu r1, -0x30(r1) - mflr r0 - stw r0, 0x34(r1) - addi r11, r1, 0x30 - bl _savegpr_22 - li r0, -1 - and. r0, r5, r0 - beq hasChannel_L1 - li r10, -1 - li r9, -1 - b hasChannel_L2 - hasChannel_L1: - li r10, -1 - li r9, 0 - hasChannel_L2: - li r4, -0x100 - li r0, -1 - and r12, r10, r4 - li r31, 0 - and r11, r9, r0 - li r27, 0 - li r28, 0xc - hasChannel_L3: - add r0, r3, r27 - li r30, 0 - li r26, 0 - mtctr r28 - hasChannel_L4: - add r22, r0, r26 - lbz r4, 0x30(r22) - cmplwi r4, 3 - bne hasChannel_L5 - lwz r4, 0x3c(r22) - lwz r29, 0x38(r22) - and r23, r4, r10 - and r22, r29, r9 - xor r23, r6, r23 - xor r22, r5, r22 - or. r22, r23, r22 - beq hasChannel_L6 - and r22, r4, r12 - and r24, r6, r12 - and r23, r29, r11 - and r25, r5, r11 - xor r24, r22, r24 - xor r25, r23, r25 - or. r25, r24, r25 - bne hasChannel_L5 - clrlwi r25, r6, 0x18 - xori r25, r25, 0x41 - cmpwi r25, 0 - bne hasChannel_L5 - hasChannel_L6: - cmpwi r7, 0 - beq hasChannel_L7 - stw r31, 0(r7) - hasChannel_L7: - cmpwi r8, 0 - beq hasChannel_L8 - stw r30, 0(r8) - hasChannel_L8: - mr r3, r29 - b hasChannel_L9 - hasChannel_L5: - addi r30, r30, 1 - addi r26, r26, 0x10 - bdnz hasChannel_L4 - addi r31, r31, 1 - addi r27, r27, 0xc0 - cmpwi r31, 4 - blt hasChannel_L3 - li r4, 0 - li r3, 0 - hasChannel_L9: - addi r11, r1, 0x30 - bl _restgpr_22 - lwz r0, 0x34(r1) - mtlr r0 - addi r1, r1, 0x30 - blr + #pragma push + #pragma opt_loop_invariants off + ESTitleId Manager::hasChannel(ESTitleId titleId, int* outIndex, int* outPage) const { + ESTitleId mask; + if (ES_TITLE_TYPE(titleId) != 0) { + mask = 0xFFFFFFFFFFFFFFFFULL; + } else { + mask = 0x00000000FFFFFFFFULL; + } + ESTitleId regionMask = mask & TITLE_NOREGION_MASK; + int page = 0; + do { + for (int index = 0; index < MAX_CHANNEL_INDEX; index++) { + if (mData.chanInfo[page][index].primaryType == channel::PRIMARY_TYPE_CHANNEL) { + ESTitleId stored = ES_TITLE_ID(mData.chanInfo[page][index].titleType, mData.chanInfo[page][index].titleCode); + if ((stored & mask) == titleId || + ((stored & regionMask) == (titleId & regionMask) && (ESTitleId)(u8)titleId == TITLE_REGION_ALL)) { + if (outIndex) { + *outIndex = page; + } + if (outPage) { + *outPage = index; + } + return stored; + } + } + } + page++; + } while (page < MAX_CHANNEL_PAGE); + return 0; } + #pragma pop + int Manager::getNumValidChannel() const { // MWCC needs this page view to preserve the original channel-base calculation. const ChannelSlot* channelSlot; diff --git a/tools/decomp-assist/a2c-hasch.attempts.md b/tools/decomp-assist/a2c-hasch.attempts.md new file mode 100644 index 00000000..4a452ba1 --- /dev/null +++ b/tools/decomp-assist/a2c-hasch.attempts.md @@ -0,0 +1,84 @@ +# a2c-hasch attempts + +Worktree data-d9; branch agent/w1009/a2c-hasch; base 85d653b0. +Full initial 43U build passed. DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d. +Owned function: hasChannel__Q33ipl8savedata7ManagerCFUxPiPi. + +Read opus-common.md, AGENTS.md, opus-sdm, opus-iro, sol-ph1, and o3-idct evidence. +Prior best C: 12 differences, 71/71 instructions, 284/284 bytes. +Prior failures covered mask spelling, helpers, parameter copies, loop forms, and eight declaration orders. +Avoid repeating those sweeps. New method: full target-register map and declaration-order simulation +restricted to implementable locals, then restructure only if captured compiler temporaries require it. +The older simulated exact allocation moved compiler temporaries, so it was diagnostic only. + +## Capture and legal declaration search + +Corrected a missing closing brace during seed extraction; the failed compile was not measured as C. +Fresh seed build: 12/71 differences, 284/284 bytes; pool identical 3/3. +Baseline completion checker: DECOMPLETE_OK. + +Two initial --args captures failed with WRITE_UNMAPPED at 40495a because --args disables automatic +sjiswrap detection. README identifies this exact failure. Recaptured through Ninja flags with sjiswrap. +Fresh capture: /mnt/drive2/projects/wii-ipl-workers/_mwdbg/runs/a2c-hasch-03. +regsim reproduces 53/53 virtual registers. The supplied vmap.py cannot align this function's +save/restore pseudo-instructions: 1 mapped register, 39 unmatched definitions. Used the existing +vmap2.py alignment fallback; it maps 29 registers across 60 instructions with unambiguous wants. + +Exhaustive permutations of legal named locals stored/index/page leave all five allocation misses. +The supplied declsearch2.py confirms cost 5. The row-base virtual r45 is @17360; full-mask halves +r46/r47 are @17357. Diagnostic relabel r45 -> 48 alone gives all 29/29 target assignments, +including the two mask-constant registers. This is a required creation-order change, not a +declaration recipe. New hypothesis: preserve a real page view or mask locals so their source +creation order becomes controllable. + +Moving the full-mask conditional inside the page loop: 53/71; inside the channel block: 50/71. +Plain SInfo row pointers add a base adjustment: 60/72, 70/72, 67/72. +Explicit nonzero if/else gives 12/71 but moves the row base to the desired r0 and swaps full/region +mask registers; capture this form to distinguish real locals from hoisted temporaries. +Scoped opt_lifetimes, opt_propagation, opt_strength_reduction off: each 12/71. +Scoped opt_loop_invariants off: 29/71. Scoped optimization_level 3: 35/71. Restored seed. + +## Exact source + +Explicit mask branches preserve mask as a named local; the region-mask expression remains an +IRO temporary when declared in the channel block. Legal declaration search stays at 4 mismatches. +A ChannelPage view makes the row pointer named, but leaves the region temporary ahead of both +row and full mask; legal search stays at 4 mismatches. Restored the experimental header fields. +All row-view candidates were rejected: 14-20 differing instructions, no lasting header edit. + +Computing regionMask once outside the loops preserves a real invariant, but default IRO also +hoists titleId & regionMask and changes the instruction stream, 45/71 differences. +A scoped opt_loop_invariants off with this source prevents that extra hoist and produces +0/71 differing instructions, 284/284 bytes, on the first compile. Scoped ppc_iro_level 1 is +also exact, but the narrower loop-invariant switch is retained. Adding opt_common_subs off +is unnecessary. The earlier declaration-only proof identified the temporary-creation blocker; +the accepted source expresses the invariant directly and uses the owner-authorized scoped pragma. + +Removed the hasChannel inventory row and decremented function/block/placeholder counts. +Removed the two external save/restore declarations that only the former assembly body used. + +## Final validation + +Final formatted source rebuilt successfully after removing assembly-only declarations. +Exact-name objdiff: hasChannel fuzzy_match_percent 100.0, size 284. +odiff: 0/71 differing; ctxdiff: 71/71 instructions, diffs 0. +Pool identical 3/3; the complete .data bytes are identical, 184/184. +Unit: 35/35 objdiff and instruction-exact functions; code 7172/7172; data 968/968; +linked code 7172. .data, .rodata, .sdata, and .text all 100.0. + +Full 43U build passed. main.dol SHA1 26116613f624061ba99c8d1a299aaa6efa85670d. +Fresh build/43U/report.json passed check_decomp_complete.py: DECOMPLETE_OK. +Gate command: gate.py src/system/iplSaveDataManager --base 85d653b0 --quick. +GATE PASS: zero regressions, zero forbidden additions, zero readability warnings. +The gate reports the scoped optimization pragma for parent review. Target comparison instructions +37 and 39 mask the input title inside the loop; default IRO with an explicit regionMask hoists +those two computations to the preheader. The scoped switch preserves those target lifetimes. +Evidence: /tmp/a2c-hasch-gate.log and /tmp/a2c-hasch-final-build.log. + +check_asm_inventory.py still returns 1 solely for the three other owned placeholders: +TMCJPEGDEC_err_restart, CNTCACHEClear, and System::warning_run. There are no missing/stale rows +or coverage failures. Counts match the updated header: 165 functions, 167 bodies/blocks, +162 ORIGINAL, 3 PLACEHOLDER. hasChannel no longer contains assembly. + +Experimental header changes and generated dependency files were removed. Only the function, +its inventory removal/counts, and this log are retained. No push, PR, merge, or rebase. -- 2.49.1 From c19151d83e91ee01a21923270b2e60afa96e454e Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:55:25 -0500 Subject: [PATCH 2/2] fix(checker): enforce section coverage and strict assembly inventory --- .github/workflows/build.yml | 3 +- AGENTS.md | 5 +- tools/check_decomp_complete.py | 55 +++++++--- .../completion-sections-attempts.md | 36 +++++++ tools/test_workflow_guards.py | 102 +++++++++++++++++- 5 files changed, 184 insertions(+), 17 deletions(-) create mode 100644 tools/decomp-assist/completion-sections-attempts.md diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f0f4c91..ec6e95fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: workflow_dispatch: inputs: require_complete: - description: Fail unless 43U code, data, functions, units, and links are all 100% + description: Fail unless 43U binary matches completely and source inventory is complete required: false default: false type: boolean @@ -79,6 +79,7 @@ jobs: python tools/check_decomp_complete.py \ build/${{ matrix.version }}/report.json \ --dol build/${{ matrix.version }}/main.dol + python tools/check_asm_inventory.py # Upload map files - name: Upload map diff --git a/AGENTS.md b/AGENTS.md index 93f2ba55..971cf2b9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -94,10 +94,11 @@ The final completion assertion is machine-checkable: ``` python3 tools/check_decomp_complete.py build/43U/report.json \ --dol build/43U/main.dol +python3 tools/check_asm_inventory.py ``` -It must pass before claiming full completion. GitHub Actions runs the same -assertion when manually dispatched with `require_complete=true`. +Both checks must pass before claiming full completion. GitHub Actions runs the same +assertions when manually dispatched with `require_complete=true`. Normal push and pull-request builds publish progress without failing on the current incomplete state. Use the manual `require_complete=true` dispatch for the terminal all-100% gate. diff --git a/tools/check_decomp_complete.py b/tools/check_decomp_complete.py index 6c8ceee3..80fabd84 100644 --- a/tools/check_decomp_complete.py +++ b/tools/check_decomp_complete.py @@ -15,6 +15,10 @@ EXPECTED_TOTAL_DATA = 1832684 EXPECTED_TOTAL_FUNCTIONS = 12563 INTEGER_PATTERN = re.compile(r"-?(0|[1-9][0-9]*)\Z") CODE_SECTIONS = frozenset({".text", ".init"}) +DATA_SECTIONS = frozenset({ + ".bss", "extab", "extabindex", ".ctors", ".ctors$10", ".dtors", + ".rodata", ".data", ".sdata2", ".sbss2", ".sdata", ".sbss", +}) # objdiff accumulates the aggregate fuzzy_match_percent in 32-bit floats over every code byte, # so a fully matched report can read 99.9998 instead of 100.0. Aggregates are accepted within # this tolerance only when every code byte is counted as matched; units, sections and functions @@ -132,6 +136,43 @@ def check_complete_measures(measures, label, failures, aggregate=False): percent(measures, "fuzzy_match_percent", f"{label} fuzzy_match_percent", failures) +def check_sections(sections, measures, name, failures): + if not isinstance(sections, list): + failures.append(f"{name}: missing sections") + return + sizes = {"code": 0, "data": 0} + names = set() + for section in sections: + if not isinstance(section, dict): + failures.append(f"{name}: invalid section entry") + continue + section_name = section.get("name") + label = f"{name} section {section_name}" + if not isinstance(section_name, str) or section_name not in CODE_SECTIONS | DATA_SECTIONS: + failures.append(f"{label}: unknown section name") + continue + if section_name in names: + failures.append(f"{label}: duplicate section") + names.add(section_name) + # Protobuf JSON omits a zero-valued size. objdiff counts data sections in + # full, but code measures exclude ignored/deduplicated function symbols. + size = count({"size": section.get("size", 0)}, "size", label, failures) + if size is not None: + sizes["code" if section_name in CODE_SECTIONS else "data"] += size + if "fuzzy_match_percent" in section: + percent(section, "fuzzy_match_percent", label, failures) + elif section_name in CODE_SECTIONS: + failures.append(f"{label}: missing fuzzy_match_percent") + for kind in ("code", "data"): + total = count({f"total_{kind}": measures.get(f"total_{kind}", 0)}, + f"total_{kind}", name, failures) + if total is not None and ( + sizes[kind] < total if kind == "code" else sizes[kind] != total + ): + relation = "<" if kind == "code" else "!=" + failures.append(f"{name} section {kind} coverage: {sizes[kind]} {relation} {total}") + + def key_for(value): return type(value).__name__, repr(value) @@ -215,19 +256,7 @@ def check_report(report): equal(unit_measures, "matched_functions", "total_functions", f"{name} function match", failures) percent(unit_measures, "matched_functions_percent", f"{name} function percent", failures) - sections = unit.get("sections") - if not isinstance(sections, list): - failures.append(f"{name}: missing sections") - else: - for section in sections: - if not isinstance(section, dict): - failures.append(f"{name}: invalid section entry") - continue - section_name = section.get("name", "") - if "fuzzy_match_percent" in section: - percent(section, "fuzzy_match_percent", f"{name} section {section_name}", failures) - elif isinstance(section_name, str) and section_name in CODE_SECTIONS: - failures.append(f"{name} section {section_name}: missing fuzzy_match_percent") + check_sections(unit.get("sections"), unit_measures, name, failures) functions = unit.get("functions", []) if total_functions is not None and total_functions > 0: diff --git a/tools/decomp-assist/completion-sections-attempts.md b/tools/decomp-assist/completion-sections-attempts.md new file mode 100644 index 00000000..ad07a9a3 --- /dev/null +++ b/tools/decomp-assist/completion-sections-attempts.md @@ -0,0 +1,36 @@ +# Strict completion section coverage + +Base: c3dd1c08c04a38975b63dded77a7aef6fce385f3 (rebased from aed62d8530993250fe0237e5adfd3b5a4d811020). +No source or build inputs changed by this candidate. + +Schema evidence: locally available objdiff source at c02eb31dbbf9dd33577aead353bb2db62933b2af, +`objdiff-cli/src/cmd/report.rs:250-325`, emits full section sizes, sums Data/Bss +section sizes into total_data, but sums only retained function symbols into +total_code. Hidden, ignored, zero-size and previously seen global/weak symbols +are excluded from code totals. `objdiff-core/protos/report.proto` declares +ReportItem.size as proto3 uint64; a missing JSON scalar size represents zero. +43U section classification comes from `config/43U/splits.txt`; `.ctors$10` +is a constructor subsection present in the generated report. + +Consequently section data bytes must equal total_data; section code bytes must +cover total_code, not necessarily equal it. In the current report msghndlr has +28 .text bytes but only 16 counted code bytes. No unit-specific exception is +needed. Unknown/duplicate section names and malformed sizes fail closed. +A structural check cannot authenticate a report against deliberately forged +sizes/names; original report generation and the independent DOL gate remain +required. Truly zero-byte records contribute no measurable coverage. + +Validation repeated after rebasing, using an unchanged copy of the parent-generated +c3dd1c08 main 43U report and DOL, without building main: + +- All 23 preexisting guards pass; 12 new guards bring the total to 35, no skips. +- Actual report and main DOL: DECOMPLETE_OK. +- All section lists emptied only in memory: 1,695 coverage failures. +- Each of the 2,676 section records deleted individually in memory: rejected. +- Data-only and protobuf zero-sized sections accepted; deduplicated code-size + slack accepted; code/data deficits, excess data and invalid records rejected. +- Strict combined report/DOL plus live inventory: exit 1, as required. + Inventory reports 166 functions / 168 bodies, 162 ORIGINAL and 4 PLACEHOLDER: + TMCJPEGDEC_err_restart, CNTCACHEClear, Manager::hasChannel, System::warning_run. +- CI inventory command is conditional on workflow_dispatch require_complete; + ordinary progress builds do not acquire a source-completion requirement. diff --git a/tools/test_workflow_guards.py b/tools/test_workflow_guards.py index ff5b171b..0fd44380 100644 --- a/tools/test_workflow_guards.py +++ b/tools/test_workflow_guards.py @@ -9,7 +9,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) -from check_decomp_complete import check_dol, check_report, exact +from check_decomp_complete import check_dol, check_report, check_sections, exact from check_asm_inventory import check_inventory @@ -138,6 +138,69 @@ void inactive() { asm("sync"); } self.assertTrue(any("inventory:" in failure for failure in self.check()[2])) +class SectionCoverageTests(unittest.TestCase): + def check(self, sections, **measures): + failures = [] + check_sections(sections, measures, "fixture", failures) + return failures + + def test_code_and_data_coverage_pass(self): + sections = [ + {"name": ".init", "size": "16", "fuzzy_match_percent": 100.0}, + {"name": ".data", "size": "8", "fuzzy_match_percent": 100.0}, + ] + self.assertEqual(self.check(sections, total_code="16", total_data="8"), []) + + def test_data_only_and_proto_zero_sizes_pass(self): + self.assertEqual(self.check([{"name": ".sbss", "size": "64"}], total_data="64"), []) + self.assertEqual(self.check([], total_code=0, total_data=0), []) + self.assertEqual(self.check([ + {"name": ".text", "fuzzy_match_percent": 100.0}, + {"name": ".bss"}, + ], total_code=0, total_data=0), []) + + def test_deduplicated_code_is_not_required_to_equal_section_size(self): + sections = [{"name": ".text", "size": "28", "fuzzy_match_percent": 100.0}] + self.assertEqual(self.check(sections, total_code="16"), []) + self.assertEqual(self.check(sections, total_code=0), []) + + def test_deleted_or_truncated_sections_fail(self): + for sections in ([], [{"name": ".text", "size": "12", "fuzzy_match_percent": 100.0}]): + with self.subTest(sections=sections): + failures = self.check(sections, total_code="16", total_data="8") + self.assertTrue(any("section code coverage" in item for item in failures)) + self.assertTrue(any("section data coverage" in item for item in failures)) + + def test_excess_data_is_not_hidden_by_code_slack(self): + failures = self.check([ + {"name": ".text", "size": "28", "fuzzy_match_percent": 100.0}, + {"name": ".bss", "size": "12"}, + ], total_code="16", total_data="8") + self.assertIn("fixture section data coverage: 12 != 8", failures) + + def test_invalid_section_sizes_fail(self): + for size in (-1, "-1", True, 1.5, "1.5", None): + with self.subTest(size=size): + self.assertTrue(self.check([{"name": ".data", "size": size}], total_data=0)) + + def test_invalid_and_duplicate_section_names_fail(self): + for name in (None, [], "", ".unknown"): + with self.subTest(name=name): + self.assertTrue(self.check([{"name": name, "size": "8"}], total_data="8")) + section = {"name": ".data", "size": "4"} + self.assertIn("fixture section .data: duplicate section", self.check([section, section], total_data="8")) + + def test_section_scores_remain_strict(self): + for section in ( + {"name": ".text", "size": "16"}, + {"name": ".text", "size": "16", "fuzzy_match_percent": 99.9999}, + {"name": ".data", "size": "8", "fuzzy_match_percent": 99.9999}, + ): + with self.subTest(section=section): + failures = self.check([section], total_code="16", total_data="8") + self.assertTrue(any("fixture section " + section["name"] in item for item in failures)) + + class WorkflowGuardTests(unittest.TestCase): def test_exact_percent_is_strict(self): self.assertTrue(exact(100.0)) @@ -233,6 +296,43 @@ class WorkflowGuardTests(unittest.TestCase): def test_complete_report_schema_passes(self): self.assertEqual(check_report(self.complete_report()), []) + def test_empty_section_arrays_cannot_claim_completion(self): + report = self.complete_report() + for unit in report["units"]: + unit["sections"] = [] + failures = check_report(report) + self.assertTrue(any("section code coverage" in failure for failure in failures)) + self.assertTrue(any("section data coverage" in failure for failure in failures)) + + def test_deleting_one_code_or_data_section_fails(self): + for kind, section_name in (("code", ".text"), ("data", ".sbss")): + with self.subTest(kind=kind): + report = self.complete_report() + unit = next(unit for unit in report["units"] + if any(section["name"] == section_name for section in unit["sections"])) + unit["sections"] = [section for section in unit["sections"] if section["name"] != section_name] + self.assertTrue(any(f"{unit['name']} section {kind} coverage" in failure + for failure in check_report(report))) + + def test_every_current_section_is_required_for_coverage(self): + for unit in self.complete_report()["units"]: + for index, section in enumerate(unit["sections"]): + with self.subTest(unit=unit["name"], section=section["name"]): + remaining = unit["sections"][:index] + unit["sections"][index + 1:] + failures = [] + check_sections(remaining, unit["measures"], unit["name"], failures) + self.assertTrue(any("coverage" in failure for failure in failures), failures) + + def test_inventory_gate_is_only_in_strict_completion_step(self): + workflow = (Path(__file__).resolve().parents[1] / ".github/workflows/build.yml").read_text(encoding="utf-8") + steps = workflow.split(" - name: ") + inventory_steps = [step for step in steps if "python tools/check_asm_inventory.py" in step] + self.assertEqual(len(inventory_steps), 1) + step = inventory_steps[0] + self.assertTrue(step.startswith("Enforce completion gate\n")) + self.assertIn("if: matrix.version == '43U' && github.event_name == 'workflow_dispatch' && inputs.require_complete == true", step) + self.assertIn("python tools/check_decomp_complete.py", step) + def test_aggregate_fuzzy_float_rounding_passes_only_when_fully_matched(self): report = self.complete_report() report["measures"]["fuzzy_match_percent"] = 99.999886 -- 2.49.1