Skip to content

Commit 1ea6bbe

Browse files
authored
Allow configure nlfaultinjection via fault-cluster in yaml (#21951)
* Define and Enable fault injection cluster * Run codegen
1 parent c037fc2 commit 1ea6bbe

File tree

69 files changed

+4051
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4051
-117
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+34
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,32 @@ server cluster TestCluster = 4294048773 {
38273827
command TestEmitTestFabricScopedEventRequest(TestEmitTestFabricScopedEventRequestRequest): TestEmitTestFabricScopedEventResponse = 21;
38283828
}
38293829

3830+
server cluster FaultInjection = 4294048774 {
3831+
enum FaultType : ENUM8 {
3832+
kUnspecified = 0;
3833+
kSystemFault = 1;
3834+
kInetFault = 2;
3835+
kChipFault = 3;
3836+
kCertFault = 4;
3837+
}
3838+
3839+
readonly attribute command_id generatedCommandList[] = 65528;
3840+
readonly attribute command_id acceptedCommandList[] = 65529;
3841+
readonly attribute attrib_id attributeList[] = 65531;
3842+
readonly attribute bitmap32 featureMap = 65532;
3843+
readonly attribute int16u clusterRevision = 65533;
3844+
3845+
request struct FailAtFaultRequest {
3846+
FaultType type = 0;
3847+
INT32U id = 1;
3848+
INT32U numCallsToSkip = 2;
3849+
INT32U numCallsToFail = 3;
3850+
BOOLEAN takeMutex = 4;
3851+
}
3852+
3853+
command access(invoke: manage) FailAtFault(FailAtFaultRequest): DefaultSuccess = 0;
3854+
}
3855+
38303856
endpoint 0 {
38313857
device type rootdevice = 22;
38323858
binding cluster OtaSoftwareUpdateProvider;
@@ -4145,6 +4171,14 @@ endpoint 0 {
41454171
ram attribute featureMap;
41464172
ram attribute clusterRevision default = 3;
41474173
}
4174+
4175+
server cluster FaultInjection {
4176+
callback attribute generatedCommandList;
4177+
callback attribute acceptedCommandList;
4178+
callback attribute attributeList;
4179+
ram attribute featureMap;
4180+
ram attribute clusterRevision default = 1;
4181+
}
41484182
}
41494183
endpoint 1 {
41504184
device type onofflight = 256;

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+142
Original file line numberDiff line numberDiff line change
@@ -8445,6 +8445,148 @@
84458445
"reportableChange": 0
84468446
}
84478447
]
8448+
},
8449+
{
8450+
"name": "Fault Injection",
8451+
"code": 4294048774,
8452+
"mfgCode": null,
8453+
"define": "FAULT_INJECTION_CLUSTER",
8454+
"side": "client",
8455+
"enabled": 0,
8456+
"commands": [
8457+
{
8458+
"name": "FailAtFault",
8459+
"code": 0,
8460+
"mfgCode": null,
8461+
"source": "client",
8462+
"incoming": 1,
8463+
"outgoing": 1
8464+
}
8465+
],
8466+
"attributes": [
8467+
{
8468+
"name": "FeatureMap",
8469+
"code": 65532,
8470+
"mfgCode": null,
8471+
"side": "client",
8472+
"type": "bitmap32",
8473+
"included": 1,
8474+
"storageOption": "RAM",
8475+
"singleton": 0,
8476+
"bounded": 0,
8477+
"defaultValue": "0",
8478+
"reportable": 1,
8479+
"minInterval": 1,
8480+
"maxInterval": 65534,
8481+
"reportableChange": 0
8482+
},
8483+
{
8484+
"name": "ClusterRevision",
8485+
"code": 65533,
8486+
"mfgCode": null,
8487+
"side": "client",
8488+
"type": "int16u",
8489+
"included": 1,
8490+
"storageOption": "RAM",
8491+
"singleton": 0,
8492+
"bounded": 0,
8493+
"defaultValue": "1",
8494+
"reportable": 1,
8495+
"minInterval": 1,
8496+
"maxInterval": 65534,
8497+
"reportableChange": 0
8498+
}
8499+
]
8500+
},
8501+
{
8502+
"name": "Fault Injection",
8503+
"code": 4294048774,
8504+
"mfgCode": null,
8505+
"define": "FAULT_INJECTION_CLUSTER",
8506+
"side": "server",
8507+
"enabled": 1,
8508+
"attributes": [
8509+
{
8510+
"name": "GeneratedCommandList",
8511+
"code": 65528,
8512+
"mfgCode": null,
8513+
"side": "server",
8514+
"type": "array",
8515+
"included": 1,
8516+
"storageOption": "External",
8517+
"singleton": 0,
8518+
"bounded": 0,
8519+
"defaultValue": "",
8520+
"reportable": 1,
8521+
"minInterval": 1,
8522+
"maxInterval": 65534,
8523+
"reportableChange": 0
8524+
},
8525+
{
8526+
"name": "AcceptedCommandList",
8527+
"code": 65529,
8528+
"mfgCode": null,
8529+
"side": "server",
8530+
"type": "array",
8531+
"included": 1,
8532+
"storageOption": "External",
8533+
"singleton": 0,
8534+
"bounded": 0,
8535+
"defaultValue": "",
8536+
"reportable": 1,
8537+
"minInterval": 1,
8538+
"maxInterval": 65534,
8539+
"reportableChange": 0
8540+
},
8541+
{
8542+
"name": "AttributeList",
8543+
"code": 65531,
8544+
"mfgCode": null,
8545+
"side": "server",
8546+
"type": "array",
8547+
"included": 1,
8548+
"storageOption": "External",
8549+
"singleton": 0,
8550+
"bounded": 0,
8551+
"defaultValue": "",
8552+
"reportable": 1,
8553+
"minInterval": 1,
8554+
"maxInterval": 65534,
8555+
"reportableChange": 0
8556+
},
8557+
{
8558+
"name": "FeatureMap",
8559+
"code": 65532,
8560+
"mfgCode": null,
8561+
"side": "server",
8562+
"type": "bitmap32",
8563+
"included": 1,
8564+
"storageOption": "RAM",
8565+
"singleton": 0,
8566+
"bounded": 0,
8567+
"defaultValue": "0",
8568+
"reportable": 1,
8569+
"minInterval": 1,
8570+
"maxInterval": 65534,
8571+
"reportableChange": 0
8572+
},
8573+
{
8574+
"name": "ClusterRevision",
8575+
"code": 65533,
8576+
"mfgCode": null,
8577+
"side": "server",
8578+
"type": "int16u",
8579+
"included": 1,
8580+
"storageOption": "RAM",
8581+
"singleton": 0,
8582+
"bounded": 0,
8583+
"defaultValue": "1",
8584+
"reportable": 1,
8585+
"minInterval": 1,
8586+
"maxInterval": 65534,
8587+
"reportableChange": 0
8588+
}
8589+
]
84488590
}
84498591
]
84508592
},

