Skip to content

Commit

Permalink
Add a TestCluster response command that just returns a boolean. (#11397)
Browse files Browse the repository at this point in the history
Use this instead of relying on status codes in various tests.

Fixes #10555
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Feb 8, 2024
1 parent 6677995 commit 3504965
Show file tree
Hide file tree
Showing 22 changed files with 494 additions and 126 deletions.
46 changes: 28 additions & 18 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,30 @@ bool emberAfTestClusterClusterTestAddArgumentsCallback(CommandHandler * apComman
return true;
}

static bool SendBooleanResponse(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, bool value)
{
Commands::BooleanResponse::Type response;
response.value = value;
CHIP_ERROR err = commandObj->AddResponseData(commandPath, response);
if (err != CHIP_NO_ERROR)
{
commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::Failure);
}
return true;
}

bool emberAfTestClusterClusterTestStructArgumentRequestCallback(
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::TestStructArgumentRequest::DecodableType & commandData)
{
emberAfSendImmediateDefaultResponse(commandData.arg1.b ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
return SendBooleanResponse(commandObj, commandPath, commandData.arg1.b);
}

bool emberAfTestClusterClusterTestNestedStructArgumentRequestCallback(
app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::TestNestedStructArgumentRequest::DecodableType & commandData)
{
emberAfSendImmediateDefaultResponse(commandData.arg1.c.b ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
return SendBooleanResponse(commandObj, commandPath, commandData.arg1.c.b);
}

bool emberAfTestClusterClusterTestListStructArgumentRequestCallback(
Expand All @@ -314,11 +324,11 @@ bool emberAfTestClusterClusterTestListStructArgumentRequestCallback(

if (CHIP_NO_ERROR != structIterator.GetStatus())
{
shouldReturnTrue = false;
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
return true;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
return SendBooleanResponse(commandObj, commandPath, shouldReturnTrue);
}

bool emberAfTestClusterClusterTestListInt8UArgumentRequestCallback(
Expand All @@ -336,11 +346,11 @@ bool emberAfTestClusterClusterTestListInt8UArgumentRequestCallback(

if (CHIP_NO_ERROR != uint8Iterator.GetStatus())
{
shouldReturnTrue = false;
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
return true;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
return SendBooleanResponse(commandObj, commandPath, shouldReturnTrue);
}

bool emberAfTestClusterClusterTestNestedStructListArgumentRequestCallback(
Expand All @@ -358,11 +368,11 @@ bool emberAfTestClusterClusterTestNestedStructListArgumentRequestCallback(

if (CHIP_NO_ERROR != structIterator.GetStatus())
{
shouldReturnTrue = false;
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
return true;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
return SendBooleanResponse(commandObj, commandPath, shouldReturnTrue);
}

bool emberAfTestClusterClusterTestListNestedStructListArgumentRequestCallback(
Expand All @@ -386,18 +396,18 @@ bool emberAfTestClusterClusterTestListNestedStructListArgumentRequestCallback(

if (CHIP_NO_ERROR != subStructIterator.GetStatus())
{
shouldReturnTrue = false;
break;
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
return true;
}
}

if (CHIP_NO_ERROR != structIterator.GetStatus())
{
shouldReturnTrue = false;
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
return true;
}

emberAfSendImmediateDefaultResponse(shouldReturnTrue ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
return true;
return SendBooleanResponse(commandObj, commandPath, shouldReturnTrue);
}

bool emberAfTestClusterClusterTestListInt8UReverseRequestCallback(
Expand Down
48 changes: 42 additions & 6 deletions src/app/tests/suites/TestClusterComplexTypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ tests:
e: "char_string",
f: 1,
}
response:
values:
- name: "value"
value: true

- label: "Send Test Command With Struct Argument and arg1.b is false"
command: "testStructArgumentRequest"
Expand All @@ -51,7 +55,9 @@ tests:
f: 1,
}
response:
error: 1
values:
- name: "value"
value: false

- label:
"Send Test Command With Nested Struct Argument and arg1.c.b is true"
Expand All @@ -74,6 +80,10 @@ tests:
f: 1,
},
}
response:
values:
- name: "value"
value: true

- label: "Send Test Command With Nested Struct Argument arg1.c.b is false"
disabled: true
Expand All @@ -96,7 +106,9 @@ tests:
},
}
response:
error: 1
values:
- name: "value"
value: false

- label:
"Send Test Command With Nested Struct List Argument and all fields b
Expand Down Expand Up @@ -147,6 +159,10 @@ tests:
],
g: [0, 255],
}
response:
values:
- name: "value"
value: false

- label:
"Send Test Command With Nested Struct List Argument and some fields b
Expand Down Expand Up @@ -198,7 +214,9 @@ tests:
g: [0, 255],
}
response:
error: 1
values:
- name: "value"
value: false

# Tests for List

Expand All @@ -208,6 +226,10 @@ tests:
values:
- name: "arg1"
value: [1, 2, 3, 4, 5, 6, 7, 8, 9]
response:
values:
- name: "value"
value: true

- label: "Send Test Command With List of INT8U and one of them is set to 0"
command: "testListInt8UArgumentRequest"
Expand All @@ -216,7 +238,9 @@ tests:
- name: "arg1"
value: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
response:
error: 1
values:
- name: "value"
value: false

- label: "Send Test Command With List of INT8U and get it reversed"
command: "testListInt8UReverseRequest"
Expand Down Expand Up @@ -255,6 +279,10 @@ tests:
f: 1,
},
]
response:
values:
- name: "value"
value: true

