diff --git a/examples/placeholder/linux/include/MatterCallbacks.h b/examples/placeholder/linux/include/MatterCallbacks.h index c4c2a6d7d608c7..ca8bf57feb8eb1 100644 --- a/examples/placeholder/linux/include/MatterCallbacks.h +++ b/examples/placeholder/linux/include/MatterCallbacks.h @@ -18,6 +18,8 @@ #pragma once +#include "Options.h" + #include #include #include @@ -25,54 +27,53 @@ #include -TestCommand * gTestCommand = nullptr; - -void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) +TestCommand * GetTargetTest() { - switch (event->Type) + const char * command = LinuxDeviceOptions::GetInstance().command; + if (command == nullptr) + { + return nullptr; + } + + static auto test = GetTestCommand(command); + if (test.get() == nullptr) { - case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: - ChipLogError(Zcl, "Commissioning complete"); - - TestCommand * command = reinterpret_cast(arg); - if (command == nullptr) - { - ChipLogError(Zcl, "No tests."); - return; - } - - gTestCommand = command; - gTestCommand->NextTest(); - break; + ChipLogError(chipTool, "Specified test command does not exist: %s", command); + return nullptr; } + + return test.get(); } void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath) { - VerifyOrReturn(gTestCommand != nullptr); + auto test = GetTargetTest(); + VerifyOrReturn(test != nullptr && test->isRunning); ChipLogError(Zcl, "Receive command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Command: " ChipLogFormatMEI, commandPath.mEndpointId, ChipLogValueMEI(commandPath.mClusterId), ChipLogValueMEI(commandPath.mCommandId)); - gTestCommand->CheckCommandPath(commandPath); + test->CheckCommandPath(commandPath); } void MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) { - VerifyOrReturn(gTestCommand != nullptr); + auto test = GetTargetTest(); + VerifyOrReturn(test != nullptr && test->isRunning); ChipLogError(Zcl, "Receive READ attribute command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI, attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), ChipLogValueMEI(attributePath.mAttributeId)); - gTestCommand->CheckAttributePath(attributePath); + test->CheckAttributePath(attributePath); } void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) { - VerifyOrReturn(gTestCommand != nullptr); + auto test = GetTargetTest(); + VerifyOrReturn(test != nullptr && test->isRunning); ChipLogError(Zcl, "Receive WRITE attribute command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI, attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), ChipLogValueMEI(attributePath.mAttributeId)); - gTestCommand->CheckAttributePath(attributePath); + test->CheckAttributePath(attributePath); } diff --git a/examples/placeholder/linux/include/TestCommand.h b/examples/placeholder/linux/include/TestCommand.h index 6aad332a399396..86b40a6bd6cc1b 100644 --- a/examples/placeholder/linux/include/TestCommand.h +++ b/examples/placeholder/linux/include/TestCommand.h @@ -18,6 +18,8 @@ #pragma once +#include + #include #include @@ -46,6 +48,27 @@ class TestCommand return CHIP_NO_ERROR; } + CHIP_ERROR WaitForCommissioning() + { + isRunning = false; + return chip::DeviceLayer::PlatformMgr().AddEventHandler(OnPlatformEvent, reinterpret_cast(this)); + } + + static void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) + { + switch (event->Type) + { + case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: + ChipLogProgress(chipTool, "Commissioning complete"); + chip::DeviceLayer::PlatformMgr().RemoveEventHandler(OnPlatformEvent, arg); + + TestCommand * command = reinterpret_cast(arg); + command->isRunning = true; + command->NextTest(); + break; + } + } + void CheckCommandPath(const chip::app::ConcreteCommandPath & commandPath) { if (commandPath == mCommandPath) @@ -76,6 +99,8 @@ class TestCommand mAttributePath = chip::app::ConcreteAttributePath(0, 0, 0); } + std::atomic_bool isRunning{ true }; + protected: chip::app::ConcreteCommandPath mCommandPath; chip::app::ConcreteAttributePath mAttributePath; diff --git a/examples/placeholder/linux/main.cpp b/examples/placeholder/linux/main.cpp index 2535f5052c3953..78744a6849ec67 100644 --- a/examples/placeholder/linux/main.cpp +++ b/examples/placeholder/linux/main.cpp @@ -17,35 +17,18 @@ */ #include "AppMain.h" -#include "Options.h" - -#include - #include "MatterCallbacks.h" -std::unique_ptr RunTestCommand() +int main(int argc, char * argv[]) { - const char * command = LinuxDeviceOptions::GetInstance().command; - if (command == nullptr) - { - return nullptr; - } + VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); - auto test = GetTestCommand(command); - if (test.get() == nullptr) + auto test = GetTargetTest(); + if (test != nullptr) { - ChipLogError(chipTool, "Specified test command does not exists: %s", command); - return nullptr; + test->NextTest(); } - chip::DeviceLayer::PlatformMgr().AddEventHandler(OnPlatformEvent, reinterpret_cast(test.get())); - return test; -} - -int main(int argc, char * argv[]) -{ - VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); - auto test = RunTestCommand(); ChipLinuxAppMainLoop(); return 0; } diff --git a/src/app/tests/suites/certification/Test_TC_DM_1_3_Simulated.yaml b/src/app/tests/suites/certification/Test_TC_DM_1_3_Simulated.yaml index 393462dcb59588..a2892e38cfc38e 100644 --- a/src/app/tests/suites/certification/Test_TC_DM_1_3_Simulated.yaml +++ b/src/app/tests/suites/certification/Test_TC_DM_1_3_Simulated.yaml @@ -19,6 +19,10 @@ config: endpoint: 0 tests: + - label: "Wait for the device to be commissioned" + cluster: "DelayCommands" + command: "WaitForCommissioning" + - label: "Log OnOff Test Startup" cluster: "LogCommands" command: "Log" diff --git a/src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js b/src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js index c1825a68857345..24320284991a1b 100644 --- a/src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js +++ b/src/app/zap-templates/common/simulated-clusters/TestDelayCommands.js @@ -30,9 +30,15 @@ const WaitForMs = { response : { arguments : [] } }; +const WaitForCommissioning = { + name : 'WaitForCommissioning', + arguments : [], + response : { arguments : [] } +}; + const DelayCommands = { name : 'DelayCommands', - commands : [ WaitForMs ], + commands : [ WaitForMs, WaitForCommissioning ], }; //