From 2d6aada3ea028214273008da1febe1e79ddac8f8 Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Fri, 6 Dec 2024 13:36:43 -0500 Subject: [PATCH] check --- src/python_testing/TestIdChecks.py | 52 +++++++++---------- .../chip/testing/global_attribute_ids.py | 24 +++++++-- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/python_testing/TestIdChecks.py b/src/python_testing/TestIdChecks.py index c86d4bfe6d0d0b..95f2b635054df3 100644 --- a/src/python_testing/TestIdChecks.py +++ b/src/python_testing/TestIdChecks.py @@ -39,29 +39,29 @@ def check_standard(id): id_type = device_type_id_type(id) msg = f"Incorrect device type range assessment, expecting standard {id:08x}, type = {id_type}" asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kStandard, msg) - asserts.assert_true(is_valid_device_type_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_device_type_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_device_type_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_device_type_id(id, allow_test=False), msg) def check_manufacturer(id): id_type = device_type_id_type(id) msg = f"Incorrect device type range assessment, expecting manufacturer {id:08x}, type = {id_type}" asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kManufacturer, msg) - asserts.assert_true(is_valid_device_type_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_device_type_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_device_type_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_device_type_id(id, allow_test=False), msg) def check_test(id): id_type = device_type_id_type(id) msg = f"Incorrect device type range assessment, expecting test {id:08x}, type = {id_type}" asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kTest, msg) - asserts.assert_true(is_valid_device_type_id(id_type, allow_test=True), msg) - asserts.assert_false(is_valid_device_type_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_device_type_id(id, allow_test=True), msg) + asserts.assert_false(is_valid_device_type_id(id, allow_test=False), msg) def check_all_bad(id): id_type = device_type_id_type(id) msg = f"Incorrect device type range assessment, expecting invalid {id:08x}, type = {id_type}" asserts.assert_equal(device_type_id_type(id), DeviceTypeIdType.kInvalid, msg) - asserts.assert_false(is_valid_device_type_id(id_type, allow_test=True), msg) - asserts.assert_false(is_valid_device_type_id(id_type, allow_test=False), msg) + asserts.assert_false(is_valid_device_type_id(id, allow_test=True), msg) + asserts.assert_false(is_valid_device_type_id(id, allow_test=False), msg) for id in standard_good: check_standard(id) @@ -100,29 +100,29 @@ def check_standard(id): id_type = cluster_id_type(id) msg = f"Incorrect cluster range assessment, expecting standard {id:08x}, type = {id_type}" asserts.assert_equal(id_type, ClusterIdType.kStandard, msg) - asserts.assert_true(is_valid_cluster_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_cluster_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_cluster_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_cluster_id(id, allow_test=False), msg) def check_manufacturer(id): id_type = cluster_id_type(id) msg = f"Incorrect cluster range assessment, expecting manufacturer {id:08x}, type = {id_type}" asserts.assert_equal(id_type, ClusterIdType.kManufacturer, msg) - asserts.assert_true(is_valid_cluster_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_cluster_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_cluster_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_cluster_id(id, allow_test=False), msg) def check_test(id): id_type = cluster_id_type(id) msg = f"Incorrect cluster range assessment, expecting test {id:08x}, type = {id_type}" asserts.assert_equal(id_type, ClusterIdType.kTest, msg) - asserts.assert_true(is_valid_cluster_id(id_type, allow_test=True), msg) - asserts.assert_false(is_valid_cluster_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_cluster_id(id, allow_test=True), msg) + asserts.assert_false(is_valid_cluster_id(id, allow_test=False), msg) def check_all_bad(id): id_type = cluster_id_type(id) msg = f"Incorrect cluster range assessment, expecting invalid {id:08x}, type = {id_type}" asserts.assert_equal(id_type, ClusterIdType.kInvalid, msg) - asserts.assert_false(is_valid_cluster_id(id_type, allow_test=True), msg) - asserts.assert_false(is_valid_cluster_id(id_type, allow_test=False), msg) + asserts.assert_false(is_valid_cluster_id(id, allow_test=True), msg) + asserts.assert_false(is_valid_cluster_id(id, allow_test=False), msg) for id in standard_good: check_standard(id) @@ -160,36 +160,36 @@ def check_standard_global(id): id_type = attribute_id_type(id) msg = f"Incorrect attribute range assessment, expecting standard global {id:08x}, type = {id_type}" asserts.assert_equal(id_type, AttributeIdType.kStandardGlobal, msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=False), msg) def check_standard_non_global(id): id_type = attribute_id_type(id) msg = f"Incorrect attribute range assessment, expecting standard non-global {id:08x}, type = {id_type}" asserts.assert_equal(id_type, AttributeIdType.kStandardNonGlobal, msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=False), msg) def check_manufacturer(id): id_type = attribute_id_type(id) msg = f"Incorrect attribute range assessment, expecting manufacturer {id:08x}, type = {id_type}" asserts.assert_equal(id_type, AttributeIdType.kManufacturer, msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=False), msg) def check_test(id): id_type = attribute_id_type(id) msg = f"Incorrect attribute range assessment, expecting test {id:08x}, type = {id_type}" asserts.assert_equal(id_type, AttributeIdType.kTest, msg) - asserts.assert_true(is_valid_attribute_id(id_type, allow_test=True), msg) - asserts.assert_false(is_valid_attribute_id(id_type, allow_test=False), msg) + asserts.assert_true(is_valid_attribute_id(id, allow_test=True), msg) + asserts.assert_false(is_valid_attribute_id(id, allow_test=False), msg) def check_all_bad(id): id_type = attribute_id_type(id) msg = f"Incorrect attribute range assessment, expecting invalid {id:08x}, type = {id_type}" asserts.assert_equal(id_type, AttributeIdType.kInvalid, msg) - asserts.assert_false(is_valid_attribute_id(id_type, allow_test=True), msg) - asserts.assert_false(is_valid_attribute_id(id_type, allow_test=False), msg) + asserts.assert_false(is_valid_attribute_id(id, allow_test=True), msg) + asserts.assert_false(is_valid_attribute_id(id, allow_test=False), msg) for id in standard_global_good: check_standard_global(id) diff --git a/src/python_testing/matter_testing_infrastructure/chip/testing/global_attribute_ids.py b/src/python_testing/matter_testing_infrastructure/chip/testing/global_attribute_ids.py index f9fbd2e2ade835..800c2be79d26a1 100644 --- a/src/python_testing/matter_testing_infrastructure/chip/testing/global_attribute_ids.py +++ b/src/python_testing/matter_testing_infrastructure/chip/testing/global_attribute_ids.py @@ -133,7 +133,13 @@ def cluster_id_type(id: int) -> ClusterIdType: return ClusterIdType.kInvalid -def is_valid_cluster_id(id_type: ClusterIdType, allow_test: bool = False) -> bool: +def is_standard_cluster_id(id: int): + id_type = cluster_id_type(id) + return id_type in [ClusterIdType.kStandard] + + +def is_valid_cluster_id(id: int, allow_test: bool = False) -> bool: + id_type = device_type_id_type(id) valid = [ClusterIdType.kStandard, ClusterIdType.kManufacturer] if allow_test: valid.append(ClusterIdType.kTest) @@ -152,13 +158,19 @@ def attribute_id_type(id: int) -> AttributeIdType: return AttributeIdType.kInvalid -def is_valid_attribute_id(id_type: AttributeIdType, allow_test: bool = False): +def is_valid_attribute_id(id: int, allow_test: bool = False): + id_type = attribute_id_type(id) valid = [AttributeIdType.kStandardGlobal, AttributeIdType.kStandardNonGlobal, AttributeIdType.kManufacturer] if allow_test: valid.append(AttributeIdType.kTest) return id_type in valid +def is_standard_attribute_id(id: int): + id_type = attribute_id_type(id) + return id_type in [AttributeIdType.kStandardGlobal, AttributeIdType.kStandardNonGlobal] + + def command_id_type(id: int) -> CommandIdType: if id in STANDARD_PREFIX and id in COMMAND_ID_GLOBAL_STANDARD_SUFFIX: return CommandIdType.kStandardGlobal @@ -171,7 +183,13 @@ def command_id_type(id: int) -> CommandIdType: return CommandIdType.kInvalid -def is_valid_command_id(id_type: CommandIdType, allow_test: bool = False): +def is_standard_command_id(id: int): + id_type = command_id_type(id) + return id in [CommandIdType.kScopedNonGlobal, CommandIdType.kStandardGlobal] + + +def is_valid_command_id(id: int, allow_test: bool = False): + id_type = command_id_type(id) valid = [CommandIdType.kStandardGlobal, CommandIdType.kScopedNonGlobal, CommandIdType.kManufacturer] if allow_test: valid.append(CommandIdType.kTest)