- label:
"Send Test Command With List of Struct Argument and arg1.b of first
Expand Down Expand Up @@ -283,7 +311,9 @@ tests:
},
]
response:
error: 1
values:
- name: "value"
value: false

- label:
"Send Test Command With List of Nested Struct List Argument and all
Expand Down Expand Up @@ -336,6 +366,10 @@ tests:
g: [0, 255],
},
]
response:
values:
- name: "value"
value: true

- label:
"Send Test Command With Nested Struct List Argument and some fields b
Expand Down Expand Up @@ -389,7 +423,9 @@ tests:
},
]
response:
error: 1
values:
- name: "value"
value: false

# Tests for Nullables and Optionals

Expand Down
72 changes: 33 additions & 39 deletions src/app/zap-templates/zcl/data-model/chip/test-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,72 +196,58 @@ limitations under the License.
<arg name="arg6" type="BOOLEAN"/>
</command>

<!--
This command expect a success response if:
* 'b' field of arg1 is true
-->
<command source="client" code="0x07" name="TestStructArgumentRequest" optional="false">
<command source="client" code="0x07" name="TestStructArgumentRequest"
response="BooleanResponse" optional="false">
<description>
Command that takes an argument which is struct
Command that takes an argument which is struct. The response echoes the
'b' field of the single arg.
</description>
<arg name="arg1" type="SimpleStruct"/>
</command>

<!--
This command expect a success response if:
* 'b' field of arg1.c is true
-->
<command source="client" code="0x08" name="TestNestedStructArgumentRequest" optional="false">
<command source="client" code="0x08" name="TestNestedStructArgumentRequest"
response="BooleanResponse" optional="false">
<description>
Command that takes an argument which is nested struct
Command that takes an argument which is nested struct. The response
echoes the 'b' field of ar1.c.
</description>
<arg name="arg1" type="NestedStruct"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1 is an empty list
* the field 'b' of all the SimpleStruct contained in arg1 are true
-->
<command source="client" code="0x09" name="TestListStructArgumentRequest" optional="false">
<command source="client" code="0x09" name="TestListStructArgumentRequest" response="BooleanResponse" optional="false">
<description>
Command that takes an argument which is a list of struct
Command that takes an argument which is a list of structs. The response
returns false if there is some struct in the list whose 'b' field is
false, and true otherwise (including if the list is empty).
</description>
<arg name="arg1" type="SimpleStruct" array="true"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1 is an empty list
* no element is 0
-->
<command source="client" code="0x0A" name="TestListInt8UArgumentRequest" optional="false">
<command source="client" code="0x0A" name="TestListInt8UArgumentRequest" response="BooleanResponse" optional="false">
<description>
Command that takes an argument which is a list of INT8U
Command that takes an argument which is a list of INT8U. The response
returns false if the list contains a 0 in it, true otherwise (including
if the list is empty).
</description>
<arg name="arg1" type="INT8U" array="true"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1.d is an empty list
* the field 'b' of all the SimpleStruct contained in arg1 are true
-->
<command source="client" code="0x0B" name="TestNestedStructListArgumentRequest" optional="false">
<command source="client" code="0x0B" name="TestNestedStructListArgumentRequest" response="BooleanResponse" optional="false">
<description>
Command that takes an argument which is a Nested Struct List
Command that takes an argument which is a Nested Struct List. The
response returns false if there is some struct in arg1 (either directly
in arg1.c or in the arg1.d list) whose 'b' field is false, and true
otherwise.
</description>
<arg name="arg1" type="NestedStructList"/>
</command>

<!--
This command expect a success response if either of the following is true:
* arg1 is an empty list
* the field 'b' of all the SimpleStruct contained in arg1 are true
-->
<command source="client" code="0x0C" name="TestListNestedStructListArgumentRequest" optional="false">
<description>
Command that takes an argument which is a list of Nested Struct List
Command that takes an argument which is a list of Nested Struct List.
The response returns false if there is some struct in arg1 (either
directly in as the 'c' field of an entry 'd' list of an entry) whose 'b'
field is false, and true otherwise (including if the list is empty).
</description>
<arg name="arg1" type="NestedStructList" array="true"/>
</command>
Expand Down Expand Up @@ -415,6 +401,14 @@ limitations under the License.
optional="true"/>
</command>

<command source="server" code="0x08" name="BooleanResponse" optional="false" disableDefaultResponse="true">
<description>
Delivers a single boolean argument. What the argument means depends on
what we're responding to.
</description>
<arg name="value" type="BOOLEAN"/>
</command>

<event code="0x0001" name="TestEvent" priority="info" side="server">
<description>Example test event</description>
<field id="1" name="arg1" type="INT8U"/>
Expand Down
10 changes: 9 additions & 1 deletion src/controller/data_model/controller-clusters.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@
"outgoing": 0
},
{
"name": "ApplyUpdateRequestResponse",
"name": "ApplyUpdateResponse",
"code": 4,
"mfgCode": null,
"source": "server",
Expand Down Expand Up @@ -11464,6 +11464,14 @@
"source": "server",
"incoming": 1,
"outgoing": 0
},
{
"name": "BooleanResponse",
"code": 8,
"mfgCode": null,
"source": "server",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
Expand Down
Loading

0 comments on commit 3504965

Please sign in to comment.