Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions ebuild/build/footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,29 @@ def measure(artifact: Path, size_tool: Optional[str] = None) -> Footprint:


def board_capacity(board: Optional[str],
board_config: Optional[dict] = None
) -> Tuple[Optional[int], Optional[int]]:
"""Flash and RAM capacity for a board, or (None, None) when unknown.

A project's own board YAML wins over the reference table: `memory.flash_size`
and `memory.ram_size` are what the hardware descriptions in `hardware/board/`
already use.
"""
if board_config:
memory = board_config.get("memory") or {}
flash = _as_bytes(memory.get("flash_size"))
ram = _as_bytes(memory.get("ram_size"))
if flash or ram:
return flash, ram
if board:
found = _REFERENCE_CAPACITY.get(board.lower())
if found:
return found
return None, None
board_config: Optional[dict] = None
) -> Tuple[Optional[int], Optional[int]]:
"""Flash and RAM capacity for a board, or (None, None) when unknown.


A project's own board YAML wins over the reference table: `memory.flash_size`
and `memory.ram_size` are what the hardware descriptions in `hardware/board/`
already use.
"""
reference = _REFERENCE_CAPACITY.get(board.lower()) if board else None
if board_config:
memory = board_config.get("memory") or {}
flash = _as_bytes(memory.get("flash_size"))
ram = _as_bytes(memory.get("ram_size"))
if flash or ram:
if flash is None and reference:
flash = reference[0]
if ram is None and reference:
ram = reference[1]
return flash, ram
if reference:
return reference
return None, None


def _as_bytes(value) -> Optional[int]:
Expand Down
2 changes: 0 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ markers =
integration: end-to-end tests spanning multiple repos
cross_repo: cross-repo integration tests requiring sibling repos
qemu: tests requiring QEMU emulator (skipped if QEMU not installed)
cross_repo: cross-repo integration tests requiring sibling repos
qemu: tests requiring QEMU emulator (skipped if QEMU not installed)
needs_yaml: tests that import modules requiring pyyaml

# ── Output ───────────────────────────────────────────────────
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ def test_a_zero_or_unparseable_size_is_not_a_capacity(self):
def test_a_board_config_without_memory_falls_back(self):
assert board_capacity("stm32f4", {"board_name": "x"})[0] == 1024 * 1024

def test_a_partial_override_fills_the_rest_from_the_reference_part(self):
"""A board YAML that only overrides RAM (say, because it was fitted
with extra SRAM) should not lose the reference flash figure for the
same part."""
cfg = {"memory": {"ram_size": 320 * 1024}}
assert board_capacity("stm32f4", cfg) == (1024 * 1024, 320 * 1024)


cfg = {"memory": {"flash_size": "0x40000"}}
assert board_capacity("stm32f4", cfg) == (262144, 192 * 1024)


class TestReport:
def test_percentages_appear_only_with_a_known_capacity(self):
Expand Down