Skip to content

Commit

Permalink
Add first test - should fail
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Jun 7, 2024
1 parent 710e901 commit ab4b6c8
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 25 deletions.
112 changes: 87 additions & 25 deletions fsw/src/hs_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,19 @@ void HS_ResetCounters(void)
CFE_Status_t HS_EnableAppMonCmd(const HS_EnableAppMonCmd_t *BufPtr)
{
HS_AppData.CmdCount++;
HS_AppMonStatusRefresh();
HS_AppData.CurrentAppMonState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_APPMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Application Monitoring Enabled");

if (HS_AppData.CurrentAppMonState == HS_STATE_ENABLED)
{
CFE_EVS_SendEvent(HS_ENABLE_APPMON_INF_EID, CFE_EVS_EventType_INFORMATION,
"Application Monitoring is *already* Enabled");
}
else
{
HS_AppMonStatusRefresh();
HS_AppData.CurrentAppMonState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_APPMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Application Monitoring Enabled");
}

return CFE_SUCCESS;
}

Expand All @@ -251,8 +261,18 @@ CFE_Status_t HS_EnableAppMonCmd(const HS_EnableAppMonCmd_t *BufPtr)
CFE_Status_t HS_DisableAppMonCmd(const HS_DisableAppMonCmd_t *BufPtr)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentAppMonState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_APPMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Application Monitoring Disabled");

if (HS_AppData.CurrentAppMonState == HS_STATE_DISABLED)
{
CFE_EVS_SendEvent(HS_DISABLE_APPMON_INF_EID, CFE_EVS_EventType_INFORMATION,
"Application Monitoring is *already* Disabled");
}
else
{
HS_AppData.CurrentAppMonState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_APPMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Application Monitoring Disabled");
}

return CFE_SUCCESS;
}

Expand All @@ -265,10 +285,12 @@ CFE_Status_t HS_EnableEventMonCmd(const HS_EnableEventMonCmd_t *BufPtr)
{
CFE_Status_t Status = CFE_SUCCESS;

/*
** Subscribe to Event Messages if currently disabled
*/
if (HS_AppData.CurrentEventMonState == HS_STATE_DISABLED)
if (HS_AppData.CurrentEventMonState == HS_STATE_ENABLED)
{
CFE_EVS_SendEvent(HS_ENABLE_EVENTMON_INF_EID, CFE_EVS_EventType_INFORMATION,
"Event Monitoring is *already* Enabled");
}
else
{
Status = CFE_SB_SubscribeEx(CFE_SB_ValueToMsgId(CFE_EVS_LONG_EVENT_MSG_MID), HS_AppData.EventPipe,
CFE_SB_DEFAULT_QOS, HS_EVENT_PIPE_DEPTH);
Expand All @@ -277,6 +299,9 @@ CFE_Status_t HS_EnableEventMonCmd(const HS_EnableEventMonCmd_t *BufPtr)
Status = CFE_SB_SubscribeEx(CFE_SB_ValueToMsgId(CFE_EVS_SHORT_EVENT_MSG_MID), HS_AppData.EventPipe,
CFE_SB_DEFAULT_QOS, HS_EVENT_PIPE_DEPTH);

HS_AppData.CurrentEventMonState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_EVENTMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Event Monitoring Enabled");

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HS_EVENTMON_SHORT_SUB_EID, CFE_EVS_EventType_ERROR,
Expand All @@ -295,8 +320,6 @@ CFE_Status_t HS_EnableEventMonCmd(const HS_EnableEventMonCmd_t *BufPtr)
if (Status == CFE_SUCCESS)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentEventMonState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_EVENTMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Event Monitoring Enabled");
}
else
{
Expand All @@ -315,17 +338,22 @@ CFE_Status_t HS_DisableEventMonCmd(const HS_DisableEventMonCmd_t *BufPtr)
{
CFE_Status_t Status = CFE_SUCCESS;

/*
** Unsubscribe from Event Messages if currently enabled
*/
if (HS_AppData.CurrentEventMonState == HS_STATE_ENABLED)
if (HS_AppData.CurrentEventMonState == HS_STATE_DISABLED)
{
CFE_EVS_SendEvent(HS_DISABLE_EVENTMON_INF_EID, CFE_EVS_EventType_INFORMATION,
"Event Monitoring is *already* Dnabled");
}
else
{
Status = CFE_SB_Unsubscribe(CFE_SB_ValueToMsgId(CFE_EVS_LONG_EVENT_MSG_MID), HS_AppData.EventPipe);

if (Status == CFE_SUCCESS)
{
Status = CFE_SB_Unsubscribe(CFE_SB_ValueToMsgId(CFE_EVS_SHORT_EVENT_MSG_MID), HS_AppData.EventPipe);

HS_AppData.CurrentEventMonState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_EVENTMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Event Monitoring Disabled");

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HS_EVENTMON_SHORT_UNSUB_EID, CFE_EVS_EventType_ERROR,
Expand All @@ -344,8 +372,6 @@ CFE_Status_t HS_DisableEventMonCmd(const HS_DisableEventMonCmd_t *BufPtr)
if (Status == CFE_SUCCESS)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentEventMonState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_EVENTMON_INF_EID, CFE_EVS_EventType_INFORMATION, "Event Monitoring Disabled");
}
else
{
Expand All @@ -363,8 +389,17 @@ CFE_Status_t HS_DisableEventMonCmd(const HS_DisableEventMonCmd_t *BufPtr)
CFE_Status_t HS_EnableAlivenessCmd(const HS_EnableAlivenessCmd_t *BufPtr)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentAlivenessState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_ALIVENESS_INF_EID, CFE_EVS_EventType_INFORMATION, "Aliveness Indicator Enabled");

if (HS_AppData.CurrentAlivenessState == HS_STATE_ENABLED)
{
CFE_EVS_SendEvent(HS_ENABLE_ALIVENESS_INF_EID, CFE_EVS_EventType_INFORMATION,
"Aliveness Indicator *already* Enabled");
}
else
{
HS_AppData.CurrentAlivenessState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_ALIVENESS_INF_EID, CFE_EVS_EventType_INFORMATION, "Aliveness Indicator Enabled");
}

return CFE_SUCCESS;
}
Expand All @@ -377,8 +412,17 @@ CFE_Status_t HS_EnableAlivenessCmd(const HS_EnableAlivenessCmd_t *BufPtr)
CFE_Status_t HS_DisableAlivenessCmd(const HS_DisableAlivenessCmd_t *BufPtr)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentAlivenessState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_ALIVENESS_INF_EID, CFE_EVS_EventType_INFORMATION, "Aliveness Indicator Disabled");