examples/all-clusters-app/esp32/main/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(PRIV_INCLUDE_DIRS_LIST
2323
"${CMAKE_CURRENT_LIST_DIR}/include"
2424
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
2525
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32"
26+
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/third_party/nlfaultinjection/repo/include"
2627
)
2728
set(SRC_DIRS_LIST
2829
"${CMAKE_CURRENT_LIST_DIR}"
@@ -41,6 +42,7 @@ set(SRC_DIRS_LIST
4142
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/application-basic-server"
4243
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/test-cluster-server"
4344
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/descriptor"
45+
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/fault-injection-server"
4446
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/fan-control-server"
4547
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/fixed-label-server"
4648
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/user-label-server"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
*
3+
* Copyright (c) 2022 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "app/server/Server.h"
19+
#include <app-common/zap-generated/af-structs.h>
20+
#include <app-common/zap-generated/attributes/Accessors.h>
21+
#include <app-common/zap-generated/cluster-objects.h>
22+
#include <app-common/zap-generated/ids/Clusters.h>
23+
#include <app/CommandResponseHelper.h>
24+
#include <app/util/af.h>
25+
#include <lib/support/CodeUtils.h>
26+
#include <lib/support/logging/CHIPLogging.h>
27+
28+
#if CHIP_WITH_NLFAULTINJECTION
29+
#include <inet/InetFaultInjection.h>
30+
#include <lib/support/CHIPFaultInjection.h>
31+
#include <system/SystemFaultInjection.h>
32+
#endif
33+
34+
using namespace chip;
35+
using namespace chip::app;
36+
using namespace chip::app::Clusters::FaultInjection;
37+
using chip::Protocols::InteractionModel::Status;
38+
39+
bool emberAfFaultInjectionClusterFailAtFaultCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
40+
const Commands::FailAtFault::DecodableType & commandData)
41+
{
42+
if (commandPath.mClusterId != Clusters::FaultInjection::Id)
43+
{
44+
// We shouldn't have been called at all.
45+
commandObj->AddStatus(commandPath, Status::UnsupportedCluster);
46+
return true;
47+
}
48+
49+
#if CHIP_WITH_NLFAULTINJECTION
50+
Status returnStatus = Status::Success;
51+
nl::FaultInjection::Manager * faultInjectionMgr = nullptr;
52+
53+
switch (commandData.type)
54+
{
55+
case FaultType::kSystemFault:
56+
faultInjectionMgr = &chip::System::FaultInjection::GetManager();
57+
break;
58+
case FaultType::kInetFault:
59+
faultInjectionMgr = &chip::Inet::FaultInjection::GetManager();
60+
break;
61+
case FaultType::kChipFault:
62+
faultInjectionMgr = &chip::FaultInjection::GetManager();
63+
break;
64+
default:
65+
ChipLogError(Zcl, "FaultInjection: Unsupported Fault type received");
66+
returnStatus = Status::InvalidCommand;
67+
break;
68+
}
69+
70+
if (faultInjectionMgr != nullptr)
71+
{
72+
ChipLogProgress(Zcl, "FaultInjection: Configure a fault of type: %d and Id: %d to be triggered deterministically",
73+
static_cast<uint8_t>(commandData.type), commandData.id);
74+
int32_t err = faultInjectionMgr->FailAtFault(commandData.id, commandData.numCallsToSkip, commandData.numCallsToFail,
75+
commandData.takeMutex);
76+
77+
if (err != 0)
78+
{
79+
ChipLogError(Zcl, "FaultInjection: Pass invalid inputs to FailAtFault");
80+
returnStatus = Status::InvalidCommand;
81+
}
82+
}
83+
else
84+
{
85+
ChipLogError(Zcl, "FaultInjection: Failed to get Fault Injection manager");
86+
returnStatus = Status::Failure;
87+
}
88+
#else
89+
Status returnStatus = Status::UnsupportedCommand;
90+
#endif // CHIP_WITH_NLFAULTINJECTION
91+
92+
commandObj->AddStatus(commandPath, returnStatus);
93+
return true;
94+
}
95+
96+
void MatterFaultInjectionPluginServerInitCallback() {}

src/app/tests/suites/TestDescriptorCluster.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ tests:
6565
0x0040, # Fixed Label
6666
0x0041, # User Label
6767
0x0405, # Relative Humidity Measurement (why on EP0?)
68+
0xFFF1FC06, # Fault Injection
6869
]
6970

