Skip to content

Commit

Permalink
Merge pull request #303 from havencarlson/fix#213
Browse files Browse the repository at this point in the history
Fix #213, updated CFDP class validation
  • Loading branch information
dzbaker authored Aug 4, 2022
2 parents dfb2b55 + 87271ed commit a67eaf4
Show file tree
Hide file tree
Showing 2 changed files with 39 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 @@ -193,7 +194,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
41 changes: 35 additions & 6 deletions unit-test/cf_cmd_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,20 @@ void Test_CF_CmdTxFile(void)

/* nominal, all zero should pass checks, just calls CF_CFDP_TxFile */
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_1;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_TX_FILE);

UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_2;
UtAssert_VOIDCALL(CF_CmdTxFile(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 2);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_EID_INF_CMD_TX_FILE);

/* out of range arguments: bad class */
UT_CF_ResetEventCapture();
memset(msg, 0, sizeof(*msg));
Expand All @@ -542,29 +551,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();
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();
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();
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_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 All @@ -587,39 +603,52 @@ void Test_CF_CmdPlaybackDir(void)

/* nominal, all zero should pass checks, just calls CF_CFDP_PlaybackDir */
memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_1;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1);

memset(msg, 0, sizeof(*msg));
msg->cfdp_class = CF_CFDP_CLASS_2;
UtAssert_VOIDCALL(CF_CmdPlaybackDir(&utbuf.buf));
UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 2);

/* out of range arguments: bad class */
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, 1);

UT_CF_ResetEventCapture();
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();
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();
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_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 a67eaf4

Please sign in to comment.