Skip to content

Commit

Permalink
Merge pull request #36 from skliper/fix10-code_coverage
Browse files Browse the repository at this point in the history
Fix #10 #14, Improve code coverage
  • Loading branch information
astrogeco authored Jun 22, 2022
2 parents cb4d5db + 3e555e6 commit acfd017
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 156 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/unit-test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ jobs:
unit-test-coverage:
name: Run unit test and coverage
uses: nasa/cFS/.github/workflows/unit-test-coverage.yml@main
with:
max-missed-branches: 8
max-missed-lines: 2
7 changes: 0 additions & 7 deletions fsw/src/cs_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,6 @@ int32 CS_AppInit(void)

#if (CS_PRESERVE_STATES_ON_PROCESSOR_RESET == true)
Result = CS_CreateRestoreStatesFromCDS();
if (Result != CFE_SUCCESS)
{
CFE_EVS_SendEvent(CS_CREATE_RESTORE_STATES_INF_EID, CFE_EVS_EventType_INFORMATION,
"Call to CDS restore command returned: RC = 0x%08X\n", (unsigned int)Result);
/* failure to restore from CDS is not a fatal error */
Result = CFE_SUCCESS;
}
#endif
}

Expand Down
12 changes: 0 additions & 12 deletions fsw/src/cs_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -1949,18 +1949,6 @@
*/
#define CS_CFE_TEXT_SEG_INF_EID 150

/**
* \brief CS Restore States From Critical Data Store Failed Event ID
*
* \par Type: INFORMATION
*
* \par Cause:
*
* This event message is issued when the call to
* CS_CreateRestoreStatesFromCDS fails
*/
#define CS_CREATE_RESTORE_STATES_INF_EID 151

/**
* \brief CS Command Failed Due To Recompute Or Oneshot In Progress Event ID
*
Expand Down
39 changes: 10 additions & 29 deletions fsw/src/cs_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,40 +665,21 @@ bool CS_BackgroundEeprom(void)
{
CS_AppData.HkPacket.CurrentEntryInTable++;
}

if (CS_AppData.HkPacket.CurrentEntryInTable >= CS_MAX_NUM_EEPROM_TABLE_ENTRIES)
{
/* Since we are done CS'ing the entire Eeprom table, update the baseline
number for telemetry */
EntireEepromCS = 0;
for (Loop = 0; Loop < CS_MAX_NUM_EEPROM_TABLE_ENTRIES; Loop++)
{
EntireEepromCS += CS_AppData.ResEepromTblPtr[Loop].ComparisonValue;
}

CS_AppData.HkPacket.EepromBaseline = EntireEepromCS;

/* We are done with this table */
CS_GoToNextTable();
}
}
else

if (CS_AppData.HkPacket.CurrentEntryInTable >= CS_MAX_NUM_EEPROM_TABLE_ENTRIES)
{
/* If we don't have a full table, the above set of code won't get
executed, so we do it if there aren't any more full entries left */
if (CS_AppData.HkPacket.CurrentEntryInTable >= CS_MAX_NUM_EEPROM_TABLE_ENTRIES)
/* Since we are done CS'ing the entire Eeprom table, update the baseline
number for telemetry */
EntireEepromCS = 0;
for (Loop = 0; Loop < CS_MAX_NUM_EEPROM_TABLE_ENTRIES; Loop++)
{
/* Since we are done CS'ing the entire Eeprom table, update the baseline
number for telemetry */
EntireEepromCS = 0;
for (Loop = 0; Loop < CS_MAX_NUM_EEPROM_TABLE_ENTRIES; Loop++)
{
EntireEepromCS += CS_AppData.ResEepromTblPtr[Loop].ComparisonValue;
}
CS_AppData.HkPacket.EepromBaseline = EntireEepromCS;
EntireEepromCS += CS_AppData.ResEepromTblPtr[Loop].ComparisonValue;
}

/* There are no enabled entries in this table */
CS_AppData.HkPacket.EepromBaseline = EntireEepromCS;

/* We are done with this table */
CS_GoToNextTable();
}
}
Expand Down
62 changes: 8 additions & 54 deletions unit-test/cs_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,6 @@ void CS_AppInit_Test_NominalPowerOnReset(void)
/* Set to prevent unintended error messages */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), CFE_SUCCESS);

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 1, CFE_PSP_RST_TYPE_POWERON);

/* Execute the function being tested */
Result = CS_AppInit();

