Skip to content

Commit 49a3c9c

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 005f1b4 commit 49a3c9c

File tree

32 files changed

+849
-2
lines changed

32 files changed

+849
-2
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
@@ -21987,6 +21987,22 @@
2198721987
"source": "server",
2198821988
"isIncoming": 0,
2198921989
"isEnabled": 1
21990+
},
21991+
{
21992+
"name": "StringEchoRequest",
21993+
"code": 24,
21994+
"mfgCode": null,
21995+
"source": "client",
21996+
"isIncoming": 1,
21997+
"isEnabled": 1
21998+
},
21999+
{
22000+
"name": "StringEchoResponse",
22001+
"code": 13,
22002+
"mfgCode": null,
22003+
"source": "server",
22004+
"isIncoming": 0,
22005+
"isEnabled": 1
2199022006
}
2199122007
],
2199222008
"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
@@ -9136,6 +9136,22 @@
91369136
"source": "server",
91379137
"isIncoming": 0,
91389138
"isEnabled": 1
9139+
},
9140+
{
9141+
"name": "StringEchoRequest",
9142+
"code": 24,
9143+
"mfgCode": null,
9144+
"source": "client",
9145+
"isIncoming": 1,
9146+
"isEnabled": 1
9147+
},
9148+
{
9149+
"name": "StringEchoResponse",
9150+
"code": 13,
9151+
"mfgCode": null,
9152+
"source": "server",
9153+
"isIncoming": 0,
9154+
"isEnabled": 1
91399155
}
91409156
],
91419157
"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/tests/suites/TestCluster.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3911,14 +3911,15 @@ tests:
39113911
21,
39123912
22,
39133913
23,
3914+
24,
39143915
4294049962,
39153916
]
39163917

39173918
- label: "Validate GeneratedCommandList attribute"
39183919
command: "readAttribute"
39193920
attribute: "GeneratedCommandList"
39203921
response:
3921-
value: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 4294049979]
3922+
value: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 4294049979]
39223923

39233924
- label: "Validate presence of MEI attribute"
39243925
command: "readAttribute"

src/app/tests/suites/TestUnitTestingClusterMei.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ tests:
5252
attribute: "GeneratedCommandList"
5353
response:
5454
constraints:
55-
contains: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 4294049979]
55+
contains: [0, 1, 4, 5, 6, 8, 9, 10, 11, 12, 13, 4294049979]
5656

5757
- label: "Validate presence of MEI attribute"
5858
command: "readAttribute"

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

+17
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,16 @@ limitations under the License.
464464
<arg name="fillCharacter" type="int8u"/>
465465
</command>
466466

467+
<command source="client" code="0x18" name="StringEchoRequest"
468+
response="StringEchoResponse" optional="true">
469+
<description>
470+
Command that takes an argument which is an octet string. The response echoes
471+
the string back. If the string is large then it would require a session that
472+
supports large payloads.
473+
</description>
474+
<arg name="payload" type="octet_string"/>
475+
</command>
476+
467477
<command source="client" code="0xFFF200AA" name="TestDifferentVendorMeiRequest"
468478
optional="true" response="TestDifferentVendorMeiResponse">
469479
<description>
@@ -605,6 +615,13 @@ limitations under the License.
605615
<arg name="buffer" type="octet_string" length="800"/>
606616
</command>
607617

618+
<command source="server" code="0xD" name="StringEchoResponse" optional="true" disableDefaultResponse="true">
619+
<description>
620+
Response to StringEchoRequest. Buffer in response is filled by the payload in the Request.
621+
</description>
622+
<arg name="payload" type="octet_string"/>
623+
</command>
624+
608625
<command source="server" code="0xFFF200BB" name="TestDifferentVendorMeiResponse" optional="true" disableDefaultResponse="true">
609626
<description>
610627
Response to TestDifferentVendorMeiRequest, which is a command having a different MEI vendor ID than the cluster.

src/controller/data_model/controller-clusters.matter

+12
Original file line numberDiff line numberDiff line change
@@ -9623,6 +9623,10 @@ internal cluster UnitTesting = 4294048773 {
96239623
int8u arg1[] = 0;
96249624
}
96259625

