Skip to content

Commit

Permalink
Fix issues causing chip-repl based yamltest to fail (#24760)
Browse files Browse the repository at this point in the history
* Fix issues causing chip-repl based yamltest to fail

* Address PR comment

* Restyle

* Address PR comment

* Remove debugging breakpoint

* Add comment to help explain where default configs are coming from

* Update comment to better describe why checking for hasValue constraint

* Address PR comment

* Address PR comment
  • Loading branch information
tehampson authored Feb 1, 2023
1 parent 554e871 commit 8accb91
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 34 deletions.
30 changes: 19 additions & 11 deletions scripts/py_matter_yamltests/matter_yamltests/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''

Expand All @@ -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)

Expand All @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions scripts/py_matter_yamltests/matter_yamltests/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_DRLK_2_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_DRLK_2_3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_LOWPOWER_2_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ tests:
- label: "TH sends Sleep command to DUT"
PICS: LOWPOWER.S.C00.Rsp
command: "Sleep"
response:
error: 0
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/app/tests/suites/certification/Test_TC_TSUIC_2_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions src/app/tests/suites/certification/Test_TC_WAKEONLAN_4_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8accb91

Please sign in to comment.