diff --git a/modules/tbl/fsw/src/cfe_tbl_api.c b/modules/tbl/fsw/src/cfe_tbl_api.c index b87155232..5333557b7 100644 --- a/modules/tbl/fsw/src/cfe_tbl_api.c +++ b/modules/tbl/fsw/src/cfe_tbl_api.c @@ -645,17 +645,13 @@ CFE_Status_t CFE_TBL_Update(CFE_TBL_Handle_t TblHandle) /* On Error conditions, notify ground of screw up */ if (Status < 0) { - if (RegRecPtr != NULL) - { - CFE_EVS_SendEventWithAppID(CFE_TBL_UPDATE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_TBL_Global.TableTaskAppId, - "%s Failed to Update '%s', Status=0x%08X", AppName, RegRecPtr->Name, - (unsigned int)Status); - } - else - { - CFE_EVS_SendEventWithAppID(CFE_TBL_UPDATE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_TBL_Global.TableTaskAppId, - "%s Failed to Update '?', Status=0x%08X", AppName, (unsigned int)Status); - } + /* + * Note that (Status < 0) specifically matches ERROR, not WARNING codes. The CFE_TBL_UpdateInternal() function + * currently only produces two possible codes (aside from CFE_SUCCESS) and both of these are defined as + * warnings, not errors. Therefore, its impossible to reach this code with RegRegPtr != NULL. + */ + CFE_EVS_SendEventWithAppID(CFE_TBL_UPDATE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_TBL_Global.TableTaskAppId, + "%s Failed to update table, Status=0x%08X", AppName, (unsigned int)Status); } else { diff --git a/modules/tbl/fsw/src/cfe_tbl_internal.c b/modules/tbl/fsw/src/cfe_tbl_internal.c index 4672cbc10..03a1ede1e 100644 --- a/modules/tbl/fsw/src/cfe_tbl_internal.c +++ b/modules/tbl/fsw/src/cfe_tbl_internal.c @@ -1425,21 +1425,31 @@ CFE_Status_t CFE_TBL_ValidateTableName(const char *Name) *-----------------------------------------------------------------*/ CFE_Status_t CFE_TBL_ValidateTableSize(const char *Name, size_t Size, uint16 TblOptionFlags) { - CFE_Status_t Status = CFE_SUCCESS; + CFE_Status_t Status; + size_t SizeLimit; - /* Check if the specified table size is zero, or above the maximum allowed */ /* Single-buffered tables are allowed to be up to CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE */ /* Double-buffered tables are allowed to be up to CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE */ - if (Size == 0 || - (Size > CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE && - (TblOptionFlags & CFE_TBL_OPT_BUFFER_MSK) == CFE_TBL_OPT_SNGL_BUFFER) || - (Size > CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE && - (TblOptionFlags & CFE_TBL_OPT_BUFFER_MSK) == CFE_TBL_OPT_DBL_BUFFER)) + if ((TblOptionFlags & CFE_TBL_OPT_BUFFER_MSK) == CFE_TBL_OPT_DBL_BUFFER) + { + SizeLimit = CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE; + } + else + { + SizeLimit = CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE; + } + + /* Check if the specified table size is zero, or above the maximum allowed */ + if (Size == 0 || Size > SizeLimit) { Status = CFE_TBL_ERR_INVALID_SIZE; CFE_ES_WriteToSysLog("%s: Table '%s' has invalid size (%d)\n", __func__, Name, (int)Size); } + else + { + Status = CFE_SUCCESS; + } return Status; } @@ -1719,52 +1729,53 @@ CFE_Status_t CFE_TBL_RestoreTableDataFromCDS(CFE_TBL_RegistryRec_t *RegRecPtr, c { CFE_ES_WriteToSysLog("%s: Failed to recover '%s.%s' from CDS (ErrCode=0x%08X)\n", __func__, AppName, Name, (unsigned int)Status); - } - } - if (Status != CFE_SUCCESS) - { - /* Treat a restore from existing CDS error the same as */ - /* after a power-on reset (CDS was created but is empty) */ - Status = CFE_SUCCESS; - } - else - { - /* Try to locate the associated information in the Critical Table Registry */ - CFE_TBL_FindCriticalTblInfo(&CritRegRecPtr, RegRecPtr->CDSHandle); - - if ((CritRegRecPtr != NULL) && (CritRegRecPtr->TableLoadedOnce)) + /* + * Treat a restore from existing CDS error the same as + * after a power-on reset (CDS was created but is empty) + */ + Status = CFE_SUCCESS; + } + else { - strncpy(WorkingBufferPtr->DataSource, CritRegRecPtr->LastFileLoaded, - sizeof(WorkingBufferPtr->DataSource) - 1); - WorkingBufferPtr->DataSource[sizeof(WorkingBufferPtr->DataSource) - 1] = '\0'; + /* Table was fully restored from existing CDS... */ + /* Try to locate the associated information in the Critical Table Registry */ + CFE_TBL_FindCriticalTblInfo(&CritRegRecPtr, RegRecPtr->CDSHandle); - WorkingBufferPtr->FileCreateTimeSecs = CritRegRecPtr->FileCreateTimeSecs; - WorkingBufferPtr->FileCreateTimeSubSecs = CritRegRecPtr->FileCreateTimeSubSecs; + if ((CritRegRecPtr != NULL) && (CritRegRecPtr->TableLoadedOnce)) + { + strncpy(WorkingBufferPtr->DataSource, CritRegRecPtr->LastFileLoaded, + sizeof(WorkingBufferPtr->DataSource) - 1); + WorkingBufferPtr->DataSource[sizeof(WorkingBufferPtr->DataSource) - 1] = '\0'; - strncpy(RegRecPtr->LastFileLoaded, CritRegRecPtr->LastFileLoaded, sizeof(RegRecPtr->LastFileLoaded) - 1); - RegRecPtr->LastFileLoaded[sizeof(RegRecPtr->LastFileLoaded) - 1] = '\0'; + WorkingBufferPtr->FileCreateTimeSecs = CritRegRecPtr->FileCreateTimeSecs; + WorkingBufferPtr->FileCreateTimeSubSecs = CritRegRecPtr->FileCreateTimeSubSecs; - RegRecPtr->TimeOfLastUpdate.Seconds = CritRegRecPtr->TimeOfLastUpdate.Seconds; - RegRecPtr->TimeOfLastUpdate.Subseconds = CritRegRecPtr->TimeOfLastUpdate.Subseconds; - RegRecPtr->TableLoadedOnce = CritRegRecPtr->TableLoadedOnce; + strncpy(RegRecPtr->LastFileLoaded, CritRegRecPtr->LastFileLoaded, + sizeof(RegRecPtr->LastFileLoaded) - 1); + RegRecPtr->LastFileLoaded[sizeof(RegRecPtr->LastFileLoaded) - 1] = '\0'; - /* Compute the CRC on the specified table buffer */ - WorkingBufferPtr->Crc = - CFE_ES_CalculateCRC(WorkingBufferPtr->BufferPtr, RegRecPtr->Size, 0, CFE_MISSION_ES_DEFAULT_CRC); + RegRecPtr->TimeOfLastUpdate.Seconds = CritRegRecPtr->TimeOfLastUpdate.Seconds; + RegRecPtr->TimeOfLastUpdate.Subseconds = CritRegRecPtr->TimeOfLastUpdate.Subseconds; + RegRecPtr->TableLoadedOnce = CritRegRecPtr->TableLoadedOnce; - /* Make sure everyone who sees the table knows that it has been updated */ - CFE_TBL_NotifyTblUsersOfUpdate(RegRecPtr); + /* Compute the CRC on the specified table buffer */ + WorkingBufferPtr->Crc = + CFE_ES_CalculateCRC(WorkingBufferPtr->BufferPtr, RegRecPtr->Size, 0, CFE_MISSION_ES_DEFAULT_CRC); - /* Make sure the caller realizes the contents have been initialized */ - Status = CFE_TBL_INFO_RECOVERED_TBL; - } - else - { - /* If an error occurred while trying to get the previous contents registry info, */ - /* Log the error in the System Log and pretend like we created a new CDS */ - CFE_ES_WriteToSysLog("%s: Failed to recover '%s.%s' info from CDS TblReg\n", __func__, AppName, Name); - Status = CFE_SUCCESS; + /* Make sure everyone who sees the table knows that it has been updated */ + CFE_TBL_NotifyTblUsersOfUpdate(RegRecPtr); + + /* Make sure the caller realizes the contents have been initialized */ + Status = CFE_TBL_INFO_RECOVERED_TBL; + } + else + { + /* If an error occurred while trying to get the previous contents registry info, */ + /* Log the error in the System Log and pretend like we created a new CDS */ + CFE_ES_WriteToSysLog("%s: Failed to recover '%s.%s' info from CDS TblReg\n", __func__, AppName, Name); + Status = CFE_SUCCESS; + } } } diff --git a/modules/tbl/ut-coverage/tbl_UT.c b/modules/tbl/ut-coverage/tbl_UT.c index 2f20125ab..ef5ca1414 100644 --- a/modules/tbl/ut-coverage/tbl_UT.c +++ b/modules/tbl/ut-coverage/tbl_UT.c @@ -3957,6 +3957,33 @@ void Test_CFE_TBL_Internal(void) #else UtAssert_NA("*Not tested* Invalid processor ID "); #endif + + /* Test CFE_TBL_RestoreTableDataFromCDS() when failed to get a working buffer */ + UT_InitData(); + + RegRecPtr = &CFE_TBL_Global.Registry[0]; + + RegRecPtr->DoubleBuffered = false; + RegRecPtr->TableLoadedOnce = true; + + for (i = 0; i < CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS; i++) + { + CFE_TBL_Global.LoadBuffs[i].Taken = true; + } + + // JPHFIX: Why does this return CFE_SUCCESS? + UtAssert_INT32_EQ(CFE_TBL_RestoreTableDataFromCDS(RegRecPtr, "UT", "UT1", NULL), CFE_TBL_ERR_NO_BUFFER_AVAIL); + + UT_ClearEventHistory(); + + UT_InitData(); + UtAssert_INT32_EQ(CFE_TBL_ValidateTableSize("UT", 0, 0), CFE_TBL_ERR_INVALID_SIZE); + UtAssert_INT32_EQ(CFE_TBL_ValidateTableSize("UT", CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE, CFE_TBL_OPT_SNGL_BUFFER), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_ValidateTableSize("UT", CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE + 1, CFE_TBL_OPT_SNGL_BUFFER), CFE_TBL_ERR_INVALID_SIZE); + UtAssert_INT32_EQ(CFE_TBL_ValidateTableSize("UT", CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE + 1, 0), CFE_TBL_ERR_INVALID_SIZE); + UtAssert_INT32_EQ(CFE_TBL_ValidateTableSize("UT", CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE, CFE_TBL_OPT_DBL_BUFFER), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_TBL_ValidateTableSize("UT", CFE_PLATFORM_TBL_MAX_DBL_TABLE_SIZE + 1, CFE_TBL_OPT_DBL_BUFFER), CFE_TBL_ERR_INVALID_SIZE); + } /*