Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #213, updated CFDP class validation #303

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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