Skip to content

Commit

Permalink
Fix nasa#296, Consistent CFE_EVS_SendEvent handling in UT
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Aug 2, 2022
1 parent 557c132 commit dc674fb
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 222 deletions.
2 changes: 1 addition & 1 deletion unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ add_cfe_coverage_stubs(cf_internal
stubs/cf_utils_stubs.c
)

target_link_libraries(coverage-cf_internal-stubs core_api ut_assert)
target_link_libraries(coverage-cf_internal-stubs ut_core_api_stubs ut_assert)
target_include_directories(coverage-cf_internal-stubs PUBLIC utilities)

# Generate a dedicated "testrunner" executable for each test file
Expand Down
27 changes: 8 additions & 19 deletions unit-test/cf_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ void Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess(void)
int32 result = -1;

UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));

/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
Expand All @@ -311,7 +310,6 @@ void Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess(void)
int32 result = -1;

UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));

/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
Expand All @@ -327,7 +325,6 @@ void Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess(void)

/* Arrange */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));

/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
Expand All @@ -343,7 +340,6 @@ void Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess(void)

/* Arrange */
UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), result);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));

/* Act */
UtAssert_INT32_EQ(CF_TableInit(), result);
Expand Down Expand Up @@ -591,7 +587,6 @@ void Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath(void)
CFE_SB_Buffer_t *arg_msg = NULL;

UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));

/* Act */
CF_ProcessMsg(arg_msg);
Expand Down Expand Up @@ -633,18 +628,14 @@ void Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_s
void Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases(void)
{
CFE_SB_Buffer_t sbbuf;
CFE_SB_Buffer_t *sbbufptr = NULL;
uint16 events[2] = {0};
CFE_SB_Buffer_t *sbbufptr = NULL;

memset(&sbbuf, 0, sizeof(sbbuf));

/* Run loop once */
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false);

/* Capture events */
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false);

/* Unit under test does not use the buffer in this case */
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false);

Expand All @@ -660,26 +651,24 @@ void Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases(void)

/* Event from CF_Init and CF_AppMain */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(events[1], CF_EID_ERR_INIT_MSG_RECV);
UtAssert_UINT32_EQ(UT_CF_CapturedEventIDs[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(UT_CF_CapturedEventIDs[1], CF_EID_ERR_INIT_MSG_RECV);

/* Reset, return CFE_SUCCESS from CFE_SB_ReceiveBuffer and buffer NULL */
UT_ResetState(UT_KEY(CFE_EVS_SendEvent));
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false);
UT_CF_ResetEventCapture();
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);

UtAssert_VOIDCALL(CF_AppMain());

/* Event from CF_Init and CF_AppMain */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2);
UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(events[1], CF_EID_ERR_INIT_MSG_RECV);
UtAssert_UINT32_EQ(UT_CF_CapturedEventIDs[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(UT_CF_CapturedEventIDs[1], CF_EID_ERR_INIT_MSG_RECV);

/* Reset, return non-error codes and non-NULL buffer */
UT_ResetState(UT_KEY(CFE_EVS_SendEvent));
UT_CF_ResetEventCapture();
UT_ResetState(UT_KEY(CFE_ES_RunLoop));
UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false);
sbbufptr = &sbbuf;
UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
Expand All @@ -691,7 +680,7 @@ void Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases(void)

/* Event from CF_Init */
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT);
UtAssert_UINT32_EQ(UT_CF_CapturedEventIDs[0], CF_EID_INF_INIT);
UtAssert_STUB_COUNT(CFE_ES_RunLoop, 3);
}

Expand Down
2 changes: 1 addition & 1 deletion unit-test/cf_cfdp_dispatch_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static void UT_CFDP_Dispatch_SetupBasicTestState(UT_CF_Setup_t setup, CF_Logical
}

/* reset the event ID capture between each sub-case */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_CF_ResetEventCapture();
}

/*******************************************************************************
Expand Down
6 changes: 3 additions & 3 deletions unit-test/cf_cfdp_r_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void UT_CFDP_R_SetupBasicTestState(UT_CF_Setup_t setup, CF_Logical_PduBuf
}

/* reset the event ID capture between each sub-case */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_CF_ResetEventCapture();
}

