diff --git a/scripts/py_matter_yamltests/matter_yamltests/constraints.py b/scripts/py_matter_yamltests/matter_yamltests/constraints.py index a41f584ae793f7..22d461c960dd43 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/constraints.py +++ b/scripts/py_matter_yamltests/matter_yamltests/constraints.py @@ -24,11 +24,6 @@ def __init__(self, message): super().__init__(message) -class ConstraintValidationError(Exception): - def __init__(self, message): - super().__init__(message) - - class BaseConstraint(ABC): '''Constraint Interface''' @@ -42,8 +37,11 @@ def is_met(self, value): return self._is_null_allowed response_type = type(value) - if self._types and response_type not in self._types: - return False + if self._types: + found_type_match = any( + [issubclass(response_type, expected) for expected in self._types]) + if not found_type_match: + return False return self.check_response(value) @@ -57,9 +55,15 @@ def __init__(self, has_value): super().__init__(types=[]) self._has_value = has_value + def is_met(self, value): + # We are overriding the BaseConstraint of is_met since has value is a special case where + # we might not be expecting a value at all, but the basic null check in BaseConstraint + # is not what we want. + return self.check_response(value) + def check_response(self, value) -> bool: - raise ConstraintValidationError( - 'HasValue constraint currently not implemented') + has_value = value is not None + return self._has_value == has_value class _ConstraintType(BaseConstraint): @@ -75,8 +79,12 @@ def check_response(self, value) -> bool: success = True elif self._type == 'char_string' and type(value) is str: success = True + elif self._type == 'long_char_string' and type(value) is str: + success = True elif self._type == 'octet_string' and type(value) is bytes: success = True + elif self._type == 'long_octet_string' and type(value) is bytes: + success = True elif self._type == 'vendor_id' and type(value) is int: success = value >= 0 and value <= 0xFFFF elif self._type == 'device_type_id' and type(value) is int: @@ -105,9 +113,9 @@ def check_response(self, value) -> bool: success = value >= 0 and value <= 0xFFFFFFFF elif self._type == 'bitmap64' and type(value) is int: success = value >= 0 and value <= 0xFFFFFFFFFFFFFFFF - elif self._type == 'enum8' and type(value) is int: + elif self._type == 'enum8' and isinstance(value, int): success = value >= 0 and value <= 0xFF - elif self._type == 'enum16' and type(value) is int: + elif self._type == 'enum16' and isinstance(value, int): success = value >= 0 and value <= 0xFFFF elif self._type == 'Percent' and type(value) is int: success = value >= 0 and value <= 0xFF diff --git a/scripts/py_matter_yamltests/matter_yamltests/parser.py b/scripts/py_matter_yamltests/matter_yamltests/parser.py index 6e65ef2ee12d74..258693b0ec20a7 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/parser.py +++ b/scripts/py_matter_yamltests/matter_yamltests/parser.py @@ -676,25 +676,22 @@ def _response_constraints_validation(self, response, result): check_type = PostProcessCheckType.CONSTRAINT_VALIDATION error_success = 'Constraints check passed' error_failure = 'Constraints check failed' - error_name_does_not_exist = 'The test expects a value named "{name}" but it does not exists in the response."' for value in self.response['values']: if 'constraints' not in value: continue - expected_name = 'value' received_value = response.get('value') if not self.is_attribute: expected_name = value.get('name') if received_value is None or expected_name not in received_value: - result.error(check_type, error_name_does_not_exist.format( - name=expected_name)) - continue - - received_value = received_value.get( - expected_name) if received_value else None + received_value = None + else: + received_value = received_value.get( + expected_name) if received_value else None constraints = get_constraints(value['constraints']) + if all([constraint.is_met(received_value) for constraint in constraints]): result.success(check_type, error_success) else: @@ -710,7 +707,6 @@ def _maybe_save_as(self, response, result): if 'saveAs' not in value: continue - expected_name = 'value' received_value = response.get('value') if not self.is_attribute: expected_name = value.get('name') @@ -835,7 +831,14 @@ def __init__(self, test_file, pics_file, definitions): self.name = _value_or_none(data, 'name') self.PICS = _value_or_none(data, 'PICS') - self._parsing_config_variable_storage = _value_or_none(data, 'config') + self._parsing_config_variable_storage = data.get('config', {}) + + # These are a list of "KnownVariables". These are defaults the codegen used to use. This + # is added for legacy support of tests that expect to uses these "defaults". + self.__populate_default_config_if_missing('nodeId', 0x12345) + self.__populate_default_config_if_missing('endpoint', '') + self.__populate_default_config_if_missing('cluster', '') + self.__populate_default_config_if_missing('timeout', '90') pics_checker = PICSChecker(pics_file) tests = _value_or_none(data, 'tests') @@ -845,6 +848,10 @@ def __init__(self, test_file, pics_file, definitions): def update_config(self, key, value): self._parsing_config_variable_storage[key] = value + def __populate_default_config_if_missing(self, key, value): + if key not in self._parsing_config_variable_storage: + self._parsing_config_variable_storage[key] = value + def __load_yaml(self, test_file): with open(test_file) as f: loader = yaml.FullLoader diff --git a/src/app/tests/suites/certification/Test_TC_DRLK_2_2.yaml b/src/app/tests/suites/certification/Test_TC_DRLK_2_2.yaml index 26f4b70bb74a59..b73e9ec9966514 100644 --- a/src/app/tests/suites/certification/Test_TC_DRLK_2_2.yaml +++ b/src/app/tests/suites/certification/Test_TC_DRLK_2_2.yaml @@ -156,8 +156,6 @@ tests: PICS: DRLK.S.C00.Rsp command: "LockDoor" timedInteractionTimeoutMs: 1000 - response: - error: 0x00 - label: "TH sends Lock Door Command to the DUT with valid PINCode" PICS: DRLK.S.C00.Rsp diff --git a/src/app/tests/suites/certification/Test_TC_DRLK_2_3.yaml b/src/app/tests/suites/certification/Test_TC_DRLK_2_3.yaml index 2fafc34e861911..764d81265c365e 100644 --- a/src/app/tests/suites/certification/Test_TC_DRLK_2_3.yaml +++ b/src/app/tests/suites/certification/Test_TC_DRLK_2_3.yaml @@ -157,8 +157,6 @@ tests: PICS: DRLK.S.C01.Rsp command: "UnlockDoor" timedInteractionTimeoutMs: 1000 - response: - error: 0x00 - label: "TH sends the unlock Door command to the DUT with valid PINCode" PICS: DRLK.S.C01.Rsp diff --git a/src/app/tests/suites/certification/Test_TC_LOWPOWER_2_1.yaml b/src/app/tests/suites/certification/Test_TC_LOWPOWER_2_1.yaml index a8cafbac8e0db1..e393a262991ed8 100644 --- a/src/app/tests/suites/certification/Test_TC_LOWPOWER_2_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_LOWPOWER_2_1.yaml @@ -34,5 +34,3 @@ tests: - label: "TH sends Sleep command to DUT" PICS: LOWPOWER.S.C00.Rsp command: "Sleep" - response: - error: 0 diff --git a/src/app/tests/suites/certification/Test_TC_MEDIAINPUT_3_12.yaml b/src/app/tests/suites/certification/Test_TC_MEDIAINPUT_3_12.yaml index 6b6482d3494950..a3b848be39ff29 100644 --- a/src/app/tests/suites/certification/Test_TC_MEDIAINPUT_3_12.yaml +++ b/src/app/tests/suites/certification/Test_TC_MEDIAINPUT_3_12.yaml @@ -47,11 +47,7 @@ tests: - label: "Show Input Status Command" PICS: MEDIAINPUT.S.C01.Rsp command: "ShowInputStatus" - response: - error: 0 - label: "Hide Input Status Command" PICS: MEDIAINPUT.S.C02.Rsp command: "HideInputStatus" - response: - error: 0 diff --git a/src/app/tests/suites/certification/Test_TC_TSUIC_2_2.yaml b/src/app/tests/suites/certification/Test_TC_TSUIC_2_2.yaml index 239d37a942c742..39bc0e7ab388e9 100644 --- a/src/app/tests/suites/certification/Test_TC_TSUIC_2_2.yaml +++ b/src/app/tests/suites/certification/Test_TC_TSUIC_2_2.yaml @@ -53,7 +53,7 @@ tests: PICS: TSUIC.S.A0000 command: "readAttribute" attribute: "TemperatureDisplayMode" - arguments: + response: value: 0 - label: "Writes a value of 1 to TemperatureDisplayMode attribute of DUT" diff --git a/src/app/tests/suites/certification/Test_TC_WAKEONLAN_4_1.yaml b/src/app/tests/suites/certification/Test_TC_WAKEONLAN_4_1.yaml index ade30fa0aa5996..357c617211c3fc 100644 --- a/src/app/tests/suites/certification/Test_TC_WAKEONLAN_4_1.yaml +++ b/src/app/tests/suites/certification/Test_TC_WAKEONLAN_4_1.yaml @@ -44,8 +44,6 @@ tests: PICS: LOWPOWER.S.C00.Rsp cluster: "Low Power" command: "Sleep" - response: - error: 0 - label: "TH sends a Wake-On LAN magic packet containing the MAC address from diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index a7cc6db443b4b2..c69097fde2ab1f 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -46750,6 +46750,7 @@ class Test_TC_TSUIC_2_2Suite : public TestCommand { uint8_t value; VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); + VerifyOrReturn(CheckValue("temperatureDisplayMode", value, 0U)); } break; case 4: diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index 099b9d79b378d1..9758f61b48976b 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -62315,6 +62315,11 @@ class Test_TC_TSUIC_2_2 : public TestCommandBridge { VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); + { + id actualValue = value; + VerifyOrReturn(CheckValue("TemperatureDisplayMode", actualValue, 0U)); + } + NextTest(); }];