Skip to content

Commit 489c8b7

Browse files
committed
Add a String Echo Request and Echo Response Command to the Unit testing cluster
The Command Request takes a string as argument that is echoed back in the Command response. The string can be large to enable Command testing for large payloads over a TCP-based session. Example ChipTool invocation: ./chip-tool unittesting string-echo-request "aaaaaaaaaaaaa" <node-id> <endpoint-id> ./chip-tool unittesting string-echo-request "aaaaaaa...aaaaaa" <node-id> <endpoint-id> --allow-large-payload true
1 parent 8ba371a commit 489c8b7

File tree

30 files changed

+846
-0
lines changed

30 files changed

+846
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -7034,6 +7034,10 @@ internal cluster UnitTesting = 4294048773 {
70347034
int8u arg1[] = 0;
70357035
}
70367036

7037+
response struct StringEchoResponse = 13 {
7038+
octet_string payload = 0;
7039+
}
7040+
70377041
request struct TestEnumsRequestRequest {
70387042
vendor_id arg1 = 0;
70397043
SimpleEnum arg2 = 1;
@@ -7088,6 +7092,10 @@ internal cluster UnitTesting = 4294048773 {
70887092
int8u fillCharacter = 2;
70897093
}
70907094

7095+
request struct StringEchoRequestRequest {
7096+
octet_string payload = 0;
7097+
}
7098+
70917099
request struct TestDifferentVendorMeiRequestRequest {
70927100
int8u arg1 = 0;
70937101
}
@@ -7167,6 +7175,10 @@ internal cluster UnitTesting = 4294048773 {
71677175
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
71687176
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
71697177
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
7178+
/** Command that takes an argument which is an octet string. The response echoes
7179+
the string back. If the string is large then it would require a session that
7180+
supports large payloads. */
7181+
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
71707182
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
71717183
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
71727184
}
@@ -9082,6 +9094,7 @@ endpoint 1 {
90829094
handle command TestEmitTestFabricScopedEventResponse;
90839095
handle command TestListNestedStructListArgumentRequest;
90849096
handle command TestListInt8UReverseRequest;
9097+
handle command StringEchoResponse;
90859098
handle command TestEnumsRequest;
90869099
handle command TestNullableOptionalRequest;
90879100
handle command SimpleStructEchoRequest;
@@ -9091,6 +9104,7 @@ endpoint 1 {
90919104
handle command TestEmitTestFabricScopedEventRequest;
90929105
handle command TestBatchHelperRequest;
90939106
handle command TestSecondBatchHelperRequest;
9107+
handle command StringEchoRequest;
90949108
handle command TestDifferentVendorMeiRequest;
90959109
handle command TestDifferentVendorMeiResponse;
90969110
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -21997,6 +21997,22 @@
2199721997
"source": "server",
2199821998
"isIncoming": 0,
2199921999
"isEnabled": 1
22000+
},
22001+
{
22002+
"name": "StringEchoRequest",
22003+
"code": 24,
22004+
"mfgCode": null,
22005+
"source": "client",
22006+
"isIncoming": 1,
22007+
"isEnabled": 1
22008+
},
22009+
{
22010+
"name": "StringEchoResponse",
22011+
"code": 13,
22012+
"mfgCode": null,
22013+
"source": "server",
22014+
"isIncoming": 0,
22015+
"isEnabled": 1
2200022016
}
2200122017
],
2200222018
"attributes": [

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

+14
Original file line numberDiff line numberDiff line change
@@ -5736,6 +5736,10 @@ internal cluster UnitTesting = 4294048773 {
57365736
int8u arg1[] = 0;
57375737
}
57385738

5739+
response struct StringEchoResponse = 13 {
5740+
octet_string payload = 0;
5741+
}
5742+
57395743
request struct TestEnumsRequestRequest {
57405744
vendor_id arg1 = 0;
57415745
SimpleEnum arg2 = 1;
@@ -5790,6 +5794,10 @@ internal cluster UnitTesting = 4294048773 {
57905794
int8u fillCharacter = 2;
57915795
}
57925796

5797+
request struct StringEchoRequestRequest {
5798+
octet_string payload = 0;
5799+
}
5800+
57935801
request struct TestDifferentVendorMeiRequestRequest {
57945802
int8u arg1 = 0;
57955803
}
@@ -5869,6 +5877,10 @@ internal cluster UnitTesting = 4294048773 {
58695877
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
58705878
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
58715879
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
5880+
/** Command that takes an argument which is an octet string. The response echoes
5881+
the string back. If the string is large then it would require a session that
5882+
supports large payloads. */
5883+
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
58725884
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
58735885
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
58745886
}
@@ -6786,6 +6798,7 @@ endpoint 1 {
67866798
handle command TestEmitTestFabricScopedEventResponse;
67876799
handle command TestListNestedStructListArgumentRequest;
67886800
handle command TestListInt8UReverseRequest;
6801+
handle command StringEchoResponse;
67896802
handle command TestEnumsRequest;
67906803
handle command TestNullableOptionalRequest;
67916804
handle command SimpleStructEchoRequest;
@@ -6795,6 +6808,7 @@ endpoint 1 {
67956808
handle command TestEmitTestFabricScopedEventRequest;
67966809
handle command TestBatchHelperRequest;
67976810
handle command TestSecondBatchHelperRequest;
6811+
handle command StringEchoRequest;
67986812
handle command TestDifferentVendorMeiRequest;
67996813
handle command TestDifferentVendorMeiResponse;
68006814
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -9135,6 +9135,22 @@
91359135
"source": "server",
91369136
"isIncoming": 0,
91379137
"isEnabled": 1
9138+
},
9139+
{
9140+
"name": "StringEchoRequest",
9141+
"code": 24,
9142+
"mfgCode": null,
9143+
"source": "client",
9144+
"isIncoming": 1,
9145+
"isEnabled": 1
9146+
},
9147+
{
9148+
"name": "StringEchoResponse",
9149+
"code": 13,
9150+
"mfgCode": null,
9151+
"source": "server",
9152+
"isIncoming": 0,
9153+
"isEnabled": 1
91389154
}
91399155
],
91409156
"attributes": [

examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter

+12
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,10 @@ internal cluster UnitTesting = 4294048773 {
17711771
int8u arg1[] = 0;
17721772
}
17731773

1774+
response struct StringEchoResponse = 13 {
1775+
octet_string payload = 0;
1776+
}
1777+
17741778
request struct TestEnumsRequestRequest {
17751779
vendor_id arg1 = 0;
17761780
SimpleEnum arg2 = 1;
@@ -1825,6 +1829,10 @@ internal cluster UnitTesting = 4294048773 {
18251829
int8u fillCharacter = 2;
18261830
}
18271831

1832+
request struct StringEchoRequestRequest {
1833+
octet_string payload = 0;
1834+
}
1835+
18281836
request struct TestDifferentVendorMeiRequestRequest {
18291837
int8u arg1 = 0;
18301838
}
@@ -1904,6 +1912,10 @@ internal cluster UnitTesting = 4294048773 {
19041912
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
19051913
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
19061914
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
1915+
/** Command that takes an argument which is an octet string. The response echoes
1916+
the string back. If the string is large then it would require a session that
1917+
supports large payloads. */
1918+
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
19071919
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
19081920
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
19091921
}

src/app/clusters/test-cluster-server/test-cluster-server.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,16 @@ bool emberAfUnitTestingClusterSimpleStructEchoRequestCallback(CommandHandler * c
10411041
return true;
10421042
}
10431043

1044+
bool emberAfUnitTestingClusterStringEchoRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
1045+
const Commands::StringEchoRequest::DecodableType & commandData)
1046+
{
1047+
Commands::StringEchoResponse::Type response;
1048+
response.payload = commandData.payload;
1049+
1050+
commandObj->AddResponse(commandPath, response);
1051+
return true;
1052+
}
1053+
10441054
bool emberAfUnitTestingClusterTimedInvokeRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
10451055
const Commands::TimedInvokeRequest::DecodableType & commandData)
10461056
{

src/app/zap-templates/zcl/data-model/chip/test-cluster.xml

+17
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,16 @@ limitations under the License.
472472
<arg name="arg1" type="int8u"/>
473473
</command>
474474

475+
<command source="client" code="0x18" name="StringEchoRequest"
476+
response="StringEchoResponse" optional="true">
477+
<description>
478+
Command that takes an argument which is an octet string. The response echoes
479+
the string back. If the string is large then it would require a session that
480+
supports large payloads.
481+
</description>
482+
<arg name="payload" type="octet_string"/>
483+
</command>
484+
475485
<command source="server" code="0x00" name="TestSpecificResponse" optional="true" disableDefaultResponse="true">
476486
<description>
477487
Simple response for TestWithResponse with a simple return value
@@ -613,6 +623,13 @@ limitations under the License.
613623
<arg name="eventNumber" type="int64u"/>>
614624
</command>
615625

626+
<command source="server" code="0xD" name="StringEchoResponse" optional="true" disableDefaultResponse="true">
627+
<description>
628+
Response to StringEchoRequest. Buffer in response is filled by the payload in the Request.
629+
</description>
630+
<arg name="payload" type="octet_string"/>
631+
</command>
632+
616633
<event code="0x0001" name="TestEvent" priority="info" side="server">
617634
<description>Example test event</description>
618635
<field id="1" name="arg1" type="int8u"/>

src/controller/data_model/controller-clusters.matter

+12
Original file line numberDiff line numberDiff line change
@@ -9326,6 +9326,10 @@ internal cluster UnitTesting = 4294048773 {
93269326
int8u arg1[] = 0;
93279327
}
93289328

9329+
response struct StringEchoResponse = 13 {
9330+
octet_string payload = 0;
9331+
}
9332+
93299333
request struct TestEnumsRequestRequest {
93309334
vendor_id arg1 = 0;
93319335
SimpleEnum arg2 = 1;
@@ -9380,6 +9384,10 @@ internal cluster UnitTesting = 4294048773 {
93809384
int8u fillCharacter = 2;
93819385
}
93829386

9387+
request struct StringEchoRequestRequest {
9388+
octet_string payload = 0;
9389+
}
9390+
93839391
request struct TestDifferentVendorMeiRequestRequest {
93849392
int8u arg1 = 0;
93859393
}
@@ -9459,6 +9467,10 @@ internal cluster UnitTesting = 4294048773 {
94599467
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
94609468
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
94619469
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
9470+
/** Command that takes an argument which is an octet string. The response echoes
9471+
the string back. If the string is large then it would require a session that
9472+
supports large payloads. */
9473+
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
94629474
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
94639475
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
94649476
}

src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java

+34
Original file line numberDiff line numberDiff line change
@@ -64082,6 +64082,36 @@ public void onResponse(StructType invokeStructValue) {
6408264082
}}, commandId, commandArgs, timedInvokeTimeoutMs);
6408364083
}
6408464084

64085+
public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload) {
64086+
stringEchoRequest(callback, payload, 0);
64087+
}
64088+
64089+
public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload, int timedInvokeTimeoutMs) {
64090+
final long commandId = 24L;
64091+
64092+
ArrayList<StructElement> elements = new ArrayList<>();
64093+
final long payloadFieldID = 0L;
64094+
BaseTLVType payloadtlvValue = new ByteArrayType(payload);
64095+
elements.add(new StructElement(payloadFieldID, payloadtlvValue));
64096+
64097+
StructType commandArgs = new StructType(elements);
64098+
invoke(new InvokeCallbackImpl(callback) {
64099+
@Override
64100+
public void onResponse(StructType invokeStructValue) {
64101+
final long payloadFieldID = 0L;
64102+
byte[] payload = null;
64103+
for (StructElement element: invokeStructValue.value()) {
64104+
if (element.contextTagNum() == payloadFieldID) {
64105+
if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) {
64106+
ByteArrayType castingValue = element.value(ByteArrayType.class);
64107+
payload = castingValue.value(byte[].class);
64108+
}
64109+
}
64110+
}
64111+
callback.onSuccess(payload);
64112+
}}, commandId, commandArgs, timedInvokeTimeoutMs);
64113+
}
64114+
6408564115
public void testDifferentVendorMeiRequest(TestDifferentVendorMeiResponseCallback callback, Integer arg1) {
6408664116
testDifferentVendorMeiRequest(callback, arg1, 0);
6408764117
}
@@ -64171,6 +64201,10 @@ public interface TestBatchHelperResponseCallback extends BaseClusterCallback {
6417164201
void onSuccess(byte[] buffer);
6417264202
}
6417364203

