Files
esp-idf/tools/test_build_system/buildv2/test_blockdev_ioctl.py
2026-06-30 16:53:44 +02:00

69 lines
2.1 KiB
Python

# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
"""Build-system integration tests for the esp_blockdev ioctl overlap checker (cmakev2)."""
from pathlib import Path
from test_build_system_helpers import IdfPyFunc
COMP_A_DEFS_NO_OVERLAP = """\
#include "esp_blockdev.h"
ESP_BLOCKDEV_RESERVE_CMD_RANGE(comp_a, 0x10, 0x1F);
"""
COMP_B_DEFS_NO_OVERLAP = """\
#include "esp_blockdev.h"
ESP_BLOCKDEV_RESERVE_CMD_RANGE(comp_b, 0x20, 0x2F);
"""
COMP_B_DEFS_OVERLAP = """\
#include "esp_blockdev.h"
ESP_BLOCKDEV_RESERVE_CMD_RANGE(comp_b, 0x18, 0x2F);
"""
COMPONENT_CMAKELISTS = """\
idf_component_register()
idf_build_set_property(
ESP_BLOCKDEV_IOCTL_DEF_FILES
"${{CMAKE_CURRENT_LIST_DIR}}/include/{filename}"
APPEND
)
"""
def _add_component(app_path: Path, name: str, defs_content: str) -> None:
comp_dir = app_path / 'components' / name
comp_dir.mkdir(parents=True, exist_ok=True)
include_dir = comp_dir / 'include'
include_dir.mkdir(exist_ok=True)
filename = f'{name}_ioctl_defs.h'
(include_dir / filename).write_text(defs_content)
(comp_dir / 'CMakeLists.txt').write_text(COMPONENT_CMAKELISTS.format(filename=filename))
def test_ioctl_overlap_checker_passes_clean_build_v2(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
"""Build succeeds when registered ioctl ranges do not overlap (cmakev2)."""
_add_component(test_app_copy, 'comp_a', COMP_A_DEFS_NO_OVERLAP)
_add_component(test_app_copy, 'comp_b', COMP_B_DEFS_NO_OVERLAP)
ret = idf_py('build')
assert ret.returncode == 0
def test_ioctl_overlap_checker_fails_on_overlap_v2(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
"""Build fails when registered ioctl ranges overlap (cmakev2)."""
_add_component(test_app_copy, 'comp_a', COMP_A_DEFS_NO_OVERLAP)
_add_component(test_app_copy, 'comp_b', COMP_B_DEFS_OVERLAP)
ret = idf_py('build', check=False)
assert ret.returncode != 0
output = ret.stdout + ret.stderr
assert 'ioctl reservation overlap' in output
assert 'comp_a' in output
assert 'comp_b' in output