From 95577c2e900308f26c406207aa0c135bde7668ea 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/test-cluster-server.cpp | 2 +- .../python/test/test_scripts/cluster_objects.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) 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..879be1c714b9f5 100644 --- a/src/controller/python/test/test_scripts/cluster_objects.py +++ b/src/controller/python/test/test_scripts/cluster_objects.py @@ -316,6 +316,7 @@ async def _TriggerEvent(cls, devCtrl): 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)) + @classmethod async def _RetryForContent(cls, request, until, retryCount=10, intervalSeconds=1): for i in range(retryCount): @@ -331,6 +332,15 @@ 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): + await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=1, payload=Clusters.TestCluster.Commands.TestEmitTestFabricScopedEventRequest(arg1=0)) + res = await devCtrl.ReadEvent(nodeid=NODE_ID, events=[ + (1, Clusters.TestCluster.Events.TestEvent, 0), + ]) + logger.info(f"{res}") + @classmethod @base.test_case async def TestReadEventRequests(cls, devCtrl, expectEventsNum): @@ -557,6 +567,7 @@ async def RunTest(cls, devCtrl): await cls.TestWriteRequest(devCtrl) await cls.TestTimedRequest(devCtrl) await cls.TestTimedRequestTimeout(devCtrl) + await cls.TestGenerateUndefinedFabricScopedEventRequests(devCtrl) except Exception as ex: logger.error( f"Unexpected error occurred when running tests: {ex}")