Skip to content

Commit

Permalink
Merge pull request nasa#34 from chillfig/lcov
Browse files Browse the repository at this point in the history
Fix nasa#29, Fix nasa#14, update code coverage
  • Loading branch information
dzbaker committed Jul 7, 2022
2 parents 3b72ff9 + 8c199bd commit 67712d4
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/unit-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ jobs:
name: Run unit test and coverage
uses: nasa/cFS/.github/workflows/unit-test-coverage.yml@main
with:
max-missed-branches: 11
max-missed-lines: 5
max-missed-branches: 1
9 changes: 4 additions & 5 deletions unit-test/ds_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,14 +964,14 @@ void DS_AppProcessHK_Test_SnprintfFail(void)
UtAssert_True(DS_AppData.FileStatus[DS_DEST_FILE_CNT - 1].FileGrowth == 0,
"DS_AppData.FileStatus[DS_DEST_FILE_CNT - 1].FileGrowth == 0");

UtAssert_INT32_EQ(UT_GetStubCount(UT_KEY(CFE_SB_TransmitMsg)), 1);
UtAssert_STUB_COUNT(CFE_SB_TransmitMsg, 1);

/* Verify command struct size minus header is at least explicitly padded to 32-bit boundaries */
UtAssert_True(TLM_STRUCT_DATA_IS_32_ALIGNED(DS_HkPacket_t), "DS_HkPacket_t is 32-bit aligned");

UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_APPHK_FILTER_TBL_PRINT_ERR_EID);
call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 1);

UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
}

void DS_AppProcessHK_Test_TblFail(void)
Expand Down Expand Up @@ -1176,8 +1176,7 @@ void UtTest_Setup(void)
"DS_AppProcessCmd_Test_InvalidCommandCode");

UtTest_Add(DS_AppProcessHK_Test, DS_Test_Setup, DS_Test_TearDown, "DS_AppProcessHK_Test");
/* UtTest_Add(DS_AppProcessHK_Test_SnprintfFail, DS_Test_Setup, DS_Test_TearDown,
* "DS_AppProcessHK_Test_SnprintfFail"); */
UtTest_Add(DS_AppProcessHK_Test_SnprintfFail, DS_Test_Setup, DS_Test_TearDown, "DS_AppProcessHK_Test_SnprintfFail");
UtTest_Add(DS_AppProcessHK_Test_TblFail, DS_Test_Setup, DS_Test_TearDown, "DS_AppProcessHK_Test_TblFail");

UtTest_Add(DS_AppStorePacket_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_AppStorePacket_Test_Nominal");
Expand Down
29 changes: 29 additions & 0 deletions unit-test/ds_cmds_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,34 @@ void DS_CmdCloseAll_Test_Nominal(void)
UtAssert_True(CMD_STRUCT_DATA_IS_32_ALIGNED(DS_CloseAllCmd_t), "DS_CloseAllCmd_t is 32-bit aligned");
} /* end DS_CmdCloseAll_Test_Nominal */

void DS_CmdCloseAll_Test_CloseAll(void)
{
uint32 i;
size_t forced_Size = sizeof(DS_CloseAllCmd_t);

UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false);

for (i = 0; i < DS_DEST_FILE_CNT; i++)
{
DS_AppData.FileStatus[i].FileHandle = DS_UT_OBJID_1;
}

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_CmdCloseAll(&UT_CmdBuf.Buf));

/* Verify results */
UtAssert_INT32_EQ(DS_AppData.CmdAcceptedCounter, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_STUB_COUNT(DS_FileUpdateHeader, DS_DEST_FILE_CNT);
UtAssert_STUB_COUNT(DS_FileCloseDest, DS_DEST_FILE_CNT);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_CLOSE_ALL_CMD_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_DEBUG);

/* Verify command struct size minus header is at least explicitly padded to 32-bit boundaries */
UtAssert_BOOL_TRUE(CMD_STRUCT_DATA_IS_32_ALIGNED(DS_CloseAllCmd_t));

} /* end DS_CmdCloseAll_Test_CloseAll */

void DS_CmdCloseAll_Test_InvalidCommandLength(void)
{

Expand Down Expand Up @@ -3660,6 +3688,7 @@ void UtTest_Setup(void)
"DS_CmdCloseFile_Test_InvalidFileTableIndex");

UtTest_Add(DS_CmdCloseAll_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_CmdCloseAll_Test_Nominal");
UtTest_Add(DS_CmdCloseAll_Test_CloseAll, DS_Test_Setup, DS_Test_TearDown, "DS_CmdCloseAll_Test_CloseAll");
UtTest_Add(DS_CmdCloseAll_Test_InvalidCommandLength, DS_Test_Setup, DS_Test_TearDown,
"DS_CmdCloseAll_Test_InvalidCommandLength");

Expand Down
189 changes: 181 additions & 8 deletions unit-test/ds_file_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,23 @@ void DS_FileSetupWrite_Test_FileHandleClosed(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false);

UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL);
UT_SetHandlerFunction(UT_KEY(OS_OpenCreate), &UT_OS_write_SuccessHandler, NULL);