Expand Down Expand Up @@ -593,60 +591,26 @@ void CS_AppInit_Test_NominalPowerOnReset(void)

void CS_AppInit_Test_NominalProcReset(void)
{
int32 Result;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "CS Initialized. Version %%d.%%d.%%d.%%d");

CS_AppData.HkPacket.EepromCSState = 99;
CS_AppData.HkPacket.MemoryCSState = 99;
CS_AppData.HkPacket.AppCSState = 99;
CS_AppData.HkPacket.TablesCSState = 99;

/* Set to prevent segmentation fault */
UT_SetDeferredRetcode(UT_KEY(CFE_MSG_GetMsgId), 1, 99);

/* Set to prevent unintended error messages */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), CFE_SUCCESS);

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 2, CFE_PSP_RST_TYPE_PROCESSOR);

UT_SetHandlerFunction(UT_KEY(CFE_ES_RestoreFromCDS), CS_APP_TEST_CFE_ES_RestoreFromCDS_Handler, NULL);

/* Execute the function being tested */
Result = CS_AppInit();
UtAssert_INT32_EQ(CS_AppInit(), CFE_SUCCESS);

/* Verify results */
UtAssert_UINT32_EQ(CS_AppData.HkPacket.EepromCSState, CS_STATE_ENABLED);
UtAssert_UINT32_EQ(CS_AppData.HkPacket.MemoryCSState, CS_STATE_ENABLED);
UtAssert_UINT32_EQ(CS_AppData.HkPacket.AppCSState, CS_STATE_ENABLED);
UtAssert_UINT32_EQ(CS_AppData.HkPacket.TablesCSState, CS_STATE_ENABLED);
UtAssert_UINT32_EQ(CS_AppData.HkPacket.OSCSState, CS_STATE_ENABLED);
UtAssert_UINT32_EQ(CS_AppData.HkPacket.CfeCoreCSState, CS_STATE_ENABLED);

UtAssert_True(Result == CFE_SUCCESS, "Result == CFE_SUCCESS");

UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, CS_INIT_INF_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION);

strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[0].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH);

UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[0].Spec);

UtAssert_True(CS_AppData.HkPacket.EepromCSState == CS_STATE_ENABLED,
"CS_AppData.HkPacket.EepromCSState == CS_STATE_ENABLED");
UtAssert_True(CS_AppData.HkPacket.MemoryCSState == CS_STATE_ENABLED,
"CS_AppData.HkPacket.MemoryCSState == CS_STATE_ENABLED");
UtAssert_True(CS_AppData.HkPacket.AppCSState == CS_STATE_ENABLED,
"CS_AppData.HkPacket.AppCSState == CS_STATE_ENABLED");
UtAssert_True(CS_AppData.HkPacket.TablesCSState == CS_STATE_ENABLED,
"CS_AppData.HkPacket.TablesCSState == CS_STATE_ENABLED");

UtAssert_True(CS_AppData.HkPacket.OSCSState == CS_STATE_ENABLED,
"CS_AppData.HkPacket.OSCSState == CS_STATE_ENABLED");
UtAssert_True(CS_AppData.HkPacket.CfeCoreCSState == CS_STATE_ENABLED,
"CS_AppData.HkPacket.CfeCoreCSState == CS_STATE_ENABLED");

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

UtAssert_True(call_count_CFE_EVS_SendEvent == 1, "CFE_EVS_SendEvent was called %u time(s), expected 1",
call_count_CFE_EVS_SendEvent);

} /* end CS_AppInit_Test_NominalProcReset */

void CS_CreateRestoreStatesFromCDS_Test_NoExistingCDS(void)
Expand All @@ -660,8 +624,6 @@ void CS_CreateRestoreStatesFromCDS_Test_NoExistingCDS(void)
CS_AppData.HkPacket.OSCSState = 99;
CS_AppData.HkPacket.CfeCoreCSState = 99;

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 2, CFE_PSP_RST_TYPE_PROCESSOR);

/* Execute the function being tested */
Result = CS_CreateRestoreStatesFromCDS();

Expand Down Expand Up @@ -695,8 +657,6 @@ void CS_CreateRestoreStatesFromCDS_Test_CDSSuccess(void)
CS_AppData.HkPacket.OSCSState = 99;
CS_AppData.HkPacket.CfeCoreCSState = 99;

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 2, CFE_PSP_RST_TYPE_PROCESSOR);

/* Set CDS return calls */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, CFE_ES_CDS_ALREADY_EXISTS);