9626+
response struct StringEchoResponse = 13 {
9627+
octet_string payload = 0;
9628+
}
9629+
96269630
request struct TestEnumsRequestRequest {
96279631
vendor_id arg1 = 0;
96289632
SimpleEnum arg2 = 1;
@@ -9677,6 +9681,10 @@ internal cluster UnitTesting = 4294048773 {
96779681
int8u fillCharacter = 2;
96789682
}
96799683

9684+
request struct StringEchoRequestRequest {
9685+
octet_string payload = 0;
9686+
}
9687+
96809688
request struct TestDifferentVendorMeiRequestRequest {
96819689
int8u arg1 = 0;
96829690
}
@@ -9756,6 +9764,10 @@ internal cluster UnitTesting = 4294048773 {
97569764
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
97579765
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
97589766
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
9767+
/** Command that takes an argument which is an octet string. The response echoes
9768+
the string back. If the string is large then it would require a session that
9769+
supports large payloads. */
9770+
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
97599771
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
97609772
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
97619773
}

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

+34
Original file line numberDiff line numberDiff line change
@@ -64543,6 +64543,36 @@ public void onResponse(StructType invokeStructValue) {
6454364543
}}, commandId, commandArgs, timedInvokeTimeoutMs);
6454464544
}
6454564545

64546+
public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload) {
64547+
stringEchoRequest(callback, payload, 0);
64548+
}
64549+
64550+
public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload, int timedInvokeTimeoutMs) {
64551+
final long commandId = 24L;
64552+
64553+
ArrayList<StructElement> elements = new ArrayList<>();
64554+
final long payloadFieldID = 0L;
64555+
BaseTLVType payloadtlvValue = new ByteArrayType(payload);
64556+
elements.add(new StructElement(payloadFieldID, payloadtlvValue));
64557+
64558+
StructType commandArgs = new StructType(elements);
64559+
invoke(new InvokeCallbackImpl(callback) {
64560+
@Override
64561+
public void onResponse(StructType invokeStructValue) {
64562+
final long payloadFieldID = 0L;
64563+
byte[] payload = null;
64564+
for (StructElement element: invokeStructValue.value()) {
64565+
if (element.contextTagNum() == payloadFieldID) {
64566+
if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) {
64567+
ByteArrayType castingValue = element.value(ByteArrayType.class);
64568+
payload = castingValue.value(byte[].class);
64569+
}
64570+
}
64571+
}
64572+
callback.onSuccess(payload);
64573+
}}, commandId, commandArgs, timedInvokeTimeoutMs);
64574+
}
64575+
6454664576
public void testDifferentVendorMeiRequest(TestDifferentVendorMeiResponseCallback callback, Integer arg1) {
6454764577
testDifferentVendorMeiRequest(callback, arg1, 0);
6454864578
}
@@ -64632,6 +64662,10 @@ public interface TestBatchHelperResponseCallback extends BaseClusterCallback {
6463264662
void onSuccess(byte[] buffer);
6463364663
}
6463464664

64665+
public interface StringEchoResponseCallback extends BaseClusterCallback {
64666+
void onSuccess(byte[] payload);
64667+
}
64668+
6463564669
public interface TestDifferentVendorMeiResponseCallback extends BaseClusterCallback {
6463664670
void onSuccess(Integer arg1, Long eventNumber);
6463764671
}

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

+18
Original file line numberDiff line numberDiff line change
@@ -17318,6 +17318,7 @@ public enum Command {
1731817318
TestEmitTestFabricScopedEventRequest(21L),
1731917319
TestBatchHelperRequest(22L),
1732017320
TestSecondBatchHelperRequest(23L),
17321+
StringEchoRequest(24L),
1732117322
TestDifferentVendorMeiRequest(4294049962L),;
1732217323
private final long id;
1732317324
Command(long id) {
@@ -17659,6 +17660,23 @@ public static TestSecondBatchHelperRequestCommandField value(int id) throws NoSu
1765917660
}
1766017661
throw new NoSuchFieldError();
1766117662
}
17663+
}public enum StringEchoRequestCommandField {Payload(0),;
17664+
private final int id;
17665+
StringEchoRequestCommandField(int id) {
17666+
this.id = id;
17667+
}
17668+
17669+
public int getID() {
17670+
return id;
17671+
}
17672+
public static StringEchoRequestCommandField value(int id) throws NoSuchFieldError {
17673+
for (StringEchoRequestCommandField field : StringEchoRequestCommandField.values()) {
17674+
if (field.getID() == id) {
17675+
return field;
17676+
}
17677+
}
17678+
throw new NoSuchFieldError();
17679+
}
1766217680
}public enum TestDifferentVendorMeiRequestCommandField {Arg1(0),;
1766317681
private final int id;
1766417682
TestDifferentVendorMeiRequestCommandField(int id) {

0 commit comments

Comments
 (0)