Skip to content

Commit

Permalink
Merge pull request #1828 from nmullane/fix472-improve-tbl-line-coverage
Browse files Browse the repository at this point in the history
Improve tbl coverage tests
  • Loading branch information
astrogeco authored Aug 19, 2021
2 parents 41b0ea2 + 73fd3a5 commit 8ef6df7
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 7 deletions.
241 changes: 234 additions & 7 deletions modules/tbl/ut-coverage/tbl_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void UtTest_Setup(void)
UT_ADD_TEST(Test_CFE_TBL_ReleaseAddresses);
UT_ADD_TEST(Test_CFE_TBL_Validate);
UT_ADD_TEST(Test_CFE_TBL_Manage);
UT_ADD_TEST(Test_CFE_TBL_DumpToBuffer);
UT_ADD_TEST(Test_CFE_TBL_Update);
UT_ADD_TEST(Test_CFE_TBL_GetStatus);
UT_ADD_TEST(Test_CFE_TBL_GetInfo);
Expand Down Expand Up @@ -1386,6 +1387,13 @@ void Test_CFE_TBL_Register(void)

UtPrintf("Begin Test Register");

/* Test response to a null table handle and null table name */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_Register(NULL, "UT_Table1", sizeof(UT_Table1_t), CFE_TBL_OPT_DEFAULT, NULL),
CFE_TBL_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_TBL_Register(&TblHandle1, NULL, sizeof(UT_Table1_t), CFE_TBL_OPT_DEFAULT, NULL),
CFE_TBL_BAD_ARGUMENT);

/* Test response to an invalid application ID */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID);
Expand Down Expand Up @@ -1732,6 +1740,23 @@ void Test_CFE_TBL_Register(void)
CFE_UtAssert_EVENTNOTSENT(CFE_TBL_REGISTER_ERR_EID);
CFE_UtAssert_EVENTCOUNT(0);

/* Test registering a critical table with no space in the critical table registry */
/* a. Setup test */
UT_InitData();
for (i = 0; i < CFE_PLATFORM_TBL_MAX_CRITICAL_TABLES; i++)
{
CFE_TBL_Global.CritReg[i].CDSHandle = CFE_TBL_BAD_TABLE_HANDLE - 1;
}
/* b. Perform test */
CFE_UtAssert_SUCCESS(CFE_TBL_Register(&TblHandle1, "NOTABLE", sizeof(UT_Table1_t), CFE_TBL_OPT_CRITICAL, NULL));
CFE_UtAssert_EVENTNOTSENT(CFE_TBL_REGISTER_ERR_EID);
CFE_UtAssert_EVENTCOUNT(0);

/* c. Test cleanup: unregister table */
UT_ClearEventHistory();
CFE_UtAssert_SUCCESS(CFE_TBL_Unregister(TblHandle1));
CFE_UtAssert_EVENTCOUNT(0);

/* Test response to no available handles */
/* a. Test setup */
UT_InitData();
Expand Down Expand Up @@ -1832,6 +1857,11 @@ void Test_CFE_TBL_Share(void)
StdFileHeader.SpacecraftID = CFE_PLATFORM_TBL_VALID_SCID_1;
StdFileHeader.ProcessorID = CFE_PLATFORM_TBL_VALID_PRID_1;

/* Test response to a null table handle and null table name */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_Share(NULL, "ut_cfe_tbl.UT_Table2"), CFE_TBL_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_TBL_Share(&App2TblHandle1, NULL), CFE_TBL_BAD_ARGUMENT);

/* Test response to an invalid application ID */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID);
Expand Down Expand Up @@ -1989,6 +2019,10 @@ void Test_CFE_TBL_Load(void)
CFE_UtAssert_EVENTNOTSENT(CFE_TBL_REGISTER_ERR_EID);
CFE_UtAssert_EVENTCOUNT(0);

/* Test response to a null source data pointer */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_Load(App1TblHandle1, CFE_TBL_SRC_ADDRESS, NULL), CFE_TBL_BAD_ARGUMENT);

