-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Python-based freestanding tests (#21567)
* Introduce Python-based freestanding tests - Testing with Cirque requires complex setup and it is not easy to add tests. - Testing with chip-repl is interactive only - We needed a way to test more complex test scenarios than possible with chip-tool which cannot deal with complex test cases including recomputed cryptographic values due to complex logic and data dependencies. This PR: - Uses existing Mobly test framework dependency to add capabilities to make freestanding tests (see `src/python_testing/hello_test.py`) - Adds a module that only depends on existing CHIP modules in the virtual environment to provide needed scaffolding for tests running, including being able to commission a device from the command line - Adds needed cryptographic dependencies to environment for upcoming tests - Adds an example test (`hello_test.py`) - Added support to Python ChipDeviceCtrl to do on-network commissioning (thanks @erjiaqing!) What will follow-up: - Better docs - More sample tests - A way to re-use credentials from chip-tool with Python (already WIP) Testing done: - Built a test for TC-DA-1.7 (not included here) and ran it successfully against an all-clusters-app - Unit tests still pass - Integration tests still pass * Restyled by clang-format * Restyled by gn * Restyled by autopep8 Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
Showing
11 changed files
with
983 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h" | ||
|
||
namespace chip { | ||
namespace Controller { | ||
|
||
void ScriptPairingDeviceDiscoveryDelegate::OnDiscoveredDevice(const Dnssd::DiscoveredNodeData & nodeData) | ||
{ | ||
// Ignore nodes with closed comissioning window | ||
VerifyOrReturn(nodeData.commissionData.commissioningMode != 0); | ||
VerifyOrReturn(mActiveDeviceCommissioner != nullptr); | ||
|
||
const uint16_t port = nodeData.resolutionData.port; | ||
char buf[chip::Inet::IPAddress::kMaxStringLength]; | ||
nodeData.resolutionData.ipAddress[0].ToString(buf); | ||
ChipLogProgress(chipTool, "Discovered Device: %s:%u", buf, port); | ||
|
||
// Stop Mdns discovery. | ||
mActiveDeviceCommissioner->RegisterDeviceDiscoveryDelegate(nullptr); | ||
|
||
Inet::InterfaceId interfaceId = | ||
nodeData.resolutionData.ipAddress[0].IsIPv6LinkLocal() ? nodeData.resolutionData.interfaceId : Inet::InterfaceId::Null(); | ||
PeerAddress peerAddress = PeerAddress::UDP(nodeData.resolutionData.ipAddress[0], port, interfaceId); | ||
|
||
RendezvousParameters keyExchangeParams = RendezvousParameters().SetSetupPINCode(mSetupPasscode).SetPeerAddress(peerAddress); | ||
|
||
CHIP_ERROR err = mActiveDeviceCommissioner->PairDevice(mNodeId, keyExchangeParams, mParams); | ||
if (err != CHIP_NO_ERROR) | ||
{ | ||
VerifyOrReturn(mPairingDelegate != nullptr); | ||
mPairingDelegate->OnCommissioningComplete(mNodeId, err); | ||
} | ||
} | ||
} // namespace Controller | ||
} // namespace chip |
52 changes: 52 additions & 0 deletions
52
src/controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ChipDeviceController-ScriptDevicePairingDelegate.h" | ||
|
||
#include <controller/CHIPDeviceController.h> | ||
|
||
namespace chip { | ||
namespace Controller { | ||
|
||
class ScriptPairingDeviceDiscoveryDelegate : public DeviceDiscoveryDelegate | ||
{ | ||
public: | ||
void Init(NodeId nodeId, uint32_t setupPasscode, CommissioningParameters commissioningParams, | ||
ScriptDevicePairingDelegate * pairingDelegate, DeviceCommissioner * activeDeviceCommissioner) | ||
{ | ||
mNodeId = nodeId; | ||
mSetupPasscode = setupPasscode; | ||
mParams = commissioningParams; | ||
mPairingDelegate = pairingDelegate; | ||
mActiveDeviceCommissioner = activeDeviceCommissioner; | ||
} | ||
void OnDiscoveredDevice(const Dnssd::DiscoveredNodeData & nodeData); | ||
|
||
private: | ||
ScriptDevicePairingDelegate * mPairingDelegate; | ||
DeviceCommissioner * mActiveDeviceCommissioner = nullptr; | ||
|
||
CommissioningParameters mParams; | ||
NodeId mNodeId; | ||
uint32_t mSetupPasscode; | ||
}; | ||
|
||
} // namespace Controller | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.