Skip to content

Commit

Permalink
Merge pull request #417 from avan989/fix-416-cleanup-unused-error
Browse files Browse the repository at this point in the history
Fix #416, cleanup cf unused error codes
  • Loading branch information
dzbaker authored Nov 30, 2023
2 parents a0d35e1 + b21b7bd commit df516ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 58 deletions.
34 changes: 7 additions & 27 deletions fsw/src/cf_cfdp_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,30 +193,16 @@ CFE_Status_t CF_CFDP_S_SendFileData(CF_Transaction_t *txn, uint32 foffs, uint32
if (success)
{
txn->state_data.send.cached_pos += status;
status = CF_CFDP_SendFd(txn, ph);
if (status == CF_SEND_PDU_NO_BUF_AVAIL_ERROR)
{
ret = CFE_SUCCESS; /* no bytes were processed */
}
else if (status == CF_SEND_PDU_ERROR)
CF_CFDP_SendFd(txn, ph); /* CF_CFDP_SendFd only returns CFE_SUCCESS */

CF_AppData.hk.channel_hk[txn->chan_num].counters.sent.file_data_bytes += actual_bytes;
CF_Assert((foffs + actual_bytes) <= txn->fsize); /* sanity check */
if (calc_crc)
{
CFE_EVS_SendEvent(CF_EID_ERR_CFDP_S_SEND_FD, CFE_EVS_EventType_ERROR,
"CF S%d(%lu:%lu): error sending fd", (txn->state == CF_TxnState_S2),
(unsigned long)txn->history->src_eid, (unsigned long)txn->history->seq_num);
ret = CF_ERROR;
CF_CRC_Digest(&txn->crc, fd->data_ptr, fd->data_len);
}
else
{
CF_AppData.hk.channel_hk[txn->chan_num].counters.sent.file_data_bytes += actual_bytes;

CF_Assert((foffs + actual_bytes) <= txn->fsize); /* sanity check */
if (calc_crc)
{
CF_CRC_Digest(&txn->crc, fd->data_ptr, fd->data_len);
}

ret = actual_bytes;
}
ret = actual_bytes;
}
}

Expand Down Expand Up @@ -754,12 +740,6 @@ void CF_CFDP_S_Tick(CF_Transaction_t *txn, int *cont /* unused */)
{
early_exit = true;
}
else if (sret == CF_SEND_PDU_ERROR)
{
CF_CFDP_SetTxnStatus(txn, CF_TxnStatus_SEND_EOF_FAILURE);
CF_CFDP_S_Reset(txn); /* can't go on, error occurred */
early_exit = true;
}

if (!early_exit)
{
Expand Down
32 changes: 1 addition & 31 deletions unit-test/cf_cfdp_s_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,11 @@ void Test_CF_CFDP_S_Tick(void)
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_SendEof), 1, CF_SEND_PDU_NO_BUF_AVAIL_ERROR);
UtAssert_VOIDCALL(CF_CFDP_S_Tick(txn, &cont));

/* same, with CF_CFDP_S_SendEof Error */
UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &txn, &config);
UT_SetDeferredRetcode(UT_KEY(CF_Timer_Expired), 2, 1);
config->chan[txn->chan_num].ack_limit = 10;
txn->state = CF_TxnState_S2;
txn->flags.com.ack_timer_armed = true;
txn->state_data.send.sub_state = CF_TxSubState_WAIT_FOR_EOF_ACK;
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_SendEof), 1, CF_SEND_PDU_ERROR);
UtAssert_VOIDCALL(CF_CFDP_S_Tick(txn, &cont));
UtAssert_STUB_COUNT(CF_CFDP_ResetTransaction, 3);

UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &txn, NULL);
txn->state = CF_TxnState_S2;
txn->state_data.send.sub_state = CF_TxSubState_SEND_FIN_ACK;
UtAssert_VOIDCALL(CF_CFDP_S_Tick(txn, &cont));
UtAssert_STUB_COUNT(CF_CFDP_ResetTransaction, 4);
UtAssert_STUB_COUNT(CF_CFDP_ResetTransaction, 3);
}

void Test_CF_CFDP_S_Tick_Nak(void)
Expand Down Expand Up @@ -463,25 +452,6 @@ void Test_CF_CFDP_S_SendFileData(void)
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[txn->chan_num].counters.sent.file_data_bytes, cumulative_read);
UtAssert_STUB_COUNT(CF_CRC_Digest, 1);

/* no message available */
UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &txn, &config);
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_SendFd), 1, CF_SEND_PDU_NO_BUF_AVAIL_ERROR);
UT_SetDeferredRetcode(UT_KEY(CF_WrappedRead), 1, read_size);
config->outgoing_file_chunk_size = read_size;
txn->fsize = 300;
UtAssert_INT32_EQ(CF_CFDP_S_SendFileData(txn, offset, read_size, true), 0);
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[txn->chan_num].counters.sent.file_data_bytes, cumulative_read);

/* other send error */
UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &txn, &config);
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_SendFd), 1, CF_SEND_PDU_ERROR);
UT_SetDeferredRetcode(UT_KEY(CF_WrappedRead), 1, read_size);
config->outgoing_file_chunk_size = read_size;
txn->fsize = 300;
UtAssert_INT32_EQ(CF_CFDP_S_SendFileData(txn, offset, read_size, true), -1);
UT_CF_AssertEventID(CF_EID_ERR_CFDP_S_SEND_FD);
UtAssert_UINT32_EQ(CF_AppData.hk.channel_hk[txn->chan_num].counters.sent.file_data_bytes, cumulative_read);

/* read w/failure */
UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &txn, &config);
UT_SetDeferredRetcode(UT_KEY(CF_WrappedRead), 1, -1);
Expand Down

0 comments on commit df516ad

Please sign in to comment.