Files
Balsam_167/tests/firmware_identity/check_build.py
T
Andrey 5d9818291b feat: add M95M02-only GAS and EEPROM profiles
Expose the existing registers through Modbus and service CAN using one GAS provider only in M95M02 builds.
Include the EEPROM layout/driver, LOAD protection and calibration, firmware identity and shared CCS build workflow.
Add transport/profile and SCI8 validation tests, documentation and the checked M95M02 firmware image.
2026-10-09 16:17:37 +03:00

43 lines
1.7 KiB
Python

"""Independent test oracle: does this built SCI8 file contain its manifest identity?
This is a build test, not a second production protocol codec. The 12-word vector
is deliberately constructed independently of the C implementation to detect a
stale compilation unit, incorrect byte order or a mismatched pre-build JSON.
Usage: python tests/firmware_identity/check_build.py path/to/firmware.bin
"""
from datetime import datetime
import hashlib
import json
from pathlib import Path
import struct
import sys
image = Path(sys.argv[1])
data = image.read_bytes()
meta = json.loads(image.with_suffix(image.suffix + '.manifest.json').read_text())
assert hashlib.sha256(data).hexdigest() == meta['sha256'], 'Wrong file hash'
assert len(data) == meta['size_bytes'], 'Wrong image size'
stamp = datetime.fromisoformat(meta['built_at_utc'])
build_id = meta['build_id']
words = [1, *meta['version'], stamp.year, stamp.month * 256 + stamp.day,
stamp.hour * 256 + stamp.minute, stamp.second]
words += [ord(build_id[i]) * 256 + ord(build_id[i+1]) for i in range(0, 8, 2)]
expected = struct.pack('<12H', *words)
assert data[:2] == b'\xaa\x08', 'Not SCI8'
offset = 22
found = 0
while True:
count, = struct.unpack_from('<H', data, offset)
offset += 2
if not count:
break
offset += 4 # destination address, not part of the loaded section payload
end = offset + count * 2
assert end <= len(data), 'Truncated boot block'
block = data[offset:end]
found += sum(block[i:i+24] == expected for i in range(0, len(block)-23, 2))
offset = end
assert offset == len(data), 'Trailing data'
assert found == 1, f'Expected one embedded identity, found {found}'
print(f'PASS: SCI8 contains manifest identity {meta["version"]}, {build_id}, {stamp.isoformat()}')