Skip to content

Commit

Permalink
python_testing: Improve TC_IDM_10_1 error msgs (#35999)
Browse files Browse the repository at this point in the history
* python_testing: Improve TC_IDM_10_1  error msgs

* Fix the prefix ID displayed in TC_IDM_10_1 error messages
* Add "(Test Vendor)" to the error message when the ID is in the test
  vendor range

* Apply suggestions from code review

Co-authored-by: Tennessee Carmel-Veilleux <[email protected]>

* Apply Cecille's suggestion to use GlobalAttributeIds checks

* Add space before (MEI)

Co-authored-by: Arkadiusz Bokowy <[email protected]>

* Apply Tennessee's review suggestions

* Restyled by isort

---------

Co-authored-by: Tennessee Carmel-Veilleux <[email protected]>
Co-authored-by: Arkadiusz Bokowy <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
5 people authored Oct 10, 2024
1 parent 14e75a4 commit a76cc9b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/python_testing/TC_DeviceBasicComposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
from chip.clusters.ClusterObjects import ClusterAttributeDescriptor, ClusterObjectFieldDescriptor
from chip.interaction_model import InteractionModelError, Status
from chip.tlv import uint
from global_attribute_ids import GlobalAttributeIds
from global_attribute_ids import AttributeIdType, ClusterIdType, GlobalAttributeIds, attribute_id_type, cluster_id_type
from matter_testing_support import (AttributePathLocation, ClusterPathLocation, CommandPathLocation, MatterBaseTest, TestStep,
async_test_body, default_matter_test_main)
from mobly import asserts
Expand All @@ -118,6 +118,11 @@
separate_endpoint_types)


def get_vendor_id(mei: int) -> int:
"""Get the vendor ID portion (MEI prefix) of an overall MEI."""
return (mei >> 16) & 0xffff


def check_int_in_range(min_value: int, max_value: int, allow_null: bool = False) -> Callable:
"""Returns a checker for whether `obj` is an int that fits in a range."""
def int_in_range_checker(obj: Any):
Expand Down Expand Up @@ -488,15 +493,17 @@ class RequiredMandatoryAttribute:
cmd_prefixes = [a & 0xFFFF_0000 for a in cmd_values]
bad_attrs = [a for a in attr_prefixes if a >= bad_prefix_min]
bad_cmds = [a for a in cmd_prefixes if a >= bad_prefix_min]
for bad in bad_attrs:
location = AttributePathLocation(endpoint_id=endpoint_id, cluster_id=cluster_id, attribute_id=bad)
for bad_attrib_id in bad_attrs:
location = AttributePathLocation(endpoint_id=endpoint_id, cluster_id=cluster_id, attribute_id=bad_attrib_id)
vendor_id = get_vendor_id(bad_attrib_id)
self.record_error(self.get_test_name(
), location=location, problem=f'Attribute with bad prefix {attribute_id} in cluster {cluster_id}', spec_location='Manufacturer Extensible Identifier (MEI)')
), location=location, problem=f'Attribute 0x{bad_attrib_id:08x} with bad prefix 0x{vendor_id:04x} in cluster 0x{cluster_id:08x}' + (' (Test Vendor)' if attribute_id_type(bad_attrib_id) == AttributeIdType.kTest else ''), spec_location='Manufacturer Extensible Identifier (MEI)')
success = False
for bad in bad_cmds:
location = CommandPathLocation(endpoint_id=endpoint_id, cluster_id=cluster_id, command_id=bad)
for bad_cmd_id in bad_cmds:
location = CommandPathLocation(endpoint_id=endpoint_id, cluster_id=cluster_id, command_id=bad_cmd_id)
vendor_id = get_vendor_id(bad_cmd_id)
self.record_error(self.get_test_name(
), location=location, problem=f'Command with bad prefix {attribute_id} in cluster {cluster_id}', spec_location='Manufacturer Extensible Identifier (MEI)')
), location=location, problem=f'Command 0x{bad_cmd_id:08x} with bad prefix 0x{vendor_id:04x} in cluster 0x{cluster_id:08x}', spec_location='Manufacturer Extensible Identifier (MEI)')
success = False

self.print_step(7, "Validate that none of the MEI global attribute IDs contain values outside of the allowed suffix range")
Expand Down Expand Up @@ -539,10 +546,11 @@ class RequiredMandatoryAttribute:
for endpoint_id, endpoint in self.endpoints_tlv.items():
cluster_prefixes = [a & 0xFFFF_0000 for a in endpoint.keys()]
bad_clusters_ids = [a for a in cluster_prefixes if a >= bad_prefix_min]
for bad in bad_clusters_ids:
location = ClusterPathLocation(endpoint_id=endpoint_id, cluster_id=bad)
for bad_cluster_id in bad_clusters_ids:
location = ClusterPathLocation(endpoint_id=endpoint_id, cluster_id=bad_cluster_id)
vendor_id = get_vendor_id(bad_cluster_id)
self.record_error(self.get_test_name(), location=location,
problem=f'Bad cluster id prefix {bad}', spec_location='Manufacturer Extensible Identifier (MEI)')
problem=f'Cluster 0x{bad_cluster_id:08x} with bad prefix 0x{vendor_id:04x}' + (' (Test Vendor)' if cluster_id_type(bad_cluster_id) == ClusterIdType.kTest else ''), spec_location='Manufacturer Extensible Identifier (MEI)')
success = False

self.print_step(9, "Validate that all clusters in the standard range have a known cluster ID")
Expand Down

0 comments on commit a76cc9b

Please sign in to comment.