File
Blob: scripts/test_music_partition.py
| 1 | import struct |
| 2 | import unittest |
| 3 | import csv |
| 4 | from pathlib import Path |
| 5 | from music_partition import require_music_partition |
| 6 | |
| 7 | |
| 8 | class PartitionTests(unittest.TestCase): |
| 9 | def entry(self, size=0x1000000, address=0x410000): |
| 10 | return struct.pack('<HBBII16sI', 0x50AA, 1, 0x40, address, size, b'music', 0) |
| 11 | |
| 12 | def test_only_the_installed_music_region_is_accepted(self): |
| 13 | require_music_partition(self.entry() + b'\xff' * 32) |
| 14 | for table in [b'', self.entry(0x400000), self.entry(address=0x10000), self.entry()*2]: |
| 15 | with self.assertRaises(ValueError): require_music_partition(table) |
| 16 | |
| 17 | def test_host_allocation_agrees_with_the_firmware_partition_table(self): |
| 18 | rows = csv.reader((Path(__file__).resolve().parents[1] / "firmware/partitions.csv").read_text().splitlines()) |
| 19 | music = next(row for row in rows if row[0].strip() == "music") |
| 20 | require_music_partition(self.entry(size=int(music[4], 0), address=int(music[3], 0))) |
| 21 | |
| 22 | |
| 23 | if __name__ == '__main__': |
| 24 | unittest.main() |