Skip to content

Commit

Permalink
[Group] Add Group msg yaml test case (#11808)
Browse files Browse the repository at this point in the history
* Add Group msg test case
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Dec 11, 2023
1 parent a67156c commit 2466528
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 4 deletions.
8 changes: 8 additions & 0 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ class {{filename}}: public TestCommand

CHIP_ERROR {{>testCommand}}()
{
{{#if isGroupCommand}}
const chip::GroupId groupId = {{groupId}};
{{else}}
const chip::EndpointId endpoint = mEndpointId.HasValue() ? mEndpointId.Value() : {{endpoint}};
{{/if}}
{{#if isCommand}}
using RequestType = chip::app::Clusters::{{asUpperCamelCase cluster}}::Commands::{{asUpperCamelCase command}}::Type;

Expand All @@ -159,7 +163,11 @@ class {{filename}}: public TestCommand
{{#unless async}}return CHIP_NO_ERROR;{{/unless}}
{{else}}
chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster;
{{#if isGroupCommand}}
cluster.AssociateWithGroup(mDevice, groupId);
{{else}}
cluster.Associate(mDevice, endpoint);
{{/if}}

{{#chip_tests_item_parameters}}
{{zapTypeToEncodableClusterObjectType type ns=parent.cluster}} {{asLowerCamelCase name}}Argument;
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function getTests()
'TestIdentifyCluster',
'TestOperationalCredentialsCluster',
'TestModeSelectCluster',
'TestGroupMessaging',
];

const SoftwareDiagnostics = [
Expand Down
54 changes: 54 additions & 0 deletions src/app/tests/suites/TestGroupMessaging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Basic Group Messaging Tests

config:
cluster: "Basic"
endpoint: 0

tests:
#TODO : Add Group membership command when implemented Issue #11077
# - label: "Add device to Group"
# command: "TODO"

- label: "Group Write Attribute"
command: "writeAttribute"
attribute: "location"
disabled: true
groupId: "1234"
arguments:
value: "us"

- label: "Read back Attribute"
command: "readAttribute"
attribute: "location"
disabled: true
response:
value: "us"

- label: "Restore initial location value"
command: "writeAttribute"
attribute: "location"
groupId: "1234"
disabled: true
arguments:
value: ""

- label: "Read back Attribute"
command: "readAttribute"
attribute: "location"
disabled: true
response:
value: ""
5 changes: 5 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const { asUpperCamelCase } = require(basePath + 'src/app/zap-templa

const kClusterName = 'cluster';
const kEndpointName = 'endpoint';
const kGroupId = 'groupId';
const kCommandName = 'command';
const kWaitCommandName = 'wait';
const kIndexName = 'index';
Expand Down Expand Up @@ -117,6 +118,10 @@ function setDefaultTypeForCommand(test)
test.commandName = 'Write';
test.isAttribute = true;
test.isWriteAttribute = true;
if ((kGroupId in test)) {
test.isGroupCommand = true;
test.groupId = parseInt(test[kGroupId], 10);
}
break;

case 'subscribeAttribute':
Expand Down
32 changes: 32 additions & 0 deletions src/controller/CHIPCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ CHIP_ERROR ClusterBase::Associate(DeviceProxy * device, EndpointId endpoint)
return err;
}

CHIP_ERROR ClusterBase::AssociateWithGroup(DeviceProxy * device, GroupId groupId)
{
// TODO Update this function to work in all possible conditions Issue #11850

CHIP_ERROR err = CHIP_NO_ERROR;

mDevice = device;
if (mDevice->GetSecureSession().HasValue())
{
// Local copy to preserve original SessionHandle for future Unicast communication.
SessionHandle session = mDevice->GetSecureSession().Value();
session.SetGroupId(groupId);
mSessionHandle.SetValue(session);

// Sanity check
if (!mSessionHandle.Value().IsGroupSession())
{
err = CHIP_ERROR_INCORRECT_STATE;
}
}
else
{
// something fishy is going on
err = CHIP_ERROR_INCORRECT_STATE;
}

// Set to 0 for now.
mEndpoint = 0;

return err;
}

void ClusterBase::Dissociate()
{
mDevice = nullptr;
Expand Down
7 changes: 5 additions & 2 deletions src/controller/CHIPCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DLL_EXPORT ClusterBase
virtual ~ClusterBase() {}

CHIP_ERROR Associate(DeviceProxy * device, EndpointId endpoint);
CHIP_ERROR AssociateWithGroup(DeviceProxy * device, GroupId groupId);

void Dissociate();

Expand Down Expand Up @@ -110,8 +111,9 @@ class DLL_EXPORT ClusterBase
}
};

return chip::Controller::WriteAttribute<AttrType>(mDevice->GetSecureSession().Value(), mEndpoint, clusterId, attributeId,
requestData, onSuccessCb, onFailureCb);
return chip::Controller::WriteAttribute<AttrType>((mSessionHandle.HasValue()) ? mSessionHandle.Value()
: mDevice->GetSecureSession().Value(),
mEndpoint, clusterId, attributeId, requestData, onSuccessCb, onFailureCb);
}

template <typename AttributeInfo>
Expand Down Expand Up @@ -179,6 +181,7 @@ class DLL_EXPORT ClusterBase
const ClusterId mClusterId;
DeviceProxy * mDevice;
EndpointId mEndpoint;
chip::Optional<SessionHandle> mSessionHandle;
};

} // namespace Controller
Expand Down
14 changes: 12 additions & 2 deletions src/controller/WriteInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,18 @@ CHIP_ERROR WriteAttribute(SessionHandle sessionHandle, chip::EndpointId endpoint
VerifyOrReturnError(callback != nullptr, CHIP_ERROR_NO_MEMORY);

ReturnErrorOnFailure(app::InteractionModelEngine::GetInstance()->NewWriteClient(handle, callback.get()));
ReturnErrorOnFailure(
handle.EncodeAttributeWritePayload(chip::app::AttributePathParams(endpointId, clusterId, attributeId), requestData));
if (sessionHandle.IsGroupSession())
{
// TODO : Issue #11604
return CHIP_ERROR_NOT_IMPLEMENTED;
// ReturnErrorOnFailure(
// handle.EncodeAttributeWritePayload(chip::app::AttributePathParams(clusterId, attributeId), requestData));
}
else
{
ReturnErrorOnFailure(
handle.EncodeAttributeWritePayload(chip::app::AttributePathParams(endpointId, clusterId, attributeId), requestData));
}
ReturnErrorOnFailure(handle.SendWriteRequest(sessionHandle));

callback.release();
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function getTests()
'TestIdentifyCluster',
'TestOperationalCredentialsCluster',
'TestModeSelectCluster',
'TestGroupMessaging',
];

const SoftwareDiagnostics = [
Expand Down
1 change: 1 addition & 0 deletions src/transport/SessionHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SessionHandle
bool HasFabricIndex() const { return (mFabric != kUndefinedFabricIndex); }
FabricIndex GetFabricIndex() const { return mFabric; }
void SetFabricIndex(FabricIndex fabricId) { mFabric = fabricId; }
void SetGroupId(GroupId groupId) { mGroupId.SetValue(groupId); }

bool operator==(const SessionHandle & that) const
{
Expand Down
49 changes: 49 additions & 0 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2466528

Please sign in to comment.