Skip to content

Commit fcd5f10

Browse files
committedFeb 22, 2024·
PICS checker: Add checks for base xml
1 parent 9c11019 commit fcd5f10

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed
 

‎src/python_testing/TC_pics_checker.py

+46-17
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,49 @@ def generated_cmd_pics(pics_base: str, id: int) -> str:
4040
def feature_pics(pics_base: str, bit: int) -> str:
4141
return f'{pics_base}.S.F{bit:02x}'
4242

43+
# Use bool-arg check_base_pics_files=True to check the base PICS xml against all known elements
44+
4345

4446
class TC_PICS_Checker(MatterBaseTest, BasicCompositionTests):
4547
@async_test_body
4648
async def setup_class(self):
4749
super().setup_class()
48-
await self.setup_class_helper(False)
50+
if not self.user_params.get("check_base_pics_files", False):
51+
await self.setup_class_helper(False)
4952
# build_xml_cluster returns a list of issues found when paring the XML
5053
# Problems in the XML shouldn't cause test failure, but we want them recorded
5154
# so they are added to the list of problems that get output when the test set completes.
5255
self.xml_clusters, self.problems = build_xml_clusters()
5356

5457
def _check_and_record_errors(self, location, required, pics):
55-
if required and not self.check_pics(pics):
58+
if self.user_params.get("check_base_pics_files", False):
59+
# We just want to know that the pics appears in the xml file (aka in the dictionary), don't care about the value
60+
have_pics = pics in self.matter_test_config.pics
61+
else:
62+
have_pics = self.check_pics(pics)
63+
64+
if required and not have_pics:
5665
self.record_error("PICS check", location=location,
5766
problem=f"An element found on the device, but the corresponding PICS {pics} was not found in pics list")
5867
self.success = False
5968
elif not required and self.check_pics(pics):
6069
self.record_error("PICS check", location=location, problem=f"PICS {pics} found in PICS list, but not on device")
6170
self.success = False
6271

72+
def _check_pics_required(self, attribute_id_of_element_list: int, cluster_id: int, element_id: int):
73+
if self.user_params.get("check_base_pics_files", False):
74+
return True
75+
76+
if cluster_id not in self.endpoint.keys():
77+
# This cluster is not on this endpoint
78+
required = False
79+
elif element_id in self.endpoint[cluster_id][attribute_id_of_element_list]:
80+
# Cluster and element are on the endpoint
81+
required = True
82+
else:
83+
# Cluster is on the endpoint but the element is not in the list
84+
required = False
85+
6386
def _add_pics_for_lists(self, cluster_id: int, attribute_id_of_element_list: GlobalAttributeIds) -> None:
6487
try:
6588
if attribute_id_of_element_list == GlobalAttributeIds.ATTRIBUTE_LIST_ID:
@@ -84,15 +107,7 @@ def _add_pics_for_lists(self, cluster_id: int, attribute_id_of_element_list: Glo
84107
continue
85108
pics = pics_mapper(self.xml_clusters[cluster_id].pics, element_id)
86109

87-
if cluster_id not in self.endpoint.keys():
88-
# This cluster is not on this endpoint
89-
required = False
90-
elif element_id in self.endpoint[cluster_id][attribute_id_of_element_list]:
91-
# Cluster and element are on the endpoint
92-
required = True
93-
else:
94-
# Cluster is on the endpoint but the element is not in the list
95-
required = False
110+
required = self._check_pics_required(attribute_id_of_element_list, cluster_id, element_id)
96111

97112
if attribute_id_of_element_list == GlobalAttributeIds.ATTRIBUTE_LIST_ID:
98113
location = AttributePathLocation(endpoint_id=self.endpoint_id, cluster_id=cluster_id, attribute_id=element_id)
@@ -113,7 +128,8 @@ def test_TC_IDM_10_4(self):
113128
# wildcard read is done in setup_class
114129
self.step(1)
115130
self.endpoint_id = self.matter_test_config.endpoint
116-
self.endpoint = self.endpoints_tlv[self.endpoint_id]
131+
if not self.user_params.get("check_base_pics_files", False):
132+
self.endpoint = self.endpoints_tlv[self.endpoint_id]
117133
self.success = True
118134

119135
# Data model XML is used to get the PICS code for this cluster. If we don't know the PICS
@@ -127,7 +143,12 @@ def test_TC_IDM_10_4(self):
127143
# Ensure the PICS.S code is correctly marked
128144
pics_cluster = f'{self.xml_clusters[cluster_id].pics}.S'
129145
location = ClusterPathLocation(endpoint_id=self.endpoint_id, cluster_id=cluster_id)
130-
self._check_and_record_errors(location, cluster_id in self.endpoint, pics_cluster)
146+
if not self.user_params.get("check_base_pics_files", False):
147+
cluster_pics_required = cluster_id in self.endpoint
148+
else:
149+
cluster_pics_required = True
150+
151+
self._check_and_record_errors(location, cluster_pics_required, pics_cluster)
131152

132153
self.step(3)
133154
for cluster_id, cluster in checkable_clusters.items():
@@ -150,10 +171,18 @@ def test_TC_IDM_10_4(self):
150171
continue
151172

152173
pics_base = self.xml_clusters[cluster_id].pics
153-
try:
154-
feature_map = self.endpoint[cluster_id][GlobalAttributeIds.FEATURE_MAP_ID]
155-
except KeyError:
156-
feature_map = 0
174+
if self.user_params.get("check_base_pics_files", False):
175+
try:
176+
feature_map = 0
177+
for f in Clusters.ClusterObjects.ALL_CLUSTERS[cluster_id].Bitmaps.Feature:
178+
feature_map &= f
179+
except KeyError:
180+
feature_map = 0
181+
else:
182+
try:
183+
feature_map = self.endpoint[cluster_id][GlobalAttributeIds.FEATURE_MAP_ID]
184+
except KeyError:
185+
feature_map = 0
157186

158187
for feature_mask in cluster_features:
159188
# Codegen in python uses feature masks (0x01, 0x02, 0x04 etc.)

0 commit comments

Comments
 (0)
Please sign in to comment.