Skip to content

Commit

Permalink
Drop-off fabric sensitive event when fabric is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed Aug 13, 2022
1 parent 37b9f20 commit 67c7236
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app/EventLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aE
eventOptions.mPriority = aEventData.GetPriorityLevel();
eventOptions.mFabricIndex = aEventData.GetFabricIndex();

VerifyOrReturnError(eventOptions.mFabricIndex != kUndefinedFabricIndex, CHIP_NO_ERROR);

//
// Unlike attributes which have a different 'EncodeForRead' for fabric-scoped structs,
// fabric-sensitive events don't require that since the actual omission of the event in its entirety
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ bool emberAfTestClusterClusterTestEmitTestFabricScopedEventRequestCallback(
{
Commands::TestEmitTestFabricScopedEventResponse::Type responseData;
Events::TestFabricScopedEvent::Type event{ commandData.arg1 };

event.fabricIndex = commandData.arg1;
if (CHIP_NO_ERROR != LogEvent(event, commandPath.mEndpointId, responseData.value))
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
Expand Down
20 changes: 19 additions & 1 deletion src/controller/python/test/test_scripts/cluster_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ async def _TriggerEvent(cls, devCtrl):
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestEventRequest())
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestEventRequest())
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestEventRequest())
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestFabricScopedEventRequest(arg1=0))
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestFabricScopedEventRequest(arg1=1))
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestFabricScopedEventRequest(arg1=2))

@classmethod
async def _RetryForContent(cls, request, until, retryCount=10, intervalSeconds=1):
Expand All @@ -331,6 +331,22 @@ async def TriggerAndWaitForEvents(cls, devCtrl, req):
await cls._TriggerEvent(devCtrl)
await cls._RetryForContent(request=lambda: devCtrl.ReadEvent(nodeid=NODE_ID, events=req), until=lambda res: res != 0)

@classmethod
@base.test_case
async def TestGenerateUndefinedFabricScopedEventRequests(cls, devCtrl, expectEventsNum):
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestFabricScopedEventRequest(arg1=0))
if isinstance(res, Clusters.TestCluster.Commands.TestEmitTestEventResponse):
logger.error(f"Unexpected response of type {type(res)} received.")
raise ValueError()

@classmethod
@base.test_case
async def TestGenerateUndefinedFabricScopedEventRequests(cls, devCtrl, expectEventsNum):
await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestFabricScopedEventRequest(arg1=1))
if isinstance(res, Clusters.TestCluster.Commands.TestEmitTestEventResponse):
logger.error(f"Unexpected response of type {type(res)} received.")
raise ValueError()

@classmethod
@base.test_case
async def TestReadEventRequests(cls, devCtrl, expectEventsNum):
Expand Down Expand Up @@ -557,6 +573,8 @@ async def RunTest(cls, devCtrl):
await cls.TestWriteRequest(devCtrl)
await cls.TestTimedRequest(devCtrl)
await cls.TestTimedRequestTimeout(devCtrl)
await cls.TestGenerateUndefinedFabricScopedEventRequests(devCtrl)
await cls.TestGenerateDefinedFabricScopedEventRequests(devCtrl)
except Exception as ex:
logger.error(
f"Unexpected error occurred when running tests: {ex}")
Expand Down

0 comments on commit 67c7236

Please sign in to comment.