Skip to content

Commit

Permalink
Merge pull request #419 from CDKnightNASA/fix-101-seq_count
Browse files Browse the repository at this point in the history
Fix #101, Always increment sequence counter
  • Loading branch information
skliper authored Jan 21, 2020
2 parents 681531b + 54fbccb commit 108d8e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 140 deletions.
14 changes: 0 additions & 14 deletions fsw/cfe-core/src/inc/cfe_sb_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,20 +430,6 @@
**/
#define CFE_SB_SUBSCRIPTION_RPT_EID 22


/** \brief <tt> 'Sending Unsubscription Report Msg=0x\%x,Pipe=\%d,Stat=0x\%x' </tt>
** \event <tt> 'Sending Unsubscription Report Msg=0x\%x,Pipe=\%d,Stat=0x\%x' </tt>
**
** \par Type: DEBUG
**
** \par Cause:
**
** This debug event message is issued when SB subscription reporting is enabled,
** (which is disabled by default) and a subscription is successfully received.
**/
#define CFE_SB_UNSUBSCRIPTION_RPT_EID 24


/** \brief <tt> 'Pipe Overflow,MsgId 0x\%x,pipe \%s,stat 0x\%x,app \%s' </tt>
** \event <tt> 'Pipe Overflow,MsgId 0x\%x,pipe \%s,stat 0x\%x,app \%s' </tt>
**
Expand Down
26 changes: 0 additions & 26 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ int32 CFE_SB_UnsubscribeFull(CFE_SB_MsgId_t MsgId,CFE_SB_PipeId_t PipeId,
uint32 PipeIdx;
uint32 TskId = 0;
bool MatchFound = false;
int32 Stat;
CFE_SB_DestinationD_t *DestPtr = NULL;
char FullName[(OS_MAX_API_NAME * 2)];

Expand Down Expand Up @@ -1098,31 +1097,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,
Expand Down
124 changes: 24 additions & 100 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -4739,6 +4741,7 @@ void Test_Subscribe_SubscriptionReporting(void)
#endif

SB_ResetUnitTest();

ActRtn = CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe");
ExpRtn = CFE_SUCCESS;

Expand Down Expand Up @@ -4816,7 +4819,7 @@ void Test_Subscribe_SubscriptionReporting(void)
}
else
{
ExpRtn = 8;
ExpRtn = 6;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -6119,6 +6023,26 @@ void Test_SendMsg_SequenceCount(void)
TestStat = CFE_FAIL;
}

CFE_SB_Unsubscribe(MsgId, PipeId); /* should have no subscribers now */

CFE_SB_SendMsg(TlmPktPtr); /* increment to 3 */

CFE_SB_Subscribe(MsgId, PipeId); /* resubscribe so we can receive a msg */

CFE_SB_SendMsg(TlmPktPtr); /* increment to 4 */

CFE_SB_RcvMsg(&PtrToMsg, PipeId, CFE_SB_PEND_FOREVER);

if (CCSDS_RD_SEQ(PtrToMsg->Hdr) != 4)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected sequence count for send in sequence count test, "
"exp=4, act=%d",
CCSDS_RD_SEQ(PtrToMsg->Hdr));
UT_Text(cMsg);
TestStat = CFE_FAIL;
}

CFE_SB_DeletePipe(PipeId);
UT_Report(__FILE__, __LINE__,
TestStat, "Test_SendMsg_API",
Expand Down

0 comments on commit 108d8e1

Please sign in to comment.