From 67c7236477f3175a6e9a9bdbf457716c2ca2389d Mon Sep 17 00:00:00 2001 From: yunhanw Date: Fri, 12 Aug 2022 17:29:11 -0700 Subject: [PATCH] Drop-off fabric sensitive event when fabric is undefined --- src/app/EventLogging.h | 2 ++ .../test-cluster-server.cpp | 2 +- .../test/test_scripts/cluster_objects.py | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/app/EventLogging.h b/src/app/EventLogging.h index 9d5d56d362d2d2..15746b80ddf797 100644 --- a/src/app/EventLogging.h +++ b/src/app/EventLogging.h @@ -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 diff --git a/src/app/clusters/test-cluster-server/test-cluster-server.cpp b/src/app/clusters/test-cluster-server/test-cluster-server.cpp index 320bce3f34ad24..0da23b39b189e1 100644 --- a/src/app/clusters/test-cluster-server/test-cluster-server.cpp +++ b/src/app/clusters/test-cluster-server/test-cluster-server.cpp @@ -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); diff --git a/src/controller/python/test/test_scripts/cluster_objects.py b/src/controller/python/test/test_scripts/cluster_objects.py index 71320e7cd92261..89b6caf49de9c0 100644 --- a/src/controller/python/test/test_scripts/cluster_objects.py +++ b/src/controller/python/test/test_scripts/cluster_objects.py @@ -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): @@ -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): @@ -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}")