DS_AppData.FileStatus[FileIndex].FileHandle = OS_OBJECT_ID_UNDEFINED;

DS_AppData.DestFileTblPtr = &DestFileTable;

DS_AppData.DestFileTblPtr = &DestFileTable;
DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileSize = 100;
UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);
DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
DS_AppData.FileStatus[FileIndex].FileHandle = OS_OBJECT_ID_UNDEFINED;
DS_AppData.FileStatus[FileIndex].FileCount = 0;
DS_AppData.FileStatus[FileIndex].FileSize = 3;

/* Execute the function being tested */
DS_FileSetupWrite(FileIndex, &UT_CmdBuf.Buf);
UtAssert_VOIDCALL(DS_FileSetupWrite(FileIndex, &UT_CmdBuf.Buf));

/* Verify results */
call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
UtAssert_INT32_EQ(call_count_CFE_EVS_SendEvent, 0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_STUB_COUNT(DS_FileWriteData, 0);
UtAssert_STUB_COUNT(OS_OpenCreate, 1);
} /* end DS_FileSetupWrite_Test_FileHandleClosed */

void DS_FileSetupWrite_Test_MaxFileSizeExceeded(void)
Expand Down Expand Up @@ -726,6 +726,24 @@ void DS_FileCreateDest_Test_Nominal(void)

} /* end DS_FileCreateDest_Test_Nominal */

void DS_FileCreateDest_Test_StringTerminate(void)
{
uint32 FileIndex = 0;
DS_DestFileTable_t DestFileTable;

/* Setup for DS_FileCreateName to succeed */
DS_AppData.DestFileTblPtr = &DestFileTable;

DS_AppData.FileStatus[FileIndex].FileName[0] = DS_STRING_TERMINATOR;

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileCreateDest(FileIndex));

/* Verify results */
UtAssert_STUB_COUNT(OS_OpenCreate, 0);

} /* end DS_FileCreateDest_Test_StringTerminate */

void DS_FileCreateDest_Test_NominalRollover(void)
{
uint32 FileIndex = 0;
Expand Down Expand Up @@ -1006,6 +1024,123 @@ void DS_FileCreateName_Test_Error(void)

} /* end DS_FileCreateName_Test_Error */

void DS_FileCreateName_Test_MaxPathnameLength(void)
{
int32 FileIndex = 0;
DS_DestFileTable_t DestFileTable;
int32 WorknameLen = 2 * DS_TOTAL_FNAME_BUFSIZE;
int32 i;

DS_AppData.DestFileTblPtr = &DestFileTable;

UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);

/* Set to fail the condition "if (TotalLength != (WorknameLen - 1))" */
for (i = 0; i < WorknameLen - 1; i++)
{
DS_AppData.DestFileTblPtr->File[FileIndex].Pathname[i] = 'a';
}

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileCreateName(FileIndex));

/* Verify results */
UtAssert_INT32_EQ(strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname), WorknameLen - 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_FILE_NAME_ERR_EID);

} /* end DS_FileCreateName_Test_MaxPathnameLength */

void DS_FileCreateName_Test_PathBaseSeqTooLarge(void)
{
int32 FileIndex = 0;
DS_DestFileTable_t DestFileTable;

DS_AppData.DestFileTblPtr = &DestFileTable;

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
DS_AppData.FileStatus[FileIndex].FileCount = 1;

/* Set to fail the condition "if ((strlen(Workname) + strlen(Sequence)) < DS_TOTAL_FNAME_BUFSIZE)" */
strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname, "PathnamePathnamePathnamePat",
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname));
strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Basename, "BasenameBasenameBasenameBase",
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Basename));

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileCreateName(FileIndex));

/* Verify results */
UtAssert_INT32_EQ(strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname) +
strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Basename) + DS_SEQUENCE_DIGITS +
strlen("/"),
DS_TOTAL_FNAME_BUFSIZE);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_FILE_NAME_ERR_EID);

} /* end DS_FileCreateName_Test_PathBaseSeqTooLarge */

void DS_FileCreateName_Test_PathBaseSeqExtTooLarge(void)
{
int32 FileIndex = 0;
DS_DestFileTable_t DestFileTable;

DS_AppData.DestFileTblPtr = &DestFileTable;

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
DS_AppData.FileStatus[FileIndex].FileCount = 1;

/* Set to fail the condition "if (strlen(Workname) < DS_TOTAL_FNAME_BUFSIZE)" */
strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname, "PathnamePathnamePathname",
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname));
strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Basename, "BasenameBasenameBasenameBase",
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Basename));
strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Extension, "ext",
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Extension));

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileCreateName(FileIndex));