/* Test attempt to perform partial INITIAL load */
UT_InitData();
strncpy(StdFileHeader.Description, "Test description", sizeof(StdFileHeader.Description) - 1);
Expand Down Expand Up @@ -2185,6 +2219,10 @@ void Test_CFE_TBL_GetAddress(void)

UtPrintf("Begin Test Get Address");

/* Test response to a null table pointer */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_GetAddress(NULL, App1TblHandle1), CFE_TBL_BAD_ARGUMENT);

/* Test attempt to get the address of a table for which the application
* does not have access
*/
Expand Down Expand Up @@ -2274,13 +2312,27 @@ void Test_CFE_TBL_GetAddresses(void)
UtAssert_NOT_NULL(Tbl1Ptr);
UtAssert_NOT_NULL(Tbl2Ptr);

/* Test getting the addresses of zero tables */
CFE_UtAssert_SUCCESS(CFE_TBL_GetAddresses(ArrayOfPtrsToTblPtrs, 0, ArrayOfHandles));

/* Test response to a null table pointer and null table handle */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_GetAddresses(NULL, 2, ArrayOfHandles), CFE_TBL_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_TBL_GetAddresses(ArrayOfPtrsToTblPtrs, 2, NULL), CFE_TBL_BAD_ARGUMENT);

/* Test attempt to get addresses of tables that the application is not
* allowed to see
*/
UT_InitData();
UT_SetAppID(CFE_ES_APPID_UNDEFINED);
UtAssert_INT32_EQ(CFE_TBL_GetAddresses(ArrayOfPtrsToTblPtrs, 2, ArrayOfHandles), CFE_TBL_ERR_NO_ACCESS);
CFE_UtAssert_EVENTCOUNT(0);

/* Test attempt to get addresses of tables with a bad app ID */
UT_InitData();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_GetAddresses(ArrayOfPtrsToTblPtrs, 2, ArrayOfHandles), CFE_ES_ERR_RESOURCEID_NOT_VALID);
CFE_UtAssert_EVENTCOUNT(0);
}

/*
Expand All @@ -2289,22 +2341,84 @@ void Test_CFE_TBL_GetAddresses(void)
*/
void Test_CFE_TBL_ReleaseAddresses(void)
{
CFE_FS_Header_t FileHeader;
UT_TempFile_t File;
CFE_TBL_Handle_t TblHandle1;
UtPrintf("Begin Test Release Addresses");

/* Test response to a null table handle pointer */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddresses(2, NULL), CFE_TBL_BAD_ARGUMENT);
CFE_UtAssert_EVENTCOUNT(0);

/* Test response to releasing two tables that have not been loaded */
UT_InitData();
UT_SetAppID(UT_TBL_APPID_1);
UtAssert_INT32_EQ(CFE_TBL_ReleaseAddresses(2, ArrayOfHandles), CFE_TBL_ERR_NEVER_LOADED);
CFE_UtAssert_EVENTCOUNT(0);

/* Test releasing 0 then 1 addresses */
UT_InitData();

/* a. Configure for successful file read to initialize table */
strncpy(FileHeader.Description, "FS header description", sizeof(FileHeader.Description) - 1);
FileHeader.Description[sizeof(FileHeader.Description) - 1] = '\0';
FileHeader.ContentType = CFE_FS_FILE_CONTENT_ID;
FileHeader.SubType = CFE_FS_SubType_TBL_IMG;
FileHeader.TimeSeconds = 1704;
FileHeader.TimeSubSeconds = 104;
strncpy(File.TblHeader.TableName, "ut_cfe_tbl.UT_RELEASE_TEST", sizeof(File.TblHeader.TableName) - 1);
File.TblHeader.TableName[sizeof(File.TblHeader.TableName) - 1] = '\0';
UT_TBL_SetupHeader(&File.TblHeader, 0, sizeof(UT_Table1_t));

if (UT_Endianess == UT_LITTLE_ENDIAN)
{
File.TblData.TblElement1 = 0x04030201;
File.TblData.TblElement2 = 0x08070605;
}
else
{
File.TblData.TblElement1 = 0x01020304;
File.TblData.TblElement2 = 0x05060708;
}

