From eebe9eac2b24fc7d3cc3c619eb94da25ad720fc5 Mon Sep 17 00:00:00 2001 From: Terence Hampson Date: Thu, 9 Feb 2023 12:40:19 -0500 Subject: [PATCH] Fix TestMultiAdmin to run on chip-repl based yamltest (#24919) * Fix TestMultiAdmin to run on chip-repl based yamltest * Restyle * Address PR comment * Restyle * Restyle * Fix CI test --- scripts/tests/chiptest/__init__.py | 1 - .../ChipDeviceController-ScriptBinding.cpp | 5 ++++ ...Controller-ScriptDevicePairingDelegate.cpp | 26 ++++++++++++++++++- ...ceController-ScriptDevicePairingDelegate.h | 3 +++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/scripts/tests/chiptest/__init__.py b/scripts/tests/chiptest/__init__.py index 795cdcdf41a986..98bcf3e4ffee9c 100644 --- a/scripts/tests/chiptest/__init__.py +++ b/scripts/tests/chiptest/__init__.py @@ -139,7 +139,6 @@ def _GetInDevelopmentTests() -> Set[str]: "TestEvents.yaml", "TestGroupMessaging.yaml", # Needs group support in repl - "TestMultiAdmin.yaml", # chip-repl hang on command expeted to fail } diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index 62fed10f223b71..0be9b561ab0b51 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -348,6 +348,7 @@ void pychip_DeviceController_SetLogFilter(uint8_t category) PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissioner * devCtrl, uint16_t discriminator, uint32_t setupPINCode, chip::NodeId nodeid) { + sPairingDelegate.SetExpectingPairingComplete(true); return ToPyChipError(devCtrl->PairDevice(nodeid, chip::RendezvousParameters() .SetPeerAddress(Transport::PeerAddress(Transport::Type::kBle)) @@ -369,12 +370,14 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr); params.SetPeerAddress(addr).SetDiscriminator(0); + sPairingDelegate.SetExpectingPairingComplete(true); return ToPyChipError(devCtrl->PairDevice(nodeid, params, sCommissioningParameters)); } PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload, chip::NodeId nodeid) { + sPairingDelegate.SetExpectingPairingComplete(true); return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters)); } @@ -467,6 +470,7 @@ PyChipError pychip_DeviceController_EstablishPASESessionIP(chip::Controller::Dev VerifyOrReturnError(chip::Inet::IPAddress::FromString(peerAddrStr, peerAddr), ToPyChipError(CHIP_ERROR_INVALID_ARGUMENT)); addr.SetTransportType(chip::Transport::Type::kUdp).SetIPAddress(peerAddr); params.SetPeerAddress(addr).SetDiscriminator(0); + sPairingDelegate.SetExpectingPairingComplete(true); return ToPyChipError(devCtrl->EstablishPASEConnection(nodeid, params)); } @@ -477,6 +481,7 @@ PyChipError pychip_DeviceController_EstablishPASESessionBLE(chip::Controller::De RendezvousParameters params = chip::RendezvousParameters().SetSetupPINCode(setupPINCode); addr.SetTransportType(chip::Transport::Type::kBle); params.SetPeerAddress(addr).SetDiscriminator(discriminator); + sPairingDelegate.SetExpectingPairingComplete(true); return ToPyChipError(devCtrl->EstablishPASEConnection(nodeid, params)); } diff --git a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp index eff99f442694b6..f6373245d27679 100644 --- a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp +++ b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.cpp @@ -66,10 +66,34 @@ void ScriptDevicePairingDelegate::SetCommissioningStatusUpdateCallback( mOnCommissioningStatusUpdateCallback = callback; } +void ScriptDevicePairingDelegate::OnStatusUpdate(DevicePairingDelegate::Status status) +{ + switch (status) + { + case DevicePairingDelegate::Status::SecurePairingSuccess: + ChipLogProgress(Zcl, "Secure Pairing Success"); + break; + case DevicePairingDelegate::Status::SecurePairingFailed: + ChipLogError(Zcl, "Secure Pairing Failed"); + if (mOnPairingCompleteCallback != nullptr && expectingPairingComplete) + { + // Incorrect state is the same error that chip-tool sends. We are also + // leveraging the on pairing complete callback to indicate that pairing + // has failed. + expectingPairingComplete = false; + mOnPairingCompleteCallback(ToPyChipError(CHIP_ERROR_INCORRECT_STATE)); + } + break; + case DevicePairingDelegate::Status::SecurePairingDiscoveringMoreDevices: + break; + } +} + void ScriptDevicePairingDelegate::OnPairingComplete(CHIP_ERROR error) { - if (mOnPairingCompleteCallback != nullptr) + if (mOnPairingCompleteCallback != nullptr && expectingPairingComplete) { + expectingPairingComplete = false; mOnPairingCompleteCallback(ToPyChipError(error)); } } diff --git a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h index a66ae6b891bc49..2bfd50b37436a8 100644 --- a/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h +++ b/src/controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h @@ -59,6 +59,7 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega void SetCommissioningSuccessCallback(DevicePairingDelegate_OnCommissioningSuccessFunct callback); void SetCommissioningFailureCallback(DevicePairingDelegate_OnCommissioningFailureFunct callback); void SetCommissioningWindowOpenCallback(DevicePairingDelegate_OnWindowOpenCompleteFunct callback); + void OnStatusUpdate(Controller::DevicePairingDelegate::Status status) override; void OnPairingComplete(CHIP_ERROR error) override; void OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err) override; void OnCommissioningSuccess(PeerId peerId) override; @@ -68,6 +69,7 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega Callback::Callback * GetOpenWindowCallback(Controller::CommissioningWindowOpener * context); void OnOpenCommissioningWindow(NodeId deviceId, CHIP_ERROR status, SetupPayload payload); + void SetExpectingPairingComplete(bool value) { expectingPairingComplete = value; } private: DevicePairingDelegate_OnPairingCompleteFunct mOnPairingCompleteCallback = nullptr; @@ -78,6 +80,7 @@ class ScriptDevicePairingDelegate final : public Controller::DevicePairingDelega DevicePairingDelegate_OnCommissioningStatusUpdateFunct mOnCommissioningStatusUpdateCallback = nullptr; Callback::Callback mOpenWindowCallback; Controller::CommissioningWindowOpener * mWindowOpener = nullptr; + bool expectingPairingComplete = false; }; } // namespace Controller