From b21b7bdcdf6098d9bd0d1307197842d42f701434 Mon Sep 17 00:00:00 2001 From: Anh Date: Fri, 24 Nov 2023 09:03:15 -0500 Subject: [PATCH] Fix #416, cleanup cf unused error codes Fix #416, clean up cf_cfdp_s.c for unused error code and update unit test --- fsw/src/cf_cfdp_s.c | 34 +++++++--------------------------- unit-test/cf_cfdp_s_tests.c | 32 +------------------------------- 2 files changed, 8 insertions(+), 58 deletions(-) diff --git a/fsw/src/cf_cfdp_s.c b/fsw/src/cf_cfdp_s.c index 225199a0..adb621a0 100644 --- a/fsw/src/cf_cfdp_s.c +++ b/fsw/src/cf_cfdp_s.c @@ -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; } } @@ -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) { diff --git a/unit-test/cf_cfdp_s_tests.c b/unit-test/cf_cfdp_s_tests.c index 38858cb9..7cb474f0 100644 --- a/unit-test/cf_cfdp_s_tests.c +++ b/unit-test/cf_cfdp_s_tests.c @@ -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) @@ -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);