"""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')) # filename -> (chip_id, eco, n_region, hidden_trailer_string_or_None) # Golden values observed from linux-firmware HEAD (2026-06-19 tree: # mt7981/mt7986 = 20260515 builds; mt7915/mt7916 = 2022/2024 builds, # unchanged since). When a value here fails against a newer snapshot, the # blob changed — update the golden *and* record the diff (docs/reports/). GOLDEN_WM = { 'mt7981_wm.bin': (0x14, 0, 11, 't-neptune-main-mt7915-1953-MT7981_MP2111_IMP-20260515121129'), 'mt7986_wm.bin': (0x0f, 0, 11, 't-neptune-main-mt7915-1953-MT7986_MP2111_IMP-20260515120228'), 'mt7916_wm.bin': (0x13, 0, 9, 't-neptune-main-mt7915-1953-MT7916_MP2111_IMP-20240823170147'), 'mt7915_wm.bin': (0x0b, 1, 7, 't-neptune-mp-mt7915-2045-MT7915_MP_7_4_2045-20220929103802'), } GOLDEN_WA = { 'mt7981_wa.bin': (0x00, 0, 3, None), 'mt7986_wa.bin': (0x00, 0, 3, None), 'mt7916_wa.bin': (0x00, 0, 3, None), 'mt7915_wa.bin': (0x00, 1, 3, None), } 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('