/* Verify results */
UtAssert_INT32_EQ(strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname) +
strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Basename) +
strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Extension) + DS_SEQUENCE_DIGITS +
strlen("/"),
DS_TOTAL_FNAME_BUFSIZE);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_FILE_NAME_ERR_EID);

} /* end DS_FileCreateName_Test_PathBaseSeqExtTooLarge */

void DS_FileCreateName_Test_ExtensionZero(void)
{
int32 FileIndex = 0;
DS_DestFileTable_t DestFileTable;
char StrCompare[] = "path/base00000001";

DS_AppData.DestFileTblPtr = &DestFileTable;

UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
DS_AppData.FileStatus[FileIndex].FileCount = 1;

/* Set to fail the condition "if (strlen(DestFile->Extension) > 0)" */
DS_AppData.DestFileTblPtr->File[FileIndex].Extension[0] = '\0';

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileCreateName(FileIndex));

/* Verify results */
UtAssert_STRINGBUF_EQ(DS_AppData.FileStatus[FileIndex].FileName, sizeof(DS_AppData.FileStatus[FileIndex].FileName),
StrCompare, sizeof(StrCompare));
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

} /* end DS_FileCreateName_Test_ExtensionZero */

#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE
void DS_FileCreateSequence_Test_ByCount(void)
{
Expand Down Expand Up @@ -1279,6 +1414,33 @@ void DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameTooLarge(void)
} /* end DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameTooLarge */
#endif

#if (DS_MOVE_FILES == true)
void DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameNull(void)
{
int32 FileIndex = 0;
DS_DestFileTable_t DestFileTable;

UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL);
DS_AppData.DestFileTblPtr = &DestFileTable;

strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Movename, "directory2/movename",
sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename));

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileCloseDest(FileIndex));

/* Verify results */
UtAssert_BOOL_FALSE(OS_ObjectIdDefined(DS_AppData.FileStatus[FileIndex].FileHandle));
UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileAge, 0);
UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileSize, 0);
UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileName[0], 0);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_MOVE_FILE_ERR_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);

} /* end DS_FileCloseDest_Test_PlatformConfigMoveFiles_Null */
#endif

#if (DS_MOVE_FILES == false)
void DS_FileCloseDest_Test_MoveFilesFalse(void)
{
Expand Down Expand Up @@ -1612,7 +1774,8 @@ void UtTest_Setup(void)
#endif

UtTest_Add(DS_FileCreateDest_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_FileCreateDest_Test_Nominal");

UtTest_Add(DS_FileCreateDest_Test_StringTerminate, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCreateDest_Test_StringTerminate");
UtTest_Add(DS_FileCreateDest_Test_NominalRollover, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCreateDest_Test_NominalRollover");
UtTest_Add(DS_FileCreateDest_Test_Error, DS_Test_Setup, DS_Test_TearDown, "DS_FileCreateDest_Test_Error");
Expand All @@ -1629,6 +1792,14 @@ void UtTest_Setup(void)
"DS_FileCreateName_Test_NominalWithPeriod");
UtTest_Add(DS_FileCreateName_Test_EmptyPath, DS_Test_Setup, DS_Test_TearDown, "DS_FileCreateName_Test_EmptyPath");
UtTest_Add(DS_FileCreateName_Test_Error, DS_Test_Setup, DS_Test_TearDown, "DS_FileCreateName_Test_Error");
UtTest_Add(DS_FileCreateName_Test_MaxPathnameLength, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCreateName_Test_MaxPathnameLength");
UtTest_Add(DS_FileCreateName_Test_PathBaseSeqTooLarge, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCreateName_Test_PathBaseSeqTooLarge");
UtTest_Add(DS_FileCreateName_Test_PathBaseSeqExtTooLarge, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCreateName_Test_PathBaseSeqExtTooLarge");
UtTest_Add(DS_FileCreateName_Test_ExtensionZero, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCreateName_Test_ExtensionZero");

#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE
UtTest_Add(DS_FileCreateSequence_Test_ByCount, DS_Test_Setup, DS_Test_TearDown,
Expand All @@ -1654,6 +1825,8 @@ void UtTest_Setup(void)
"DS_FileCloseDest_Test_PlatformConfigMoveFiles_MoveError");
UtTest_Add(DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameTooLarge, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameTooLarge");
UtTest_Add(DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameNull, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameNull");
#else
UtTest_Add(DS_FileCloseDest_Test_MoveFilesFalse, DS_Test_Setup, DS_Test_TearDown,
"DS_FileCloseDest_Test_MoveFilesFalse");
Expand Down

0 comments on commit 67712d4

Please sign in to comment.