Skip to content

Commit 61653fe

Browse files
authored
TC-SM-1.2: Use correct data type (project-chip#31644)
* TC-SM-1.2: Use correct data type Credit to Manjunath for finding this. Fixes: project-chip/matter-test-scripts#105 * one more fix * one more * Pull this out and add a test * linter * add docstring
1 parent 354d692 commit 61653fe

3 files changed

+20
-7
lines changed

src/python_testing/TC_DeviceBasicComposition.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
async_test_body, default_matter_test_main)
3030
from mobly import asserts
3131
from taglist_and_topology_test_support import (create_device_type_list_for_root, create_device_type_lists, find_tag_list_problems,
32-
find_tree_roots, get_all_children, get_direct_children_of_root, parts_list_cycles,
32+
find_tree_roots, flat_list_ok, get_direct_children_of_root, parts_list_cycles,
3333
separate_endpoint_types)
3434

3535

@@ -554,13 +554,10 @@ def test_TC_SM_1_2(self):
554554
ok = True
555555
for endpoint_id in flat:
556556
# ensure that every sub-id in the parts list is included in the parent
557-
sub_children = []
558-
for child in self.endpoints[endpoint_id][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList]:
559-
sub_children.update(get_all_children(child))
560-
if not all(item in sub_children for item in self.endpoints[endpoint_id][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList]):
557+
if not flat_list_ok(endpoint_id, self.endpoints):
561558
location = AttributePathLocation(endpoint_id=endpoint_id, cluster_id=cluster_id, attribute_id=attribute_id)
562559
self.record_error(self.get_test_name(), location=location,
563-
problem='Flat parts list does not include all the sub-parts', spec_location='Endpoint composition')
560+
problem='Flat parts list does not exactly match sub-parts', spec_location='Endpoint composition')
564561
ok = False
565562
if not ok:
566563
self.fail_current_test()

src/python_testing/TestMatterTestingSupport.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
utc_time_in_matter_epoch)
2929
from mobly import asserts, signals
3030
from taglist_and_topology_test_support import (TagProblem, create_device_type_list_for_root, create_device_type_lists,
31-
find_tag_list_problems, find_tree_roots, get_all_children,
31+
find_tag_list_problems, find_tree_roots, flat_list_ok, get_all_children,
3232
get_direct_children_of_root, parts_list_cycles, separate_endpoint_types)
3333

3434

@@ -304,6 +304,14 @@ def test_cycle_detection_and_splitting(self):
304304
cycles = parts_list_cycles(tree, endpoints)
305305
asserts.assert_equal(cycles, [2, 3, 4, 5, 9, 10, 13, 14, 16])
306306

307+
def test_flat_list(self):
308+
endpoints = self.create_example_topology()
309+
# check the aggregator endpoint to ensure it's ok - aggregator is on 11
310+
asserts.assert_true(flat_list_ok(11, endpoints), "Incorrect failure on flat list")
311+
# Remove one of the sub-children endpoints from the parts list - it should fail
312+
endpoints[11][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList].remove(14)
313+
asserts.assert_false(flat_list_ok(11, endpoints), "Incorrect pass on flat list missing a part list entry")
314+
307315
def test_get_all_children(self):
308316
endpoints = self.create_example_topology()
309317
asserts.assert_equal(get_all_children(2, endpoints), {1, 3, 4, 5, 9}, "Child list for ep2 is incorrect")

src/python_testing/taglist_and_topology_test_support.py

+8
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,11 @@ def find_tag_list_problems(roots: list[int], device_types: dict[int, dict[int, s
189189
missing_feature=missing_feature, duplicates=endpoints)
190190

191191
return tag_problems
192+
193+
194+
def flat_list_ok(flat_endpoint_id_to_check: int, endpoints_dict: dict[int, Any]) -> bool:
195+
'''Checks if the (flat) PartsList on the supplied endpoint contains all the sub-children of its parts.'''
196+
sub_children = set()
197+
for child in endpoints_dict[flat_endpoint_id_to_check][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList]:
198+
sub_children.update(get_all_children(child, endpoints_dict))
199+
return all(item in endpoints_dict[flat_endpoint_id_to_check][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList] for item in sub_children)

0 commit comments

Comments
 (0)