Expand Down Expand Up @@ -745,8 +705,6 @@ void CS_CreateRestoreStatesFromCDS_Test_CDSFail(void)
CS_AppData.HkPacket.OSCSState = 99;
CS_AppData.HkPacket.CfeCoreCSState = 99;

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 2, CFE_PSP_RST_TYPE_PROCESSOR);

/* Set CDS return calls */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, CFE_ES_CDS_ALREADY_EXISTS);

Expand Down Expand Up @@ -803,8 +761,6 @@ void CS_CreateRestoreStatesFromCDS_Test_CopyToCDSFail(void)
CS_AppData.HkPacket.OSCSState = 99;
CS_AppData.HkPacket.CfeCoreCSState = 99;

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 2, CFE_PSP_RST_TYPE_PROCESSOR);

/* Set CDS return calls */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, CFE_SUCCESS);

Expand Down Expand Up @@ -863,8 +819,6 @@ void CS_CreateRestoreStatesFromCDS_Test_RegisterCDSFail(void)
CS_AppData.HkPacket.OSCSState = 99;
CS_AppData.HkPacket.CfeCoreCSState = 99;

UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetResetType), 2, CFE_PSP_RST_TYPE_PROCESSOR);

/* Set CDS return calls */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDS), 1, -1);

Expand Down
73 changes: 22 additions & 51 deletions unit-test/cs_compute_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,23 +1668,19 @@ void CS_RecomputeAppChildTask_Test_CouldNotGetAddress(void)
{
CS_Res_App_Table_Entry_t RecomputeAppEntry;
CS_Def_App_Table_Entry_t DefAppTbl[10];
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

memset(&RecomputeAppEntry, 0, sizeof(RecomputeAppEntry));
memset(&DefAppTbl, 0, sizeof(DefAppTbl));

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"App %%s recompute failed. Could not get address");

CS_AppData.RecomputeAppEntryPtr = &RecomputeAppEntry;
CS_AppData.DefAppTblPtr = DefAppTbl;

CS_AppData.ChildTaskTable = CS_OSCORE;

CS_AppData.ChildTaskEntryID = 1;

DefAppTbl[1].State = 1;
/* No matching non-empty state entry */
DefAppTbl[1].State = CS_STATE_EMPTY;

CS_AppData.RecomputeAppEntryPtr->State = 99;

Expand All @@ -1702,30 +1698,20 @@ void CS_RecomputeAppChildTask_Test_CouldNotGetAddress(void)
CS_RecomputeAppChildTask();

/* Verify results */
UtAssert_True(CS_AppData.RecomputeAppEntryPtr->State == 99, "CS_AppData.RecomputeAppEntryPtr->State == 99");
UtAssert_True(CS_AppData.DefAppTblPtr[CS_AppData.ChildTaskEntryID].State == 1,
"CS_AppData.DefAppTblPtr[CS_AppData.ChildTaskEntryID].State == 1");
UtAssert_True(CS_AppData.RecomputeAppEntryPtr->TempChecksumValue == 0,
"CS_AppData.RecomputeAppEntryPtr->TempChecksumValue == 0");
UtAssert_True(CS_AppData.RecomputeAppEntryPtr->ByteOffset == 0, "CS_AppData.RecomputeAppEntryPtr->ByteOffset == 0");
UtAssert_True(CS_AppData.RecomputeAppEntryPtr->ComputedYet == false,
"CS_AppData.RecomputeAppEntryPtr->ComputedYet == false");
UtAssert_UINT32_EQ(CS_AppData.RecomputeAppEntryPtr->State, 99);
UtAssert_UINT32_EQ(CS_AppData.DefAppTblPtr[CS_AppData.ChildTaskEntryID].State, CS_STATE_EMPTY);
UtAssert_UINT32_EQ(CS_AppData.RecomputeAppEntryPtr->TempChecksumValue, 0);
UtAssert_UINT32_EQ(CS_AppData.RecomputeAppEntryPtr->ByteOffset, 0);

UtAssert_BOOL_FALSE(CS_AppData.RecomputeAppEntryPtr->ComputedYet);
UtAssert_BOOL_FALSE(CS_AppData.HkPacket.RecomputeInProgress);

UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, CS_COMPUTE_APP_ERR_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, CS_RECOMPUTE_ERROR_APP_ERR_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventType, CFE_EVS_EventType_ERROR);

strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[1].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH);

UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[1].Spec);