/*******************************************************************************
Expand Down Expand Up @@ -368,7 +368,7 @@ void Test_CF_CFDP_R_Init(void)
t->flags.rx.md_recv = true;
UtAssert_VOIDCALL(CF_CFDP_R_Init(t));
UtAssert_STUB_COUNT(CF_CFDP_ArmAckTimer, 2);
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

/* failure of file open, class 1 */
UT_CFDP_R_SetupBasicTestState(UT_CF_Setup_RX, NULL, NULL, NULL, &t, NULL);
Expand Down Expand Up @@ -478,7 +478,7 @@ void Test_CF_CFDP_R_CheckCrc(void)
UT_CFDP_R_SetupBasicTestState(UT_CF_Setup_RX, NULL, NULL, NULL, &t, NULL);
t->crc.result = 0xc0ffee;
UtAssert_INT32_EQ(CF_CFDP_R_CheckCrc(t, 0xc0ffee), 0);
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
}

void Test_CF_CFDP_R2_Complete(void)
Expand Down
6 changes: 3 additions & 3 deletions unit-test/cf_cfdp_s_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_t setup, CF_Logical_PduBuf
}

/* reset the event ID capture between each sub-case */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_CF_ResetEventCapture();
}

/*******************************************************************************
Expand Down Expand Up @@ -664,7 +664,7 @@ void Test_CF_CFDP_S_SubstateSendMetadata(void)
UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, NULL);
OS_OpenCreate(&t->fd, "ut", 0, 0); /* sets fd */
UtAssert_VOIDCALL(CF_CFDP_S_SubstateSendMetadata(t));
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_UINT32_EQ(t->state_data.s.sub_state, CF_TxSubState_FILEDATA);

/* this retval is sticky and applies for the rest of the test cases */
Expand Down Expand Up @@ -705,7 +705,7 @@ void Test_CF_CFDP_S_SubstateSendMetadata(void)
UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, NULL);
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_SendMd), 1, CF_SendRet_NO_MSG);
UtAssert_VOIDCALL(CF_CFDP_S_SubstateSendMetadata(t));
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
UtAssert_UINT32_EQ(t->history->cc, 0);

/* everything works */
Expand Down
14 changes: 7 additions & 7 deletions unit-test/cf_cfdp_sbintf_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void UT_CFDP_SetupBasicTestState(UT_CF_Setup_t setup, CF_Logical_PduBuffe
}

/* reset the event ID capture between each sub-case */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_CF_ResetEventCapture();
}

/* end cf_cfdp_tests local utility functions */
Expand Down Expand Up @@ -333,20 +333,20 @@ void Test_CF_CFDP_MsgOutGet(void)
UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, NULL);
UtAssert_NOT_NULL(CF_CFDP_MsgOutGet(t, false));
UtAssert_STUB_COUNT(CFE_SB_ReleaseMessageBuffer, 0);
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

/* This should discard the old message, and get a new one */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, NULL);
UtAssert_NOT_NULL(CF_CFDP_MsgOutGet(t, false));
UtAssert_STUB_COUNT(CFE_SB_ReleaseMessageBuffer, 1);
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

/* test the various throttling mechanisms */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, &config);
config->chan[UT_CFDP_CHANNEL].max_outgoing_messages_per_wakeup = 3;
UtAssert_NOT_NULL(CF_CFDP_MsgOutGet(t, false));
UtAssert_NULL(CF_CFDP_MsgOutGet(t, false));
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, NULL, &c, NULL, &t, NULL);
c->sem_id = OS_ObjectIdFromInteger(123);
Expand All @@ -359,13 +359,13 @@ void Test_CF_CFDP_MsgOutGet(void)
UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, NULL);
t->flags.com.suspended = 1;
UtAssert_NULL(CF_CFDP_MsgOutGet(t, false));
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);

/* channel is frozen */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, NULL);
CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].frozen = 1;
UtAssert_NULL(CF_CFDP_MsgOutGet(t, false));
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
CF_AppData.hk.channel_hk[UT_CFDP_CHANNEL].frozen = 0;

/* no msg available from SB */
Expand All @@ -376,7 +376,7 @@ void Test_CF_CFDP_MsgOutGet(void)
/* same, but the silent flag should supress the event */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_NONE, NULL, NULL, NULL, &t, NULL);
UtAssert_NULL(CF_CFDP_MsgOutGet(t, true));
UT_CF_AssertEventID(0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
}

/*******************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion unit-test/cf_cfdp_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static void UT_CFDP_SetupBasicTestState(UT_CF_Setup_t setup, CF_Logical_PduBuffe
}

/* reset the event ID capture between each sub-case */
UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent));
UT_CF_ResetEventCapture();
}

/* end cf_cfdp_tests local utility functions */
Expand Down
Loading

0 comments on commit dc674fb

Please sign in to comment.