Skip to content

Commit

Permalink
Drop-off fabric sensitive event when fabric is undefined (#21942)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored Aug 17, 2022
1 parent 96c1b28 commit c037fc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/EventLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventNumber & aE
eventOptions.mPath = path;
eventOptions.mPriority = aEventData.GetPriorityLevel();
eventOptions.mFabricIndex = aEventData.GetFabricIndex();
// this skips logging the event if it's fabric-scoped but no fabric association exists yet.
VerifyOrReturnError(eventOptions.mFabricIndex != kUndefinedFabricIndex, CHIP_NO_ERROR);

//
// Unlike attributes which have a different 'EncodeForRead' for fabric-scoped structs,
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
11 changes: 11 additions & 0 deletions src/controller/python/test/test_scripts/cluster_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ 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):
logger.info("Running TestGenerateUndefinedFabricScopedEventRequests")
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"return result is {res}")

@classmethod
@base.test_case
async def TestReadEventRequests(cls, devCtrl, expectEventsNum):
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit c037fc2

Please sign in to comment.