Skip to content

Commit 1148036

Browse files
vivien-applepull[bot]
authored andcommitted
[matter_yamltests] Add saveDataVersionAs supports (#27324)
1 parent d49258d commit 1148036

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/encoder.py

+45
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,36 @@ def __get_command_name(self, request):
234234
return command_name, command_specifier
235235

236236
def __get_arguments(self, request):
237+
# chip-tool expects a json encoded string that contains both mandatory and optional arguments for the target command.
238+
#
239+
# Those arguments are either top level properties of the request object or under the 'arguments' property.
240+
#
241+
# Usually if an argument is used by multiple commands (e.g: 'endpoint', 'min-interval', 'commissioner-name') it is represented as
242+
# a top level property of the request.
243+
# Otherwise if the argument is a command specific argument, it can be retrieved as a member of the 'arguments' property.
244+
#
245+
# As an example, the following test step:
246+
#
247+
# - label: "Send Test Add Arguments Command"
248+
# nodeId: 0x12344321
249+
# endpoint: 1
250+
# cluster: Unit Testing
251+
# command: TestAddArguments
252+
# identity: beta
253+
# arguments:
254+
# values:
255+
# - name: arg1
256+
# value: 3
257+
# - name: arg2
258+
# value: 4
259+
#
260+
# Will be translated to:
261+
# destination-id": "0x12344321", "endpoint-id-ignored-for-group-commands": "1", "arg1":"3", "arg2":"17", "commissioner-name": "beta"
237262
arguments = ''
238263
arguments = self.__maybe_add_destination(arguments, request)
239264
arguments = self.__maybe_add_endpoint(arguments, request)
240265
arguments = self.__maybe_add_command_arguments(arguments, request)
266+
arguments = self.__maybe_add_data_version(arguments, request)
241267
arguments = self.__maybe_add(
242268
arguments, request.min_interval, "min-interval")
243269
arguments = self.__maybe_add(
@@ -304,6 +330,25 @@ def __maybe_add_command_arguments(self, rv, request):
304330

305331
return rv
306332

333+
def __maybe_add_data_version(self, rv, request):
334+
if request.data_version is None:
335+
return rv
336+
337+
value = ''
338+
if type(request.data_version) is list:
339+
for index, version in enumerate(request.data_version):
340+
value += str(version)
341+
if index != len(request.data_version) - 1:
342+
value += ','
343+
else:
344+
value = request.data_version
345+
346+
if rv:
347+
rv += ', '
348+
rv += f'"data-version":"{value}"'
349+
350+
return rv
351+
307352
def __get_argument_name(self, request, entry):
308353
cluster_name = request.cluster
309354
command_name = request.command

scripts/py_matter_yamltests/matter_yamltests/parser.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ def __init__(self, test: dict, config: dict, definitions: SpecDefinitions, pics_
201201
self.max_interval = _value_or_none(test, 'maxInterval')
202202
self.timed_interaction_timeout_ms = _value_or_none(
203203
test, 'timedInteractionTimeoutMs')
204+
self.data_version = _value_or_none(
205+
test, 'dataVersion')
204206
self.busy_wait_ms = _value_or_none(test, 'busyWaitMs')
205207
self.wait_for = _value_or_none(test, 'wait')
206208
self.event_number = _value_or_none(test, 'eventNumber')
@@ -412,7 +414,8 @@ def _convert_single_value_to_values(self, container):
412414
# members of the 'values' array which is what is used for other tests.
413415
value = {}
414416

415-
known_keys_to_copy = ['value', 'constraints', 'saveAs']
417+
known_keys_to_copy = ['value', 'constraints',
418+
'saveAs', 'saveDataVersionAs']
416419
known_keys_to_allow = ['error', 'clusterError']
417420

418421
for key, item in list(container.items()):
@@ -473,6 +476,8 @@ def _update_with_definition(self, container: dict, mapping_type):
473476
item_value, mapping)
474477
elif key == 'saveAs' and type(item_value) is str and item_value not in self._parsing_config_variable_storage:
475478
self._parsing_config_variable_storage[item_value] = None
479+
elif key == 'saveDataVersionAs' and type(item_value) is str and item_value not in self._parsing_config_variable_storage:
480+
self._parsing_config_variable_storage[item_value] = None
476481
elif key == 'constraints':
477482
for constraint, constraint_value in item_value.items():
478483
# Only apply update_value_with_definition to constraints that have a value that depends on
@@ -563,6 +568,8 @@ def __init__(self, test: _TestStepWithPlaceholders, step_index: int, runtime_con
563568
if test.is_pics_enabled:
564569
self._update_placeholder_values(self.arguments)
565570
self._update_placeholder_values(self.responses)
571+
self._test.data_version = self._config_variable_substitution(
572+
self._test.data_version)
566573
self._test.node_id = self._config_variable_substitution(
567574
self._test.node_id)
568575
self._test.run_if = self._config_variable_substitution(
@@ -654,6 +661,10 @@ def max_interval(self):
654661
def timed_interaction_timeout_ms(self):
655662
return self._test.timed_interaction_timeout_ms
656663

664+
@property
665+
def data_version(self):
666+
return self._test.data_version
667+
657668
@property
658669
def busy_wait_ms(self):
659670
return self._test.busy_wait_ms
@@ -702,7 +713,10 @@ def post_process_response(self, received_responses):
702713
expected_response, received_response, result)
703714
self._response_constraints_validation(
704715
expected_response, received_response, result)
705-
self._maybe_save_as(expected_response, received_response, result)
716+
self._maybe_save_as('saveAs', 'value',
717+
expected_response, received_response, result)
718+
self._maybe_save_as('saveDataVersionAs', 'dataVersion',
719+
expected_response, received_response, result)
706720

707721
# An empty response array in a test step (responses: []) implies that the test step does expect a response
708722
# but without any associated value.
@@ -936,17 +950,17 @@ def _response_constraints_validation(self, expected_response, received_response,
936950
e.update_context(expected_response, self.step_index)
937951
result.error(check_type, error_failure, e)
938952

939-
def _maybe_save_as(self, expected_response, received_response, result):
953+
def _maybe_save_as(self, key: str, default_target: str, expected_response, received_response, result):
940954
check_type = PostProcessCheckType.SAVE_AS_VARIABLE
941955
error_success = 'The test save the value "{value}" as {name}.'
942956
error_name_does_not_exist = 'The test expects a value named "{name}" but it does not exists in the response."'
943957

944958
for value in expected_response['values']:
945-
if 'saveAs' not in value:
959+
if key not in value:
946960
continue
947961

948-
received_value = received_response.get('value')
949-
if not self.is_attribute and not self.is_event:
962+
received_value = received_response.get(default_target)
963+
if not self.is_attribute and not self.is_event and not (self.command in ANY_COMMANDS_LIST):
950964
expected_name = value.get('name')
951965
if received_value is None or expected_name not in received_value:
952966
result.error(check_type, error_name_does_not_exist.format(
@@ -956,7 +970,7 @@ def _maybe_save_as(self, expected_response, received_response, result):
956970
received_value = received_value.get(
957971
expected_name) if received_value else None
958972

959-
save_as = value.get('saveAs')
973+
save_as = value.get(key)
960974
self._runtime_config_variable_storage[save_as] = received_value
961975
result.success(check_type, error_success.format(
962976
value=received_value, name=save_as))

scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __check_test_step(self, content):
105105
'minInterval': int,
106106
'maxInterval': int,
107107
'timedInteractionTimeoutMs': int,
108+
'dataVersion': (list, int, str), # Can be a variable
108109
'busyWaitMs': int,
109110
'wait': str,
110111
}
@@ -166,7 +167,8 @@ def __check_test_step_response_value(self, content, allow_name_key=False):
166167
'error': str,
167168
'clusterError': int,
168169
'constraints': dict,
169-
'saveAs': str
170+
'saveAs': str,
171+
'saveDataVersionAs': str,
170172
}
171173

172174
if allow_name_key:

0 commit comments

Comments
 (0)