64204+
public interface StringEchoResponseCallback extends BaseClusterCallback {
64205+
void onSuccess(byte[] payload);
64206+
}
64207+
6417464208
public interface TestDifferentVendorMeiResponseCallback extends BaseClusterCallback {
6417564209
void onSuccess(Integer arg1, Long eventNumber);
6417664210
}

src/controller/java/generated/java/chip/devicecontroller/ClusterIDMapping.java

+18
Original file line numberDiff line numberDiff line change
@@ -17190,6 +17190,7 @@ public enum Command {
1719017190
TestEmitTestFabricScopedEventRequest(21L),
1719117191
TestBatchHelperRequest(22L),
1719217192
TestSecondBatchHelperRequest(23L),
17193+
StringEchoRequest(24L),
1719317194
TestDifferentVendorMeiRequest(4294049962L),;
1719417195
private final long id;
1719517196
Command(long id) {
@@ -17531,6 +17532,23 @@ public static TestSecondBatchHelperRequestCommandField value(int id) throws NoSu
1753117532
}
1753217533
throw new NoSuchFieldError();
1753317534
}
17535+
}public enum StringEchoRequestCommandField {Payload(0),;
17536+
private final int id;
17537+
StringEchoRequestCommandField(int id) {
17538+
this.id = id;
17539+
}
17540+
17541+
public int getID() {
17542+
return id;
17543+
}
17544+
public static StringEchoRequestCommandField value(int id) throws NoSuchFieldError {
17545+
for (StringEchoRequestCommandField field : StringEchoRequestCommandField.values()) {
17546+
if (field.getID() == id) {
17547+
return field;
17548+
}
17549+
}
17550+
throw new NoSuchFieldError();
17551+
}
1753417552
}public enum TestDifferentVendorMeiRequestCommandField {Arg1(0),;
1753517553
private final int id;
1753617554
TestDifferentVendorMeiRequestCommandField(int id) {

src/controller/java/generated/java/chip/devicecontroller/ClusterInfoMapping.java

+40
Original file line numberDiff line numberDiff line change
@@ -20027,6 +20027,28 @@ public void onError(Exception error) {
2002720027
}
2002820028
}
2002920029

20030+
public static class DelegatedUnitTestingClusterStringEchoResponseCallback implements ChipClusters.UnitTestingCluster.StringEchoResponseCallback, DelegatedClusterCallback {
20031+
private ClusterCommandCallback callback;
20032+
@Override
20033+
public void setCallbackDelegate(ClusterCommandCallback callback) {
20034+
this.callback = callback;
20035+
}
20036+
20037+
@Override
20038+
public void onSuccess(byte[] payload) {
20039+
Map<CommandResponseInfo, Object> responseValues = new LinkedHashMap<>();
20040+
20041+
CommandResponseInfo payloadResponseValue = new CommandResponseInfo("payload", "byte[]");
20042+
responseValues.put(payloadResponseValue, payload);
20043+
callback.onSuccess(responseValues);
20044+
}
20045+
20046+
@Override
20047+
public void onError(Exception error) {
20048+
callback.onFailure(error);
20049+
}
20050+
}
20051+
2003020052
public static class DelegatedUnitTestingClusterTestDifferentVendorMeiResponseCallback implements ChipClusters.UnitTestingCluster.TestDifferentVendorMeiResponseCallback, DelegatedClusterCallback {
2003120053
private ClusterCommandCallback callback;
2003220054
@Override
@@ -28434,6 +28456,24 @@ public Map<String, Map<String, InteractionInfo>> getCommandMap() {
2843428456
);
2843528457
unitTestingClusterInteractionInfoMap.put("testSecondBatchHelperRequest", unitTestingtestSecondBatchHelperRequestInteractionInfo);
2843628458

28459+
Map<String, CommandParameterInfo> unitTestingstringEchoRequestCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
28460+
28461+
CommandParameterInfo unitTestingstringEchoRequestpayloadCommandParameterInfo = new CommandParameterInfo("payload", byte[].class, byte[].class);
28462+
unitTestingstringEchoRequestCommandParams.put("payload",unitTestingstringEchoRequestpayloadCommandParameterInfo);
28463+
InteractionInfo unitTestingstringEchoRequestInteractionInfo = new InteractionInfo(
28464+
(cluster, callback, commandArguments) -> {
28465+
((ChipClusters.UnitTestingCluster) cluster)
28466+
.stringEchoRequest((ChipClusters.UnitTestingCluster.StringEchoResponseCallback) callback
28467+
, (byte[])
28468+
commandArguments.get("payload")
28469+
28470+
);
28471+
},
28472+
() -> new DelegatedUnitTestingClusterStringEchoResponseCallback(),
28473+
unitTestingstringEchoRequestCommandParams
28474+
);
28475+
unitTestingClusterInteractionInfoMap.put("stringEchoRequest", unitTestingstringEchoRequestInteractionInfo);
28476+
2843728477
Map<String, CommandParameterInfo> unitTestingtestDifferentVendorMeiRequestCommandParams = new LinkedHashMap<String, CommandParameterInfo>();
2843828478

2843928479
CommandParameterInfo unitTestingtestDifferentVendorMeiRequestarg1CommandParameterInfo = new CommandParameterInfo("arg1", Integer.class, Integer.class);

0 commit comments

Comments
 (0)