UT_SetReadBuffer(&File, sizeof(File));
UT_SetReadHeader(&FileHeader, sizeof(FileHeader));
UT_SetDeferredRetcode(UT_KEY(OS_read), 3, 0);

/* b. Perform load */
CFE_UtAssert_SUCCESS(
CFE_TBL_Register(&TblHandle1, "UT_RELEASE_TEST", sizeof(UT_Table1_t), CFE_TBL_OPT_DEFAULT, NULL));
CFE_UtAssert_SUCCESS(CFE_TBL_Load(TblHandle1, CFE_TBL_SRC_FILE, "MyInputFile"));

/* c. Get addresses */
ArrayOfHandles[0] = TblHandle1;
ArrayOfPtrsToTblPtrs[0] = &Tbl1Ptr;
CFE_UtAssert_SUCCESS(CFE_TBL_GetAddresses(ArrayOfPtrsToTblPtrs, 1, ArrayOfHandles));
UT_ClearEventHistory();

/* d. Release 0 addresses */
CFE_UtAssert_SUCCESS(CFE_TBL_ReleaseAddresses(0, ArrayOfHandles));
CFE_UtAssert_EVENTCOUNT(0);

/* e. Release 1 addresses */
CFE_UtAssert_SUCCESS(CFE_TBL_ReleaseAddresses(1, ArrayOfHandles));
CFE_UtAssert_EVENTCOUNT(0);
}

/*
** Test function for validating the table image for a specified table
*/
void Test_CFE_TBL_Validate(void)
{
int16 RegIndex;
CFE_TBL_RegistryRec_t *RegRecPtr;
UtPrintf("Begin Test Validate");

/* Test setup */
RegIndex = CFE_TBL_FindTableInRegistry("ut_cfe_tbl.UT_Table1");
RegRecPtr = &CFE_TBL_Global.Registry[RegIndex];

/* Test response to attempt to validate a table that an application is
* not allowed to see
*/
Expand All @@ -2320,6 +2434,44 @@ void Test_CFE_TBL_Validate(void)
UT_SetAppID(UT_TBL_APPID_1);
UtAssert_INT32_EQ(CFE_TBL_Validate(App1TblHandle1), CFE_TBL_INFO_NO_VALIDATION_PENDING);
CFE_UtAssert_EVENTCOUNT(0);

/* Test failed validation */
UT_InitData();

/* a. Configure table for validation */
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_PENDING;
CFE_TBL_Global.ValidationResults[0].Result = 0;
strncpy(CFE_TBL_Global.ValidationResults[0].TableName, "ut_cfe_tbl.UT_Table1",
sizeof(CFE_TBL_Global.ValidationResults[0].TableName) - 1);
CFE_TBL_Global.ValidationResults[0].TableName[sizeof(CFE_TBL_Global.ValidationResults[0].TableName) - 1] = '\0';
CFE_TBL_Global.ValidationResults[0].CrcOfTable = 0;
CFE_TBL_Global.ValidationResults[0].ActiveBuffer = false;
RegRecPtr->ValidateInactiveIndex = 0;

/* b. Perform failed validation */
UT_SetDeferredRetcode(UT_KEY(Test_CFE_TBL_ValidationFunc), 1, -1);
CFE_UtAssert_SUCCESS(CFE_TBL_Validate(App1TblHandle1));
CFE_UtAssert_EVENTSENT(CFE_TBL_VALIDATION_ERR_EID);
CFE_UtAssert_EVENTCOUNT(1);
UtAssert_INT32_EQ(CFE_TBL_Global.ValidationResults[0].Result, -1);

/* Test successful validation */
UT_InitData();

/* a. Configure table for validation */
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_PENDING;
CFE_TBL_Global.ValidationResults[0].Result = 0;
strncpy(CFE_TBL_Global.ValidationResults[0].TableName, "ut_cfe_tbl.UT_Table1",
sizeof(CFE_TBL_Global.ValidationResults[0].TableName) - 1);
CFE_TBL_Global.ValidationResults[0].TableName[sizeof(CFE_TBL_Global.ValidationResults[0].TableName) - 1] = '\0';
CFE_TBL_Global.ValidationResults[0].CrcOfTable = 0;
CFE_TBL_Global.ValidationResults[0].ActiveBuffer = false;
RegRecPtr->ValidateInactiveIndex = 0;

/* b. Perform failed validation */
UT_SetDeferredRetcode(UT_KEY(Test_CFE_TBL_ValidationFunc), 1, CFE_SUCCESS);
CFE_UtAssert_SUCCESS(CFE_TBL_Validate(App1TblHandle1));
UtAssert_INT32_EQ(CFE_TBL_Global.ValidationResults[0].Result, CFE_SUCCESS);
}

