Skip to content

Commit

Permalink
Fix #213, updated CFDP class validation
Browse files Browse the repository at this point in the history
  • Loading branch information
havencarlson committed Aug 3, 2022
1 parent 557c132 commit 44c7f0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
6 changes: 4 additions & 2 deletions fsw/src/cf_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ void CF_CmdTxFile(CFE_SB_Buffer_t *msg)
* "keep" should only be 0 or 1 (logical true/false).
* For priority and dest_id params, anything is acceptable.
*/
if (tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS || tx->keep > 1)
if (tx->cfdp_class < CF_CFDP_CLASS_1 || tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS ||
tx->keep > 1)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_BAD_PARAM, CFE_EVS_EventType_ERROR,
"CF: bad parameter in CF_CmdTxFile(): chan=%u, class=%u keep=%u", (unsigned int)tx->chan_num,
Expand Down Expand Up @@ -192,7 +193,8 @@ void CF_CmdPlaybackDir(CFE_SB_Buffer_t *msg)
* "keep" should only be 0 or 1 (logical true/false).
* For priority and dest_id params, anything is acceptable.
*/
if (tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS || tx->keep > 1)
if (tx->cfdp_class < CF_CFDP_CLASS_1 || tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS ||
tx->keep > 1)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_BAD_PARAM, CFE_EVS_EventType_ERROR,
"CF: bad parameter in CF_CmdPlaybackDir(): chan=%u, class=%u keep=%u",
Expand Down
26 changes: 20 additions & 6 deletions unit-test/cf_cmd_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,29 +559,36 @@ void Test_CF_CmdTxFile(void)
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);

UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = -10;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 2);

/* out of range arguments: bad channel */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
memset(msg, 0, sizeof(*msg));
msg->chan_num = CF_NUM_CHANNELS;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 2);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 3);

/* out of range arguments: bad keep */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
memset(msg, 0, sizeof(*msg));
msg->keep = 15;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 3);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 4);

/* CF_CFDP_TxFile fails*/
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_TxFile), -1);
memset(msg, 0, sizeof(*msg));
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_TX_FILE);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 4);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 5);
}

/* end CF_CmdTxFile tests */
Expand Down Expand Up @@ -615,29 +622,36 @@ void Test_CF_CmdPlaybackDir(void)
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1);

UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = -10;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 2);

/* out of range arguments: bad channel */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
memset(msg, 0, sizeof(*msg));
msg->chan_num = CF_NUM_CHANNELS;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 2);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 3);

/* out of range arguments: bad keep */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
memset(msg, 0, sizeof(*msg));
msg->keep = 15;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_BAD_PARAM);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 3);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 4);

/* CF_CFDP_PlaybackDir fails*/
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_PlaybackDir), -1);
memset(msg, 0, sizeof(*msg));
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UT_CF_AssertEventID(CF_EID_ERR_CMD_PLAYBACK_DIR);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 4);
UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 5);
}

/* end CF_CmdPlaybackDir tests */
Expand Down

0 comments on commit 44c7f0e

Please sign in to comment.