From f10478236e6f52d59b1ce24c3744f4e0cacd3a9b Mon Sep 17 00:00:00 2001 From: Terence Hampson Date: Thu, 12 Jan 2023 12:04:26 -0500 Subject: [PATCH] Add ability to process WaitForCommissionee YAML test command with chip-repl runner (#24332) * Add ability to process WaitForCommissionee YAML test command * Address PR comments * Address PR comments --- src/controller/python/chip/yaml/runner.py | 47 ++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/controller/python/chip/yaml/runner.py b/src/controller/python/chip/yaml/runner.py index d5dde80ea8454f..a4414b69d46c70 100644 --- a/src/controller/python/chip/yaml/runner.py +++ b/src/controller/python/chip/yaml/runner.py @@ -211,6 +211,40 @@ def parse_raw_response(self, raw_resp) -> _ActionResult: return _ActionResult(status=_ActionStatus.SUCCESS, response=return_val) +class WaitForCommissioneeAction(BaseAction): + ''' Wait for commissionee action to be executed.''' + + def __init__(self, test_step): + super().__init__(test_step.label) + self._node_id = test_step.node_id + self._expire_existing_session = False + # This is the default when no timeout is provided. + _DEFAULT_TIMEOUT_MS = 10 * 1000 + self._timeout_ms = _DEFAULT_TIMEOUT_MS + + if test_step.arguments is None: + # Nothing left for us to do the default values are what we want + return + + args = test_step.arguments['values'] + request_data_as_dict = Converter.convert_list_of_name_value_pair_to_dict(args) + + self._expire_existing_session = request_data_as_dict.get('expireExistingSession', False) + if 'timeout' in request_data_as_dict: + # Timeout is provided in seconds we need to conver to milliseconds. + self._timeout_ms = request_data_as_dict['timeout'] * 1000 + + def run_action(self, dev_ctrl: ChipDeviceCtrl) -> _ActionResult: + try: + if self._expire_existing_session: + dev_ctrl.ExpireSessions(self._node_id) + dev_ctrl.GetConnectedDeviceSync(self._node_id, timeoutMs=self._timeout_ms) + except TimeoutError: + return _ActionResult(status=_ActionStatus.ERROR, response=None) + + return _ActionResult(status=_ActionStatus.SUCCESS, response=None) + + class AttributeChangeAccumulator: def __init__(self, name: str, expected_attribute: Clusters.ClusterAttributeDescriptor, output_queue: queue.SimpleQueue): @@ -461,6 +495,15 @@ def _attribute_write_action_factory(self, test_step, cluster: str): except ParsingError: return None + def _wait_for_commissionee_action_factory(self, test_step): + try: + return WaitForCommissioneeAction(test_step) + except ParsingError: + # TODO For now, ParsingErrors are largely issues that will be addressed soon. Once this + # runner has matched parity of the codegen YAML test, this exception should be + # propogated. + return None + def _wait_for_report_action_factory(self, test_step): try: return WaitForReportAction(test_step, self._context) @@ -476,7 +519,9 @@ def encode(self, request) -> BaseAction: command = request.command # Some of the tests contain 'cluster over-rides' that refer to a different # cluster than that specified in 'config'. - if command == 'writeAttribute': + if cluster == 'DelayCommands' and command == 'WaitForCommissionee': + action = self._wait_for_commissionee_action_factory(request) + elif command == 'writeAttribute': action = self._attribute_write_action_factory(request, cluster) elif command == 'readAttribute': action = self._attribute_read_action_factory(request, cluster)