/*
Expand Down Expand Up @@ -2399,6 +2551,27 @@ void Test_CFE_TBL_Manage(void)
CFE_UtAssert_EVENTCOUNT(1);
UtAssert_INT32_EQ(CFE_TBL_Global.ValidationResults[0].Result, 1);

/* Test response to processing an unsuccessful validation request;
* CFE_TBL_Validate does not return CFE_SUCCESS
*/
UT_InitData();

/* Configure table for validation */
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_PENDING;
CFE_TBL_Global.ValidationResults[0].Result = 0;
strncpy(CFE_TBL_Global.ValidationResults[0].TableName, "ut_cfe_tbl.UT_Table1",
sizeof(CFE_TBL_Global.ValidationResults[0].TableName) - 1);
CFE_TBL_Global.ValidationResults[0].TableName[sizeof(CFE_TBL_Global.ValidationResults[0].TableName) - 1] = '\0';
CFE_TBL_Global.ValidationResults[0].CrcOfTable = 0;
CFE_TBL_Global.ValidationResults[0].ActiveBuffer = false;
RegRecPtr->ValidateInactiveIndex = 0;

/* Perform validation via manage call */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 2, CFE_ES_ERR_RESOURCEID_NOT_VALID);
UtAssert_INT32_EQ(CFE_TBL_Manage(App1TblHandle1), CFE_ES_ERR_RESOURCEID_NOT_VALID);
CFE_UtAssert_EVENTCOUNT(0);
UtAssert_INT32_EQ(CFE_TBL_Global.ValidationResults[0].Result, 0);

/* Test response to processing a successful validation request on an
* inactive buffer
*/
Expand Down Expand Up @@ -2664,13 +2837,61 @@ void Test_CFE_TBL_Manage(void)
CFE_UtAssert_EVENTCOUNT(0);
}

