Skip to content

Commit

Permalink
Fix nasa#73, correct status checks of CFE_SB_ReceiveBuffer
Browse files Browse the repository at this point in the history
Check generically for CFE_SUCCESS, rather than a single error code,
since there is more than one error.
  • Loading branch information
jphickey committed Dec 1, 2021
1 parent 7b99b91 commit b2ff945
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
20 changes: 13 additions & 7 deletions fsw/src/cf_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ static void CF_ProcessMsg(CFE_SB_Buffer_t *msg)
*************************************************************************/
void CF_AppMain(void)
{
int32 status;
int32 status;
CFE_SB_Buffer_t *msg;

CFE_ES_PerfLogEntry(CF_PERF_ID_APPMAIN);

Expand All @@ -465,24 +466,29 @@ void CF_AppMain(void)
CF_AppData.run_status = CFE_ES_RunStatus_APP_ERROR;
}

msg = NULL;

while (CFE_ES_RunLoop(&CF_AppData.run_status))
{
CFE_SB_Buffer_t *msg;
CFE_ES_PerfLogExit(CF_PERF_ID_APPMAIN);

status = CFE_SB_ReceiveBuffer(&msg, CF_AppData.cmd_pipe, CF_RCVMSG_TIMEOUT);
CFE_ES_PerfLogEntry(CF_PERF_ID_APPMAIN);

if (((status != CFE_SUCCESS) && (status != CFE_SB_TIME_OUT)) || ((status == CFE_SUCCESS) && !msg))
/*
* note that CFE_SB_ReceiveBuffer() guarantees that a CFE_SUCCESS status is accompanied by
* a valid (non-NULL) output message pointer. However the unit test can force this condition.
*/
if (status == CFE_SUCCESS && msg != NULL)
{
CF_ProcessMsg(msg);
}
else if (status != CFE_SB_TIME_OUT && status != CFE_SB_NO_MESSAGE)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_MSG_RECV, CFE_EVS_EventType_ERROR,
"CF: exiting due to CFE_SB_ReceiveBuffer error 0x%08x", status);
CF_AppData.run_status = CFE_ES_RunStatus_APP_ERROR;
}
else if (msg)
{
CF_ProcessMsg(msg);
}
else
{
/* nothing */
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ static void CF_CFDP_ReceiveMessage(channel_t *c)
for (; count < CF_AppData.config_table->chan[chan_num].rx_max_messages_per_wakeup; ++count)
{
status = CFE_SB_ReceiveBuffer(&CF_AppData.engine.in.msg, c->pipe, CFE_SB_POLL);
if (status == CFE_SB_NO_MESSAGE)
if (status != CFE_SUCCESS)
{
break; /* no more messages */
}
Expand Down
20 changes: 10 additions & 10 deletions unit-test/cf_cfdp_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -4673,7 +4673,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTO_CF_CFDP_RecvPh_Returns_non0_Set_CF_AppDa
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;

Expand Down Expand Up @@ -4711,7 +4711,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_CF_CFDP_FindTransactionBySequenceNumber_
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;

Expand Down Expand Up @@ -4864,7 +4864,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_src_And_dst_AreNot_config_table_local_ei
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -4956,7 +4956,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_Then_CallTo_FGV_Returns_non0_And_dst_IsN
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -5053,7 +5053,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_Then_bytes_received_IsLessThanExpected_A
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -5147,7 +5147,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_Then_directive_code_IsNotEqTo_PDU_FIN_An
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -5242,7 +5242,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_Then_CallTo_CF_CFDP_RecvFin_Returns_neg1
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -5333,7 +5333,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_Then_CallTo_CF_CFDP_RecvFin_Returns_0_In
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -5432,7 +5432,7 @@ void Test_CF_CFDP_ReceiveMessage_CallTo_Then_CallTo_CF_CFDP_RecvFin_Returns_0_Ca
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = (CFE_SB_Buffer_t *)&dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down Expand Up @@ -5718,7 +5718,7 @@ void Test_2CF_CFDP_ReceiveMessage_CallTo_src_IsNotEqTo_config_table_local_eid_Bu
CF_AppData.config_table = &dummy_config_table;
CF_AppData.config_table->chan[dummy_chan_num].rx_max_messages_per_wakeup = 1; /* 1 forces for loop to run */

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), Any_CFE_Status_t_Except(CFE_SB_NO_MESSAGE));
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SUCCESS);

CF_AppData.engine.in.msg = &dummy_msg;
CF_AppData.config_table->local_eid = Any_uint8(); /*TODO: change to any_cf_entity_id_t */
Expand Down

0 comments on commit b2ff945

Please sign in to comment.