Skip to content

Commit

Permalink
Add ability to process WaitForCommissionee YAML test command with chi…
Browse files Browse the repository at this point in the history
…p-repl runner (#24332)

* Add ability to process WaitForCommissionee YAML test command

* Address PR comments

* Address PR comments
  • Loading branch information
tehampson authored Jan 12, 2023
1 parent ff8fe37 commit f104782
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/controller/python/chip/yaml/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit f104782

Please sign in to comment.