Skip to content

Commit

Permalink
Fix #445, update to meet standard
Browse files Browse the repository at this point in the history
Fix #445, update CF_DoSuspRes to increment command counter and issue info event instead of error event.
Update Enable_engine command to increment cmd counter when state stays the same.
Update Disable engine command to increment cmd counter when stat stays the same.
  • Loading branch information
Anh committed May 31, 2024
1 parent 12eff1c commit e305cd3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
12 changes: 6 additions & 6 deletions fsw/inc/cf_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -1157,13 +1157,13 @@
/**
* \brief CF Suspend/Resume Command For Single Transaction State Unchanged Event ID
*
* \par Type: ERROR
* \par Type: INFORMATION
*
* \par Cause:
*
* Suspend/resume command received affecting single transaction already set to that state
*/
#define CF_EID_ERR_CMD_SUSPRES_SAME (133)
#define CF_EID_INF_CMD_SUSPRES_SAME (133)

/**
* \brief CF Suspend/Resume Command No Matching Transaction Event ID
Expand Down Expand Up @@ -1333,24 +1333,24 @@
/**
* \brief CF Enable Engine Command Engine Already Enabled Event ID
*
* \par Type: ERROR
* \par Type: INFORMATION
*
* \par Cause:
*
* Enable engine command received while engine is already enabled
*/
#define CF_EID_ERR_CMD_ENG_ALREADY_ENA (149)
#define CF_EID_INF_CMD_ENG_ALREADY_ENA (149)

/**
* \brief CF Disable Engine Command Engine Already Disabled Event ID
*
* \par Type: ERROR
* \par Type: INFORMATION
*
* \par Cause:
*
* Disable engine command received while engine is already disabled
*/
#define CF_EID_ERR_CMD_ENG_ALREADY_DIS (150)
#define CF_EID_INF_CMD_ENG_ALREADY_DIS (150)

/**
* \brief CF Command Length Verification Failed Event ID
Expand Down
14 changes: 7 additions & 7 deletions fsw/src/cf_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ void CF_DoSuspRes(const CF_Transaction_Payload_t *payload, uint8 action)
if (ret == 1 && args.same)
{
/* A single transaction was mached, and it was already set the same way */
CFE_EVS_SendEvent(CF_EID_ERR_CMD_SUSPRES_SAME, CFE_EVS_EventType_ERROR,
CFE_EVS_SendEvent(CF_EID_INF_CMD_SUSPRES_SAME, CFE_EVS_EventType_INFORMATION,
"CF: %s cmd: setting suspend flag to current value of %d", msgstr[action], action);
++CF_AppData.hk.Payload.counters.err;
++CF_AppData.hk.Payload.counters.cmd;
}
else if (ret <= 0)
{
Expand Down Expand Up @@ -1184,9 +1184,9 @@ CFE_Status_t CF_EnableEngineCmd(const CF_EnableEngineCmd_t *msg)
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_ENG_ALREADY_ENA, CFE_EVS_EventType_ERROR,
CFE_EVS_SendEvent(CF_EID_INF_CMD_ENG_ALREADY_ENA, CFE_EVS_EventType_INFORMATION,
"CF: received enable engine command while engine already enabled");
++CF_AppData.hk.Payload.counters.err;
++CF_AppData.hk.Payload.counters.cmd;
}

return CFE_SUCCESS;
Expand All @@ -1204,15 +1204,15 @@ CFE_Status_t CF_DisableEngineCmd(const CF_DisableEngineCmd_t *msg)
{
CF_CFDP_DisableEngine();
CFE_EVS_SendEvent(CF_EID_INF_CMD_DISABLE_ENGINE, CFE_EVS_EventType_INFORMATION, "CF: disabled CFDP engine");
++CF_AppData.hk.Payload.counters.cmd;
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_ENG_ALREADY_DIS, CFE_EVS_EventType_ERROR,
CFE_EVS_SendEvent(CF_EID_INF_CMD_ENG_ALREADY_DIS, CFE_EVS_EventType_INFORMATION,
"CF: received disable engine command while engine already disabled");
++CF_AppData.hk.Payload.counters.err;
}

++CF_AppData.hk.Payload.counters.cmd;

return CFE_SUCCESS;
}

Expand Down
37 changes: 17 additions & 20 deletions unit-test/cf_cmd_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,8 @@ void Test_CF_DoSuspRes(void)
UT_SetHandlerFunction(UT_KEY(CF_TraverseAllTransactions), UT_AltHandler_CF_TraverseAllTransactions_SetSuspResArg,
&utargs);
UtAssert_VOIDCALL(CF_DoSuspRes(cmd, 0));
UT_CF_AssertEventID(CF_EID_ERR_CMD_SUSPRES_SAME);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, 2);
UT_CF_AssertEventID(CF_EID_INF_CMD_SUSPRES_SAME);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 2);

