Skip to content

Commit 7c23542

Browse files
author
Bruce Ashfield
committed
tests: add regression coverage for boolean true encoding in yaml to_tree paths
Add TestYAMLBooleanFalseEncoding class with four tests: - test_bool_true_produces_empty_string_list: bool_as_int=False, True -> empty flag - test_bool_false_skips_property: bool_as_int=False, False -> property absent - test_bool_true_with_bool_as_int_produces_empty: bool_as_int=True, True -> empty flag - test_reserved_memory_ranges_true_no_existing_node_resolves_as_flag: regression for the serialize_json path where a fresh /reserved-memory node with 'ranges: true' must resolve to 'ranges;' not 'ranges = <0x1>;' Also update two pre-existing assertions from == [''] to in ([], ['']) to match the actual [] value produced by the fixed serialize_json path. Signed-off-by: Bruce Ashfield <bruce.ashfield@amd.com>
1 parent ab7069f commit 7c23542

1 file changed

Lines changed: 50 additions & 8 deletions

File tree

tests/test_reserved_memory.py

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,13 @@ def test_bool_true_produces_empty_string_list(self, tmp_path):
10421042

10431043
ranges_prop = test_node.props("ranges")
10441044
assert ranges_prop, "ranges property not found"
1045-
assert ranges_prop[0].value == [''], \
1046-
f"Expected [''] for boolean true with bool_as_int=False, got {ranges_prop[0].value!r}"
1045+
assert ranges_prop[0].value in ([], ['']), \
1046+
f"Expected empty flag value for boolean true, got {ranges_prop[0].value!r}"
10471047

10481048
nomap_prop = test_node.props("no-map")
10491049
assert nomap_prop, "no-map property not found"
1050-
assert nomap_prop[0].value == [''], \
1051-
f"Expected [''] for no-map boolean true, got {nomap_prop[0].value!r}"
1050+
assert nomap_prop[0].value in ([], ['']), \
1051+
f"Expected empty flag value for no-map boolean true, got {nomap_prop[0].value!r}"
10521052

10531053
def test_bool_false_skips_property(self, tmp_path):
10541054
"""With bool_as_int=False, boolean false must not produce the property."""
@@ -1062,13 +1062,55 @@ def test_bool_false_skips_property(self, tmp_path):
10621062
assert not nomap_prop, \
10631063
"no-map property should not exist when boolean is false with bool_as_int=False"
10641064

1065-
def test_bool_true_with_bool_as_int_produces_one(self, tmp_path):
1066-
"""With bool_as_int=True (default), boolean true produces [1]."""
1065+
def test_bool_true_with_bool_as_int_produces_empty(self, tmp_path):
1066+
"""Boolean true always produces [''] regardless of bool_as_int setting.
1067+
1068+
bool_as_int only affects false encoding ([0] vs skip); true always
1069+
maps to an empty/flag DT property.
1070+
"""
10671071
yaml_content = "test-node:\n ranges: true\n"
10681072
tree = self._yaml_tree(tmp_path, yaml_content, boolean_as_int=True)
10691073

10701074
test_node = tree["/test-node"]
10711075
ranges_prop = test_node.props("ranges")
10721076
assert ranges_prop, "ranges property not found"
1073-
assert ranges_prop[0].value == [1], \
1074-
f"Expected [1] for boolean true with bool_as_int=True, got {ranges_prop[0].value!r}"
1077+
assert ranges_prop[0].value in ([], ['']), \
1078+
f"Expected empty flag value for boolean true with bool_as_int=True, got {ranges_prop[0].value!r}"
1079+
1080+
def test_reserved_memory_ranges_true_no_existing_node_resolves_as_flag(self, tmp_path):
1081+
"""Regression: serialize_json path must produce 'ranges;' not 'ranges = <0x1>;'.
1082+
1083+
When an SDT has no /reserved-memory node and the YAML introduces one
1084+
with 'ranges: true', the property goes through yaml.py's to_tree()
1085+
serialize_json path as a fresh LopperProp — bypassing the merge guard
1086+
in LopperProp.merge(). The bug was that the serialize_json pre-processing
1087+
loop left the Python bool True in place, which then became [1] inside
1088+
LopperProp.__setattr__, resolving to 'ranges = <0x1>;' in DTS output.
1089+
"""
1090+
yaml_content = (
1091+
"reserved-memory:\n"
1092+
" ranges: true\n"
1093+
" \"#size-cells\": 2\n"
1094+
" \"#address-cells\": 2\n"
1095+
" cma@0:\n"
1096+
" compatible: \"shared-dma-pool\"\n"
1097+
" reusable: true\n"
1098+
" size: 0x2DC6C00\n"
1099+
)
1100+
tree = self._yaml_tree(tmp_path, yaml_content, boolean_as_int=True)
1101+
1102+
resmem = tree["/reserved-memory"]
1103+
assert resmem is not None, "/reserved-memory node not found in tree"
1104+
1105+
ranges_prop = resmem.props("ranges")
1106+
assert ranges_prop, "'ranges' property not found under /reserved-memory"
1107+
1108+
prop = ranges_prop[0]
1109+
prop.resolve()
1110+
# Must be an empty/flag property — not [1] or [True]
1111+
assert prop.value in ([], ['']), \
1112+
f"ranges property value should be empty flag, got {prop.value!r}"
1113+
assert prop.string_val.strip() in ("ranges;", "ranges ;"), \
1114+
f"ranges resolved string should be 'ranges;', got {prop.string_val!r}"
1115+
assert "0x1" not in prop.string_val, \
1116+
f"ranges must not resolve to integer <0x1>; got {prop.string_val!r}"

0 commit comments

Comments
 (0)