UtAssert_True(CS_AppData.HkPacket.RecomputeInProgress == false, "CS_AppData.HkPacket.RecomputeInProgress == false");

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

UtAssert_True(call_count_CFE_EVS_SendEvent == 2, "CFE_EVS_SendEvent was called %u time(s), expected 2",
call_count_CFE_EVS_SendEvent);
/* Generates 1 event message we don't care about in this test */

} /* end CS_RecomputeAppChildTask_Test_CouldNotGetAddress */

void CS_RecomputeAppChildTask_Test_DefEntryId(void)
Expand Down Expand Up @@ -1879,23 +1865,19 @@ void CS_RecomputeTablesChildTask_Test_CouldNotGetAddress(void)
{
CS_Res_Tables_Table_Entry_t RecomputeTablesEntry;
CS_Def_Tables_Table_Entry_t DefTablesTbl[10];
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

memset(&RecomputeTablesEntry, 0, sizeof(RecomputeTablesEntry));
memset(&DefTablesTbl, 0, sizeof(DefTablesTbl));

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Table %%s recompute failed. Could not get address");

CS_AppData.RecomputeTablesEntryPtr = &RecomputeTablesEntry;
CS_AppData.DefTablesTblPtr = DefTablesTbl;

CS_AppData.ChildTaskTable = CS_OSCORE;

CS_AppData.ChildTaskEntryID = 1;

DefTablesTbl[1].State = 1;
/* No matching non-empty state entry */
DefTablesTbl[1].State = CS_STATE_EMPTY;

CS_AppData.RecomputeTablesEntryPtr->State = 99;

Expand All @@ -1911,29 +1893,18 @@ void CS_RecomputeTablesChildTask_Test_CouldNotGetAddress(void)
CS_RecomputeTablesChildTask();

/* Verify results */
UtAssert_True(CS_AppData.RecomputeTablesEntryPtr->State == 99, "CS_AppData.RecomputeTablesEntryPtr->State == 99");
UtAssert_True(CS_AppData.DefTablesTblPtr[CS_AppData.ChildTaskEntryID].State == 1,
"CS_AppData.DefTablesTblPtr[CS_AppData.ChildTaskEntryID].State == 1");
UtAssert_True(CS_AppData.RecomputeTablesEntryPtr->TempChecksumValue == 0,
"CS_AppData.RecomputeTablesEntryPtr->TempChecksumValue == 0");
UtAssert_True(CS_AppData.RecomputeTablesEntryPtr->ByteOffset == 0,
"CS_AppData.RecomputeTablesEntryPtr->ByteOffset == 0");
UtAssert_True(CS_AppData.RecomputeTablesEntryPtr->ComputedYet == false,
"CS_AppData.RecomputeTablesEntryPtr->ComputedYet == false");
UtAssert_UINT32_EQ(CS_AppData.RecomputeTablesEntryPtr->State, 99);
UtAssert_UINT32_EQ(CS_AppData.DefTablesTblPtr[CS_AppData.ChildTaskEntryID].State, CS_STATE_EMPTY);
UtAssert_UINT32_EQ(CS_AppData.RecomputeTablesEntryPtr->TempChecksumValue, 0);
UtAssert_UINT32_EQ(CS_AppData.RecomputeTablesEntryPtr->ByteOffset, 0);

UtAssert_BOOL_FALSE(CS_AppData.RecomputeTablesEntryPtr->ComputedYet);
UtAssert_BOOL_FALSE(CS_AppData.HkPacket.RecomputeInProgress);

UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, CS_RECOMPUTE_ERROR_TABLES_ERR_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventType, CFE_EVS_EventType_ERROR);

strCmpResult = strncmp(ExpectedEventString, context_CFE_EVS_SendEvent[1].Spec, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH);

UtAssert_True(strCmpResult == 0, "Event string matched expected result, '%s'", context_CFE_EVS_SendEvent[1].Spec);

UtAssert_True(CS_AppData.HkPacket.RecomputeInProgress == false, "CS_AppData.HkPacket.RecomputeInProgress == false");

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

UtAssert_True(call_count_CFE_EVS_SendEvent == 2, "CFE_EVS_SendEvent was called %u time(s), expected 2",
call_count_CFE_EVS_SendEvent);
/* Note: generates 1 event message we don't care about in this test */

} /* end CS_RecomputeTablesChildTask_Test_CouldNotGetAddress */
Expand Down

0 comments on commit acfd017

Please sign in to comment.