/* Output the CF_ChanAction_SuspResArg_t back to the caller, to set the "same" flag to 1 */
/* however this time CF_TraverseAllTransactions reports it matched multiple transactions, so it should NOT reject it
Expand All @@ -1306,7 +1306,7 @@ void Test_CF_DoSuspRes(void)
UtAssert_VOIDCALL(CF_DoSuspRes(cmd, 1));
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_SUSPRES);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 2);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 3);
}

/*******************************************************************************
Expand Down Expand Up @@ -3609,17 +3609,17 @@ void Test_CF_CmdEnableEngine_WithEngineNotEnableFailsInitSendEventAndIncrementEr
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, (initial_hk_err_counter + 1) & 0xFFFF);
}

void Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounter(void)
void Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementCmdCounter(void)
{
/* Arrange */
CF_EnableEngineCmd_t utbuf;
uint16 initial_hk_err_counter = Any_uint16();
uint16 initial_hk_cmd_counter = Any_uint16();

memset(&utbuf, 0, sizeof(utbuf));

CF_AppData.engine.enabled = 1; /* 1 is enabled */

CF_AppData.hk.Payload.counters.err = initial_hk_err_counter;
CF_AppData.hk.Payload.counters.cmd = initial_hk_cmd_counter;

/* Act */
CF_EnableEngineCmd(&utbuf);
Expand All @@ -3629,9 +3629,9 @@ void Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounte
/* Assert */
UtAssert_STUB_COUNT(CF_CFDP_InitEngine, 0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_ENG_ALREADY_ENA);
UT_CF_AssertEventID(CF_EID_INF_CMD_ENG_ALREADY_ENA);
/* Assert for incremented counter */
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, (initial_hk_err_counter + 1) & 0xFFFF);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF);
}

/*******************************************************************************
Expand Down Expand Up @@ -3664,30 +3664,27 @@ void Test_CF_CmdDisableEngine_SuccessWhenEngineEnabledAndIncrementCmdCounter(voi
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF);
}

void Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail(void)
void Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdCounter(void)
{
/* Arrange */
CF_DisableEngineCmd_t utbuf;
uint16 initial_hk_err_counter = Any_uint16();
uint16 initial_hk_counter = Any_uint16();

memset(&utbuf, 0, sizeof(utbuf));

CF_AppData.engine.enabled = 0; /* 0 is not enabled */

CF_AppData.hk.Payload.counters.err = initial_hk_err_counter;
CF_AppData.hk.Payload.counters.cmd = initial_hk_counter;

/* Act */
CF_DisableEngineCmd(&utbuf);

/* Assert */
UtAssert_STUB_COUNT(CF_CFDP_DisableEngine, 0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_ERR_CMD_ENG_ALREADY_DIS);
UT_CF_AssertEventID(CF_EID_INF_CMD_ENG_ALREADY_DIS);
/* Assert for incremented counter */
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, (initial_hk_err_counter + 1) & 0xFFFF);
UtAssert_True(CF_AppData.hk.Payload.counters.err == (uint16)(initial_hk_err_counter + 1),
"CF_AppData.hk.Payload.counters.err is %d and should be 1 more than %d",
CF_AppData.hk.Payload.counters.err, initial_hk_err_counter);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, (initial_hk_counter + 1) & 0xFFFF);
}

/*******************************************************************************
Expand Down Expand Up @@ -4103,16 +4100,16 @@ void add_CF_CmdEnableEngine_tests(void)
UtTest_Add(Test_CF_CmdEnableEngine_WithEngineNotEnableFailsInitSendEventAndIncrementErrCounter, cf_cmd_tests_Setup,
cf_cmd_tests_Teardown,
"Test_CF_CmdEnableEngine_WithEngineNotEnableFailsInitSendEventAndIncrementErrCounter");
UtTest_Add(Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounter, cf_cmd_tests_Setup,
cf_cmd_tests_Teardown, "Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounter");
UtTest_Add(Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementCmdCounter, cf_cmd_tests_Setup,
cf_cmd_tests_Teardown, "Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementCmdCounter");
}

void add_CF_CmdDisableEngine_tests(void)
{
UtTest_Add(Test_CF_CmdDisableEngine_SuccessWhenEngineEnabledAndIncrementCmdCounter, cf_cmd_tests_Setup,
cf_cmd_tests_Teardown, "Test_CF_CmdDisableEngine_SuccessWhenEngineEnabledAndIncrementCmdCounter");
UtTest_Add(Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail, cf_cmd_tests_Setup,
cf_cmd_tests_Teardown, "Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail");
UtTest_Add(Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdCounter, cf_cmd_tests_Setup,
cf_cmd_tests_Teardown, "Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdCounter");
}

void add_CF_SendHkCmd_tests(void)
Expand Down

0 comments on commit e305cd3

Please sign in to comment.