-
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.
Allow configure nlfaultinjection via fault-cluster in yaml (#21951)
* Define and Enable fault injection cluster * Run codegen
- Loading branch information
1 parent
c327880
commit 7976628
Showing
69 changed files
with
4,051 additions
and
117 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
96 changes: 96 additions & 0 deletions
96
src/app/clusters/fault-injection-server/fault-injection-server.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,96 @@ | ||
/** | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* 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 "app/server/Server.h" | ||
#include <app-common/zap-generated/af-structs.h> | ||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
#include <app-common/zap-generated/cluster-objects.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <app/CommandResponseHelper.h> | ||
#include <app/util/af.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
#if CHIP_WITH_NLFAULTINJECTION | ||
#include <inet/InetFaultInjection.h> | ||
#include <lib/support/CHIPFaultInjection.h> | ||
#include <system/SystemFaultInjection.h> | ||
#endif | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters::FaultInjection; | ||
using chip::Protocols::InteractionModel::Status; | ||
|
||
bool emberAfFaultInjectionClusterFailAtFaultCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, | ||
const Commands::FailAtFault::DecodableType & commandData) | ||
{ | ||
if (commandPath.mClusterId != Clusters::FaultInjection::Id) | ||
{ | ||
// We shouldn't have been called at all. | ||
commandObj->AddStatus(commandPath, Status::UnsupportedCluster); | ||
return true; | ||
} | ||
|
||
#if CHIP_WITH_NLFAULTINJECTION | ||
Status returnStatus = Status::Success; | ||
nl::FaultInjection::Manager * faultInjectionMgr = nullptr; | ||
|
||
switch (commandData.type) | ||
{ | ||
case FaultType::kSystemFault: | ||
faultInjectionMgr = &chip::System::FaultInjection::GetManager(); | ||
break; | ||
case FaultType::kInetFault: | ||
faultInjectionMgr = &chip::Inet::FaultInjection::GetManager(); | ||
break; | ||
case FaultType::kChipFault: | ||
faultInjectionMgr = &chip::FaultInjection::GetManager(); | ||
break; | ||
default: | ||
ChipLogError(Zcl, "FaultInjection: Unsupported Fault type received"); | ||
returnStatus = Status::InvalidCommand; | ||
break; | ||
} | ||
|
||
if (faultInjectionMgr != nullptr) | ||
{ | ||
ChipLogProgress(Zcl, "FaultInjection: Configure a fault of type: %d and Id: %d to be triggered deterministically", | ||
static_cast<uint8_t>(commandData.type), commandData.id); | ||
int32_t err = faultInjectionMgr->FailAtFault(commandData.id, commandData.numCallsToSkip, commandData.numCallsToFail, | ||
commandData.takeMutex); | ||
|
||
if (err != 0) | ||
{ | ||
ChipLogError(Zcl, "FaultInjection: Pass invalid inputs to FailAtFault"); | ||
returnStatus = Status::InvalidCommand; | ||
} | ||
} | ||
else | ||
{ | ||
ChipLogError(Zcl, "FaultInjection: Failed to get Fault Injection manager"); | ||
returnStatus = Status::Failure; | ||
} | ||
#else | ||
Status returnStatus = Status::UnsupportedCommand; | ||
#endif // CHIP_WITH_NLFAULTINJECTION | ||
|
||
commandObj->AddStatus(commandPath, returnStatus); | ||
return true; | ||
} | ||
|
||
void MatterFaultInjectionPluginServerInitCallback() {} |
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
43 changes: 43 additions & 0 deletions
43
src/app/zap-templates/zcl/data-model/chip/fault-injection-cluster.xml
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,43 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
Copyright (c) 2022 Project CHIP Authors | ||
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. | ||
--> | ||
<configurator> | ||
<domain name="CHIP"/> | ||
<enum name="FaultType" type="ENUM8"> | ||
<cluster code="0xFFF1FC06"/> | ||
<item name="Unspecified" value="0x00"/> | ||
<item name="SystemFault" value="0x01"/> | ||
<item name="InetFault" value="0x02"/> | ||
<item name="ChipFault" value="0x03"/> | ||
<item name="CertFault" value="0x04"/> | ||
</enum> | ||
<cluster> | ||
<domain>CHIP</domain> | ||
<name>Fault Injection</name> | ||
<code>0xFFF1FC06</code> | ||
<define>FAULT_INJECTION_CLUSTER</define> | ||
<description>The Fault Injection Cluster provide a means for a test harness to configure faults(for example triggering a fault in the system).</description> | ||
<command source="client" code="0x00" name="FailAtFault" optional="false"> | ||
<description>Configure a fault to be triggered deterministically</description> | ||
<arg name="Type" type="FaultType"/> | ||
<arg name="Id" type="INT32U"/> | ||
<arg name="NumCallsToSkip" type="INT32U"/> | ||
<arg name="NumCallsToFail" type="INT32U"/> | ||
<arg name="TakeMutex" type="BOOLEAN"/> | ||
<access op="invoke" role="manage"/> | ||
</command> | ||
</cluster> | ||
</configurator> |
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.