Skip to content

Commit

Permalink
Merge pull request #605 from dmknutsen/issue_494
Browse files Browse the repository at this point in the history
Fix #494, Updates CFE_SB_GetLastSenderID to check if message has been sent on pipe
  • Loading branch information
astrogeco authored Apr 21, 2020
2 parents 8ed578e + 79e4bfb commit d9ade13
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 11 deletions.
10 changes: 10 additions & 0 deletions fsw/cfe-core/src/inc/cfe_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,16 @@
#define CFE_SB_BUFFER_INVALID ((int32)0xca00000e)


/**
* @brief No Message Recieved
*
* When trying to determine the last senders ID, this return
* value indicates that there was not a message recived on the pipe.
*
*/
#define CFE_SB_NO_MSG_RECV ((int32)0xca00000f)


/**
* @brief Not Implemented
*
Expand Down
20 changes: 14 additions & 6 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,12 +1651,20 @@ uint32 CFE_SB_GetLastSenderId(CFE_SB_SenderId_t **Ptr,CFE_SB_PipeId_t PipeId)
/* Get ptr to buffer descriptor for the last msg received on the given pipe */
Ptr2BufDescriptor = CFE_SB.PipeTbl[PipeId].CurrentBuff;

/* Set the receivers pointer to the adr of 'Sender' struct in buf descriptor */
*Ptr = (CFE_SB_SenderId_t *) &Ptr2BufDescriptor -> Sender;

CFE_SB_UnlockSharedData(__func__,__LINE__);

return CFE_SUCCESS;
if ( Ptr2BufDescriptor == NULL )
{
*Ptr = NULL;
CFE_SB.PipeTbl[PipeId].LastSender = CFE_SB_INVALID_MSG_ID;
CFE_SB_UnlockSharedData(__func__,__LINE__);
return CFE_SB_NO_MSG_RECV;
}
else
{
/* Set the receivers pointer to the adr of 'Sender' struct in buf descriptor */
*Ptr = (CFE_SB_SenderId_t *) &Ptr2BufDescriptor -> Sender;
CFE_SB_UnlockSharedData(__func__,__LINE__);
return CFE_SUCCESS;
}

}/* end CFE_SB_GetLastSenderId */

Expand Down
67 changes: 62 additions & 5 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -7531,6 +7531,7 @@ void Test_RcvMsg_API(void)
Test_RcvMsg_GetLastSenderNull();
Test_RcvMsg_GetLastSenderInvalidPipe();
Test_RcvMsg_GetLastSenderInvalidCaller();
Test_RcvMsg_GetLastSenderNoValidSender();
Test_RcvMsg_GetLastSenderSuccess();
Test_RcvMsg_Timeout();
Test_RcvMsg_PipeReadError();
Expand Down Expand Up @@ -7876,10 +7877,8 @@ void Test_RcvMsg_GetLastSenderInvalidCaller(void)
"GetLastSenderId invalid caller test");
} /* end Test_RcvMsg_GetLastSenderInvalidCaller */

/*
** Test successful receive last message request
*/
void Test_RcvMsg_GetLastSenderSuccess(void)

void Test_RcvMsg_GetLastSenderNoValidSender(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_SenderId_t *GLSPtr;
Expand All @@ -7888,12 +7887,70 @@ void Test_RcvMsg_GetLastSenderSuccess(void)
int32 ActRtn;
int32 TestStat = CFE_PASS;

#ifdef UT_VERBOSE
UT_Text("Begin Test for GetLastSender No Valid Sender");
#endif

SB_ResetUnitTest();
CFE_SB_CreatePipe(&PipeId, PipeDepth, "RcvMsgTestPipe");
ActRtn = CFE_SB_GetLastSenderId(&GLSPtr, PipeId);
ExpRtn = CFE_SB_NO_MSG_RECV;

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected return in GetLastSenderId No Valid Sender test, "
"exp=0x%lx, act=0x%lx",
(unsigned long) ExpRtn, (unsigned long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}

ExpRtn = 1;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected rtn from UT_GetNumEventsSent, exp=%ld, act=%ld",
(long) ExpRtn, (long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}

CFE_SB_DeletePipe(PipeId);
UT_Report(__FILE__, __LINE__,
TestStat, "Test_RcvMsg_API",
"GetLastSenderId No Valid Sender test");

} /* end Test_RcvMsg_GetLastSenderNoValidSender */


/*
** Test successful receive last message request
*/
void Test_RcvMsg_GetLastSenderSuccess(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_SenderId_t *GLSPtr;
SB_UT_Test_Tlm_t TlmPkt;
CFE_SB_MsgPtr_t TlmPktPtr = (CFE_SB_MsgPtr_t) &TlmPkt;
CFE_SB_MsgPtr_t PtrToMsg;
uint32 PipeDepth = 10;
int32 ExpRtn;
int32 ActRtn;
int32 TestStat = CFE_PASS;

#ifdef UT_VERBOSE
UT_Text("Begin Test for GetLastSender Success");
#endif

SB_ResetUnitTest();
CFE_SB_CreatePipe(&PipeId, PipeDepth, "RcvMsgTestPipe");
CFE_SB_InitMsg(&TlmPkt, SB_UT_TLM_MID, sizeof(TlmPkt), true);
CFE_SB_Subscribe(SB_UT_TLM_MID, PipeId);
CFE_SB_SendMsg(TlmPktPtr);
CFE_SB_RcvMsg(&PtrToMsg, PipeId,CFE_SB_PEND_FOREVER);
ActRtn = CFE_SB_GetLastSenderId(&GLSPtr, PipeId);
ExpRtn = CFE_SUCCESS;

Expand All @@ -7907,7 +7964,7 @@ void Test_RcvMsg_GetLastSenderSuccess(void)
TestStat = CFE_FAIL;
}

ExpRtn = 1;
ExpRtn = 3;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down
21 changes: 21 additions & 0 deletions fsw/cfe-core/unit-test/sb_UT.h
Original file line number Diff line number Diff line change
Expand Up @@ -2946,6 +2946,27 @@ void Test_RcvMsg_GetLastSenderInvalidPipe(void);
******************************************************************************/
void Test_RcvMsg_GetLastSenderInvalidCaller(void);

/*****************************************************************************/
/**
** \brief Test receive last message response when there is no last sender
**
** \par Description
** This function tests the receive last message response when no last
** sender.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
**
** \sa #UT_Text, #SB_ResetUnitTest, #CFE_SB_CreatePipe,
** \sa #CFE_SB_GetLastSenderId, #UT_GetNumEventsSent, #UT_EventIsInHistory,
** \sa #CFE_SB_DeletePipe, #UT_Report
**
******************************************************************************/
void Test_RcvMsg_GetLastSenderNoValidSender(void);

/*****************************************************************************/
/**
** \brief Test successful receive last message request
Expand Down

0 comments on commit d9ade13

Please sign in to comment.