Skip to content

Commit

Permalink
Part nasa#17, update code coverage for FM_ChildSleepStat, FM_ChildDel…
Browse files Browse the repository at this point in the history
…eteDirCmd, FM_Cmds

Removed UtAsserts for FM_ChildSizeTimeMode
Removed UtAssert for CFE_ES_ExitChildTask
Updated whitespace to clang format
Added Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLengthInLoop
  • Loading branch information
chillfig committed Jun 15, 2022
1 parent 51707f2 commit 6b71fb5
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 16 deletions.
138 changes: 124 additions & 14 deletions unit-test/fm_child_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,9 @@ void Test_FM_ChildDeleteDirCmd_StrCmpThisDirectoryZero(void)
UT_SetDeferredRetcode(UT_KEY(strcmp), 1, 1);
UT_SetDefaultReturnValue(UT_KEY(OS_rmdir), OS_SUCCESS);

os_dirent_t dummy_direntry = {.FileName = FM_THIS_DIRECTORY};
UT_SetDataBuffer(UT_KEY(OS_DirectoryRead), &dummy_direntry, sizeof(dummy_direntry), false);

uint8 count_childcmdcounter_before = FM_GlobalData.ChildCmdCounter;
uint8 count_childcmderrcounter_before = FM_GlobalData.ChildCmdErrCounter;
uint8 commandcode_before = dummy_CC.CommandCode;
Expand Down Expand Up @@ -2682,24 +2685,23 @@ void Test_FM_ChildDirListPktCmd_DirListPktPacketFilesGreaterDIRListPktEntries(vo

void Test_FM_ChildDirListPktCmd_EntryLengthGreaterListEntryName(void)
{
/*
// Arrange
FM_ChildQueueEntry_t dummy_CC = {.CommandCode = FM_DELETE_ALL_CC,
FM_ChildQueueEntry_t dummy_CC = {.CommandCode = FM_DELETE_ALL_CC,
.Source1 = "dummy_source1",
.Source2 = "dummy_source2",
.DirListOffset = UT_Utils_Any_uint8_LessThan(MAX_UINT8)};
FM_GlobalData.ChildCmdCounter = UT_Utils_Any_uint8_LessThan(MAX_UINT8);
FM_GlobalData.ChildCmdWarnCounter = UT_Utils_Any_uint8_LessThan(MAX_UINT8);
FM_GlobalData.ChildCmdCounter = UT_Utils_Any_uint8_LessThan(MAX_UINT8);
FM_GlobalData.ChildCmdWarnCounter = UT_Utils_Any_uint8_LessThan(MAX_UINT8);

UT_SetDefaultReturnValue(UT_KEY(OS_DirectoryOpen), OS_SUCCESS);
UT_SetDefaultReturnValue(UT_KEY(OS_DirectoryRead), OS_SUCCESS);
UT_SetDeferredRetcode(UT_KEY(OS_DirectoryRead), 2, !OS_SUCCESS);
os_dirent_t dummy_direntry = {.FileName="MaxCharactersIs20"};
os_dirent_t dummy_direntry = {.FileName = "MaxCharactersIs20"};
UT_SetDataBuffer(UT_KEY(OS_DirectoryRead), &dummy_direntry, sizeof(dummy_direntry), false);
FM_DirListEntry_t dummy_listentry = {.EntryName="short"};
FM_GlobalData.DirListPkt.TotalFiles = dummy_CC.DirListOffset + 1;
uint32 temp_packetfiles = FM_DIR_LIST_PKT_ENTRIES - 1;
FM_GlobalData.DirListPkt.PacketFiles = temp_packetfiles;
FM_DirListEntry_t dummy_listentry = {.EntryName = "short"};
FM_GlobalData.DirListPkt.TotalFiles = dummy_CC.DirListOffset + 1;
uint32 temp_packetfiles = FM_DIR_LIST_PKT_ENTRIES - 1;
FM_GlobalData.DirListPkt.PacketFiles = temp_packetfiles;
FM_GlobalData.DirListPkt.FileList[temp_packetfiles] = dummy_listentry;

uint8 childcmdcounter_before = FM_GlobalData.ChildCmdCounter;
Expand All @@ -2709,9 +2711,9 @@ void Test_FM_ChildDirListPktCmd_EntryLengthGreaterListEntryName(void)
// Act
FM_ChildDirListPktCmd(&dummy_CC);

uint8 count_sendevent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
uint8 count_osdiropen = UT_GetStubCount(UT_KEY(OS_DirectoryOpen));
uint8 count_osdirread = UT_GetStubCount(UT_KEY(OS_DirectoryRead));
uint8 count_sendevent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
uint8 count_osdiropen = UT_GetStubCount(UT_KEY(OS_DirectoryOpen));
uint8 count_osdirread = UT_GetStubCount(UT_KEY(OS_DirectoryRead));

// Assert
UtAssert_INT32_EQ(count_osdiropen, 1);
Expand All @@ -2723,7 +2725,6 @@ void Test_FM_ChildDirListPktCmd_EntryLengthGreaterListEntryName(void)
UtAssert_INT32_EQ(childcmdwarncountr_before + 1, FM_GlobalData.ChildCmdWarnCounter);
UtAssert_INT32_EQ(dirlist_totalfiles_before + 1, FM_GlobalData.DirListPkt.TotalFiles);
UtAssert_INT32_EQ(temp_packetfiles, FM_GlobalData.DirListPkt.PacketFiles);
*/
UtAssert_MIR("Unable to change the OS_MAX_FILE_NAME value in order to test this branch of the if statement");
}

Expand Down Expand Up @@ -3286,6 +3287,53 @@ void Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLength(void)
UtAssert_INT32_EQ(count_fileentries, 1);
}

void Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLengthInLoop(void)
{
// Arrange
osal_id_t dirid = FM_UT_OBJID_1;
osal_id_t fileid = FM_UT_OBJID_2;
const char *dummy_directory = "dummy_directory";
const char *dummy_filename = "dummy_filename";
const char *dummy_dirwithstep = "dummy_dirwithstep";
uint8 dummy_getsizetimemode = UT_Utils_Any_uint8();

FM_GlobalData.ChildCmdErrCounter = UT_Utils_Any_uint8();
FM_GlobalData.ChildCmdCounter = UT_Utils_Any_uint8();
FM_GlobalData.ChildCmdWarnCounter = UT_Utils_Any_uint8();
UT_SetDefaultReturnValue(UT_KEY(OS_DirectoryRead), OS_SUCCESS);
os_dirent_t dummy_direntry = {.FileName = "dummy_directory_nam"};
UT_SetDataBuffer(UT_KEY(OS_DirectoryRead), &dummy_direntry, sizeof(dummy_direntry), false);
UT_SetDefaultReturnValue(UT_KEY(OS_write), sizeof(FM_DirListEntry_t) - 1);
UT_SetDeferredRetcode(UT_KEY(OS_DirectoryRead), 2, !OS_SUCCESS);

uint8 count_childcmderrcounter_before = FM_GlobalData.ChildCmdErrCounter;
uint8 count_childcmdcounter_before = FM_GlobalData.ChildCmdCounter;
uint8 count_childcmdwarncounter_before = FM_GlobalData.ChildCmdWarnCounter;

// Act
FM_ChildDirListFileLoop(dirid, fileid, dummy_directory, dummy_dirwithstep, dummy_filename, dummy_getsizetimemode);

uint8 count_sendevent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));
uint8 count_osdirread = UT_GetStubCount(UT_KEY(OS_DirectoryRead));
uint8 count_oswrite = UT_GetStubCount(UT_KEY(OS_write));
uint8 count_oslseek = UT_GetStubCount(UT_KEY(OS_lseek));
uint8 count_direntries = FM_GlobalData.DirListFileStats.DirEntries;
uint8 count_fileentries = FM_GlobalData.DirListFileStats.FileEntries;

// Assert
UtAssert_INT32_EQ(count_sendevent, 1);
UtAssert_INT32_EQ(count_osdirread, 2);
UtAssert_INT32_EQ(count_oswrite, 2);
UtAssert_INT32_EQ(count_oslseek, 1);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, FM_GET_DIR_FILE_UPSTATS_ERR_EID);
UtAssert_INT32_EQ(count_childcmderrcounter_before + 1, FM_GlobalData.ChildCmdErrCounter);
UtAssert_INT32_EQ(count_childcmdcounter_before, FM_GlobalData.ChildCmdCounter);
UtAssert_INT32_EQ(count_childcmdwarncounter_before, FM_GlobalData.ChildCmdWarnCounter);
UtAssert_INT32_EQ(count_direntries, 1);
UtAssert_INT32_EQ(count_fileentries, 1);
}

