From 4e325994a5584ab6cd0b9cac2765ffc9c8c6bbda Mon Sep 17 00:00:00 2001 From: Chris Knight Date: Wed, 27 Nov 2019 08:40:11 -0800 Subject: [PATCH] Fix #101, Always increment sequence counter Maintains a sequential counter on SB messages even when there is no subscribers. Behavior changes: Routes will never be deleted and pipes will never receive an "unsubscribe" notification --- fsw/cfe-core/src/sb/cfe_sb_api.c | 25 -------- fsw/cfe-core/unit-test/sb_UT.c | 104 ++----------------------------- 2 files changed, 4 insertions(+), 125 deletions(-) diff --git a/fsw/cfe-core/src/sb/cfe_sb_api.c b/fsw/cfe-core/src/sb/cfe_sb_api.c index 43d1bb27a..bab1c074c 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_api.c +++ b/fsw/cfe-core/src/sb/cfe_sb_api.c @@ -1081,31 +1081,6 @@ int32 CFE_SB_UnsubscribeFull(CFE_SB_MsgId_t MsgId,CFE_SB_PipeId_t PipeId, }while((MatchFound == false)&&(DestPtr != NULL)); - /* if 'Destinations' was decremented to zero above... */ - if(RoutePtr->Destinations==0){ - CFE_SB.StatTlmMsg.Payload.MsgIdsInUse--; - CFE_SB_RouteIdxPush_Unsync(RouteIdx); /* Return the idx to the available list (stack) for reuse */ - CFE_SB_SetRoutingTblIdx(MsgKey,CFE_SB_INVALID_ROUTE_IDX); - - /* Send unsubscribe report only if there are zero requests for this pkt */ - if((CFE_SB.SubscriptionReporting == CFE_SB_ENABLE)&& - (Scope == CFE_SB_GLOBAL)) - { - CFE_SB.SubRprtMsg.Payload.MsgId = MsgId; - CFE_SB.SubRprtMsg.Payload.Pipe = PipeId; - CFE_SB.SubRprtMsg.Payload.Qos.Priority = 0; - CFE_SB.SubRprtMsg.Payload.Qos.Reliability = 0; - CFE_SB.SubRprtMsg.Payload.SubType = CFE_SB_UNSUBSCRIPTION; - CFE_SB_UnlockSharedData(__func__,__LINE__); - Stat = CFE_SB_SendMsg((CFE_SB_Msg_t *)&CFE_SB.SubRprtMsg); - CFE_EVS_SendEventWithAppID(CFE_SB_UNSUBSCRIPTION_RPT_EID,CFE_EVS_EventType_DEBUG,CFE_SB.AppId, - "Sending Unsubscription Report Msg=0x%x,Pipe=%d,Stat=0x%x", - (unsigned int)MsgId,(int)PipeId,(unsigned int)Stat); - CFE_SB_LockSharedData(__func__,__LINE__); - }/* end if */ - - }/* end if */ - CFE_SB_UnlockSharedData(__func__,__LINE__); CFE_EVS_SendEventWithAppID(CFE_SB_SUBSCRIPTION_REMOVED_EID,CFE_EVS_EventType_DEBUG,CFE_SB.AppId, diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index 424116338..e08052ed8 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -4485,6 +4485,8 @@ void Test_Subscribe_MaxMsgIdCount(void) UT_Text("Begin Test for Maximum Message ID Count"); #endif + SB_ResetUnitTest(); + CFE_SB_CreatePipe(&PipeId0, PipeDepth, "TestPipe0"); CFE_SB_CreatePipe(&PipeId1, PipeDepth, "TestPipe1"); CFE_SB_CreatePipe(&PipeId2, PipeDepth, "TestPipe2"); @@ -4739,6 +4741,7 @@ void Test_Subscribe_SubscriptionReporting(void) #endif SB_ResetUnitTest(); + ActRtn = CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe"); ExpRtn = CFE_SUCCESS; @@ -4816,7 +4819,7 @@ void Test_Subscribe_SubscriptionReporting(void) } else { - ExpRtn = 8; + ExpRtn = 6; ActRtn = UT_GetNumEventsSent(); if (ActRtn != ExpRtn) @@ -4923,7 +4926,6 @@ void Test_Unsubscribe_API(void) Test_Unsubscribe_Local(); Test_Unsubscribe_InvalParam(); Test_Unsubscribe_NoMatch(); - Test_Unsubscribe_SubscriptionReporting(); Test_Unsubscribe_InvalidPipe(); Test_Unsubscribe_InvalidPipeOwner(); Test_Unsubscribe_FirstDestWithMany(); @@ -5235,104 +5237,6 @@ void Test_Unsubscribe_NoMatch(void) TestStat, "Test_Unsubscribe_API", "No match test"); } /* end Test_Unsubscribe_NoMatch */ -/* -** Test message unsubscription response to enabling/disabling subscription -** reporting -*/ -void Test_Unsubscribe_SubscriptionReporting(void) -{ - CFE_SB_PipeId_t TestPipe; - CFE_SB_MsgId_t MsgId = SB_UT_TLM_MID; - uint32 CallerId = 0xFFFFFFFF; - uint16 PipeDepth = 50; - int32 ExpRtn; - int32 ActRtn; - int32 TestStat = CFE_PASS; - -#ifdef UT_VERBOSE - UT_Text("Begin Test Unsubscribe Subscription Reporting"); -#endif - - SB_ResetUnitTest(); - CFE_SB_CreatePipe(&TestPipe, PipeDepth, "TestPipe"); - CFE_SB_Subscribe(MsgId, TestPipe); - CFE_SB_SetSubscriptionReporting(CFE_SB_ENABLE); - CFE_SB_Unsubscribe(MsgId, TestPipe); - ExpRtn = CFE_SB_UNSUBSCRIPTION; - ActRtn = CFE_SB.SubRprtMsg.Payload.SubType; - - if (ActRtn != ExpRtn) - { - snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, - "Unsubscribe not enabled as expected in CFE_SB_Unsubscribe, " - "exp=%ld, act=%ld", - (long) ExpRtn, (long) ActRtn); - UT_Text(cMsg); - TestStat = CFE_FAIL; - } - else - { - CFE_SB_Subscribe(MsgId, TestPipe); - - /* Get the caller's Application ID */ - ExpRtn = CFE_SUCCESS; - ActRtn = CFE_ES_GetAppID(&CallerId); - - if (ActRtn != ExpRtn) - { - snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, - "Unexpected return from GetAppID in unsubscribe test, " - "exp=0x%lx, act=0x%lx", - (unsigned long) ExpRtn, (unsigned long) ActRtn); - UT_Text(cMsg); - TestStat = CFE_FAIL; - } - else - { - /* Subscribe to message: LOCAL */ - ExpRtn = CFE_SUCCESS; - ActRtn = CFE_SB_UnsubscribeFull(MsgId, TestPipe, CFE_SB_LOCAL, - CallerId); - - if (ActRtn != ExpRtn) - { - snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, - "Unexpected return from UnsubscribeFull in " - "subscription reporting test, exp=0x%lx, act=0x%lx", - (unsigned long) ExpRtn, (unsigned long) ActRtn); - UT_Text(cMsg); - TestStat = CFE_FAIL; - } - else - { - ExpRtn = 9; - ActRtn = UT_GetNumEventsSent(); - - if (ActRtn != ExpRtn) - { - snprintf(cMsg, UT_MAX_MESSAGE_LENGTH, - "Unexpected rtn from UT_GetNumEventsSent, " - "exp=%lx, act=%lx", - (unsigned long) ExpRtn, (unsigned long) ActRtn); - UT_Text(cMsg); - TestStat = CFE_FAIL; - } - else if (UT_EventIsInHistory(CFE_SB_UNSUBSCRIPTION_RPT_EID) == false) - { - UT_Text("CFE_SB_UNSUBSCRIPTION_RPT_EID not sent"); - TestStat = CFE_FAIL; - } - } - } - } - - CFE_SB_SetSubscriptionReporting(CFE_SB_DISABLE); - CFE_SB_DeletePipe(TestPipe); - UT_Report(__FILE__, __LINE__, - TestStat, "Test_Unsubscribe_API", - "Subscription reporting test"); -} /* end Test_Unsubscribe_SubscriptionReporting */ - /* ** Test message unsubscription response to an invalid pipe ID */