if (HS_AppData.CurrentAlivenessState == HS_STATE_DISABLED)
{
CFE_EVS_SendEvent(HS_DISABLE_ALIVENESS_INF_EID, CFE_EVS_EventType_INFORMATION,
"Aliveness Indicator *already* Disabled");
}
else
{
HS_AppData.CurrentAlivenessState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_ALIVENESS_INF_EID, CFE_EVS_EventType_INFORMATION, "Aliveness Indicator Disabled");
}

return CFE_SUCCESS;
}
Expand All @@ -391,8 +435,17 @@ CFE_Status_t HS_DisableAlivenessCmd(const HS_DisableAlivenessCmd_t *BufPtr)
CFE_Status_t HS_EnableCpuHogCmd(const HS_EnableCpuHogCmd_t *BufPtr)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentCPUHogState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_CPUHOG_INF_EID, CFE_EVS_EventType_INFORMATION, "CPU Hogging Indicator Enabled");

if (HS_AppData.CurrentCPUHogState == HS_STATE_ENABLED)
{
CFE_EVS_SendEvent(HS_ENABLE_CPUHOG_INF_EID, CFE_EVS_EventType_INFORMATION,
"CPU Hogging Indicator *already* Enabled");
}
else
{
HS_AppData.CurrentCPUHogState = HS_STATE_ENABLED;
CFE_EVS_SendEvent(HS_ENABLE_CPUHOG_INF_EID, CFE_EVS_EventType_INFORMATION, "CPU Hogging Indicator Enabled");
}

return CFE_SUCCESS;
}
Expand All @@ -405,8 +458,17 @@ CFE_Status_t HS_EnableCpuHogCmd(const HS_EnableCpuHogCmd_t *BufPtr)
CFE_Status_t HS_DisableCpuHogCmd(const HS_DisableCpuHogCmd_t *BufPtr)
{
HS_AppData.CmdCount++;
HS_AppData.CurrentCPUHogState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_CPUHOG_INF_EID, CFE_EVS_EventType_INFORMATION, "CPU Hogging Indicator Disabled");

if (HS_AppData.CurrentCPUHogState == HS_STATE_DISABLED)
{
CFE_EVS_SendEvent(HS_DISABLE_CPUHOG_INF_EID, CFE_EVS_EventType_INFORMATION,
"CPU Hogging Indicator *already* Disabled");
}
else
{
HS_AppData.CurrentCPUHogState = HS_STATE_DISABLED;
CFE_EVS_SendEvent(HS_DISABLE_CPUHOG_INF_EID, CFE_EVS_EventType_INFORMATION, "CPU Hogging Indicator Disabled");
}

return CFE_SUCCESS;
}
Expand Down
43 changes: 43 additions & 0 deletions unit-test/hs_cmds_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,49 @@ void HS_EnableAppMonCmd_Test(void)
call_count_CFE_EVS_SendEvent);
}

void HS_EnableAppMonCmd_Test_AlreadyEnabled(void)
{
CFE_SB_MsgId_t TestMsgId;
CFE_MSG_FcnCode_t FcnCode;
size_t MsgSize;
HS_AMTEntry_t AMTable[HS_MAX_MONITORED_APPS];
int32 strCmpResult;
char ExpectedEventString[2][CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
snprintf(ExpectedEventString[0], CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Application Monitoring is *already* Enabled");

memset(AMTable, 0, sizeof(AMTable));

TestMsgId = CFE_SB_ValueToMsgId(HS_CMD_MID);
FcnCode = HS_ENABLE_APP_MON_CC;
MsgSize = sizeof(UT_CmdBuf.EnableAppMonCmd);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false);

HS_AppData.AMTablePtr = AMTable;

/* Execute the function being tested */
HS_EnableAppMonCmd(&UT_CmdBuf.EnableAppMonCmd);

/* Verify results */
UtAssert_True(HS_AppData.CmdCount == 1, "HS_AppData.CmdCount == 1");

UtAssert_True(HS_AppData.CurrentAppMonState == HS_STATE_ENABLED,
"HS_AppData.CurrentAppMonState == HS_STATE_ENABLED");

UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, HS_ENABLE_APPMON_INF_EID);
UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_INFORMATION);

strCmpResult =
strncmp(ExpectedEventString[0], 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);

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);
}

void HS_DisableAppMonCmd_Test(void)
{
CFE_SB_MsgId_t TestMsgId;
Expand Down

0 comments on commit ab4b6c8

Please sign in to comment.