Устранить пересечение образа логгера с параметрами EEPROM и проверять размер BIN
This commit is contained in:
55
tests/ump_logger/test_firmware_image.py
Normal file
55
tests/ump_logger/test_firmware_image.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Exercise the release gate without TI tools or hardware."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
LIMIT = (0x3FFF - (128 + 1)) * 2
|
||||
|
||||
|
||||
def image(size):
|
||||
header = struct.pack('<H', 0x08AA) + bytes(16) + struct.pack('<HH', 0, 0x8000)
|
||||
words = (size - 30) // 2
|
||||
return header + struct.pack('<HHH', words, 0, 0x8000) + bytes(words * 2) + bytes(2)
|
||||
|
||||
|
||||
class FirmwareGateTest(unittest.TestCase):
|
||||
def check_image(self, data, success):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
source = Path(directory) / 'candidate.pending'
|
||||
output = Path(directory) / 'firmware.bin'
|
||||
source.write_bytes(data)
|
||||
result = subprocess.run([
|
||||
shutil.which('powershell') or 'pwsh', '-NoProfile', '-ExecutionPolicy', 'Bypass',
|
||||
'-File', str(ROOT / 'check_firmware.ps1'), '-Path', str(source),
|
||||
'-PublishPath', str(output),
|
||||
], capture_output=True)
|
||||
self.assertEqual(result.returncode == 0, success, result.stderr.decode(errors='replace'))
|
||||
self.assertEqual(output.exists(), success)
|
||||
if success:
|
||||
self.assertEqual(output.read_bytes(), data)
|
||||
self.assertFalse(source.exists())
|
||||
return result.stdout + result.stderr
|
||||
|
||||
def test_exact_boundary_is_accepted(self):
|
||||
self.check_image(image(LIMIT), True)
|
||||
|
||||
def test_34a95bc5_size_is_rejected(self):
|
||||
diagnostic = self.check_image(image(32518), False)
|
||||
self.assertIn(b'overlaps saved parameters by 10 bytes', diagnostic)
|
||||
|
||||
def test_missing_boot_terminator_is_rejected(self):
|
||||
self.check_image(image(100)[:-2], False)
|
||||
|
||||
def test_partial_block_is_rejected(self):
|
||||
self.check_image(image(100)[:-10], False)
|
||||
|
||||
def test_wrong_format_is_rejected(self):
|
||||
self.check_image(bytes(100), False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user