[nrf52] Run analyze-memory on the sdk-nrf toolchain (#19730)

This commit is contained in:
J. Nick Koston
2026-09-27 05:05:26 +01:00
committed by GitHub
parent 5d415ad505
commit 89ce3ab98c
6 changed files with 126 additions and 8 deletions
+8 -1
View File
@@ -7489,6 +7489,8 @@ def test_command_idedata_arduino_no_build_errors(tmp_path: Path) -> None:
[
(PLATFORM_ESP8266, Toolchain.ARDUINO, "esphome.arduino8266.toolchain"),
(PLATFORM_ESP32, Toolchain.ESP_IDF, "esphome.espidf.toolchain"),
# No native build backend, but its binutils and ELF are known
(PLATFORM_NRF52, Toolchain.SDK_NRF, "esphome.components.nrf52.toolchain"),
],
)
def test_command_analyze_memory_native_toolchains(
@@ -7708,7 +7710,12 @@ def test_command_analyze_memory_unsupported_toolchain(
mock_write_cpp.return_value = 0
mock_compile_program.return_value = 0
result = command_analyze_memory(MockArgs(), {CONF_ESPHOME: {CONF_NAME: "t"}})
# Every toolchain has analysis hooks today; drop sdk-nrf's to stand in for
# one that does not
with patch.dict(
"esphome.build_helpers.native.ANALYSIS_TOOLCHAIN_MODULES", clear=True
):
result = command_analyze_memory(MockArgs(), {CONF_ESPHOME: {CONF_NAME: "t"}})
assert result == 1
assert "analyze-memory is not supported" in caplog.text
+54
View File
@@ -0,0 +1,54 @@
"""Tests for the nRF52 sdk-nrf memory analysis hooks."""
import os
from pathlib import Path
import pytest
from esphome.components.nrf52 import toolchain
from esphome.components.nrf52.framework import TOOLCHAIN_VERSION, get_sdk_nrf_tools_path
import esphome.config_validation as cv
from esphome.const import KEY_CORE, KEY_FRAMEWORK_VERSION
from esphome.core import CORE
@pytest.fixture
def nrf52_build(tmp_path: Path) -> Path:
CORE.name = "test_device"
CORE.build_path = tmp_path / "build" / "test_device"
return CORE.build_path / ".pioenvs" / "test_device" / "zephyr"
def _set_sdk_version(version: cv.Version) -> None:
CORE.data.setdefault(KEY_CORE, {})[KEY_FRAMEWORK_VERSION] = version
def test_binutils_come_from_the_pinned_zephyr_sdk() -> None:
bin_path = (
get_sdk_nrf_tools_path()
/ "toolchains"
/ TOOLCHAIN_VERSION
/ "arm-zephyr-eabi"
/ "bin"
)
# Windows hosts get the .exe binaries (CI covers both)
suffix = ".exe" if os.name == "nt" else ""
assert toolchain.get_objdump_path() == bin_path / f"arm-zephyr-eabi-objdump{suffix}"
assert toolchain.get_readelf_path() == bin_path / f"arm-zephyr-eabi-readelf{suffix}"
def test_elf_uses_the_nested_layout_from_sdk_2_9_2(nrf52_build: Path) -> None:
_set_sdk_version(cv.Version(2, 9, 2))
# A flat image left by an older SDK must not be picked over the current
# layout, so the choice follows the version rather than what exists
(nrf52_build / "zephyr.elf").parent.mkdir(parents=True)
(nrf52_build / "zephyr.elf").write_text("")
assert toolchain.get_elf_path() == nrf52_build / "zephyr" / "zephyr.elf"
def test_elf_uses_the_flat_layout_before_sdk_2_9_2(nrf52_build: Path) -> None:
_set_sdk_version(cv.Version(2, 6, 1))
nested = nrf52_build / "zephyr" / "zephyr.elf"
nested.parent.mkdir(parents=True)
nested.write_text("")
assert toolchain.get_elf_path() == nrf52_build / "zephyr.elf"