void Test_FM_ChildDirListFileLoop_WritelengthEqualToBytesWritten(void)
{
// Arrange
Expand Down Expand Up @@ -3512,6 +3560,55 @@ void Test_FM_ChildLoop_CountSemTakeSuccessDefault(void)
* ChildSleepStat Tests
* ***************/

void Test_FM_ChildSleepStat_getSizeTimeModeFalse(void)
{
// Arrange
const char * dummy_filename = "dummy_filename";
FM_DirListEntry_t dummy_DirListData = {.EntrySize = 1, .ModifyTime = 1, .Mode = 1};
int32 dummy_FilesTillSleep = 1;
uint8 dummy_getSizeTimeMode = 0;

// Act
FM_ChildSleepStat(dummy_filename, &dummy_DirListData, &dummy_FilesTillSleep, dummy_getSizeTimeMode);

// Assert
UtAssert_INT32_EQ(dummy_DirListData.EntrySize, 0);
UtAssert_INT32_EQ(dummy_DirListData.ModifyTime, 0);
UtAssert_INT32_EQ(dummy_DirListData.Mode, 0);
}

void Test_FM_ChildSleepStat_FilesTillSleepPositive(void)
{
// Arrange
const char * dummy_filename = "dummy_filename";
FM_DirListEntry_t dummy_DirListData = {.EntrySize = 1, .ModifyTime = 1, .Mode = 1};
int32 dummy_FilesTillSleep = FM_CHILD_STAT_SLEEP_FILECOUNT + 1;
uint8 dummy_getSizeTimeMode = 1;
int32 dummy_FilesTillSleep_before = dummy_FilesTillSleep;

// Act
FM_ChildSleepStat(dummy_filename, &dummy_DirListData, &dummy_FilesTillSleep, dummy_getSizeTimeMode);

// Assert
UtAssert_INT32_EQ(dummy_FilesTillSleep, dummy_FilesTillSleep_before - 1);
}

void Test_FM_ChildSleepStat_FilesTillSleepLTEQZero(void)
{
// Arrange
const char * dummy_filename = "dummy_filename";
FM_DirListEntry_t dummy_DirListData = {.EntrySize = 1, .ModifyTime = 1, .Mode = 1};
int32 dummy_FilesTillSleep = FM_CHILD_STAT_SLEEP_FILECOUNT;
uint8 dummy_getSizeTimeMode = 1;

// Act
FM_ChildSleepStat(dummy_filename, &dummy_DirListData, &dummy_FilesTillSleep, dummy_getSizeTimeMode);

// Assert
UtAssert_STUB_COUNT(OS_TaskDelay, 1);
UtAssert_INT32_EQ(dummy_FilesTillSleep, FM_CHILD_STAT_SLEEP_FILECOUNT - 1);
}

/* * * * * * * * * * * * * *
* Add Method Tests
* * * * * * * * * * * * * */
Expand Down Expand Up @@ -3841,6 +3938,9 @@ void add_FM_ChildDirListFileLoop_tests(void)
UtTest_Add(Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLength, FM_Test_Setup, FM_Test_Teardown,
"Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLength");

UtTest_Add(Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLengthInLoop, FM_Test_Setup, FM_Test_Teardown,
"Test_FM_ChildDirListFileLoop_BytesWrittenNotEqualWriteLengthInLoop");

UtTest_Add(Test_FM_ChildDirListFileLoop_WritelengthEqualToBytesWritten, FM_Test_Setup, FM_Test_Teardown,
"Test_FM_ChildDirListFileLoop_WritelengthEqualToBytesWritten");
}
Expand All @@ -3854,7 +3954,17 @@ void add_FM_ChildSizeTimeMode_tests(void)
"Test_FM_ChildSizeTimeMode_OSFilestateTimeDefined");
}

void add_FM_ChildSleepStat_tests(void) {}
void add_FM_ChildSleepStat_tests(void)
{
UtTest_Add(Test_FM_ChildSleepStat_getSizeTimeModeFalse, FM_Test_Setup, FM_Test_Teardown,
"Test_FM_ChildSleepStat_getSizeTimeModeFalse");

UtTest_Add(Test_FM_ChildSleepStat_FilesTillSleepPositive, FM_Test_Setup, FM_Test_Teardown,
"Test_FM_ChildSleepStat_FilesTillSleepPositive");

UtTest_Add(Test_FM_ChildSleepStat_FilesTillSleepLTEQZero, FM_Test_Setup, FM_Test_Teardown,
"Test_FM_ChildSleepStat_FilesTillSleepLTEQZero");
}

void add_FM_ChildLoop_tests(void)
{
Expand Down
4 changes: 2 additions & 2 deletions unit-test/fm_cmds_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2273,9 +2273,9 @@ void UtTest_Setup(void)
add_FM_NoopCmd_tests();
add_FM_ResetCountersCmd_tests();
add_FM_CopyFileCmd_tests();
// add_FM_MoveFileCmd_tests();
add_FM_MoveFileCmd_tests();
add_FM_RenameFileCmd_tests();
// add_FM_DeleteFileCmd_tests();
add_FM_DeleteFileCmd_tests();
add_FM_DeleteAllFilesCmd_tests();

#ifdef FM_INCLUDE_DECOMPRESS
Expand Down

0 comments on commit 6b71fb5

Please sign in to comment.