7071
- label: "Read attribute Client list"

src/app/zap-templates/zcl/data-model/all.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<xi:include href="chip/diagnostic-logs-cluster.xml" />
2020
<xi:include href="chip/door-lock-cluster.xml" />
2121
<xi:include href="chip/ethernet-network-diagnostics-cluster.xml" />
22+
<xi:include href="chip/fault-injection-cluster.xml" />
2223
<xi:include href="chip/fixed-label-cluster.xml" />
2324
<xi:include href="chip/flow-measurement-cluster.xml" />
2425
<xi:include href="chip/general-commissioning-cluster.xml" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright (c) 2022 Project CHIP Authors
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<configurator>
18+
<domain name="CHIP"/>
19+
<enum name="FaultType" type="ENUM8">
20+
<cluster code="0xFFF1FC06"/>
21+
<item name="Unspecified" value="0x00"/>
22+
<item name="SystemFault" value="0x01"/>
23+
<item name="InetFault" value="0x02"/>
24+
<item name="ChipFault" value="0x03"/>
25+
<item name="CertFault" value="0x04"/>
26+
</enum>
27+
<cluster>
28+
<domain>CHIP</domain>
29+
<name>Fault Injection</name>
30+
<code>0xFFF1FC06</code>
31+
<define>FAULT_INJECTION_CLUSTER</define>
32+
<description>The Fault Injection Cluster provide a means for a test harness to configure faults(for example triggering a fault in the system).</description>
33+
<command source="client" code="0x00" name="FailAtFault" optional="false">
34+
<description>Configure a fault to be triggered deterministically</description>
35+
<arg name="Type" type="FaultType"/>
36+
<arg name="Id" type="INT32U"/>
37+
<arg name="NumCallsToSkip" type="INT32U"/>
38+
<arg name="NumCallsToFail" type="INT32U"/>
39+
<arg name="TakeMutex" type="BOOLEAN"/>
40+
<access op="invoke" role="manage"/>
41+
</command>
42+
</cluster>
43+
</configurator>

src/app/zap-templates/zcl/zcl-with-test-extensions.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"diagnostic-logs-cluster.xml",
3232
"door-lock-cluster.xml",
3333
"ethernet-network-diagnostics-cluster.xml",
34+
"fault-injection-cluster.xml",
3435
"fixed-label-cluster.xml",
3536
"flow-measurement-cluster.xml",
3637
"general-commissioning-cluster.xml",

src/app/zap-templates/zcl/zcl.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"diagnostic-logs-cluster.xml",
2727
"door-lock-cluster.xml",
2828
"ethernet-network-diagnostics-cluster.xml",
29+
"fault-injection-cluster.xml",
2930
"fixed-label-cluster.xml",
3031
"flow-measurement-cluster.xml",
3132
"general-commissioning-cluster.xml",

0 commit comments

Comments
 (0)