Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cFE Integration candidate: Equuleus-rc1+dev8 #2533

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix #2387, update for unit test coverage
Corrects some missed branches and lines in the unit test
  • Loading branch information
jphickey committed Mar 14, 2024
commit 8962f4749cdaed340dab9cbc77998625a953cf11
18 changes: 7 additions & 11 deletions modules/tbl/fsw/src/cfe_tbl_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
101 changes: 56 additions & 45 deletions modules/tbl/fsw/src/cfe_tbl_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_TBL_ValidateTableName(const char *Name)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_Status_t Status = CFE_SUCCESS;
size_t NameLength = strlen(Name);
Expand All @@ -1423,23 +1423,33 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_TBL_ValidateTableSize(const char *Name, size_t Size, uint16 TblOptionFlags)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
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;
}
Expand All @@ -1450,7 +1460,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_TBL_ValidateTableOptions(const char *Name, uint16 TblOptionFlags)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_Status_t Status = CFE_SUCCESS;

Expand Down Expand Up @@ -1487,7 +1497,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_TBL_CheckForDuplicateRegistration(int16 *RegIndxPtr, const char *TblName,

Check notice

Code scanning / CodeQL-coding-standard

Function too long Note

CFE_TBL_CheckForDuplicateRegistration has too many lines (77, while 60 are allowed).

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
CFE_TBL_RegistryRec_t *RegRecPtr, CFE_ES_AppId_t ThisAppId,
size_t Size, CFE_TBL_Handle_t *TblHandlePtr)
{
Expand Down Expand Up @@ -1525,19 +1535,19 @@
/* Find the existing access descriptor for the table */
/* and return the same handle that was returned previously */
AccessIndex = RegRecPtr->HeadOfAccessList;
while ((AccessIndex != CFE_TBL_END_OF_LIST) && (*TblHandlePtr == CFE_TBL_BAD_TABLE_HANDLE))
{
if ((CFE_TBL_Global.Handles[AccessIndex].UsedFlag == true) &&
CFE_RESOURCEID_TEST_EQUAL(CFE_TBL_Global.Handles[AccessIndex].AppId, ThisAppId) &&
(CFE_TBL_Global.Handles[AccessIndex].RegIndex == *RegIndxPtr))
{
*TblHandlePtr = AccessIndex;
}
else
{
AccessIndex = CFE_TBL_Global.Handles[AccessIndex].NextLink;
}
}
}
}
else /* Duplicate named table owned by another Application */
Expand Down Expand Up @@ -1571,7 +1581,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_TBL_AllocateTableBuffer(CFE_TBL_RegistryRec_t *RegRecPtr, size_t Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_Status_t Status;

Expand Down Expand Up @@ -1600,7 +1610,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_TBL_AllocateSecondaryBuffer(CFE_TBL_RegistryRec_t *RegRecPtr, size_t Size)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_Status_t Status;

Expand Down Expand Up @@ -1656,7 +1666,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TBL_InitTableAccessDescriptor(CFE_TBL_Handle_t *TblHandlePtr, CFE_ES_AppId_t ThisAppId,

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
CFE_TBL_RegistryRec_t *RegRecPtr, int16 RegIndx)
{
CFE_TBL_AccessDescriptor_t *AccessDescPtr = NULL;
Expand Down Expand Up @@ -1693,7 +1703,7 @@
*
*-----------------------------------------------------------------*/

CFE_Status_t CFE_TBL_RestoreTableDataFromCDS(CFE_TBL_RegistryRec_t *RegRecPtr, const char *AppName, const char *Name,

Check notice

Code scanning / CodeQL

Function too long Note

CFE_TBL_RestoreTableDataFromCDS has too many lines (81, while 60 are allowed).

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
CFE_TBL_CritRegRec_t *CritRegRecPtr)
{
CFE_Status_t Status = CFE_SUCCESS;
Expand All @@ -1719,52 +1729,53 @@
{
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;
}
}
}

Expand All @@ -1780,7 +1791,7 @@
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TBL_RegisterWithCriticalTableRegistry(CFE_TBL_CritRegRec_t *CritRegRecPtr, CFE_TBL_RegistryRec_t *RegRecPtr,

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
const char *TblName)
{
/* Find and initialize a free entry in the Critical Table Registry */
Expand Down
41 changes: 36 additions & 5 deletions modules/tbl/ut-coverage/tbl_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
{ .Method = UT_TaskPipeDispatchMethod_MSG_ID_CC, UT_TPD_SETERR(CFE_STATUS_UNKNOWN_MSG_ID) };
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TBL_CMD_INVALID_CC =
{ TBL_UT_ERROR_DISPATCH(CMD, -1, CFE_STATUS_BAD_COMMAND_CODE) };

/* clang-format on */

CFE_TBL_RegistryRec_t Original[CFE_PLATFORM_TBL_MAX_NUM_TABLES];

Expand Down Expand Up @@ -3052,7 +3052,7 @@
CFE_TBL_Handle_t AccessIterator;
uint8 CDS_Data[sizeof(UT_Table1_t)];
uint32 ExpectedCrc;
int maxPathLenDiff = (int) CFE_MISSION_MAX_PATH_LEN - (int) OS_MAX_PATH_LEN;
int maxPathLenDiff = (int)CFE_MISSION_MAX_PATH_LEN - (int)OS_MAX_PATH_LEN;

memset(&TblInfo1, 0, sizeof(TblInfo1));

Expand Down Expand Up @@ -3198,14 +3198,14 @@
UtAssert_StrnCmp(TblInfo1.LastFileLoaded, MyFilename, sizeof(TblInfo1.LastFileLoaded) - 4, "%s == %s, %ld",
TblInfo1.LastFileLoaded, MyFilename, (long)sizeof(TblInfo1.LastFileLoaded) - 4);

if(maxPathLenDiff >= 0)
if (maxPathLenDiff >= 0)

Check warning

Code scanning / CodeQL

Comparison result is always the same Warning

Comparison is always true because maxPathLenDiff >= 0.
{
UtAssert_StrCmp(&TblInfo1.LastFileLoaded[sizeof(MyFilename) - 4], "(*)", "%s == (*)",
&TblInfo1.LastFileLoaded[sizeof(MyFilename) - 4]);
}
else if(maxPathLenDiff > -3)
else if (maxPathLenDiff > -3)
{
int modIndicatorStart = (int) CFE_MISSION_MAX_PATH_LEN -4 - maxPathLenDiff;
int modIndicatorStart = (int)CFE_MISSION_MAX_PATH_LEN - 4 - maxPathLenDiff;
UtAssert_StrCmp(&TblInfo1.LastFileLoaded[modIndicatorStart], "(*)", "%s == (*)",
&TblInfo1.LastFileLoaded[modIndicatorStart]);
}
Expand Down Expand Up @@ -3957,6 +3957,37 @@
#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;
}

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);
}

/*
Expand Down
Loading