* Initial plan * Fix max_decode_depth to properly control decoder hierarchy and port generation Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * Fix test that relied on old depth behavior Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * Update documentation for max_decode_depth parameter Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * fix format * Add variable_depth RDL file and smoke tests for max_decode_depth parameter Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * Add variable depth tests for APB3 and AXI4-Lite CPUIFs Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> * fix * fix * bump --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com>
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""Pytest fixtures for unit tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
collect_ignore_glob = ["cocotb/*/smoke/test_register_access.py", "cocotb/*/smoke/test_variable_depth.py"]
|
|
|
|
import os
|
|
from collections.abc import Callable
|
|
from pathlib import Path
|
|
from tempfile import NamedTemporaryFile
|
|
|
|
import pytest
|
|
from systemrdl import RDLCompileError, RDLCompiler # type:ignore
|
|
from systemrdl.node import AddrmapNode
|
|
|
|
_SHIM_DIR = Path(__file__).resolve().parents[1] / "tools" / "shims"
|
|
os.environ["PATH"] = f"{_SHIM_DIR}{os.pathsep}{os.environ.get('PATH', '')}"
|
|
|
|
|
|
@pytest.fixture
|
|
def compile_rdl(tmp_path: Path) -> Callable[..., AddrmapNode]:
|
|
"""Compile inline SystemRDL source and return the elaborated root node.
|
|
|
|
Parameters
|
|
----------
|
|
tmp_path:
|
|
Temporary directory provided by pytest.
|
|
"""
|
|
|
|
def _compile(
|
|
source: str,
|
|
*,
|
|
top: str | None = None,
|
|
defines: dict[str, str] | None = None,
|
|
include_paths: list[Path | str] | None = None,
|
|
) -> AddrmapNode:
|
|
compiler = RDLCompiler()
|
|
# Use delete=False to keep the file around after closing
|
|
with NamedTemporaryFile("w", suffix=".rdl", dir=tmp_path, delete=False) as tmp_file:
|
|
tmp_file.write(source)
|
|
tmp_file.flush()
|
|
|
|
try:
|
|
compiler.compile_file(
|
|
tmp_file.name,
|
|
incl_search_paths=(list(map(str, include_paths)) if include_paths else None),
|
|
defines=defines,
|
|
)
|
|
if top is not None:
|
|
root = compiler.elaborate(top) # type:ignore
|
|
return root.top
|
|
root = compiler.elaborate() # type:ignore
|
|
return root.top
|
|
except RDLCompileError:
|
|
# Print error messages if available
|
|
if hasattr(compiler, "print_messages"):
|
|
compiler.print_messages() # type:ignore
|
|
raise
|
|
|
|
return _compile
|