/*
** Test function for dumping to a buffer
*/
void Test_CFE_TBL_DumpToBuffer(void)
{
UtPrintf("Begin Test Dump To Buffer");

/* Test successfully dumping to a buffer */
UT_InitData();
CFE_UtAssert_SUCCESS(CFE_TBL_DumpToBuffer(App1TblHandle1));

/* Test response to an attempt to dump the buffer on a table that the
* application is not allowed to see
*/
UT_InitData();
UT_SetAppID(CFE_ES_APPID_UNDEFINED);
UtAssert_INT32_EQ(CFE_TBL_DumpToBuffer(App1TblHandle1), CFE_TBL_ERR_NO_ACCESS);
CFE_UtAssert_EVENTCOUNT(0);

/* Test response to an attempt to dump the buffer on a bad table handle */
UT_InitData();
UT_SetAppID(CFE_ES_APPID_UNDEFINED);
UtAssert_INT32_EQ(CFE_TBL_DumpToBuffer(CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE);
CFE_UtAssert_EVENTCOUNT(0);
}

/*
** Test function that updates the contents of a table if an update is pending
*/
void Test_CFE_TBL_Update(void)
{
int16 RegIndex;
CFE_TBL_LoadBuff_t * WorkingBufferPtr;
CFE_TBL_AccessDescriptor_t *AccessDescPtr;
CFE_TBL_RegistryRec_t * RegRecPtr;
AccessDescPtr = &CFE_TBL_Global.Handles[App1TblHandle1];
RegRecPtr = &CFE_TBL_Global.Registry[AccessDescPtr->RegIndex];

UtPrintf("Begin Test Update");

/* Test a successful update */
UT_InitData();

/* a. Configure table for update */
RegIndex = CFE_TBL_FindTableInRegistry("ut_cfe_tbl.UT_Table1");
RegRecPtr = &CFE_TBL_Global.Registry[RegIndex];
CFE_UtAssert_SUCCESS(CFE_TBL_GetWorkingBuffer(&WorkingBufferPtr, RegRecPtr, false));
UT_SetAppID(UT_TBL_APPID_1);
RegRecPtr->LoadPending = true;

/* b. Perform update test */
UtAssert_INT32_EQ(CFE_TBL_Update(App1TblHandle1), CFE_SUCCESS);
CFE_UtAssert_EVENTSENT(CFE_TBL_UPDATE_SUCCESS_INF_EID);
CFE_UtAssert_EVENTCOUNT(1);

/* Test processing an update on a single buffered table without
* privileges
*/
Expand All @@ -2694,6 +2915,9 @@ void Test_CFE_TBL_Update(void)
UT_SetAppID(CFE_ES_APPID_UNDEFINED);
UtAssert_INT32_EQ(CFE_TBL_Update(App1TblHandle1), CFE_TBL_ERR_NO_ACCESS);
CFE_UtAssert_EVENTCOUNT(1);

/* Successfully process an update */
UT_InitData();
}

/*
Expand All @@ -2703,20 +2927,17 @@ void Test_CFE_TBL_GetStatus(void)
{
UtPrintf("Begin Test Get Status");

/* Test response to an attempt to get the status on a table that the
* application is not allowed to see
*/
/* Test response to successfully getting status of a table */
UT_InitData();
UT_SetAppID(CFE_ES_APPID_UNDEFINED);
UtAssert_INT32_EQ(CFE_TBL_GetStatus(App1TblHandle1), CFE_TBL_ERR_NO_ACCESS);
CFE_UtAssert_SUCCESS(CFE_TBL_GetStatus(App1TblHandle1));
CFE_UtAssert_EVENTCOUNT(0);

/* Test response to an attempt to dump the buffer on a table that the
/* Test response to an attempt to get the status on a table that the
* application is not allowed to see
*/
UT_InitData();
UT_SetAppID(CFE_ES_APPID_UNDEFINED);
UtAssert_INT32_EQ(CFE_TBL_DumpToBuffer(App1TblHandle1), CFE_TBL_ERR_NO_ACCESS);
UtAssert_INT32_EQ(CFE_TBL_GetStatus(App1TblHandle1), CFE_TBL_ERR_NO_ACCESS);
CFE_UtAssert_EVENTCOUNT(0);
}

Expand All @@ -2729,6 +2950,12 @@ void Test_CFE_TBL_GetInfo(void)

UtPrintf("Begin Test Get Info");

/* Test response to a null table info and null table name */
UT_InitData();
UtAssert_INT32_EQ(CFE_TBL_GetInfo(NULL, "ut_cfe_tbl.UT_Table1"), CFE_TBL_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_TBL_GetInfo(&TblInfo, NULL), CFE_TBL_BAD_ARGUMENT);
CFE_UtAssert_EVENTCOUNT(0);

/* Test successfully getting information on a table */
UT_InitData();
UT_SetAppID(UT_TBL_APPID_1);
Expand Down
15 changes: 15 additions & 0 deletions modules/tbl/ut-coverage/tbl_UT.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,21 @@ void Test_CFE_TBL_Validate(void);
******************************************************************************/
void Test_CFE_TBL_Manage(void);

/*****************************************************************************/
/**
** \brief Test function for dumping to a buffer
**
** \par Description
** This function tests the function for dumping a table to a buffer
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** This function does not return a value.
******************************************************************************/
void Test_CFE_TBL_DumpToBuffer(void);

/*****************************************************************************/
/**
** \brief Test function that updates the contents of a table if an update
Expand Down

0 comments on commit 8ef6df7

Please sign in to comment.