Skip to content

Commit

Permalink
Add a String Echo Request and Echo Response Command to the Unit testi…
Browse files Browse the repository at this point in the history
…ng 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
  • Loading branch information
pidarped committed Jun 19, 2024
1 parent 8ba371a commit 489c8b7
Show file tree
Hide file tree
Showing 30 changed files with 846 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7034,6 +7034,10 @@ internal cluster UnitTesting = 4294048773 {
int8u arg1[] = 0;
}

response struct StringEchoResponse = 13 {
octet_string payload = 0;
}

request struct TestEnumsRequestRequest {
vendor_id arg1 = 0;
SimpleEnum arg2 = 1;
Expand Down Expand Up @@ -7088,6 +7092,10 @@ internal cluster UnitTesting = 4294048773 {
int8u fillCharacter = 2;
}

request struct StringEchoRequestRequest {
octet_string payload = 0;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -7167,6 +7175,10 @@ internal cluster UnitTesting = 4294048773 {
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
/** Command that takes an argument which is an octet string. The response echoes
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down Expand Up @@ -9082,6 +9094,7 @@ endpoint 1 {
handle command TestEmitTestFabricScopedEventResponse;
handle command TestListNestedStructListArgumentRequest;
handle command TestListInt8UReverseRequest;
handle command StringEchoResponse;
handle command TestEnumsRequest;
handle command TestNullableOptionalRequest;
handle command SimpleStructEchoRequest;
Expand All @@ -9091,6 +9104,7 @@ endpoint 1 {
handle command TestEmitTestFabricScopedEventRequest;
handle command TestBatchHelperRequest;
handle command TestSecondBatchHelperRequest;
handle command StringEchoRequest;
handle command TestDifferentVendorMeiRequest;
handle command TestDifferentVendorMeiResponse;
}
Expand Down
16 changes: 16 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -21997,6 +21997,22 @@
"source": "server",
"isIncoming": 0,
"isEnabled": 1
},
{
"name": "StringEchoRequest",
"code": 24,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "StringEchoResponse",
"code": 13,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5736,6 +5736,10 @@ internal cluster UnitTesting = 4294048773 {
int8u arg1[] = 0;
}

response struct StringEchoResponse = 13 {
octet_string payload = 0;
}

request struct TestEnumsRequestRequest {
vendor_id arg1 = 0;
SimpleEnum arg2 = 1;
Expand Down Expand Up @@ -5790,6 +5794,10 @@ internal cluster UnitTesting = 4294048773 {
int8u fillCharacter = 2;
}

request struct StringEchoRequestRequest {
octet_string payload = 0;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -5869,6 +5877,10 @@ internal cluster UnitTesting = 4294048773 {
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
/** Command that takes an argument which is an octet string. The response echoes
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down Expand Up @@ -6786,6 +6798,7 @@ endpoint 1 {
handle command TestEmitTestFabricScopedEventResponse;
handle command TestListNestedStructListArgumentRequest;
handle command TestListInt8UReverseRequest;
handle command StringEchoResponse;
handle command TestEnumsRequest;
handle command TestNullableOptionalRequest;
handle command SimpleStructEchoRequest;
Expand All @@ -6795,6 +6808,7 @@ endpoint 1 {
handle command TestEmitTestFabricScopedEventRequest;
handle command TestBatchHelperRequest;
handle command TestSecondBatchHelperRequest;
handle command StringEchoRequest;
handle command TestDifferentVendorMeiRequest;
handle command TestDifferentVendorMeiResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9135,6 +9135,22 @@
"source": "server",
"isIncoming": 0,
"isEnabled": 1
},
{
"name": "StringEchoRequest",
"code": 24,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "StringEchoResponse",
"code": 13,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
Expand Down
12 changes: 12 additions & 0 deletions examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ internal cluster UnitTesting = 4294048773 {
int8u arg1[] = 0;
}

response struct StringEchoResponse = 13 {
octet_string payload = 0;
}

request struct TestEnumsRequestRequest {
vendor_id arg1 = 0;
SimpleEnum arg2 = 1;
Expand Down Expand Up @@ -1825,6 +1829,10 @@ internal cluster UnitTesting = 4294048773 {
int8u fillCharacter = 2;
}

request struct StringEchoRequestRequest {
octet_string payload = 0;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -1904,6 +1912,10 @@ internal cluster UnitTesting = 4294048773 {
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
/** Command that takes an argument which is an octet string. The response echoes
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,16 @@ bool emberAfUnitTestingClusterSimpleStructEchoRequestCallback(CommandHandler * c
return true;
}

bool emberAfUnitTestingClusterStringEchoRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::StringEchoRequest::DecodableType & commandData)
{
Commands::StringEchoResponse::Type response;
response.payload = commandData.payload;

commandObj->AddResponse(commandPath, response);
return true;
}

bool emberAfUnitTestingClusterTimedInvokeRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::TimedInvokeRequest::DecodableType & commandData)
{
Expand Down
17 changes: 17 additions & 0 deletions src/app/zap-templates/zcl/data-model/chip/test-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@ limitations under the License.
<arg name="arg1" type="int8u"/>
</command>

<command source="client" code="0x18" name="StringEchoRequest"
response="StringEchoResponse" optional="true">
<description>
Command that takes an argument which is an octet string. The response echoes
the string back. If the string is large then it would require a session that
supports large payloads.
</description>
<arg name="payload" type="octet_string"/>
</command>

<command source="server" code="0x00" name="TestSpecificResponse" optional="true" disableDefaultResponse="true">
<description>
Simple response for TestWithResponse with a simple return value
Expand Down Expand Up @@ -613,6 +623,13 @@ limitations under the License.
<arg name="eventNumber" type="int64u"/>>
</command>

<command source="server" code="0xD" name="StringEchoResponse" optional="true" disableDefaultResponse="true">
<description>
Response to StringEchoRequest. Buffer in response is filled by the payload in the Request.
</description>
<arg name="payload" type="octet_string"/>
</command>

<event code="0x0001" name="TestEvent" priority="info" side="server">
<description>Example test event</description>
<field id="1" name="arg1" type="int8u"/>
Expand Down
12 changes: 12 additions & 0 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -9326,6 +9326,10 @@ internal cluster UnitTesting = 4294048773 {
int8u arg1[] = 0;
}

response struct StringEchoResponse = 13 {
octet_string payload = 0;
}

request struct TestEnumsRequestRequest {
vendor_id arg1 = 0;
SimpleEnum arg2 = 1;
Expand Down Expand Up @@ -9380,6 +9384,10 @@ internal cluster UnitTesting = 4294048773 {
int8u fillCharacter = 2;
}

request struct StringEchoRequestRequest {
octet_string payload = 0;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -9459,6 +9467,10 @@ internal cluster UnitTesting = 4294048773 {
command TestBatchHelperRequest(TestBatchHelperRequestRequest): TestBatchHelperResponse = 22;
/** Second command that responds after sleepBeforeResponseTimeMs with an octet_string the size requested with fillCharacter. */
command TestSecondBatchHelperRequest(TestSecondBatchHelperRequestRequest): TestBatchHelperResponse = 23;
/** Command that takes an argument which is an octet string. The response echoes
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64082,6 +64082,36 @@ public void onResponse(StructType invokeStructValue) {
}}, commandId, commandArgs, timedInvokeTimeoutMs);
}

public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload) {
stringEchoRequest(callback, payload, 0);
}

public void stringEchoRequest(StringEchoResponseCallback callback, byte[] payload, int timedInvokeTimeoutMs) {
final long commandId = 24L;

ArrayList<StructElement> elements = new ArrayList<>();
final long payloadFieldID = 0L;
BaseTLVType payloadtlvValue = new ByteArrayType(payload);
elements.add(new StructElement(payloadFieldID, payloadtlvValue));

StructType commandArgs = new StructType(elements);
invoke(new InvokeCallbackImpl(callback) {
@Override
public void onResponse(StructType invokeStructValue) {
final long payloadFieldID = 0L;
byte[] payload = null;
for (StructElement element: invokeStructValue.value()) {
if (element.contextTagNum() == payloadFieldID) {
if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) {
ByteArrayType castingValue = element.value(ByteArrayType.class);
payload = castingValue.value(byte[].class);
}
}
}
callback.onSuccess(payload);
}}, commandId, commandArgs, timedInvokeTimeoutMs);
}

public void testDifferentVendorMeiRequest(TestDifferentVendorMeiResponseCallback callback, Integer arg1) {
testDifferentVendorMeiRequest(callback, arg1, 0);
}
Expand Down Expand Up @@ -64171,6 +64201,10 @@ public interface TestBatchHelperResponseCallback extends BaseClusterCallback {
void onSuccess(byte[] buffer);
}

public interface StringEchoResponseCallback extends BaseClusterCallback {
void onSuccess(byte[] payload);
}

public interface TestDifferentVendorMeiResponseCallback extends BaseClusterCallback {
void onSuccess(Integer arg1, Long eventNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17190,6 +17190,7 @@ public enum Command {
TestEmitTestFabricScopedEventRequest(21L),
TestBatchHelperRequest(22L),
TestSecondBatchHelperRequest(23L),
StringEchoRequest(24L),
TestDifferentVendorMeiRequest(4294049962L),;
private final long id;
Command(long id) {
Expand Down Expand Up @@ -17531,6 +17532,23 @@ public static TestSecondBatchHelperRequestCommandField value(int id) throws NoSu
}
throw new NoSuchFieldError();
}
}public enum StringEchoRequestCommandField {Payload(0),;
private final int id;
StringEchoRequestCommandField(int id) {
this.id = id;
}

public int getID() {
return id;
}
public static StringEchoRequestCommandField value(int id) throws NoSuchFieldError {
for (StringEchoRequestCommandField field : StringEchoRequestCommandField.values()) {
if (field.getID() == id) {
return field;
}
}
throw new NoSuchFieldError();
}
}public enum TestDifferentVendorMeiRequestCommandField {Arg1(0),;
private final int id;
TestDifferentVendorMeiRequestCommandField(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20027,6 +20027,28 @@ public void onError(Exception error) {
}
}

public static class DelegatedUnitTestingClusterStringEchoResponseCallback implements ChipClusters.UnitTestingCluster.StringEchoResponseCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
@Override
public void setCallbackDelegate(ClusterCommandCallback callback) {
this.callback = callback;
}

@Override
public void onSuccess(byte[] payload) {
Map<CommandResponseInfo, Object> responseValues = new LinkedHashMap<>();

CommandResponseInfo payloadResponseValue = new CommandResponseInfo("payload", "byte[]");
responseValues.put(payloadResponseValue, payload);
callback.onSuccess(responseValues);
}

@Override
public void onError(Exception error) {
callback.onFailure(error);
}
}

public static class DelegatedUnitTestingClusterTestDifferentVendorMeiResponseCallback implements ChipClusters.UnitTestingCluster.TestDifferentVendorMeiResponseCallback, DelegatedClusterCallback {
private ClusterCommandCallback callback;
@Override
Expand Down Expand Up @@ -28434,6 +28456,24 @@ public Map<String, Map<String, InteractionInfo>> getCommandMap() {
);
unitTestingClusterInteractionInfoMap.put("testSecondBatchHelperRequest", unitTestingtestSecondBatchHelperRequestInteractionInfo);

Map<String, CommandParameterInfo> unitTestingstringEchoRequestCommandParams = new LinkedHashMap<String, CommandParameterInfo>();

CommandParameterInfo unitTestingstringEchoRequestpayloadCommandParameterInfo = new CommandParameterInfo("payload", byte[].class, byte[].class);
unitTestingstringEchoRequestCommandParams.put("payload",unitTestingstringEchoRequestpayloadCommandParameterInfo);
InteractionInfo unitTestingstringEchoRequestInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.UnitTestingCluster) cluster)
.stringEchoRequest((ChipClusters.UnitTestingCluster.StringEchoResponseCallback) callback
, (byte[])
commandArguments.get("payload")

);
},
() -> new DelegatedUnitTestingClusterStringEchoResponseCallback(),
unitTestingstringEchoRequestCommandParams
);
unitTestingClusterInteractionInfoMap.put("stringEchoRequest", unitTestingstringEchoRequestInteractionInfo);

Map<String, CommandParameterInfo> unitTestingtestDifferentVendorMeiRequestCommandParams = new LinkedHashMap<String, CommandParameterInfo>();

CommandParameterInfo unitTestingtestDifferentVendorMeiRequestarg1CommandParameterInfo = new CommandParameterInfo("arg1", Integer.class, Integer.class);
Expand Down
Loading

0 comments on commit 489c8b7

Please sign in to comment.