add utility tests

This commit is contained in:
Arnav Sacheti
2025-12-24 20:12:05 +00:00
parent bc8b2c8807
commit ad364ab8d6
3 changed files with 115 additions and 5 deletions

View File

@@ -159,22 +159,21 @@ class TestGetIndexedPath:
addrmap my_addrmap {
reg {
field {} data;
} always_reg;
} always;
};
"""
top = compile_rdl(rdl_source, top="my_addrmap")
reg_node = None
for child in top.children():
if child.inst_name == "always_reg":
if child.inst_name == "always":
reg_node = child
break
assert reg_node is not None
# With keyword filter (default) - SystemRDL identifiers can use keywords but SV can't
path = get_indexed_path(top, reg_node)
# The path should contain always_reg
assert "always_reg" in path
assert path == "always_"
# Without keyword filter
path = get_indexed_path(top, reg_node, skip_kw_filter=True)
assert path == "always_reg"
assert path == "always"

View File

@@ -0,0 +1,62 @@
from collections.abc import Callable
from systemrdl.node import AddrmapNode
from systemrdl.rdltypes.references import PropertyReference
from peakrdl_busdecoder.utils import ref_is_internal
def _find_child_by_name(node: AddrmapNode, inst_name: str):
for child in node.children():
if child.inst_name == inst_name:
return child
raise AssertionError(f"Child with name {inst_name} not found")
class TestRefIsInternal:
"""Tests for ref_is_internal utility."""
def test_external_components_flagged(
self, compile_rdl: Callable[..., AddrmapNode]
) -> None:
"""External components should be treated as non-internal."""
rdl_source = """
reg reg_t {
field { sw=rw; hw=r; } data[7:0];
};
addrmap top {
external reg_t ext @ 0x0;
reg_t intrnl @ 0x10;
};
"""
top = compile_rdl(rdl_source, top="top")
internal_reg = _find_child_by_name(top, "intrnl")
assert ref_is_internal(top, internal_reg) is True
external_reg = _find_child_by_name(top, "ext")
assert external_reg.external is True
assert ref_is_internal(top, external_reg) is False
external_prop_ref = PropertyReference.__new__(PropertyReference)
external_prop_ref.node = external_reg
assert ref_is_internal(top, external_prop_ref) is False
def test_property_reference_without_node_defaults_internal(
self, compile_rdl: Callable[..., AddrmapNode]
) -> None:
"""Root-level property references should be treated as internal."""
rdl_source = """
addrmap top {
reg {
field { sw=rw; hw=r; } data[7:0];
} reg0 @ 0x0;
};
"""
top = compile_rdl(rdl_source, top="top")
prop_ref = PropertyReference.__new__(PropertyReference)
prop_ref.node = None
assert ref_is_internal(top, prop_ref) is True