"""Golden-manifest tests for the Connac2 container extractor. Runs against whatever MediaTek blobs exist on this host (skip otherwise). Golden values observed from linux-firmware snapshot 2026-04-20; when a value here fails against a newer snapshot, the blob changed — update the golden value *and* note it in the changelog, don't silently absorb it. """ import os import subprocess import sys import unittest from pathlib import Path REPO = Path(__file__).resolve().parent.parent FW = Path(os.environ.get('MTK_FW_DIR', '/lib/firmware/mediatek')) # Golden source of truth: dataset/history.jsonl (one record per # linux-firmware revision, sha256-keyed). Any tested blob must be a known # revision and its parse must match the recorded metadata. A new upstream # build therefore fails here until the dataset is refreshed (by design): # # python3 tools/fw_history.py firmware/linux-firmware -o dataset/history.jsonl import json HISTORY = json.loads( '[' + ','.join(l for l in (REPO / 'dataset' / 'history.jsonl').read_text().splitlines() if l) + ']') BY_SHA = {r['sha256']: r for r in HISTORY} def _expected(path: Path, sha: str): rec = BY_SHA.get(sha) if rec is None: raise AssertionError( f'{path.name}: sha {sha} is not a known linux-firmware revision ' f'in dataset/history.jsonl — refresh the dataset (see comment ' f'above) or verify the blob provenance') return rec def parse(path: Path, out: Path) -> dict: out.mkdir(parents=True, exist_ok=True) sys.path.insert(0, str(REPO / 'tools')) import mtk_fw_extract as x return (x.carve_patch if 'patch' in path.name else x.carve_ram)(path, out) class LayoutClosure(unittest.TestCase): """sum(region.len) + hidden trailer + table + trailer == file size.""" def test_closure(self): blobs = sorted(FW.glob('mt79*_wm.bin')) + sorted(FW.glob('mt79*_wa.bin')) if not blobs: self.skipTest('no mediatek blobs on this host') import struct T = struct.Struct('<5B2s10s15sI') R = struct.Struct('