Skip to content

Commit

Permalink
Add FailRandomlyAtFault command to Fault Injection cluster (#22008)
Browse files Browse the repository at this point in the history
* Add FailRandomlyAtFault command to Fault Injection cluster

* Run codegen

* Address review comments
  • Loading branch information
yufengwangca authored Aug 18, 2022
1 parent a8679f0 commit c9d2148
Show file tree
Hide file tree
Showing 22 changed files with 498 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3850,7 +3850,14 @@ server cluster FaultInjection = 4294048774 {
BOOLEAN takeMutex = 4;
}

request struct FailRandomlyAtFaultRequest {
FaultType type = 0;
INT32U id = 1;
INT8U percentage = 2;
}

command access(invoke: manage) FailAtFault(FailAtFaultRequest): DefaultSuccess = 0;
command access(invoke: manage) FailRandomlyAtFault(FailRandomlyAtFaultRequest): DefaultSuccess = 1;
}

endpoint 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8461,6 +8461,14 @@
"source": "client",
"incoming": 1,
"outgoing": 1
},
{
"name": "FailRandomlyAtFault",
"code": 1,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
Expand Down
82 changes: 69 additions & 13 deletions src/app/clusters/fault-injection-server/fault-injection-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,14 @@ 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;
}
namespace {

#if CHIP_WITH_NLFAULTINJECTION
Status returnStatus = Status::Success;
nl::FaultInjection::Manager * GetFaultInjectionManager(FaultType type)
{
nl::FaultInjection::Manager * faultInjectionMgr = nullptr;

switch (commandData.type)
switch (type)
{
case FaultType::kSystemFault:
faultInjectionMgr = &chip::System::FaultInjection::GetManager();
Expand All @@ -62,11 +55,29 @@ bool emberAfFaultInjectionClusterFailAtFaultCallback(CommandHandler * commandObj
faultInjectionMgr = &chip::FaultInjection::GetManager();
break;
default:
ChipLogError(Zcl, "FaultInjection: Unsupported Fault type received");
returnStatus = Status::InvalidCommand;
break;
}

return faultInjectionMgr;
}
#endif

} // anonymous namespace

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 = GetFaultInjectionManager(commandData.type);

if (faultInjectionMgr != nullptr)
{
ChipLogProgress(Zcl, "FaultInjection: Configure a fault of type: %d and Id: %d to be triggered deterministically",
Expand All @@ -93,4 +104,49 @@ bool emberAfFaultInjectionClusterFailAtFaultCallback(CommandHandler * commandObj
return true;
}

bool emberAfFaultInjectionClusterFailRandomlyAtFaultCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::FailRandomlyAtFault::DecodableType & commandData)
{
if (commandPath.mClusterId != Clusters::FaultInjection::Id)
{
// We shouldn't have been called at all.
commandObj->AddStatus(commandPath, Status::UnsupportedCluster);
return true;
}

if (commandData.percentage > 100)
{
commandObj->AddStatus(commandPath, Status::InvalidCommand);
return true;
}

#if CHIP_WITH_NLFAULTINJECTION
Status returnStatus = Status::Success;
nl::FaultInjection::Manager * faultInjectionMgr = GetFaultInjectionManager(commandData.type);

if (faultInjectionMgr != nullptr)
{
ChipLogProgress(Zcl, "FaultInjection: Configure a fault of type: %d and Id: %d to be triggered randomly",
static_cast<uint8_t>(commandData.type), commandData.id);
int32_t err = faultInjectionMgr->FailRandomlyAtFault(commandData.id, commandData.percentage);

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() {}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@ limitations under the License.
<arg name="TakeMutex" type="BOOLEAN"/>
<access op="invoke" role="manage"/>
</command>
<command source="client" code="0x01" name="FailRandomlyAtFault" optional="false">
<description>Configure a fault to be triggered randomly, with a given probability defined as a percentage</description>
<arg name="Type" type="FaultType"/>
<arg name="Id" type="INT32U"/>
<arg name="Percentage" type="INT8U"/>
<access op="invoke" role="manage"/>
</command>
</cluster>
</configurator>
19 changes: 19 additions & 0 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRClusters.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRClusters.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions zzz_generated/all-clusters-app/zap-generated/access.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c9d2148

Please sign in to comment.