Skip to content

Commit

Permalink
Part nasa#17, update code coverage fm_child_tests.c and fm_cmds_tests.c
Browse files Browse the repository at this point in the history
  • Loading branch information
chillfig committed Jun 13, 2022
1 parent 51707f2 commit 2d225fe
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
70 changes: 69 additions & 1 deletion 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 @@ -3512,6 +3515,61 @@ 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_STUB_COUNT(FM_ChildSizeTimeMode, 1);
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);

uint8 count_ExitTask = UT_GetStubCount(UT_KEY(CFE_ES_ExitChildTask));
uint8 count_ostaskdelay = UT_GetStubCount(UT_KEY(OS_TaskDelay));

// Assert
UtAssert_STUB_COUNT(FM_ChildSizeTimeMode, 1);
UtAssert_INT32_EQ(count_ExitTask, 1);
UtAssert_INT32_EQ(count_ostaskdelay, 1);
UtAssert_INT32_EQ(dummy_FilesTillSleep, FM_CHILD_STAT_SLEEP_FILECOUNT - 1);
}

/* * * * * * * * * * * * * *
* Add Method Tests
* * * * * * * * * * * * * */
Expand Down Expand Up @@ -3854,7 +3912,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 2d225fe

Please sign in to comment.