Skip to content

Commit

Permalink
Merge pull request nasa#136 from jphickey/fix-66-tbl-api-success
Browse files Browse the repository at this point in the history
Fix nasa#66, handle alt-success code from TBL API
  • Loading branch information
astrogeco authored Dec 17, 2021
2 parents aa7f901 + 61c340f commit 446dcd9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
27 changes: 21 additions & 6 deletions fsw/src/cf_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,43 @@ static void CF_HkCmd(void)
*************************************************************************/
static void CF_CheckTables(void)
{
CFE_Status_t status;

/* check the table for an update only if engine is disabled */
if (!CF_AppData.engine.enabled)
{
/* check the table for an update only if engine is disabled */
int32 status = CFE_TBL_ReleaseAddress(CF_AppData.config_handle);

if (status != CFE_SUCCESS)
/*
* NOTE: As of CFE 7.0 (Caelum), some the CFE TBL APIs return success codes
* other than CFE_SUCCESS, so it is not sufficient to check for only this
* result here. For example they may return something like CFE_TBL_INFO_UPDATED.
* But from the standpoint of this routine, they are all success, because the
* function still did its expected job.
*
* For now, the safest way to check is to check for negative values,
* as the alt-success codes are in the positive range by design, and
* error codes are all in the negative range of CFE_Status_t.
*
* This should continue to work even if CFE TBL APIs change to
* remove the problematic alt-success codes at some point.
*/
status = CFE_TBL_ReleaseAddress(CF_AppData.config_handle);
if (status < CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_CHECK_REL, CFE_EVS_EventType_ERROR,
"CF: error in CFE_TBL_ReleaseAddress (check), returned 0x%08x", status);
CF_AppData.run_status = CFE_ES_RunStatus_APP_ERROR;
}

status = CFE_TBL_Manage(CF_AppData.config_handle);
if (status != CFE_SUCCESS)
if (status < CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_CHECK_MAN, CFE_EVS_EventType_ERROR,
"CF: error in CFE_TBL_Manage (check), returned 0x%08x", status);
CF_AppData.run_status = CFE_ES_RunStatus_APP_ERROR;
}

status = CFE_TBL_GetAddress((void *)&CF_AppData.config_table, CF_AppData.config_handle);
if ((status != CFE_SUCCESS) && (status != CFE_TBL_INFO_UPDATED))
if (status < CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_TBL_CHECK_GA, CFE_EVS_EventType_ERROR,
"CF: failed to get table address (check), returned 0x%08x", status);
Expand Down
7 changes: 3 additions & 4 deletions unit-test/cf_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled(void)
void Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_SendEvent(void)
{
/* Arrange */
int32 forced_return_CFE_TBL_ReleaseAddress = Any_int32_Except(CFE_SUCCESS);
int32 forced_return_CFE_TBL_ReleaseAddress = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; /* any generic failure */

/* CF_AppData.engine.enabled being 0 runs code in CUT */
CF_AppData.engine.enabled = 0;
Expand All @@ -122,7 +122,7 @@ void Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_Se
void Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent(void)
{
/* Arrange */
int32 forced_return_CFE_TBL_Manage = Any_int32_Except(CFE_SUCCESS);
int32 forced_return_CFE_TBL_Manage = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; /* any generic failure */

/* CF_AppData.engine.enabled being 0 runs code in CUT */
CF_AppData.engine.enabled = 0;
Expand All @@ -141,8 +141,7 @@ void Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent(
void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE_TBL_INFO_UPDATED_SendEvent(void)
{
/* Arrange */
int32 exceptions[2] = {CFE_SUCCESS, CFE_TBL_INFO_UPDATED};
int32 forced_return_CFE_TBL_GetAddress = Any_int32_ExceptThese(exceptions, 2);
int32 forced_return_CFE_TBL_GetAddress = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; /* any generic failure */

/* CF_AppData.engine.enabled being 0 runs code in CUT */
CF_AppData.engine.enabled = 0;
Expand Down

0 comments on commit 446dcd9

Please sign in to comment.