From 4316dd314ca578c75f3c9cf39f954adeb21a97b9 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 16 Jun 2022 12:08:47 -0600 Subject: [PATCH 1/6] Fix #194, Remove UT use of hooks that pass pointers out of context --- unit-test/CMakeLists.txt | 1 - unit-test/cf_app_tests.c | 290 ++++++----------------- unit-test/cf_cmd_tests.c | 142 ++--------- unit-test/utilities/cf_test_utils.c | 8 +- unit-test/utilities/cf_test_utils.h | 16 +- unit-test/utilities/ut_utils_cfe_hooks.c | 130 ---------- unit-test/utilities/ut_utils_cfe_hooks.h | 87 ------- 7 files changed, 103 insertions(+), 571 deletions(-) delete mode 100644 unit-test/utilities/ut_utils_cfe_hooks.c delete mode 100644 unit-test/utilities/ut_utils_cfe_hooks.h diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index da1d43bd..e929c003 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -37,7 +37,6 @@ add_cfe_coverage_stubs(cf_internal utilities/cf_test_utils.c utilities/cf_test_alt_handler.c - utilities/ut_utils_cfe_hooks.c stubs/cf_app_global.c stubs/cf_app_stubs.c diff --git a/unit-test/cf_app_tests.c b/unit-test/cf_app_tests.c index 180a0eb2..ab76a808 100644 --- a/unit-test/cf_app_tests.c +++ b/unit-test/cf_app_tests.c @@ -69,38 +69,17 @@ void UT_UpdatedDefaultHandler_CFE_SB_ReceiveBuffer(void *UserObj, UT_EntryKey_t ** *******************************************************************************/ -void Test_CF_HkCmd_TimestampAndSendMessageWith_CF_AppData_hk(void) +void Test_CF_HkCmd(void) { - /* Arrange */ - CFE_TIME_SysTime_t fake_time; - CFE_SB_TransmitMsg_context_t context_CFE_SB_TransmitMsg; - CFE_MSG_SetMsgTime_context_t context_CFE_MSG_SetMsgTime; - - Any_CFE_TIME_SysTime_Set(&fake_time); - - UT_SetDataBuffer(UT_KEY(CFE_TIME_GetTime), &fake_time, sizeof(fake_time), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_SetMsgTime), UT_Hook_CFE_MSG_SetMsgTime, &context_CFE_MSG_SetMsgTime); - UT_SetHookFunction(UT_KEY(CFE_SB_TransmitMsg), UT_Hook_CFE_SB_TransmitMsg, &context_CFE_SB_TransmitMsg); /* Act */ CF_HkCmd(); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_SetMsgTime, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_SetMsgTime.MsgPtr, &CF_AppData.hk.tlm_header.Msg); - UtAssert_True(context_CFE_MSG_SetMsgTime.Time.Seconds == fake_time.Seconds, - "CFE_MSG_SetMsgTime received Time.Seconds %lu and should be %lu (call to CFE_TIME_GetTime Seconds)", - (unsigned long)context_CFE_MSG_SetMsgTime.Time.Seconds, (unsigned long)fake_time.Seconds); - UtAssert_True( - context_CFE_MSG_SetMsgTime.Time.Subseconds == fake_time.Subseconds, - "CFE_MSG_SetMsgTime received Time.Subseconds %lu and should be %lu (call to CFE_TIME_GetTime Subseconds)", - (unsigned long)context_CFE_MSG_SetMsgTime.Time.Subseconds, (unsigned long)fake_time.Subseconds); UtAssert_STUB_COUNT(CFE_SB_TransmitMsg, 1); - UtAssert_ADDRESS_EQ(context_CFE_SB_TransmitMsg.MsgPtr, &CF_AppData.hk.tlm_header.Msg); - UtAssert_True(context_CFE_SB_TransmitMsg.IncrementSequenceCount == true, - "CFE_SB_TransmitMsg received IncrementSequenceCount '%s' and should be 'true'", - context_CFE_SB_TransmitMsg.IncrementSequenceCount ? "true" : "false"); -} /* end Test_CF_HkCmd_TimestampAndSendMessageWith_CF_AppData_hk */ + UtAssert_STUB_COUNT(CFE_TIME_GetTime, 1); +} /* end CF_HkCmd tests */ @@ -113,8 +92,7 @@ void Test_CF_HkCmd_TimestampAndSendMessageWith_CF_AppData_hk(void) void Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled(void) { /* Arrange */ - /* CF_AppData.engine.enabled not being 0 bypasses all code in CUT */ - CF_AppData.engine.enabled = Any_uint8_Except(0); + CF_AppData.engine.enabled = 1; /* Act */ CF_CheckTables(); @@ -125,13 +103,7 @@ void Test_CF_CheckTables_DoNotReleaseAddressBecauseEngineIsEnabled(void) void Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_SendEvent(void) { - /* Arrange */ - int32 forced_return_CFE_TBL_ReleaseAddress = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; /* any generic failure */ - - /* CF_AppData.engine.enabled being 0 runs code in CUT */ - CF_AppData.engine.enabled = 0; - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_ReleaseAddress), forced_return_CFE_TBL_ReleaseAddress); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_ReleaseAddress), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Act */ CF_CheckTables(); @@ -143,13 +115,7 @@ void Test_CF_CheckTables_CallTo_CFE_TBL_ReleaseAddress_ReturnsNot_CFE_SUCCESS_Se void Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent(void) { - /* Arrange */ - int32 forced_return_CFE_TBL_Manage = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; /* any generic failure */ - - /* CF_AppData.engine.enabled being 0 runs code in CUT */ - CF_AppData.engine.enabled = 0; - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), forced_return_CFE_TBL_Manage); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Act */ CF_CheckTables(); @@ -162,13 +128,7 @@ void Test_CF_CheckTables_CallTo_CFE_TBL_Manage_ReturnsNot_CFE_SUCCESS_SendEvent( void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE_TBL_INFO_UPDATED_SendEvent(void) { - /* Arrange */ - int32 forced_return_CFE_TBL_GetAddress = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; /* any generic failure */ - - /* CF_AppData.engine.enabled being 0 runs code in CUT */ - CF_AppData.engine.enabled = 0; - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), forced_return_CFE_TBL_GetAddress); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Act */ CF_CheckTables(); @@ -182,12 +142,6 @@ void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_ReturnsNot_CFE_SUCCESS_Or_CFE void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_SUCCESS(void) { - /* Arrange */ - /* CF_AppData.engine.enabled being 0 runs code in CUT */ - CF_AppData.engine.enabled = 0; - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_SUCCESS); - /* Act */ CF_CheckTables(); @@ -200,10 +154,6 @@ void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_SUCCESS(void) void Test_CF_CheckTables_CallTo_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED(void) { - /* Arrange */ - /* CF_AppData.engine.enabled being 0 runs code in CUT */ - CF_AppData.engine.enabled = 0; - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED); /* Act */ @@ -343,80 +293,68 @@ void Test_CF_ValidateConfigTable_Success(void) void Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess(void) { - /* Arrange */ - int32 expected_result = Any_int32_Except(CFE_SUCCESS); + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), expected_result); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), result); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); /* Act */ - UtAssert_INT32_EQ(CF_TableInit(), expected_result); + UtAssert_INT32_EQ(CF_TableInit(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_REG); - /* TODO: CFE_EVS_SendEvent needs to check all context values! */ } /* end Test_CF_TableInit_FailBecause_CFE_TBL_Register_DidNotReturnSuccess */ void Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess(void) { - /* Arrange */ - int32 expected_result = Any_int32_Except(CFE_SUCCESS); + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), expected_result); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Load), result); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); /* Act */ - UtAssert_INT32_EQ(CF_TableInit(), expected_result); + UtAssert_INT32_EQ(CF_TableInit(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_LOAD); - /* TODO: CFE_EVS_SendEvent needs to check all context values! */ } /* end Test_CF_TableInit_FailBecause_CFE_TBL_Load_DidNotReturnSuccess */ void Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess(void) { - /* Arrange */ - int32 expected_result = Any_int32_Except(CFE_SUCCESS); + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), expected_result); + /* Arrange */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Manage), result); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); /* Act */ - UtAssert_INT32_EQ(CF_TableInit(), expected_result); + UtAssert_INT32_EQ(CF_TableInit(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_MANAGE); - /* TODO: CFE_EVS_SendEvent needs to check all context values! */ } /* end Test_CF_TableInit_FailBecause_CFE_TBL_Manage_DidNotReturnSuccess */ void Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess(void) { - /* Arrange */ - int32 possible_success_results[2] = {CFE_SUCCESS, CFE_TBL_INFO_UPDATED}; - int32 expected_result = Any_int32_ExceptThese(possible_success_results, sizeof(possible_success_results) / - sizeof(possible_success_results[0])); + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), expected_result); + /* Arrange */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), result); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); /* Act */ - UtAssert_INT32_EQ(CF_TableInit(), expected_result); + UtAssert_INT32_EQ(CF_TableInit(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_INIT_TBL_GETADDR); - /* TODO: CFE_EVS_SendEvent needs to check all context values! */ } /* end Test_CF_TableInit_FailBecause_CFE_TBL_GetAddress_DidNotReturnSuccess */ void Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_SUCCESS_SuccessAndDoNotSendEvent(void) { - /* Arrange */ - - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_SUCCESS); - /* Act */ UtAssert_INT32_EQ(CF_TableInit(), CFE_SUCCESS); @@ -427,7 +365,6 @@ void Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_SUCCESS_SuccessAndDoN void Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED_SuccessAndDoNotSendEvent(void) { /* Arrange */ - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_INFO_UPDATED); /* Act */ @@ -447,51 +384,45 @@ void Test_CF_TableInit_When_CFE_TBL_GetAddress_Returns_CFE_TBL_INFO_UPDATED_Succ void Test_CF_Init_CallTo_CFE_EVS_Register_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void) { - /* Arrange */ - int32 forced_return_CFE_MSG_Init = Any_int32_Except(CFE_SUCCESS); - int32 result; + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_Register), forced_return_CFE_MSG_Init); + UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_Register), result); /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); UtAssert_STUB_COUNT(CFE_EVS_Register, 1); UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); - UtAssert_INT32_EQ(result, forced_return_CFE_MSG_Init); } /* end Test_CF_Init_CallTo_CFE_EVS_Register_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */ void Test_CF_Init_CallTo_CFE_SB_CreatePipe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void) { /* Arrange */ - int32 forced_return_CFE_SB_CreatePipe = Any_int32_Except(CFE_SUCCESS); - int32 result; + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_CreatePipe), forced_return_CFE_SB_CreatePipe); + UT_SetDefaultReturnValue(UT_KEY(CFE_SB_CreatePipe), result); /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); UtAssert_STUB_COUNT(CFE_EVS_Register, 1); UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1); UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); - UtAssert_INT32_EQ(result, forced_return_CFE_SB_CreatePipe); } /* end Test_CF_Init_CallTo_CFE_SB_CreatePipe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */ void Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void) { /* Arrange */ - int32 forced_return_CFE_SB_Subscribe = Any_int32_Except(CFE_SUCCESS); - int32 result; + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_Subscribe), forced_return_CFE_SB_Subscribe); + UT_SetDefaultReturnValue(UT_KEY(CFE_SB_Subscribe), result); /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); @@ -499,7 +430,6 @@ void Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_E UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1); UtAssert_STUB_COUNT(CFE_SB_Subscribe, 1); UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1); - UtAssert_INT32_EQ(result, forced_return_CFE_SB_Subscribe); } /* end Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */ /* NOTE: multi call test for CFE_SB_Subscribe would be helpful but not necessary for coverage */ @@ -507,56 +437,49 @@ void Test_CF_Init_FirstCallTo_CFE_SB_Subscribe_ReturnsNot_CFE_SUCCESS_Call_CFE_E void Test_CF_Init_CallTo_CF_TableInit_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus(void) { /* Arrange */ - int32 result; + int32 result = -1; /* Arrange unstubbable: CF_TableInit */ - int32 forced_return_CFE_TBL_Register = Any_int32_Except(CFE_SUCCESS); - UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), forced_return_CFE_TBL_Register); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_Register), result); /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); UtAssert_STUB_COUNT(CFE_EVS_Register, 1); UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1); UtAssert_STUB_COUNT(CFE_SB_Subscribe, 3); - /* Assert for CF_TableInit */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UtAssert_INT32_EQ(result, forced_return_CFE_TBL_Register); } /* end Test_CF_Init_CallTo_CF_TableInit_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus */ void Test_CF_Init_CallTo_CF_CFDP_InitEngine_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus(void) { /* Arrange */ - int32 result; - int32 forced_return_CF_CFDP_InitEngine = Any_int32_Except(CFE_SUCCESS); + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_InitEngine), forced_return_CF_CFDP_InitEngine); + UT_SetDefaultReturnValue(UT_KEY(CF_CFDP_InitEngine), result); /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); UtAssert_STUB_COUNT(CFE_EVS_Register, 1); UtAssert_STUB_COUNT(CFE_SB_CreatePipe, 1); UtAssert_STUB_COUNT(CFE_SB_Subscribe, 3); - // UtAssert_STUB_COUNT(CF_TableInit, 1); UtAssert_STUB_COUNT(CF_CFDP_InitEngine, 1); - UtAssert_INT32_EQ(result, forced_return_CF_CFDP_InitEngine); } /* end Test_CF_Init_CallTo_CF_CFDP_InitEngine_ReturnsNot_CFE_SUCCESS_ReturnErrorStatus */ void Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus(void) { /* Arrange */ - int32 force_return_CFE_EVS_SendEvent = Any_int32_Except(CFE_SUCCESS); - int32 result; + int32 result = -1; - UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_SendEvent), force_return_CFE_EVS_SendEvent); + UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_SendEvent), result); /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), result); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); @@ -566,20 +489,15 @@ void Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_Wr // UtAssert_STUB_COUNT(CF_TableInit, 1); UtAssert_STUB_COUNT(CF_CFDP_InitEngine, 1); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UtAssert_INT32_EQ(result, force_return_CFE_EVS_SendEvent); } /* end Test_CF_Init_CallTo_CFE_EVS_SendEvent_ReturnsNot_CFE_SUCCESS_Call_CFE_ES_WriteToSysLog_ReturnErrorStatus */ void Test_CF_Init_Success(void) { - /* Arrange */ - int32 result; - /* Act */ - result = CF_Init(); + UtAssert_INT32_EQ(CF_Init(), CFE_SUCCESS); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_Init, 1); - UtAssert_INT32_EQ(result, CFE_SUCCESS); } /* end Test_CF_Init_Success */ /* end CF_Init tests */ @@ -611,120 +529,77 @@ void Test_CF_WakeUp(void) void Test_CF_ProcessMsg_ProcessGroundCommand(void) { /* Arrange */ - CFE_SB_Buffer_t dummy_msg; - CFE_SB_Buffer_t * arg_msg = &dummy_msg; - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_CMD_MID); - CFE_SB_Buffer_t * context_CF_ProcessGroundCommand_msg; - CFE_MSG_GetMsgId_context_t context_CFE_MSG_GetMsgId; + CFE_SB_Buffer_t sbbuf; + CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_CMD_MID); + + memset(&sbbuf, 0, sizeof(sbbuf)); /* CFE_MSG_GetMsgId uses return by ref */ UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetMsgId), UT_Hook_CFE_MSG_GetMsgId, &context_CFE_MSG_GetMsgId); - - UT_SetDataBuffer(UT_KEY(CF_ProcessGroundCommand), &context_CF_ProcessGroundCommand_msg, - sizeof(context_CF_ProcessGroundCommand_msg), false); /* Act */ - CF_ProcessMsg(arg_msg); + CF_ProcessMsg(&sbbuf); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetMsgId, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetMsgId.MsgPtr, (CFE_MSG_Message_t *)arg_msg); UtAssert_STUB_COUNT(CF_ProcessGroundCommand, 1); - UtAssert_ADDRESS_EQ(context_CF_ProcessGroundCommand_msg, arg_msg); } /* end Test_CF_ProcessMsg_ProcessGroundCommand */ void Test_CF_ProcessMsg_WakeUp(void) { /* Arrange */ - CFE_SB_Buffer_t dummy_msg; - CFE_SB_Buffer_t * arg_msg = &dummy_msg; - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_WAKE_UP_MID); - CFE_MSG_GetMsgId_context_t context_CFE_MSG_GetMsgId; + CFE_SB_Buffer_t sbbuf; + CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_WAKE_UP_MID); + + memset(&sbbuf, 0, sizeof(sbbuf)); /* CFE_MSG_GetMsgId uses return by ref */ UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetMsgId), UT_Hook_CFE_MSG_GetMsgId, &context_CFE_MSG_GetMsgId); /* Act */ - CF_ProcessMsg(arg_msg); + CF_ProcessMsg(&sbbuf); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetMsgId, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetMsgId.MsgPtr, &arg_msg->Msg); - /* Assert Unstubbable - CF_WakeUp */ UtAssert_STUB_COUNT(CF_CFDP_CycleEngine, 1); + } /* end Test_CF_ProcessMsg_WakeUp */ void Test_CF_ProcessMsg_SendHk(void) { - /* Arrange */ - /* TODO: figure out if message is required here - not used at time of writing this */ - // CFE_MSG_Message_t dummy_Msg; - // CFE_SB_Buffer_t dummy_msg; - CFE_SB_Buffer_t * arg_msg = NULL; - CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_SEND_HK_MID); - CFE_MSG_GetMsgId_context_t context_CFE_MSG_GetMsgId; + CFE_SB_Buffer_t sbbuf; + CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(CF_SEND_HK_MID); + + memset(&sbbuf, 0, sizeof(sbbuf)); /* CFE_MSG_GetMsgId uses return by ref */ UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetMsgId), UT_Hook_CFE_MSG_GetMsgId, &context_CFE_MSG_GetMsgId); - /* CFE_MSG_GetMsgId return value ignored in code! Therefore no setup of return value requried */ - - /* Arrange unstubbable: CF_HkCmd exists in same source file */ - CFE_SB_TransmitMsg_context_t context_CFE_SB_TransmitMsg; - - UT_SetHookFunction(UT_KEY(CFE_SB_TransmitMsg), UT_Hook_CFE_SB_TransmitMsg, &context_CFE_SB_TransmitMsg); /* Act */ - CF_ProcessMsg(arg_msg); + CF_ProcessMsg(&sbbuf); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetMsgId, 1); - /* Assert for CF_HkCmd*/ - UtAssert_ADDRESS_EQ(context_CFE_SB_TransmitMsg.MsgPtr, &CF_AppData.hk.tlm_header.Msg); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); + UtAssert_STUB_COUNT(CFE_MSG_SetMsgTime, 1); /* Confirms CF_HkCmd path was taken */ } /* end Test_CF_ProcessMsg_SendHk */ void Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath(void) { /* Arrange */ - uint16 initial_err_count = CF_AppData.hk.counters.err; - CFE_SB_MsgId_Atom_t midval; - CFE_SB_MsgId_t forced_MsgID; - CFE_SB_Buffer_t * arg_msg = NULL; - CFE_MSG_GetMsgId_context_t context_CFE_MSG_GetMsgId; - CFE_EVS_SendEvent_context_t context_CFE_EVS_SendEvent; - - /* do not use one of the three real MIDs. - * As this depends on configuration, should not hardcode values here - */ - midval = 1; - while (midval == CF_CMD_MID || midval == CF_WAKE_UP_MID || midval == CF_SEND_HK_MID) - { - ++midval; - } - - forced_MsgID = CFE_SB_ValueToMsgId(midval); + CFE_SB_MsgId_t forced_MsgID = CFE_SB_INVALID_MSG_ID; + CFE_SB_Buffer_t *arg_msg = NULL; UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetMsgId), UT_Hook_CFE_MSG_GetMsgId, &context_CFE_MSG_GetMsgId); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_Hook_CFE_EVS_SendEvent, &context_CFE_EVS_SendEvent); /* Act */ CF_ProcessMsg(arg_msg); /* Assert */ - UtAssert_True(CF_AppData.hk.counters.err == (uint16)(initial_err_count + 1), - "CF_AppData.hk.counters.err is %d which is 1 more than %d", CF_AppData.hk.counters.err, - initial_err_count); - /* TODO: event sent not checked, does it need to be? found 1/19/21 */ + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_INIT_CMD_LENGTH); - UtAssert_True(context_CFE_EVS_SendEvent.EventType == CFE_EVS_EventType_ERROR, - "CFE_EVS_SendEvent received EventType %u and should have received %u (CFE_EVS_EventType_ERROR)", - context_CFE_EVS_SendEvent.EventType, CFE_EVS_EventType_ERROR); } /* end Test_CF_ProcessMsg_UnrecognizedCommandEnterDefaultPath */ @@ -742,10 +617,7 @@ void Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_s /* Arrange */ UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); - /* Arrange unstubbable: CF_Init */ - CFE_Status_t forced_return_CFE_EVS_Register = Any_CFE_Status_t_Except(CFE_SUCCESS); - - UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_Register), forced_return_CFE_EVS_Register); + UT_SetDefaultReturnValue(UT_KEY(CFE_EVS_Register), -1); /* Act */ CF_AppMain(); @@ -777,16 +649,15 @@ void Test_CF_AppMain_CallTo_CFE_ES_RunLoop_Returns_false_AppExit(void) void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_ReturnsNot_CFE_SUCCESS_AndNot_CFE_SB_TIME_OUT_SendEvent(void) { /* Arrange */ - int32 forced_return_CFE_SB_ReceiveBuffer = - Any_int32_Negative(); /* TODO: has to be negative unless a handler is used */ - CFE_SB_Buffer_t *dummy_msg = NULL; + CFE_SB_Buffer_t *sbbufptr = NULL; UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); - /* TODO: setting the data buffer only removes a TSF, otherwise in this test it does nothing */ - UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &dummy_msg, sizeof(dummy_msg), false); - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), forced_return_CFE_SB_ReceiveBuffer); + /* Unit under test does not use the buffer in this case */ + UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false); + + UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), -1); /* Act */ CF_AppMain(); @@ -802,15 +673,13 @@ void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_ReturnsNot_CFE_SUCCESS_A void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_And_msg_Is_NULL_SendEvent(void) { /* Arrange */ - int32 forced_return_CFE_SB_ReceiveBuffer = CFE_SUCCESS; - CFE_SB_Buffer_t *dummy_msg = NULL; + CFE_SB_Buffer_t *sbbufptr = NULL; UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); - /* TODO: setting the data buffer only removes a TSF, otherwise in this test it does nothing */ - UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &dummy_msg, sizeof(dummy_msg), false); - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), forced_return_CFE_SB_ReceiveBuffer); + /* Unit under test does not use the buffer in this case */ + UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false); /* Act */ CF_AppMain(); @@ -827,16 +696,16 @@ void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SB_TIME_OUT_ void) { /* Arrange */ - int32 forced_return_CFE_SB_ReceiveBuffer = CFE_SB_TIME_OUT; - CFE_SB_Buffer_t *dummy_BufPtr = NULL; + CFE_SB_Buffer_t *dummy_BufPtr = NULL; UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); - /* TODO: setting the data buffer only removes a TSF, otherwise in this test it does nothing */ + /* Unit under test does not use the buffer in this case */ UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &dummy_BufPtr, sizeof(dummy_BufPtr), false); + UT_SetHandlerFunction(UT_KEY(CFE_SB_ReceiveBuffer), UT_UpdatedDefaultHandler_CFE_SB_ReceiveBuffer, NULL); - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), forced_return_CFE_SB_ReceiveBuffer); + UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SB_TIME_OUT); /* Act */ CF_AppMain(); @@ -855,8 +724,7 @@ void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndV /* Arrange */ CFE_SB_MsgId_t forced_MsgID = CFE_SB_INVALID_MSG_ID; CFE_SB_Buffer_t fake_msg; - CFE_SB_Buffer_t *dummy_msg = &fake_msg; - uint16 initial_hk_counters_err = Any_uint16(); + CFE_SB_Buffer_t *dummy_msg = &fake_msg; UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); @@ -866,7 +734,6 @@ void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndV /* Arrange unstubbable: CF_ProcessMsg, invalid ID */ UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); - CF_AppData.hk.counters.err = initial_hk_counters_err; /* Act */ CF_AppMain(); @@ -878,9 +745,7 @@ void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndV /* Assert for CF_Init call and CF_ProcessMsg */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); /* Assert for CF_ProcessMsg */ - UtAssert_True(CF_AppData.hk.counters.err == (uint16)(initial_hk_counters_err + 1), - "CF_AppData.hk.counters.err is %u and should be 1 more than %u (value before call)", - CF_AppData.hk.counters.err, initial_hk_counters_err); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg */ /* end CF_AppMain tests */ @@ -893,9 +758,8 @@ void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndV void add_CF_HkCmd_tests(void) { - UtTest_Add(Test_CF_HkCmd_TimestampAndSendMessageWith_CF_AppData_hk, cf_app_tests_Setup, CF_App_Tests_Teardown, - "Test_CF_HkCmd_TimestampAndSendMessageWith_CF_AppData_hk"); -} /* end add_CF_HkCmd_tests */ + UtTest_Add(Test_CF_HkCmd, cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_HkCmd"); +} void add_CF_CheckTables_tests(void) { diff --git a/unit-test/cf_cmd_tests.c b/unit-test/cf_cmd_tests.c index 08dd42d1..764af5a6 100644 --- a/unit-test/cf_cmd_tests.c +++ b/unit-test/cf_cmd_tests.c @@ -2855,8 +2855,7 @@ void Test_CF_CmdWriteQueue_When_CF_WriteHistoryDataToFile_FailsOnSecondCallAnd_w UT_SetDataBuffer(UT_KEY(CF_WriteTxnQueueDataToFile), &context_CF_WriteTxnQueueDataToFile, sizeof(context_CF_WriteTxnQueueDataToFile), false); UT_SetDefaultReturnValue(UT_KEY(CF_WriteTxnQueueDataToFile), forced_return_CF_WriteTxnQueueDataToFile_1st_call); - UT_SetDeferredRetcode(UT_KEY(CF_WriteTxnQueueDataToFile), SECOND_CALL, - forced_return_CF_WriteTxnQueueDataToFile_2nd_call); + UT_SetDeferredRetcode(UT_KEY(CF_WriteTxnQueueDataToFile), 2, forced_return_CF_WriteTxnQueueDataToFile_2nd_call); /* goto out_close */ int32 context_CF_WrappedClose_fd; @@ -4020,90 +4019,56 @@ void Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdAccCounterThenFai void Test_CF_ProcessGroundCommand_When_cmd_EqTo_CF_NUM_COMMANDS_FailAndSendEvent(void) { /* Arrange */ - CFE_SB_Buffer_t utbuf; - CFE_SB_Buffer_t * arg_msg = &utbuf; - CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = CF_NUM_COMMANDS; - const char * expected_Spec = "CF: invalid ground command packet cmd_code=0x%02x"; - CFE_MSG_GetFcnCode_context_t context_CFE_MSG_GetFcnCode; - CFE_EVS_SendEvent_context_t context_CFE_EVS_SendEvent; + CFE_SB_Buffer_t utbuf; + CFE_SB_Buffer_t * arg_msg = &utbuf; + CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = CF_NUM_COMMANDS; memset(&utbuf, 0, sizeof(utbuf)); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_return_CFE_MSG_GetFcnCode, sizeof(forced_return_CFE_MSG_GetFcnCode), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetFcnCode), UT_Hook_CFE_MSG_GetFcnCode, &context_CFE_MSG_GetFcnCode); /* CFE_MSG_GetSize does not matter for Test_CF_ProcessGroundCommand_When_cmd_EqTo_CF_NUM_COMMANDS_FailAndSendEvent */ UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_Hook_CFE_EVS_SendEvent, &context_CFE_EVS_SendEvent); - - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.err = initial_hk_err_counter; /* Act */ CF_ProcessGroundCommand(arg_msg); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetFcnCode, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetFcnCode.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_CMD_GCMD_CC); - UtAssert_True(context_CFE_EVS_SendEvent.EventType == CFE_EVS_EventType_ERROR, - "CFE_EVS_SendEvent received EventType %u and should have received %u (CFE_EVS_EventType_ERROR)", - context_CFE_EVS_SendEvent.EventType, CFE_EVS_EventType_ERROR); - UtAssert_StrCmp(context_CFE_EVS_SendEvent.Spec, expected_Spec, - "CFE_EVS_SendEvent received expected Spec\n'%s' - Received\n'%s' - Expected", - context_CFE_EVS_SendEvent.Spec, expected_Spec); /* Assert for CF_CmdRej */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_ProcessGroundCommand_When_cmd_EqTo_CF_NUM_COMMANDS_FailAndSendEvent */ void Test_CF_ProcessGroundCommand_When_cmd_GreaterThan_CF_NUM_COMMANDS_FailAndSendEvent(void) { /* Arrange */ - CFE_SB_Buffer_t utbuf; - CFE_SB_Buffer_t * arg_msg = &utbuf; - CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = Any_uint8_GreaterThan(CF_NUM_COMMANDS); - CFE_MSG_GetFcnCode_context_t context_CFE_MSG_GetFcnCode; - const char * expected_Spec = "CF: invalid ground command packet cmd_code=0x%02x"; - CFE_EVS_SendEvent_context_t context_CFE_EVS_SendEvent; + CFE_SB_Buffer_t utbuf; + CFE_SB_Buffer_t * arg_msg = &utbuf; + CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = CF_NUM_COMMANDS + 1; memset(&utbuf, 0, sizeof(utbuf)); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_return_CFE_MSG_GetFcnCode, sizeof(forced_return_CFE_MSG_GetFcnCode), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetFcnCode), UT_Hook_CFE_MSG_GetFcnCode, &context_CFE_MSG_GetFcnCode); /* CFE_MSG_GetSize does not matter for Test_CF_ProcessGroundCommand_When_cmd_EqTo_CF_NUM_COMMANDS_FailAndSendEvent */ UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_Hook_CFE_EVS_SendEvent, &context_CFE_EVS_SendEvent); - - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.err = initial_hk_err_counter; /* Act */ CF_ProcessGroundCommand(arg_msg); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetFcnCode, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetFcnCode.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_CMD_GCMD_CC); - UtAssert_True(context_CFE_EVS_SendEvent.EventType == CFE_EVS_EventType_ERROR, - "CFE_EVS_SendEvent received EventType %u and should have received %u (CFE_EVS_EventType_ERROR)", - context_CFE_EVS_SendEvent.EventType, CFE_EVS_EventType_ERROR); - UtAssert_StrCmp(context_CFE_EVS_SendEvent.Spec, expected_Spec, - "CFE_EVS_SendEvent received expected Spec\n'%s' - Received\n'%s' - Expected", - context_CFE_EVS_SendEvent.Spec, expected_Spec); /* Assert for CF_CmdRej */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_ProcessGroundCommand_When_cmd_GreaterThan_CF_NUM_COMMANDS_FailAndSendEvent */ @@ -4113,54 +4078,28 @@ void Test_CF_ProcessGroundCommand_Receives_cmd_AndLengthDoesNotMatchExpectedForT /* Arrange */ CFE_SB_Buffer_t utbuf; CFE_SB_Buffer_t * arg_msg = &utbuf; - CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = 0x00; /* 0x00 forces fns[0] which is CF_CmdNoop */ - - /* - * sizeof(CF_NoArgsCmd_t) is expected size of CF_CmdNoop, using uint16 as a - * reasonable size constraint here as size_t is at least 16 bit - */ - CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = Any_uint16_Except(sizeof(CF_NoArgsCmd_t)); - - const char *expected_Spec = "CF: invalid ground command length for command 0x%02x, expected %d got %zd"; - CFE_MSG_GetFcnCode_context_t context_CFE_MSG_GetFcnCode; - CFE_MSG_GetSize_context_t context_CFE_MSG_GetSize; - CFE_EVS_SendEvent_context_t context_CFE_EVS_SendEvent; + CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = CF_NOOP_CC; + CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = sizeof(CF_NoArgsCmd_t) + 1; /* Invalid size */ memset(&utbuf, 0, sizeof(utbuf)); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_return_CFE_MSG_GetFcnCode, sizeof(forced_return_CFE_MSG_GetFcnCode), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetFcnCode), UT_Hook_CFE_MSG_GetFcnCode, &context_CFE_MSG_GetFcnCode); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_return_CFE_MSG_GetSize, sizeof(forced_return_CFE_MSG_GetSize), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetSize), UT_Hook_CFE_MSG_GetSize, &context_CFE_MSG_GetSize); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_Hook_CFE_EVS_SendEvent, &context_CFE_EVS_SendEvent); - - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.err = initial_hk_err_counter; /* Act */ CF_ProcessGroundCommand(arg_msg); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetFcnCode, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetFcnCode.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_MSG_GetSize, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetSize.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_CMD_GCMD_LEN); - UtAssert_True(context_CFE_EVS_SendEvent.EventType == CFE_EVS_EventType_ERROR, - "CFE_EVS_SendEvent received EventType %u and should have received %u (CFE_EVS_EventType_ERROR)", - context_CFE_EVS_SendEvent.EventType, CFE_EVS_EventType_ERROR); - UtAssert_StrCmp(context_CFE_EVS_SendEvent.Spec, expected_Spec, - "CFE_EVS_SendEvent received expected Spec\n'%s' - Received\n'%s' - Expected", - context_CFE_EVS_SendEvent.Spec, expected_Spec); /* Assert for CF_CmdRej */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_ProcessGroundCommand_Receives_cmd_AndLengthDoesNotMatchExpectedForThatCommandSendEventAndCall_CF_CmdRej */ @@ -4170,50 +4109,29 @@ void Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x00_AndCall_CF_CmdNoop_With_m /* Arrange */ CFE_SB_Buffer_t utbuf; CFE_SB_Buffer_t * arg_msg = &utbuf; - CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = 0x00; /* 0x00 forces fns[0] which is CF_CmdNoop */ - CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = - sizeof(CF_NoArgsCmd_t); /* sizeof(CF_NoArgsCmd_t) is expected size of CF_CmdNoop */ - const char * expected_Spec = "CF: No-Op received, Version %d.%d.%d.%d"; - CFE_MSG_GetFcnCode_context_t context_CFE_MSG_GetFcnCode; - CFE_MSG_GetSize_context_t context_CFE_MSG_GetSize; - CFE_EVS_SendEvent_context_t context_CFE_EVS_SendEvent; + CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = CF_NOOP_CC; + CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = sizeof(CF_NoArgsCmd_t); /* Valid size */ memset(&utbuf, 0, sizeof(utbuf)); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_return_CFE_MSG_GetFcnCode, sizeof(forced_return_CFE_MSG_GetFcnCode), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetFcnCode), UT_Hook_CFE_MSG_GetFcnCode, &context_CFE_MSG_GetFcnCode); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_return_CFE_MSG_GetSize, sizeof(forced_return_CFE_MSG_GetSize), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetSize), UT_Hook_CFE_MSG_GetSize, &context_CFE_MSG_GetSize); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - UT_SetHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_Hook_CFE_EVS_SendEvent, &context_CFE_EVS_SendEvent); - - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_cmd_counter = Any_uint16(); - - CF_AppData.hk.counters.cmd = initial_hk_cmd_counter; /* Act */ CF_ProcessGroundCommand(arg_msg); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetFcnCode, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetFcnCode.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_MSG_GetSize, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetSize.MsgPtr, &arg_msg->Msg); /* Assert for CF_CmdNoop */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_INF_CMD_NOOP); - UtAssert_True(context_CFE_EVS_SendEvent.EventType == CFE_EVS_EventType_INFORMATION, - "CFE_EVS_SendEvent received EventType %u and should have received %u (CFE_EVS_EventType_INFORMATION)", - context_CFE_EVS_SendEvent.EventType, CFE_EVS_EventType_INFORMATION); - UtAssert_StrCmp(context_CFE_EVS_SendEvent.Spec, expected_Spec, - "CFE_EVS_SendEvent received expected Spec\n'%s' - Received\n'%s' - Expected", - context_CFE_EVS_SendEvent.Spec, expected_Spec); /* Assert for CF_CmdAcc */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1); } /* end Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x00_AndCall_CF_CmdNoop_With_msg */ @@ -4223,47 +4141,31 @@ void Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x00_AndCall_CF_CmdNoop_With_m void Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x0C_AndDoNothingBecause_fns_12_Is_NULL(void) { /* Arrange */ - CFE_SB_Buffer_t utbuf; - CFE_SB_Buffer_t * arg_msg = &utbuf; - CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = 0x0C; /* 0x0C forces a null slot */ - CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = 0; - CFE_MSG_GetFcnCode_context_t context_CFE_MSG_GetFcnCode; - CFE_MSG_GetSize_context_t context_CFE_MSG_GetSize; + CFE_SB_Buffer_t utbuf; + CFE_SB_Buffer_t * arg_msg = &utbuf; + CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = 0x0C; /* 0x0C forces a null slot */ + CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = 0; memset(&utbuf, 0, sizeof(utbuf)); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_return_CFE_MSG_GetFcnCode, sizeof(forced_return_CFE_MSG_GetFcnCode), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetFcnCode), UT_Hook_CFE_MSG_GetFcnCode, &context_CFE_MSG_GetFcnCode); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_return_CFE_MSG_GetSize, sizeof(forced_return_CFE_MSG_GetSize), false); - UT_SetHookFunction(UT_KEY(CFE_MSG_GetSize), UT_Hook_CFE_MSG_GetSize, &context_CFE_MSG_GetSize); /* Arrange unstubbable: CF_CmdAcc, CF_CmdRej */ /* technically these are NOT called, but makes sense when looking at other tests for CF_ProcessGroundCommand */ - uint16 initial_hk_cmd_counter = Any_uint16(); - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.cmd = initial_hk_cmd_counter; - CF_AppData.hk.counters.err = initial_hk_err_counter; /* Act */ CF_ProcessGroundCommand(arg_msg); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetFcnCode, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetFcnCode.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_MSG_GetSize, 1); - UtAssert_ADDRESS_EQ(context_CFE_MSG_GetSize.MsgPtr, &arg_msg->Msg); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - /* Assert for CF_CmdAcc */ /* TODO: just to note because of other CF_ProcessGroundCommand tests note, no problem - here with overflow because no values should have been altered */ - UtAssert_True(CF_AppData.hk.counters.cmd == initial_hk_cmd_counter, - "CF_AppData.hk.counters.cmd is %u and should not have changed from %u (value before call)", - CF_AppData.hk.counters.cmd, initial_hk_cmd_counter); - UtAssert_True(CF_AppData.hk.counters.err == initial_hk_err_counter, - "CF_AppData.hk.counters.err is %u and should not have changed from %u (value before call)", - CF_AppData.hk.counters.err, initial_hk_err_counter); + /* Assert for CF_CmdAcc */ + UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 0); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 0); } /* end Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x0C_AndDoNothingBecause_fns_12_Is_NULL */ /* end CF_ProcessGroundCommand tests */ diff --git a/unit-test/utilities/cf_test_utils.c b/unit-test/utilities/cf_test_utils.c index ea27f668..5118df46 100644 --- a/unit-test/utilities/cf_test_utils.c +++ b/unit-test/utilities/cf_test_utils.c @@ -109,6 +109,8 @@ void cf_tests_Setup(void) /* Note This cannot set up for CFE_EVS_SendEvent, although it is commonly used/needed, not every unit uses it */ UT_CF_ResetEventCapture(0); + + memset(&CF_AppData, 0, sizeof(CF_AppData)); } void cf_tests_Teardown(void) @@ -137,12 +139,6 @@ void TestUtil_InitializeRandomSeed(void) UtPrintf("RANDOM_VALUES_SEED = %d\n", seed); } -void TestUtil_InitMsg(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_MSG_Size_t Size) -{ - // CFE_MSG_Init(MsgPtr, MsgId, Size); - UtAssert_Abort("using TestUtil_InitMsg!!"); -} - /****************************************************************************** * The 'Any' randomized values section ******************************************************************************/ diff --git a/unit-test/utilities/cf_test_utils.h b/unit-test/utilities/cf_test_utils.h index 3801ea00..2e6e3bf2 100644 --- a/unit-test/utilities/cf_test_utils.h +++ b/unit-test/utilities/cf_test_utils.h @@ -39,30 +39,19 @@ #include "utstubs.h" #include "utgenstub.h" -/* ut_utils_lib includes */ -#include "ut_utils_cfe_hooks.h" - /* cf_tests constants */ -#define UT_INT_32_DEFAULT 0xABBACABB /* 0xABBACABB == 2881145531 decimal */ -#define UT_UINT_16_DEFAULT 0xEFFD /* 0xEFFD == 61437 decimal */ -#define UT_INT_16_DEFAULT 0xBADD /* 0xBADD == 47837 decimal */ -#define UT_UINT_8_DEFAULT 0xED /* 0xED == 237 decimal */ +#define UT_INT_16_DEFAULT 0xBADD /* 0xBADD == 47837 decimal */ +#define UT_UINT_8_DEFAULT 0xED /* 0xED == 237 decimal */ #define MAX_INT 2147484647 /* Set at 32bit for now, pow(2, 31) - 1 */ #define ALL_CHANNELS 255 #define COMPOUND_KEY 254 -#define ERROR_RETRIEVING_ANY_VALUE -86 - #ifndef RANDOM_VALUES_SEED #define RANDOM_VALUES_SEED 0 #endif /* !RANDOM_VALUES_SEED */ -#define FIRST_CALL 1 -#define SECOND_CALL 2 -#define NEXT_CALL 1 - #define UT_CFDP_CHANNEL 0 typedef enum @@ -238,7 +227,6 @@ void cf_tests_Setup(void); void cf_tests_Teardown(void); void TestUtil_InitializeRandomSeed(void); -void TestUtil_InitMsg(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_MSG_Size_t Size); unsigned int AnyCoinFlip(void); diff --git a/unit-test/utilities/ut_utils_cfe_hooks.c b/unit-test/utilities/ut_utils_cfe_hooks.c deleted file mode 100644 index 313e7619..00000000 --- a/unit-test/utilities/ut_utils_cfe_hooks.c +++ /dev/null @@ -1,130 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,447-1, and identified as “CFS CFDP (CF) - * Application version 3.0.0” - * - * Copyright (c) 2019 United States Government as represented by the - * Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ************************************************************************/ - -#include - -/* UT includes */ -#include "ut_utils_cfe_hooks.h" -#include "cf_test_utils.h" -#include "utstubs.h" - -int32 UT_Hook_CFE_EVS_SendEvent(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_EVS_SendEvent_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->EventID = UT_Hook_GetArgValueByName(Context, "EventID", uint16); - ctxt->EventType = UT_Hook_GetArgValueByName(Context, "EventType", uint16); - ctxt->Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_MSG_GetSize(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_MSG_GetSize_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", const CFE_MSG_Message_t *); - ctxt->Size = UT_Hook_GetArgValueByName(Context, "Size", CFE_MSG_Size_t *); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_MSG_SetSize(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_MSG_SetSize_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", CFE_MSG_Message_t *); - ctxt->Size = UT_Hook_GetArgValueByName(Context, "Size", CFE_MSG_Size_t); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_MSG_SetMsgId(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_MSG_SetMsgId_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", CFE_MSG_Message_t *); - ctxt->MsgId = UT_Hook_GetArgValueByName(Context, "MsgId", CFE_SB_MsgId_t); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_MSG_GetMsgId(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_MSG_GetMsgId_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", const CFE_MSG_Message_t *); - ctxt->returned_MsgId = UT_Hook_GetArgValueByName(Context, "MsgId", CFE_SB_MsgId_t *); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_MSG_GetFcnCode(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_MSG_GetFcnCode_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", const CFE_MSG_Message_t *); - ctxt->FcnCode = UT_Hook_GetArgValueByName(Context, "FcnCode", CFE_MSG_FcnCode_t *); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_MSG_SetMsgTime(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_MSG_SetMsgTime_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", CFE_MSG_Message_t *); - ctxt->Time = UT_Hook_GetArgValueByName(Context, "NewTime", CFE_TIME_SysTime_t); - } - - return StubRetcode; -} - -int32 UT_Hook_CFE_SB_TransmitMsg(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) -{ - CFE_SB_TransmitMsg_context_t *ctxt = UserObj; - - if (ctxt) - { - ctxt->MsgPtr = UT_Hook_GetArgValueByName(Context, "MsgPtr", CFE_MSG_Message_t *); - ctxt->IncrementSequenceCount = UT_Hook_GetArgValueByName(Context, "IncrementSequenceCount", bool); - } - - return StubRetcode; -} diff --git a/unit-test/utilities/ut_utils_cfe_hooks.h b/unit-test/utilities/ut_utils_cfe_hooks.h deleted file mode 100644 index 27b45455..00000000 --- a/unit-test/utilities/ut_utils_cfe_hooks.h +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************************************ - * NASA Docket No. GSC-18,447-1, and identified as “CFS CFDP (CF) - * Application version 3.0.0” - * - * Copyright (c) 2019 United States Government as represented by the - * Administrator of the National Aeronautics and Space Administration. - * All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ************************************************************************/ - -#ifndef UT_UTILS_CFE_HOOKS_H -#define UT_UTILS_CFE_HOOKS_H - -/* cfe includes */ -#include "cfe.h" - -/* UT includes */ -#include "utstubs.h" - -typedef struct -{ - CFE_MSG_Message_t *MsgPtr; - CFE_TIME_SysTime_t Time; -} CFE_MSG_SetMsgTime_context_t; - -typedef struct -{ - const CFE_MSG_Message_t *MsgPtr; - CFE_SB_MsgId_t * returned_MsgId; -} CFE_MSG_GetMsgId_context_t; - -typedef struct -{ - uint16 EventID; - uint16 EventType; - const char *Spec; -} CFE_EVS_SendEvent_context_t; - -typedef struct -{ - const CFE_MSG_Message_t *MsgPtr; - CFE_MSG_Size_t * Size; -} CFE_MSG_GetSize_context_t; - -typedef struct -{ - CFE_MSG_Message_t *MsgPtr; - CFE_SB_MsgId_t MsgId; -} CFE_MSG_SetMsgId_context_t; - -typedef struct -{ - CFE_MSG_Message_t *MsgPtr; - bool IncrementSequenceCount; -} CFE_SB_TransmitMsg_context_t; - -typedef struct -{ - const CFE_MSG_Message_t *MsgPtr; - CFE_MSG_FcnCode_t * FcnCode; -} CFE_MSG_GetFcnCode_context_t; - -typedef struct -{ - CFE_MSG_Message_t *MsgPtr; - CFE_MSG_Size_t Size; -} CFE_MSG_SetSize_context_t; - -int32 UT_Hook_CFE_EVS_SendEvent(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_MSG_SetSize(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_MSG_GetSize(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_MSG_SetMsgId(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_MSG_GetMsgId(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_MSG_GetFcnCode(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_MSG_SetMsgTime(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); -int32 UT_Hook_CFE_SB_TransmitMsg(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context); - -#endif \ No newline at end of file From 3a44f15a16e7831a347de7331a392d313556aafe Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 16 Jun 2022 15:38:42 -0600 Subject: [PATCH 2/6] Fix #108, Resolve TODOs in unit test code --- unit-test/cf_cmd_tests.c | 212 ++++++++-------------------- unit-test/cf_utils_tests.c | 5 +- unit-test/utilities/cf_test_utils.c | 168 +--------------------- unit-test/utilities/cf_test_utils.h | 15 +- 4 files changed, 65 insertions(+), 335 deletions(-) diff --git a/unit-test/cf_cmd_tests.c b/unit-test/cf_cmd_tests.c index 764af5a6..ee3ba4ab 100644 --- a/unit-test/cf_cmd_tests.c +++ b/unit-test/cf_cmd_tests.c @@ -1282,29 +1282,21 @@ void Test_CF_TsnChanAction_cmd_chan_Eq_ALL_CHANNELS_Return_CF_TraverseAllTransac void Test_CF_TsnChanAction_cmd_chan_IsASingleChannel(void) { /* Arrange */ - CF_UT_cmd_transaction_buf_t utbuf; - CF_TransactionCmd_t * arg_cmd = &utbuf.xact; - const char arg_cmdstr[1] = ""; - CF_TsnChanAction_fn_t arg_fn = &Dummy_CF_TsnChanAction_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - int expected_result = Any_int(); - CF_TraverseAllTransactions_context_t context_CF_TraverseAllTransactions; + CF_TransactionCmd_t cmd; + int result = 1; - memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->chan = Any_cf_channel(); + memset(&cmd, 0, sizeof(cmd)); UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - UT_SetDataBuffer(UT_KEY(CF_TraverseAllTransactions), &context_CF_TraverseAllTransactions, - sizeof(context_CF_TraverseAllTransactions), false); - UT_SetDefaultReturnValue(UT_KEY(CF_TraverseAllTransactions), expected_result); + UT_SetDefaultReturnValue(UT_KEY(CF_TraverseAllTransactions), result); /* Act */ - UtAssert_INT32_EQ(CF_TsnChanAction(arg_cmd, arg_cmdstr, arg_fn, arg_context), expected_result); + UtAssert_INT32_EQ(CF_TsnChanAction(&cmd, NULL, NULL, NULL), result); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - /* TODO: values for context_CF_TraverseAllTransactions need checked!! */ + UtAssert_STUB_COUNT(CF_TraverseAllTransactions, 1); + } /* end Test_CF_TsnChanAction_cmd_chan_Eq_ALL_CHANNELS_Return_CF_TraverseAllTransactions_All_Channels */ void Test_CF_TsnChanAction_cmd_FailBecause_cmd_chan_IsInvalid(void) @@ -1466,40 +1458,31 @@ void Test_CF_DoSuspRes(void) ** CF_CmdSuspend tests ** *******************************************************************************/ -/* TODO: SendEvent needs to be able to check all values before action = 1 can be verified in - * Test_CF_CmdSuspend_Call_CF_DoSuspRes_WithGiven_msg_And_action_1 */ + +/* Test_CF_CmdSuspend_Call_CF_DoSuspRes_WithGiven_msg_And_action_1 */ void Test_CF_CmdSuspend_Call_CF_DoSuspRes_WithGiven_msg_And_action_1(void) { /* Arrange */ CF_UT_cmd_transaction_buf_t utbuf; - CF_TransactionCmd_t * dummy_cmd = &utbuf.xact; - CFE_SB_Buffer_t * arg_cmd = &utbuf.buf; + uint16 events[2] = {0}; memset(&utbuf, 0, sizeof(utbuf)); - /* Arrange unstubbable: CF_DoSuspRes */ - UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - - /* Arrange unstubbable: CF_TsnChanAction - causes areturn -1*/ - dummy_cmd->chan = Any_uint8_BetweenExcludeMax(CF_NUM_CHANNELS, COMPOUND_KEY); - - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); + UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false); - CF_AppData.hk.counters.err = initial_hk_err_counter; + /* Set to invalid channel */ + utbuf.xact.chan = CF_NUM_CHANNELS; /* Act */ - CF_CmdSuspend(arg_cmd); + CF_CmdSuspend(&utbuf.buf); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); - UT_CF_AssertEventID(CF_EID_ERR_CMD_TSN_CHAN_INVALID); - UT_CF_AssertEventID(CF_EID_ERR_CMD_SUSPRES_CHAN); + UtAssert_UINT32_EQ(events[0], CF_EID_ERR_CMD_TSN_CHAN_INVALID); + UtAssert_UINT32_EQ(events[1], CF_EID_ERR_CMD_SUSPRES_CHAN); /* Assert CF_CmdRej */ - UtAssert_True(CF_AppData.hk.counters.err == (uint16)(initial_hk_err_counter + 1), - "CF_AppData.hk.counters.err is %d and should be 1 more than %d", CF_AppData.hk.counters.err, - initial_hk_err_counter); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_CmdSuspend_Call_CF_DoSuspRes_WithGiven_msg_And_action_1 */ /* end CF_CmdSuspend tests */ @@ -1509,40 +1492,32 @@ void Test_CF_CmdSuspend_Call_CF_DoSuspRes_WithGiven_msg_And_action_1(void) ** CF_CmdResume tests ** *******************************************************************************/ -/* TODO: SendEvent needs to be able to check all values before action = 0 can be verified in - * Test_CF_CmdResume_Call_CF_DoSuspRes_WithGiven_msg_And_action_0 */ + +/* Test_CF_CmdResume_Call_CF_DoSuspRes_WithGiven_msg_And_action_0 */ void Test_CF_CmdResume_Call_CF_DoSuspRes_WithGiven_msg_And_action_0(void) { /* Arrange */ CF_UT_cmd_transaction_buf_t utbuf; - CF_TransactionCmd_t * dummy_cmd = &utbuf.xact; - CFE_SB_Buffer_t * arg_cmd = &utbuf.buf; + uint16 events[2] = {0}; memset(&utbuf, 0, sizeof(utbuf)); - /* Arrange unstubbable: CF_DoSuspRes */ - UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - - /* Arrange unstubbable: CF_TsnChanAction - causes areturn -1*/ - dummy_cmd->chan = Any_uint8_BetweenExcludeMax(CF_NUM_CHANNELS, COMPOUND_KEY); + /* Capture events */ + UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), events, sizeof(events), false); - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.err = initial_hk_err_counter; + /* Invalid channel */ + utbuf.xact.chan = CF_NUM_CHANNELS; /* Act */ - CF_CmdResume(arg_cmd); + CF_CmdResume(&utbuf.buf); /* Assert */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); - UT_CF_AssertEventID(CF_EID_ERR_CMD_TSN_CHAN_INVALID); - UT_CF_AssertEventID(CF_EID_ERR_CMD_SUSPRES_CHAN); + UtAssert_UINT32_EQ(events[0], CF_EID_ERR_CMD_TSN_CHAN_INVALID); + UtAssert_UINT32_EQ(events[1], CF_EID_ERR_CMD_SUSPRES_CHAN); /* Assert CF_CmdRej */ - UtAssert_True(CF_AppData.hk.counters.err == (uint16)(initial_hk_err_counter + 1), - "CF_AppData.hk.counters.err is %d and should be 1 more than %d", CF_AppData.hk.counters.err, - initial_hk_err_counter); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_CmdResume_Call_CF_DoSuspRes_WithGiven_msg_And_action_0 */ /* end CF_CmdResume tests */ @@ -1582,39 +1557,18 @@ void Test_CF_CmdCancel_Call_CF_CmdCond_WithNotted_CF_TsnChanAction(void) { /* Arrange */ CF_UT_cmd_transaction_buf_t utbuf; - CF_TransactionCmd_t * dummy_msg = &utbuf.xact; - CFE_SB_Buffer_t * arg_msg = &utbuf.buf; - - // TODO: CF_TsnChanAction result is default with no setup; it should be controlled, but in the essence of time this - // default value is used to show functionality of the code - /* Arrange unstubbable: CF_TsnChanAction */ - CF_TraverseAllTransactions_context_t context_CF_TraverseAllTransactions; memset(&utbuf, 0, sizeof(utbuf)); - dummy_msg->chan = Any_cf_chan_num(); - - UT_SetDataBuffer(UT_KEY(CF_TraverseAllTransactions), &context_CF_TraverseAllTransactions, - sizeof(context_CF_TraverseAllTransactions), false); + /* Nominally returns number of transactions affected, cause failure */ UT_SetDefaultReturnValue(UT_KEY(CF_TraverseAllTransactions), 0); - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.err = initial_hk_err_counter; - /* Act */ - CF_CmdCancel(arg_msg); + CF_CmdCancel(&utbuf.buf); /* Assert */ - /* Assert for CF_TsnChanAction */ UtAssert_STUB_COUNT(CF_TraverseAllTransactions, 1); - UtAssert_ADDRESS_EQ(context_CF_TraverseAllTransactions.c, CF_AppData.engine.channels + dummy_msg->chan); - UtAssert_True(context_CF_TraverseAllTransactions.fn == CF_CmdCancel_Txn, - "context_CF_TraverseAllTransactions.fn == CF_CmdCancel_Txn"); - UtAssert_ADDRESS_EQ(context_CF_TraverseAllTransactions.context, NULL); - /* Assert for CF_CmdRej */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_CmdCancel_Call_CF_CmdCond_WithNotted_CF_TsnChanAction */ /******************************************************************************* @@ -1655,39 +1609,18 @@ void Test_CF_CmdAbandon_Call_CF_CmdCond_WithNotted_CF_TsnChanAction(void) { /* Arrange */ CF_UT_cmd_transaction_buf_t utbuf; - CF_TransactionCmd_t * dummy_msg = &utbuf.xact; - CFE_SB_Buffer_t * arg_msg = &utbuf.buf; - - // TODO: CF_TsnChanAction result is default with no setup; it should be controlled, but in the essence of time this - // default value is used to show functionality of the code - /* Arrange unstubbable: CF_TsnChanAction */ - CF_TraverseAllTransactions_context_t context_CF_TraverseAllTransactions; memset(&utbuf, 0, sizeof(utbuf)); - dummy_msg->chan = Any_cf_chan_num(); - - UT_SetDataBuffer(UT_KEY(CF_TraverseAllTransactions), &context_CF_TraverseAllTransactions, - sizeof(context_CF_TraverseAllTransactions), false); + /* Nominally returns number of transactions acted on, force failure */ UT_SetDefaultReturnValue(UT_KEY(CF_TraverseAllTransactions), 0); - /* Arrange unstubbable: CF_CmdRej */ - uint16 initial_hk_err_counter = Any_uint16(); - - CF_AppData.hk.counters.err = initial_hk_err_counter; - /* Act */ - CF_CmdAbandon(arg_msg); + CF_CmdAbandon(&utbuf.buf); /* Assert */ - /* Assert for CF_TsnChanAction */ UtAssert_STUB_COUNT(CF_TraverseAllTransactions, 1); - UtAssert_ADDRESS_EQ(context_CF_TraverseAllTransactions.c, CF_AppData.engine.channels + dummy_msg->chan); - UtAssert_True(context_CF_TraverseAllTransactions.fn == CF_CmdAbandon_Txn, - "context_CF_TraverseAllTransactions.fn == CF_CmdAbandon_Txn"); - UtAssert_ADDRESS_EQ(context_CF_TraverseAllTransactions.context, NULL); - /* Assert for CF_CmdRej */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.err, 1); } /* end Test_CF_CmdAbandon_Call_CF_CmdCond_WithNotted_CF_TsnChanAction */ /******************************************************************************* @@ -3768,44 +3701,34 @@ void Test_CF_CmdGetSetParam(void) ** *******************************************************************************/ -/* TODO: Test_CF_CmdSetParam_Call_CF_CmdGetSetParam_With_cmd_key_And_cmd_value only uses 0 as key, there could be more - * tests here, but only because CF_CmdGetSetParam is unstubbable, this test mimics - * Test_CF_CmdGetSetParam_When_is_set_Is_1_And_param_id_Is_0_HasANull_fn_ThenCopy_value_To_ptr_SendEventAndAcceptCommand*/ void Test_CF_CmdSetParam_Call_CF_CmdGetSetParam_With_cmd_key_And_cmd_value(void) { /* Arrange */ CF_UT_cmd_set_param_args_buf_t utbuf; - CF_SetParamCmd_t * dummy_msg = &utbuf.sp; - CFE_SB_Buffer_t * arg_msg = &utbuf.buf; - - /* Arrange unstubbable: CF_CmdGetSetParam */ - CF_ConfigTable_t dummy_config_table; + CF_ConfigTable_t dummy_config_table; + uint16 event = 0; memset(&utbuf, 0, sizeof(utbuf)); memset(&dummy_config_table, 0, sizeof(dummy_config_table)); - dummy_msg->key = 0; - dummy_msg->value = Any_uint32(); - dummy_msg->chan_num = 0; + utbuf.sp.key = CF_GetSet_ValueID_ticks_per_second; + utbuf.sp.value = 1; + utbuf.sp.chan_num = 0; CF_AppData.config_table = &dummy_config_table; - UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); - - /* Arrange unstubbable: CF_CmdAcc */ - uint16 initial_hk_cmd_counter = Any_uint16(); - - CF_AppData.hk.counters.cmd = initial_hk_cmd_counter; + /* Set up to capture event id */ + UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), &event, sizeof(event), false); /* Act */ - CF_CmdSetParam(arg_msg); + CF_CmdSetParam(&utbuf.buf); /* Assert */ - UtAssert_UINT32_EQ(CF_AppData.config_table->ticks_per_second, dummy_msg->value); + UtAssert_UINT32_EQ(CF_AppData.config_table->ticks_per_second, utbuf.sp.value); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UT_CF_AssertEventID(CF_EID_INF_CMD_GETSET1); + UtAssert_UINT32_EQ(event, CF_EID_INF_CMD_GETSET1); /* Assert for CF_CmdAcc() */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1); } /* end Test_CF_CmdSetParam_Call_CF_CmdGetSetParam_With_cmd_key_And_cmd_value */ @@ -3817,44 +3740,33 @@ void Test_CF_CmdSetParam_Call_CF_CmdGetSetParam_With_cmd_key_And_cmd_value(void) ** *******************************************************************************/ -/* TODO: Test_CF_CmdGetParam_Call_CF_CmdGetSetParam_With_cmd_data_byte_0_And_0 only uses 0 as key, there could be more - * tests here, but only because CF_CmdGetSetParam is unstubbable, this test mimics - * Test_CF_CmdGetSetParam_When_is_set_Is_0_And_param_id_Is_0_MemCopySendEventAndAcceptCommand*/ void Test_CF_CmdGetParam_Call_CF_CmdGetSetParam_With_cmd_data_byte_0_AndConstantValue_0(void) { /* Arrange */ CF_UT_cmd_get_param_args_buf_t utbuf; - CF_GetParamCmd_t * dummy_msg = &utbuf.gp; - CFE_SB_Buffer_t * arg_msg = &utbuf.buf; + CF_ConfigTable_t config_table; + uint16 event; memset(&utbuf, 0, sizeof(utbuf)); + memset(&config_table, 0, sizeof(config_table)); - dummy_msg->key = 0; - dummy_msg->chan_num = Any_cf_chan_num(); - - /* Arrange unstubbable: CF_CmdGetSetParam */ - CF_ConfigTable_t dummy_config_table; - - CF_AppData.config_table = &dummy_config_table; - - UT_CF_ResetEventCapture(UT_KEY(CFE_EVS_SendEvent)); + utbuf.gp.key = CF_GetSet_ValueID_ticks_per_second; + utbuf.gp.chan_num = 0; - /* Arrange unstubbable: CF_CmdAcc */ - uint16 initial_hk_cmd_counter = Any_uint16(); + CF_AppData.config_table = &config_table; - CF_AppData.hk.counters.cmd = initial_hk_cmd_counter; + /* Set up to capture event id */ + UT_SetDataBuffer(UT_KEY(CFE_EVS_SendEvent), &event, sizeof(event), false); /* Act */ - CF_CmdGetParam(arg_msg); + CF_CmdGetParam(&utbuf.buf); /* Assert */ - /* Assert for CF_CmdGetSetParam */ - /* TODO: CANNOT test memcpy because copies it to a local value (the arg value, but it was not passed by ref) and - * then only used in the SendEvent function which does not track that value as of the writing of this comment. */ + /* Note actual value not tested, just flow */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UT_CF_AssertEventID(CF_EID_INF_CMD_GETSET2); + UtAssert_UINT32_EQ(event, CF_EID_INF_CMD_GETSET2); /* Assert for CF_CmdAcc() */ - UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.counters.cmd, 1); } /* end Test_CF_CmdGetParam_Call_CF_CmdGetSetParam_With_cmd_data_byte_0_AndConstantValue_0 */ @@ -4135,14 +4047,11 @@ void Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x00_AndCall_CF_CmdNoop_With_m } /* end Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x00_AndCall_CF_CmdNoop_With_msg */ -/* TODO: Not sure if it is even possible to have a NULL get to this check, but -** Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x0C_AndDoNothingBecause_fns_12_Is_NULL is forcing it -** to happen. The reason is, I'm not sure CFE_SB_GetTotalMsgLength can ever actually return 0. */ +/* Hit a NULL entry to exercise that conditional and no action */ void Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x0C_AndDoNothingBecause_fns_12_Is_NULL(void) { /* Arrange */ CFE_SB_Buffer_t utbuf; - CFE_SB_Buffer_t * arg_msg = &utbuf; CFE_MSG_FcnCode_t forced_return_CFE_MSG_GetFcnCode = 0x0C; /* 0x0C forces a null slot */ CFE_MSG_Size_t forced_return_CFE_MSG_GetSize = 0; @@ -4153,11 +4062,8 @@ void Test_CF_ProcessGroundCommand_ReceivesCmdCode_0x0C_AndDoNothingBecause_fns_1 UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_return_CFE_MSG_GetSize, sizeof(forced_return_CFE_MSG_GetSize), false); - /* Arrange unstubbable: CF_CmdAcc, CF_CmdRej */ /* technically these are NOT called, but makes sense when looking at - other tests for CF_ProcessGroundCommand */ - /* Act */ - CF_ProcessGroundCommand(arg_msg); + CF_ProcessGroundCommand(&utbuf); /* Assert */ UtAssert_STUB_COUNT(CFE_MSG_GetFcnCode, 1); diff --git a/unit-test/cf_utils_tests.c b/unit-test/cf_utils_tests.c index ddc0b987..bb740f41 100644 --- a/unit-test/cf_utils_tests.c +++ b/unit-test/cf_utils_tests.c @@ -399,9 +399,8 @@ void Test_cf_move_transaction_Call_CF_CList_InsertBack_AndSet_q_index_ToGiven_q( expected_insert_back_head = &CF_AppData.engine.channels[arg_t->chan_num].qs[arg_q]; expected_insert_back_node = &arg_t->cl_node; - /* after here must have chan_num set */ - CF_AppData.hk.channel_hk[arg_t->chan_num].q_size[arg_t->flags.com.q_index] = - Any_uint8_LessThanCeilingExcept(CF_QueueIdx_NUM + 1, 0); + /* Queue size needes to be >= 1 */ + CF_AppData.hk.channel_hk[arg_t->chan_num].q_size[arg_t->flags.com.q_index] = 1; /* Act */ CF_MoveTransaction(arg_t, arg_q); diff --git a/unit-test/utilities/cf_test_utils.c b/unit-test/utilities/cf_test_utils.c index 5118df46..03647584 100644 --- a/unit-test/utilities/cf_test_utils.c +++ b/unit-test/utilities/cf_test_utils.c @@ -165,20 +165,6 @@ char Any_char(void) return (char)Any_uint8(); } -char Any_char_Except(char exception) -{ - char random_value = exception; - - /* TODO: Technically while (random_value == exception) could last forever, it won't */ - while (random_value == exception) - { - - random_value = (char)Any_uint8(); - } - - return random_value; -} - unsigned int Any_unsigned_int(void) { int random_val = rand(); @@ -186,7 +172,7 @@ unsigned int Any_unsigned_int(void) return random_val; } -// TODO: AnyBufferOf_uint8_WithSize works, but name/design could use overhaul +// AnyBufferOf_uint8_WithSize works, but name/design could use overhaul // should it return a pointer? or should it be named different because it alters // the buffer given? void AnyBufferOf_uint8_WithSize(uint8 *buffer, size_t size) @@ -295,19 +281,6 @@ uint8 Any_uint8_LessThan(uint8 ceiling) return random_val; } -uint8 Any_uint8_LessThanCeilingExcept(uint8 ceiling, uint8 exception) -{ - uint8 random_val = exception; - - /* TODO: technically could loop forever here */ - while (random_val == exception) - { - random_val = Any_uint8_LessThan(ceiling); - } - - return random_val; -} - uint8 Any_uint8_GreaterThan(uint8 floor) { uint8 random_val; @@ -338,30 +311,6 @@ uint8 Any_uint8_Except(uint8 exception) return random_val; } -uint8 Any_uint8_ExceptThese(uint8 exceptions[], uint8 num_exceptions) -{ - uint8 i = 0; - uint8 random_val = Any_uint8(); - - while (i != num_exceptions) - { - /* TODO: technically this could go forever so it SHOULD have some - ** sort of stop mechanism, but practically speaking this will - ** never really happen - so it is not that important for test code */ - if (random_val == exceptions[i]) - { - random_val = Any_uint8(); - i = 0; - } - else - { - ++i; - } - } - - return random_val; -} - uint16 Any_uint16(void) { return (uint16)Any_unsigned_int(); @@ -386,31 +335,6 @@ uint16 Any_uint16_Except(uint16 exception) return random_val; } -uint16 Any_uint16_ExceptThese(uint16 exceptions[], uint8 num_exceptions) -{ - uint8 i = 0; - uint16 random_val = Any_uint16(); - - i = 0; - while (i != num_exceptions) - { - /* TODO: technically this could go forever so it SHOULD have some - ** sort of stop mechanism, but practically speaking this will - ** never really happen - so it is not that important for test code */ - if (random_val == exceptions[i]) - { - random_val = Any_uint16(); - i = 0; - } - else - { - ++i; - } - } - - return random_val; -} - uint16 Any_uint16_GreaterThan(uint16 floor) { uint16 random_val; @@ -420,7 +344,6 @@ uint16 Any_uint16_GreaterThan(uint16 floor) return random_val; } -/* TODO: Any_uint16_LessThan cannot accept 0 */ uint16 Any_uint16_LessThan(uint16 ceiling) { return rand() % ceiling; @@ -480,30 +403,6 @@ int32 Any_int32_LessThan(int32 ceiling) return random_val; } -uint32 Any_uint32_ExceptThese(uint32 exceptions[], uint8 num_exceptions) -{ - uint8 i = 0; - uint32 random_val = Any_uint32(); - - while (i != num_exceptions) - { - /* TODO: technically this could go forever so it SHOULD have some - ** sort of stop mechanism, but practically speaking this will - ** never realy happen - so it is not that important for test code */ - if (random_val == exceptions[i]) - { - random_val = Any_uint32(); - i = 0; - } - else - { - ++i; - } - } - - return random_val; -} - uint32 Any_uint32_GreaterThan(uint32 floor) { uint32 random_val; @@ -620,30 +519,6 @@ int32 Any_int32_Except(int32 exception) return (int32)Any_int_Except(exception); } -int32 Any_int32_ExceptThese(int32 exceptions[], uint8 num_exceptions) -{ - uint8 i = 0; - int32 random_val = Any_int32(); - - while (i != num_exceptions) - { - /* TODO: technically this could go forever so it SHOULD have some - ** sort of stop mechanism, but practically speaking this will - ** never realy happen - so it is not that important for test code */ - if (random_val == exceptions[i]) - { - random_val = Any_int32(); - i = 0; - } - else - { - ++i; - } - } - - return random_val; -} - int32 Any_int32_Negative(void) { return Any_int_Negative(); @@ -765,47 +640,6 @@ CFE_Status_t Any_CFE_Status_t_Except(CFE_Status_t exception) return rand_val; } -CFE_MSG_Size_t Any_CFE_MSG_Size_t() -{ - CFE_MSG_Size_t rand_val; - /* TODO: development machine uses 64 bit size_t */ - switch (sizeof(CFE_MSG_Size_t)) - { - case 8: - rand_val = (CFE_MSG_Size_t)Any_uint64(); - break; - case 4: - rand_val = (CFE_MSG_Size_t)Any_uint32(); - break; - default: - /* size_t is guaranteed to be at least 16 bit? */ - rand_val = (CFE_MSG_Size_t)Any_uint16(); - } - - return rand_val; -} - -CFE_MSG_Size_t Any_CFE_MSG_Size_t_LessThan(size_t ceiling) -{ - CFE_MSG_Size_t rand_val = UT_INT_16_DEFAULT; /* switch(sizeof(CFE_MSG_Size_t)) statements will ensure this value is - never used, but this removes the build warning */ - /* TODO: development machine uses 64 bit size_t */ - switch (sizeof(CFE_MSG_Size_t)) - { - case 8: - UtAssert_Abort("Implementation of Any_uint64_LessThan pending"); - break; - case 4: - rand_val = (CFE_MSG_Size_t)Any_uint32_LessThan(ceiling); - break; - default: - /* size_t is guaranteed to be at least 16 bit? */ - rand_val = (CFE_MSG_Size_t)Any_uint16_LessThan(ceiling); - } - - return rand_val; -} - /* cf specific */ uint8 Any_cf_chan_num(void) { diff --git a/unit-test/utilities/cf_test_utils.h b/unit-test/utilities/cf_test_utils.h index 2e6e3bf2..6ed361bb 100644 --- a/unit-test/utilities/cf_test_utils.h +++ b/unit-test/utilities/cf_test_utils.h @@ -146,7 +146,6 @@ typedef struct CF_Channel_t * c; CF_TraverseAllTransactions_fn_t fn; void * context; - /* TODO: add forced return? Stub is kinda using it but not from context */ } CF_TraverseAllTransactions_context_t; typedef struct @@ -233,7 +232,6 @@ unsigned int AnyCoinFlip(void); bool Any_bool(void); void AnyBufferOf_uint8_WithSize(uint8 *buffer, size_t size); char Any_char(void); -char Any_char_Except(char exception); uint8 Any_0_or_1(void); uint8 Any_uint8(void); uint8 Any_uint8_BetweenExcludeMax(uint8 floor, uint8 ceiling); @@ -242,28 +240,23 @@ uint8 Any_uint8_ExceptSetBits(uint8 mask); uint8 Any_uint8_ExceptUnsetBits(uint8 mask); uint8 Any_uint8_FromThese(uint8 values[], uint8 num_values); uint8 Any_uint8_LessThan(uint8 ceiling); -uint8 Any_uint8_LessThanCeilingExcept(uint8 ceiling, uint8 exception); uint8 Any_uint8_GreaterThan(uint8 floor); uint8 Any_uint8_GreaterThan_or_EqualTo(uint8 floor); uint8 Any_uint8_Except(uint8 exception); -uint8 Any_uint8_ExceptThese(uint8 exceptions[], uint8 num_exceptions); uint16 Any_uint16(void); uint16 Any_uint16_BetweenExcludeMax(uint16 floor, uint16 ceiling); uint16 Any_uint16_Except(uint16 exception); -uint16 Any_uint16_ExceptThese(uint16 exceptions[], uint8 num_exceptions); uint16 Any_uint16_GreaterThan(uint16 floor); uint16 Any_uint16_LessThan(uint16 ceiling); uint32 Any_uint32(void); uint32 Any_uint32_BetweenInclusive(uint32 min, uint32 max); uint32 Any_uint32_BetweenExcludeMax(uint32 min, uint32 max); uint32 Any_uint32_Except(uint32 exception); -uint32 Any_uint32_ExceptThese(uint32 exceptions[], uint8 num_exceptions); uint32 Any_uint32_GreaterThan(uint32 floor); uint32 Any_uint32_LessThan(uint32 ceiling); uint32 Any_uint32_LessThan_or_EqualTo(uint32 max); int32 Any_int32(void); int32 Any_int32_Except(int32 exception); -int32 Any_int32_ExceptThese(int32 exceptions[], uint8 num_exceptions); int32 Any_int32_LessThan(int32 ceiling); int32 Any_int32_Negative(void); int32 Any_int32_ZeroOrPositive(void); @@ -284,10 +277,8 @@ void AnyRandomStringOfLettersOfLengthCopy(char *random_string, size_t le uint8 Any_cf_chan_num(void); -void Any_CFE_TIME_SysTime_Set(CFE_TIME_SysTime_t *fake_time); -CFE_Status_t Any_CFE_Status_t_Negative(void); -CFE_Status_t Any_CFE_Status_t_Except(CFE_Status_t exception); -CFE_MSG_Size_t Any_CFE_MSG_Size_t(void); -CFE_MSG_Size_t Any_CFE_MSG_Size_t_LessThan(size_t ceiling); +void Any_CFE_TIME_SysTime_Set(CFE_TIME_SysTime_t *fake_time); +CFE_Status_t Any_CFE_Status_t_Negative(void); +CFE_Status_t Any_CFE_Status_t_Except(CFE_Status_t exception); #endif From b6ab9559bf7b562bbfaa65038605246706691964 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Thu, 16 Jun 2022 08:22:22 -0600 Subject: [PATCH 3/6] Fix #215, Improve unit test coverage and simplify tests --- unit-test/cf_app_tests.c | 116 ++---- unit-test/cf_cfdp_s_tests.c | 9 + unit-test/cf_cfdp_tests.c | 14 +- unit-test/cf_chunk_tests.c | 316 --------------- unit-test/cf_clist_tests.c | 789 +++++------------------------------- unit-test/cf_cmd_tests.c | 12 - unit-test/cf_timer_tests.c | 14 +- unit-test/cf_utils_tests.c | 139 ------- 8 files changed, 160 insertions(+), 1249 deletions(-) diff --git a/unit-test/cf_app_tests.c b/unit-test/cf_app_tests.c index ab76a808..a41f0418 100644 --- a/unit-test/cf_app_tests.c +++ b/unit-test/cf_app_tests.c @@ -630,94 +630,70 @@ void Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_s } /* end Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_status_To_CFE_ES_RunStatus_APP_ERROR */ -void Test_CF_AppMain_CallTo_CFE_ES_RunLoop_Returns_false_AppExit(void) +void Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases(void) { - /* Arrange */ - UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); - - /* Act */ - CF_AppMain(); - - /* Assert */ - UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 2); - UtAssert_STUB_COUNT(CFE_ES_RunLoop, 1); - UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1); - /* Assert for CF_Init call */ - UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); -} /* end Test_CF_AppMain_CallTo_CFE_ES_RunLoop_Returns_false_AppExit */ + CFE_SB_Buffer_t sbbuf; + CFE_SB_Buffer_t *sbbufptr = NULL; + uint16 events[2] = {0}; -void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_ReturnsNot_CFE_SUCCESS_AndNot_CFE_SB_TIME_OUT_SendEvent(void) -{ - /* Arrange */ - 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); - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), -1); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, -1); /* Act */ - CF_AppMain(); + UtAssert_VOIDCALL(CF_AppMain()); /* Assert */ UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 4); UtAssert_STUB_COUNT(CFE_ES_RunLoop, 2); UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1); - /* Assert for CF_Init call and CF_AppMain */ - UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); -} /* end Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_ReturnsNot_CFE_SUCCESS_AndNot_CFE_SB_TIME_OUT_SendEvent */ -void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_And_msg_Is_NULL_SendEvent(void) -{ - /* Arrange */ - CFE_SB_Buffer_t *sbbufptr = NULL; - - UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); - UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); + /* 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); - /* Unit under test does not use the buffer in this case */ + /* 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_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &sbbufptr, sizeof(sbbufptr), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); - /* Act */ - CF_AppMain(); + UtAssert_VOIDCALL(CF_AppMain()); - /* Assert */ - UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 4); - UtAssert_STUB_COUNT(CFE_ES_RunLoop, 2); - UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1); - /* Assert for CF_Init call and CF_AppMain */ + /* Event from CF_Init and CF_AppMain */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); -} /* end Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_And_msg_Is_NULL_SendEvent */ - -void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SB_TIME_OUT_And_msg_Is_NULL_DoNothingDuringLoop( - void) -{ - /* Arrange */ - CFE_SB_Buffer_t *dummy_BufPtr = NULL; - + UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT); + UtAssert_UINT32_EQ(events[1], CF_EID_ERR_INIT_MSG_RECV); + + /* Reset, return non-error codes and non-NULL buffer */ + UT_ResetState(UT_KEY(CFE_EVS_SendEvent)); + 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); - UT_SetDefaultReturnValue(UT_KEY(CFE_ES_RunLoop), false); - - /* Unit under test does not use the buffer in this case */ - UT_SetDataBuffer(UT_KEY(CFE_SB_ReceiveBuffer), &dummy_BufPtr, sizeof(dummy_BufPtr), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SB_TIME_OUT); + UT_SetDeferredRetcode(UT_KEY(CFE_SB_ReceiveBuffer), 1, CFE_SB_NO_MESSAGE); - UT_SetHandlerFunction(UT_KEY(CFE_SB_ReceiveBuffer), UT_UpdatedDefaultHandler_CFE_SB_ReceiveBuffer, NULL); - UT_SetDefaultReturnValue(UT_KEY(CFE_SB_ReceiveBuffer), CFE_SB_TIME_OUT); + UtAssert_VOIDCALL(CF_AppMain()); - /* Act */ - CF_AppMain(); - - /* Assert */ - UtAssert_STUB_COUNT(CFE_ES_PerfLogAdd, 4); - UtAssert_STUB_COUNT(CFE_ES_RunLoop, 2); - UtAssert_STUB_COUNT(CFE_ES_ExitApp, 1); - /* Assert for CF_Init call, but CF_AppMain did not send event */ + /* Event from CF_Init */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); -} /* end Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SB_TIME_OUT_And_msg_Is_NULL_DoNothingDuringLoop - */ + UtAssert_UINT32_EQ(events[0], CF_EID_INF_INIT); + UtAssert_STUB_COUNT(CFE_ES_RunLoop, 3); +} void Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg(void) { @@ -862,20 +838,8 @@ void add_CF_AppMain_tests(void) cf_app_tests_Setup, CF_App_Tests_Teardown, "Test_CF_AppMain_CallTo_CF_Init_DoNotReturn_CFE_SUCCESS_Set_CF_AppData_run_status_To_CFE_ES_RunStatus_APP_" "ERROR"); - UtTest_Add(Test_CF_AppMain_CallTo_CFE_ES_RunLoop_Returns_false_AppExit, cf_app_tests_Setup, CF_App_Tests_Teardown, - "Test_CF_AppMain_CallTo_CFE_ES_RunLoop_Returns_false_AppExit"); - UtTest_Add( - Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_ReturnsNot_CFE_SUCCESS_AndNot_CFE_SB_TIME_OUT_SendEvent, - cf_app_tests_Setup, CF_App_Tests_Teardown, - "Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_ReturnsNot_CFE_SUCCESS_AndNot_CFE_SB_TIME_OUT_SendEvent"); - UtTest_Add(Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_And_msg_Is_NULL_SendEvent, - cf_app_tests_Setup, CF_App_Tests_Teardown, - "Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_And_msg_Is_NULL_SendEvent"); - UtTest_Add( - Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SB_TIME_OUT_And_msg_Is_NULL_DoNothingDuringLoop, - cf_app_tests_Setup, CF_App_Tests_Teardown, - "Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SB_TIME_OUT_And_msg_Is_NULL_" - "DoNothingDuringLoop"); + UtTest_Add(Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases, cf_app_tests_Setup, CF_App_Tests_Teardown, + "Test_CF_AppMain_CFE_SB_ReceiveBuffer_Cases"); UtTest_Add( Test_CF_AppMain_RunLoopCallTo_CFE_SB_ReceiveBuffer_Returns_CFE_SUCCESS_AndValid_msg_Call_CF_ProcessMsg, cf_app_tests_Setup, CF_App_Tests_Teardown, diff --git a/unit-test/cf_cfdp_s_tests.c b/unit-test/cf_cfdp_s_tests.c index 1954e8c0..7cd65b2f 100644 --- a/unit-test/cf_cfdp_s_tests.c +++ b/unit-test/cf_cfdp_s_tests.c @@ -611,6 +611,15 @@ void Test_CF_CFDP_S_CheckAndRespondNak(void) UT_SetHandlerFunction(UT_KEY(CF_ChunkList_GetFirstChunk), UT_AltHandler_GenericPointerReturn, &ut_chunk); UT_SetDeferredRetcode(UT_KEY(CF_WrappedRead), 1, -1); UtAssert_INT32_EQ(CF_CFDP_S_CheckAndRespondNak(t), -1); + + /* with chunklist but CF_CFDP_S_SendFileData returning 0 (nothing to send) */ + UT_CFDP_S_SetupBasicTestState(UT_CF_Setup_TX, NULL, NULL, NULL, &t, &config); + config->outgoing_file_chunk_size = CF_MAX_PDU_SIZE; + t->fsize = ut_chunk.size; + t->chunks = &chunks; + UT_SetHandlerFunction(UT_KEY(CF_ChunkList_GetFirstChunk), UT_AltHandler_GenericPointerReturn, &ut_chunk); + UT_ResetState(UT_KEY(CF_CFDP_ConstructPduHeader)); /* Returns NULL by default */ + UtAssert_INT32_EQ(CF_CFDP_S_CheckAndRespondNak(t), 0); } void Test_CF_CFDP_S2_SubstateSendFileData(void) diff --git a/unit-test/cf_cfdp_tests.c b/unit-test/cf_cfdp_tests.c index 5647213d..def13214 100644 --- a/unit-test/cf_cfdp_tests.c +++ b/unit-test/cf_cfdp_tests.c @@ -614,16 +614,16 @@ void Test_CF_CFDP_SendMd(void) UtAssert_STRINGBUF_EQ(md->source_filename.data_ptr, md->source_filename.length, h->fnames.src_filename, sizeof(h->fnames.src_filename)); + /* Class 2, also hit maximum string length */ UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, &ph, NULL, &h, &t, NULL); md = &ph->int_header.md; - strncpy(h->fnames.dst_filename, "dst2", sizeof(h->fnames.dst_filename)); + memset(h->fnames.dst_filename, 0xFF, sizeof(h->fnames.dst_filename)); strncpy(h->fnames.src_filename, "src2", sizeof(h->fnames.src_filename)); t->state = CF_TxnState_S2; t->fsize = 5678; UtAssert_INT32_EQ(CF_CFDP_SendMd(t), CF_SendRet_SUCCESS); UtAssert_UINT32_EQ(md->size, t->fsize); - UtAssert_STRINGBUF_EQ(md->dest_filename.data_ptr, md->dest_filename.length, h->fnames.dst_filename, - sizeof(h->fnames.dst_filename)); + UtAssert_UINT32_EQ(md->dest_filename.length, sizeof(h->fnames.dst_filename)); UtAssert_STRINGBUF_EQ(md->source_filename.data_ptr, md->source_filename.length, h->fnames.src_filename, sizeof(h->fnames.src_filename)); } @@ -638,6 +638,14 @@ void Test_CF_CFDP_SendFd(void) UT_CFDP_SetupBasicTestState(UT_CF_Setup_TX, &ph, NULL, NULL, &t, NULL); UtAssert_INT32_EQ(CF_CFDP_SendFd(t, ph), CF_SendRet_SUCCESS); + + /* Hit CF_CFDP_SetPduLength condition where final_pos < the header_encoded_length */ + ph->pdu_header.header_encoded_length = CF_CODEC_GET_POSITION(ph->penc) + 1; + ph->pdu_header.data_encoded_length = 0; + + UtAssert_INT32_EQ(CF_CFDP_SendFd(t, ph), CF_SendRet_SUCCESS); + + UtAssert_UINT32_EQ(ph->pdu_header.data_encoded_length, 0); } void Test_CF_CFDP_SendEof(void) diff --git a/unit-test/cf_chunk_tests.c b/unit-test/cf_chunk_tests.c index dd0ab92b..acc273ef 100644 --- a/unit-test/cf_chunk_tests.c +++ b/unit-test/cf_chunk_tests.c @@ -100,40 +100,6 @@ void Test_MAX_WhenItIsEqualTo_b_Returns_a(void) ** *******************************************************************************/ -/* NOTE: memmove could be stubbed, but proving problematic. - * CF_Chunks_EraseRange tests will use the memmove call for now */ - -void Test_CF_Chunks_EraseRange_AssertsBecause_end_IsLessThan_start(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_start = Any_uint32_Except(UINT32_MAX); - // CF_ChunkIdx_t arg_end = Any_uint32_LessThan(arg_start); - - // /* Act */ - // CF_Chunks_EraseRange(&Test_chunks, Test_start, Test_end); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - end>=start"); -} /* end Test_CF_Chunks_EraseRange_AssertsBecause_end_IsLessThan_start */ - -/* NOTE: Test_CF_Chunks_EraseRange_AssertsBecause_end_EqTo_start not required but desired */ -// void Test_CF_Chunks_EraseRange_AssertsBecause_end_EqTo_start(void) -// { -// /* Arrange */ -// CF_ChunkList_t dummy_chunks; -// CF_ChunkList_t* arg_chunks = &dummy_chunks; -// CF_ChunkIdx_t arg_start = Any_uint32_Except(UINT32_MAX); -// CF_ChunkIdx_t arg_end = arg_start; - -// /* Act */ -// //CF_Chunks_EraseRange(&Test_chunks, Test_start, Test_end); - -// /* Assert */ -// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - end>=start"); -// } /* end Test_CF_Chunks_EraseRange_AssertsBecause_end_EqTo_start */ - void Test_CF_Chunks_When_start_Is_OneMoreThan_end_MovesOneChunk_EraseRange(void) { /* Arrange */ @@ -200,43 +166,6 @@ void Test_CF_Chunks_When_start_IsLessThan_chunks_count_DoesNotChangeStart_EraseR ** *******************************************************************************/ -/* NOTE: memmove could be stubbed, but proving problematic. - * CF_Chunks_EraseChunk tests will use the memmove call for now */ - -void Test_CF_Chunks_EraseChunk_AssertsBecause_Given_chunks_count_IsEqTo_0(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_erase_index = Any_index_t(); - - // arg_chunks->count = 0; - - // /* Act */ - // CF_Chunks_EraseChunk(arg_chunks, arg_erase_index); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_EraseChunk_AssertsBecause_Given_chunks_count_IsEqTo_0 */ - -void Test_CF_Chunks_EraseChunk_AssertsBecause_Given_erase_index_IsEqTo_chunks_count(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_erase_index; - - // arg_chunks->count = 1; - - // arg_erase_index = 2; - - // /* Act */ - // CF_Chunks_EraseChunk(arg_chunks, arg_erase_index); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_EraseChunk_AssertsBecause_Given_erase_index_IsEqTo_chunks_count */ - void Test_CF_Chunks_EraseChunk_WhenThereIsOnlyOneEraseOneChunkAndDecrement_count_To_0(void) { /* Arrange */ @@ -595,47 +524,6 @@ void Test_CF_Chunks_FindInsertPosition_Given_chunks_HasAnyItemsAndReturnCorrectE ** *******************************************************************************/ -void Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsEqTo_chunks_CF_max_Chunks(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_i; - // CF_Chunk_t dummy_chunk = {0}; - // CF_Chunk_t* arg_chunk = &dummy_chunk; - // CF_ChunkIdx_t local_result; - - // arg_chunks->max_chunks = Any_uint32_Except(0); - // arg_i = arg_chunks->max_chunks; - - // /* Act */ - // local_result = CF_Chunks_CombinePrevious(arg_chunks, arg_i, arg_chunk); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsEqTo_chunks_CF_max_Chunks */ - -/* NOTE: Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsGreaterThan_chunks_CF_max_Chunks not required but desired */ -// void Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsGreaterThan_chunks_CF_max_Chunks(void) -// { -// /* Arrange */ -// CF_ChunkList_t dummy_chunks; -// CF_ChunkList_t* arg_chunks = &dummy_chunks; -// CF_ChunkIdx_t arg_i; -// CF_Chunk_t dummy_chunk = {0}; -// CF_Chunk_t* arg_chunk = &dummy_chunk; -// CF_ChunkIdx_t local_result; - -// arg_chunks->max_chunks = Any_uint32_Except(0); -// arg_i = Any_uint32_GreaterThan(arg_chunks->max_chunks); - -// /* Act */ -// //local_result = CF_Chunks_CombinePrevious(arg_chunks, arg_i, arg_chunk); - -// /* Assert */ -// UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -// } /* end Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsGreaterThan_chunks_CF_max_Chunks */ - void Test_CF_Chunks_CombinePrevious_Given_i_Is_0_Return_0(void) { /* Arrange */ @@ -903,30 +791,6 @@ void Test_CF_Chunks_CombineNext_Given_i_IsEqTo_Given_chunks_count_Return_0(void) UtAssert_UINT32_EQ(local_result, 0); } /* end Test_CF_Chunks_CombineNext_Given_i_IsEqTo_Given_chunks_count_Return_0 */ -void Test_CF_Chunks_CombineNext_Given_i_IsNotEqTo_Given_chunks_count_AssertsBecauseGiven_chunk_end_LessThanGiven_chunk_offset( - void) -{ - // /* Arrange */ - // CF_Chunk_t dummy_chunks_chunks = {0}; - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_i; - // CF_Chunk_t dummy_chunk = {0}; - // CF_Chunk_t* arg_chunk = &dummy_chunk; - // int local_result = Any_int_Except(0); - - // arg_chunks->count = Any_uint32(); - // arg_i = Any_uint32_Except(arg_chunks->count); - - // /* Act */ - // local_result = CF_Chunks_CombineNext(arg_chunks, arg_i, arg_chunk); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end - Test_CF_Chunks_CombineNext_Given_i_IsNotEqTo_Given_chunks_count_AssertsBecauseGiven_chunk_end_LessThanGiven_chunk_offset - */ - void Test_CF_Chunks_CombineNext_Given_i_IsNotEqTo_Given_chunks_count_Given_chunks_chunks_i_offset_IsGreaterThan_chunk_end_Return_0( void) { @@ -1366,81 +1230,6 @@ void Test_CF_Chunks_Insert_CallTo_CF_Chunks_CombineNext_Returns_0_CallTo_CF_Chun ** CF_ChunkListAdd tests ** *******************************************************************************/ -void Test_CF_Chunks_Add_Asserts_WhenGiven_offset_Plus_size_IsLessThanGiven_offset(void) -{ - // /* Arrange */ - // CF_ChunkOffset_t arg_offset = UINT32_MAX; - // CF_ChunkSize_t arg_size = 1; - // CF_Chunk_t initial_chunks[20] = { {0} }; /* 20 used as a reasonably fast size for the test, but is - // still illustrative */ CF_ChunkList_t dummy_chunks; CF_ChunkList_t* arg_chunks = &dummy_chunks; - - // /* Arrange for CF_Chunks_FindInsertPosition */ - // CF_Chunk_t dummy_chunk = {0}; - // uint8 num_chunks_before = Any_uint8_LessThan(10); - // uint8 num_chunks_after = Any_uint8_LessThan(10); - // uint8 i = 0; - - // dummy_chunk.offset = Any_uint32_BetweenInclusive(1, UINT32_MAX - 1); - - // for(i = 0; i < num_chunks_before; ++i) - // { - // initial_chunks[i].offset = Any_uint32_LessThan(dummy_chunk.offset); - // } - - // for(i = 0; i < num_chunks_after; ++i) - // { - // initial_chunks[i + num_chunks_before].offset = Any_uint32_GreaterThan(dummy_chunk.offset); - // } - - // arg_chunks->count = num_chunks_before + num_chunks_after; - // arg_chunks->chunks = initial_chunks; - - // /* Act */ - // CF_ChunkListAdd(arg_chunks, arg_offset, arg_size); - - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_Add_Asserts_WhenGiven_offset_Plus_size_IsLessThanGiven_offset */ - -void Test_CF_Chunks_Add_Asserts_WhenInsertPositionIsNotEqualToGiven_chunks_count_And_chunk_offset_IsNotLessThanOrEqToGiven_chunks_i_offset( - void) -{ - // /* Arrange */ - // CF_ChunkOffset_t arg_offset = 1; - // CF_ChunkSize_t arg_size = 1; - // CF_Chunk_t initial_chunks[20] = { {0} }; /* 20 used as a reasonably fast size for the test, but is - // still illustrative */ CF_ChunkList_t dummy_chunks; CF_ChunkList_t* arg_chunks = &dummy_chunks; - - // /* Arrange for CF_Chunks_FindInsertPosition */ - // CF_Chunk_t dummy_chunk = {0}; - // uint8 num_chunks_before = Any_uint8_LessThan(10); - // uint8 num_chunks_after = Any_uint8_LessThan(10); - // uint8 i = 0; - - // dummy_chunk.offset = Any_uint32_BetweenInclusive(1, UINT32_MAX - 1); - - // for(i = 0; i < num_chunks_before; ++i) - // { - // initial_chunks[i].offset = Any_uint32_LessThan(dummy_chunk.offset); - // } - - // for(i = 0; i < num_chunks_after; ++i) - // { - // initial_chunks[i + num_chunks_before].offset = Any_uint32_GreaterThan(dummy_chunk.offset); - // } - - // arg_chunks->count = num_chunks_before + num_chunks_after; - // arg_chunks->chunks = initial_chunks; - - // /* Act */ - // /* NOTE: unsure how to set this up to hit the assert. */ - // CF_ChunkListAdd(arg_chunks, arg_offset, arg_size); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end - Test_CF_Chunks_Add_Asserts_WhenInsertPositionIsNotEqualToGiven_chunks_count_And_chunk_offset_IsNotLessThanOrEqToGiven_chunks_i_offset - */ void Test_CF_Chunks_Add_WhenNotAtEndCall_CF_Chunks_Insert(void) { @@ -1670,21 +1459,6 @@ void Test_CF_Chunks_GetFirstChunk_WhenGiven_chunks_count_Is_Any_index_t_ReturnFi ** *******************************************************************************/ -void Test_CF_Chunks_Init_AssertsBecauseGiven_max_chunks_Is_0(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_max_chunks = Any_uint16() + 2; /* 2-65537, uint16 is used instead of CF_ChunkIdx_t - // to have a reasonably decent size for the test without being too large (segfault) */ CF_Chunk_t* arg_chunks_mem; - - // /* Act */ - // CF_ChunkListInit(arg_chunks, arg_max_chunks, arg_chunks_mem); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_Init_AssertsBecauseGiven_max_chunks_Is_0 */ - void Test_CF_Chunks_Init_SetGiven_chunks_max_chunks_ToGiven_max_chunks(void) { /* Arrange */ @@ -1751,60 +1525,6 @@ void Test_CF_ChunksReset_Set_count_To_0_Keeps_max_chunks_AndMemsets_chunks_ToAll ** *******************************************************************************/ -void Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_total_Is_0(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_max_gaps = Any_uint32(); - // CF_ChunkSize_t arg_total = 0; - // CF_ChunkOffset_t arg_start = Any_uint32(); - // CF_ChunkList_ComputeGapFn_t arg_compute_gap_fn = Dummy_compute_gap_fn_t; - // void* arg_opaque = NULL; - - // /* Act */ - // CF_ChunkList_ComputeGaps(arg_chunks, arg_max_gaps, arg_total, arg_start, arg_compute_gap_fn, arg_opaque); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_total_Is_0 */ - -void Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsGreaterThanGiven_total(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_max_gaps = Any_uint32(); - // CF_ChunkSize_t arg_total = Any_uint32_Except(UINT32_MAX - 1) + 1; /* from 1 to (UINT32_MAX - 1) */ - // CF_ChunkOffset_t arg_start = Any_uint32_GreaterThan(arg_total); - // CF_ChunkList_ComputeGapFn_t arg_compute_gap_fn = Dummy_compute_gap_fn_t; - // void* arg_opaque = NULL; - - // /* Act */ - // CF_ChunkList_ComputeGaps(arg_chunks, arg_max_gaps, arg_total, arg_start, arg_compute_gap_fn, arg_opaque); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsGreaterThanGiven_total */ - -void Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsEqToGiven_total(void) -{ - // /* Arrange */ - // CF_ChunkList_t dummy_chunks; - // CF_ChunkList_t* arg_chunks = &dummy_chunks; - // CF_ChunkIdx_t arg_max_gaps = Any_uint32(); - // CF_ChunkSize_t arg_total = Any_uint32_Except(UINT32_MAX) + 1; /* from 1 to UINT32_MAX */ - // CF_ChunkOffset_t arg_start = arg_total; - // CF_ChunkList_ComputeGapFn_t arg_compute_gap_fn = Dummy_compute_gap_fn_t; - // void* arg_opaque = NULL; - - // /* Act */ - // CF_ChunkList_ComputeGaps(arg_chunks, arg_max_gaps, arg_total, arg_start, arg_compute_gap_fn, arg_opaque); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsGreaterThanGiven_total */ - void Test_CF_Chunks_ComputeGaps_Given_chunks_count_Is_0_And_compute_gap_fn_Is_NULL_And_start_IsOneLessThan_total_Return_1( void) { @@ -2138,11 +1858,6 @@ void add_macro_tests(void) void add_CF_Chunks_EraseRange_tests(void) { - UtTest_Add(Test_CF_Chunks_EraseRange_AssertsBecause_end_IsLessThan_start, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, "Test_CF_Chunks_EraseRange_AssertsBecause_end_IsLessThan_start"); - // UtTest_Add(Test_CF_Chunks_EraseRange_AssertsBecause_end_EqTo_start, - // cf_chunk_tests_Setup, cf_chunk_tests_Teardown, - // "Test_CF_Chunks_EraseRange_AssertsBecause_end_EqTo_start"); UtTest_Add(Test_CF_Chunks_When_start_Is_OneMoreThan_end_MovesOneChunk_EraseRange, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, "Test_CF_Chunks_When_start_Is_OneMoreThan_end_MovesOneChunk_EraseRange"); UtTest_Add(Test_CF_Chunks_When_start_IsLessThan_chunks_count_DoesNotChangeStart_EraseRange, cf_chunk_tests_Setup, @@ -2152,11 +1867,6 @@ void add_CF_Chunks_EraseRange_tests(void) void add_CF_Chunks_EraseChunk_tests(void) { - UtTest_Add(Test_CF_Chunks_EraseChunk_AssertsBecause_Given_chunks_count_IsEqTo_0, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, "Test_CF_Chunks_EraseChunk_AssertsBecause_Given_chunks_count_IsEqTo_0"); - UtTest_Add(Test_CF_Chunks_EraseChunk_AssertsBecause_Given_erase_index_IsEqTo_chunks_count, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, - "Test_CF_Chunks_EraseChunk_AssertsBecause_Given_erase_index_IsEqTo_chunks_count"); UtTest_Add(Test_CF_Chunks_EraseChunk_WhenThereIsOnlyOneEraseOneChunkAndDecrement_count_To_0, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, "Test_CF_Chunks_EraseChunk_WhenThereIsOnlyOneEraseOneChunkAndDecrement_count_To_0"); @@ -2194,11 +1904,6 @@ void add_CF_Chunks_FindInsertPosition_tests(void) void add_CF_Chunks_CombinePrevious_tests(void) { - UtTest_Add(Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsEqTo_chunks_CF_max_Chunks, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, "Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsEqTo_chunks_CF_max_Chunks"); - // UtTest_Add(Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsGreaterThan_chunks_CF_max_Chunks, - // cf_chunk_tests_Setup, cf_chunk_tests_Teardown, - // "Test_CF_Chunks_CombinePrevious_Asserts_i_GivenIsGreaterThan_chunks_CF_max_Chunks"); UtTest_Add(Test_CF_Chunks_CombinePrevious_Given_i_Is_0_Return_0, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, "Test_CF_Chunks_CombinePrevious_Given_i_Is_0_Return_0"); UtTest_Add(Test_CF_Chunks_CombinePrevious_Given_chunks_count_Is_0_Return_0, cf_chunk_tests_Setup, @@ -2236,11 +1941,6 @@ void add_CF_Chunks_CombineNext_tests(void) { UtTest_Add(Test_CF_Chunks_CombineNext_Given_i_IsEqTo_Given_chunks_count_Return_0, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, "Test_CF_Chunks_CombineNext_Given_i_IsEqTo_Given_chunks_count_Return_0"); - UtTest_Add( - Test_CF_Chunks_CombineNext_Given_i_IsNotEqTo_Given_chunks_count_AssertsBecauseGiven_chunk_end_LessThanGiven_chunk_offset, - cf_chunk_tests_Setup, cf_chunk_tests_Teardown, - "Test_CF_Chunks_CombineNext_Given_i_IsNotEqTo_Given_chunks_count_AssertsBecauseGiven_chunk_end_LessThanGiven_" - "chunk_offset"); UtTest_Add( Test_CF_Chunks_CombineNext_Given_i_IsNotEqTo_Given_chunks_count_Given_chunks_chunks_i_offset_IsGreaterThan_chunk_end_Return_0, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, @@ -2298,13 +1998,6 @@ void add_CF_Chunks_Insert_tests(void) void add_CF_Chunks_Add_tests(void) { - UtTest_Add(Test_CF_Chunks_Add_Asserts_WhenGiven_offset_Plus_size_IsLessThanGiven_offset, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, "Test_CF_Chunks_Add_Asserts_WhenGiven_offset_Plus_size_IsLessThanGiven_offset"); - UtTest_Add( - Test_CF_Chunks_Add_Asserts_WhenInsertPositionIsNotEqualToGiven_chunks_count_And_chunk_offset_IsNotLessThanOrEqToGiven_chunks_i_offset, - cf_chunk_tests_Setup, cf_chunk_tests_Teardown, - "Test_CF_Chunks_Add_Asserts_WhenInsertPositionIsNotEqualToGiven_chunks_count_And_chunk_offset_" - "IsNotLessThanOrEqToGiven_chunks_i_offset"); UtTest_Add(Test_CF_Chunks_Add_WhenNotAtEndCall_CF_Chunks_Insert, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, "Test_CF_Chunks_Add_WhenNotAtEndCall_CF_Chunks_Insert"); UtTest_Add(Test_CF_Chunks_Add_WhenAtEndCall_CF_Chunks_Insert, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, @@ -2343,8 +2036,6 @@ void add_CF_Chunks_GetFirstChunk_tests(void) void add_CF_Chunks_Init_tests(void) { - UtTest_Add(Test_CF_Chunks_Init_AssertsBecauseGiven_max_chunks_Is_0, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, - "Test_CF_Chunks_Init_AssertsBecauseGiven_max_chunks_Is_0"); UtTest_Add(Test_CF_Chunks_Init_SetGiven_chunks_max_chunks_ToGiven_max_chunks, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, "Test_CF_Chunks_Init_SetGiven_chunks_max_chunks_ToGiven_max_chunks"); } /* end add_CF_Chunks_Init_tests */ @@ -2358,13 +2049,6 @@ void add_CF_ChunksReset_tests(void) void add_CF_Chunks_ComputeGaps_tests(void) { - UtTest_Add(Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_total_Is_0, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, - "Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_total_Is_0"); - UtTest_Add(Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsGreaterThanGiven_total, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, - "Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsGreaterThanGiven_total"); - UtTest_Add(Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsEqToGiven_total, cf_chunk_tests_Setup, - cf_chunk_tests_Teardown, "Test_CF_Chunks_ComputeGaps_AssertsBecauseGiven_start_IsEqToGiven_total"); UtTest_Add( Test_CF_Chunks_ComputeGaps_Given_chunks_count_Is_0_And_compute_gap_fn_Is_NULL_And_start_IsOneLessThan_total_Return_1, cf_chunk_tests_Setup, cf_chunk_tests_Teardown, diff --git a/unit-test/cf_clist_tests.c b/unit-test/cf_clist_tests.c index 53bb939b..37304745 100644 --- a/unit-test/cf_clist_tests.c +++ b/unit-test/cf_clist_tests.c @@ -27,40 +27,27 @@ ** *******************************************************************************/ -typedef struct +int UT_CListFn(CF_CListNode_t *node, void *context) { - CF_CListNode_t *node; - void * context; -} Dummy_clist_fn_t_context_t; + int status = CF_CLIST_CONT; + int *param = context; -typedef struct -{ - CF_CListNode_t *node; - void * context; -} Hook_clist_fn_t_context_t; - -int Dummy_clist_fn_t(CF_CListNode_t *node, void *context) -{ - Dummy_clist_fn_t_context_t my_ctxt; - - my_ctxt.node = node; - my_ctxt.context = context; - UT_Stub_CopyFromLocal(UT_KEY(Dummy_clist_fn_t), &my_ctxt, sizeof(my_ctxt)); + /* Passing in a negative value will exit when zero is hit */ + (*param)++; + if (*param == 0) + { + status = CF_CLIST_EXIT; + } - /* UT_DEFAULT_IMPL returns uint32 */ - return (int)UT_DEFAULT_IMPL(Dummy_clist_fn_t); + return status; } -int Hook_clist_fn_t(CF_CListNode_t *node, void *context) +int UT_CListFn_Rm(CF_CListNode_t *node, void *context) { - Hook_clist_fn_t_context_t my_ctxt; - - my_ctxt.node = node; - my_ctxt.context = context; - UT_Stub_CopyFromLocal(UT_KEY(Hook_clist_fn_t), &my_ctxt, sizeof(my_ctxt)); - - /* UT_DEFAULT_IMPL returns uint32 */ - return (int)UT_DEFAULT_IMPL(Hook_clist_fn_t); + (*((int *)context))--; + node->next = node; + node->prev = node; + return CF_CLIST_CONT; } /******************************************************************************* @@ -110,38 +97,6 @@ void Test_CF_CList_InitNode_PointNodeToItselfAsNextAndPrev(void) ** *******************************************************************************/ -void Test_CF_CList_InsertFront_AssertsBecauseHeadIs_NULL(void) -{ - // /* Arrange */ - // /* Act */ - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - head"); -} /* end Test_CF_CList_InsertFront_AssertsBecauseHeadIs_NULL */ - -void Test_CF_CList_InsertFront_AssertsBecauseNodeIs_NULL(void) -{ - // /* Arrange */ - // /* Act */ - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert- node"); -} /* end Test_CF_CList_InsertFront_AssertsBecauseNodeIs_NULL */ - -void Test_CF_CList_InsertFront_AssertsBecauseNodeNextDoesNotPointToItself(void) -{ - // /* Arrange */ - // /* Act */ - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node->next==node"); -} /* end Test_CF_CList_InsertFront_AssertsBecauseNodeNextDoesNotPointToItself */ - -void Test_CF_CList_InsertFront_AssertsBecauseNodePrevDoesNotPointToItself(void) -{ - // /* Arrange */ - // /* Act */ - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node->prev==node"); -} /* end Test_CF_CList_InsertFront_AssertsBecauseNodePrevDoesNotPointToItself */ - void Test_CF_CList_InsertFront_InsertNodeIntoEmptyList(void) { /* Arrange */ @@ -297,38 +252,6 @@ void Test_CF_CList_InsertFront_WhenNodeListIsGreaterThanTwoNodesAndTheyPointToCo ** *******************************************************************************/ -void Test_CF_CList_InsertBack_AssertsBecauseHeadIs_NULL(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - head"); -} /* end Test_CF_CList_InsertBack_AssertsBecauseHeadIs_NULL */ - -void Test_CF_CList_InsertBack_AssertsBecauseNodeIs_NULL(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node"); -} /* end Test_CF_CList_InsertBack_AssertsBecauseNodeIs_NULL */ - -void Test_CF_CList_InsertBack_AssertsBecauseNodeNextDoesNotPointToItself(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node->next==node"); -} /* end Test_CF_CList_InsertBack_AssertsBecauseNodeNextDoesNotPointToItself */ - -void Test_CF_CList_InsertBack_AssertsBecauseNodePrevDoesNotPointToItself(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node->prev==node"); -} /* end Test_CF_CList_InsertBack_AssertsBecauseNodePrevDoesNotPointToItself */ - void Test_CF_CList_InsertBack_InsertNodeIntoEmptyList(void) { /* Arrange */ @@ -483,14 +406,6 @@ void Test_CF_CList_InsertBack_WhenNodeListIsGreaterThanTwoNodesAndTheyPointToCor ** *******************************************************************************/ -void Test_CF_CList_Pop_AssertsBecause_head_Is_NULL(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - head"); -} /* end Test_CF_CList_Pop_AssertsBecause_head_Is_NULL */ - void Test_CF_CList_Pop_WhenListIsEmptySuccessReturn_NULL(void) { /* Arrange */ @@ -587,46 +502,6 @@ void Test_CF_CList_Pop_WhenListIsAnySizeGreaterThanOneSuccessPopsHeadNodeAndRetu ** *******************************************************************************/ -void Test_CF_CList_Remove_AssertsBecauseHeadIs_NULL(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - head"); -} /* end Test_CF_CList_Remove_AssertsBecauseHeadIs_NULL */ - -void Test_CF_CList_Remove_AssertsBecauseNodeIs_NULL(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node"); -} /* end Test_CF_CList_Remove_AssertsBecauseNodeIs_NULL */ - -void Test_CF_CList_Remove_AssertsBecauseHeadPointedAtValueIs_NULL(void) -{ - /* Arrange */ - /* Act */ - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - *head"); -} /* end Test_CF_CList_Remove_AssertsBecauseHeadPointedAtValueIs_NULL */ - -void Test_CF_ClistRemove_AssertsBecauseHeadPointedAtValueIsNotNode(void) -{ - /* Arrange */ - CF_CListNode_t dummy_node; - CF_CListNode_t *arg_node = &dummy_node; - - arg_node->prev = arg_node; - arg_node->next = arg_node; - - /* Act */ - // CF_CList_Remove(arg_head, arg_node); - - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - node==*head"); -} /* end Test_CF_ClistRemove_AssertsBecauseHeadPointedAtValueIsNotNode */ - void Test_CF_ClistRemove_WhenOnlyNodeSetHeadTo_NULL(void) { /* Arrange */ @@ -884,38 +759,6 @@ void Test_CF_ClistRemove_RemovingAnyNodeHasNodesPrevAndNextPointToEachOther(void } /* end Test_CF_ClistRemove_RemovingAnyNodeHasNodesPrevAndNextPointToEachOther */ -void Test_CF_CList_Remove_ReceivesBad_node_Because_next_PointsTo_node_But_prev_DoesNot(void) -{ - // /* Arrange */ - // CF_CListNode_t dummy_head_node; - // CF_CListNode_t * dummy_head = &dummy_head_node; - // CF_CListNode_t ** arg_head = &dummy_head; - // CF_CListNode_t dummy_last_node; - // CF_CListNode_t * arg_node = &dummy_last_node; - - // dummy_head->prev = dummy_head; - // dummy_head->next = dummy_head; - - // /* setting bad node */ - // arg_node->prev = dummy_head; - // arg_node->next = arg_node; - - // /* Act */ - // CF_CList_Remove(arg_head, arg_node); - - // /* Assert */ - // UtAssert_ADDRESS_EQ(*arg_head, &dummy_head_node); - // UtAssert_ADDRESS_EQ(dummy_head->prev, dummy_head); - // UtAssert_ADDRESS_EQ(dummy_head->next, dummy_head); - // /* Assert for CF_CList_InitNode - note this cannot be verified because node state does not change */ - // UtAssert_ADDRESS_EQ(arg_node->prev, arg_node); - // UtAssert_ADDRESS_EQ(arg_node->next, arg_node); - UtAssert_MIR("JIRA: GSFCCFS-1719 Odd behavior - Is this desired?\n" - "A bad node is passed to CF_CList_Remove, but it carries on unaware\n" - "This was found because branch 3 of if((node->next==node)&&(node->prev==node))\n" - "can only be covered by this type of test, node->next == node, node-prev != node"); -} /* end Test_CF_CList_Remove_ReceivesBad_node_Because_next_PointsTo_node_But_prev_DoesNot */ - /* end CF_CList_Remove tests */ /******************************************************************************* @@ -924,68 +767,6 @@ void Test_CF_CList_Remove_ReceivesBad_node_Because_next_PointsTo_node_But_prev_D ** *******************************************************************************/ -void Test_CF_CList_InsertAfter_AssertsBecause_head_Is_NULL(void) -{ - /* Arrange */ - // CF_CListNode_t ** arg_head = NULL; - // CF_CListNode_t * arg_start; - // CF_CListNode_t * arg_after; - - /* Act */ - // CF_CList_InsertAfter(arg_head, arg_start, arg_after); - - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - head"); -} /* end CF_CList_InsertAfter_AssertsBecause_head_Is_NULL */ - -void Test_CF_CList_InsertAfter_AssertsBecauseValueAt_head_Is_NULL(void) -{ - /* Arrange */ - // CF_CListNode_t * dummy_head = NULL; - // CF_CListNode_t ** arg_head = &dummy_head; - // CF_CListNode_t * arg_start; - // CF_CListNode_t * arg_after; - - /* Act */ - // CF_CList_InsertAfter(arg_head, arg_start, arg_after); - - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - *head"); -} /* end Test_CF_CList_InsertAfter_AssertsBecauseValueAt_head_Is_NULL */ - -void Test_CF_CList_InsertAfter_AssertsBecause_start_Is_NULL(void) -{ - /* Arrange */ - // CF_CListNode_t dummy_head_node; - // CF_CListNode_t * dummy_head = &dummy_head_node; - // CF_CListNode_t ** arg_head = &dummy_head; - // CF_CListNode_t * arg_start = NULL; - // CF_CListNode_t * arg_after; - - /* Act */ - // CF_CList_InsertAfter(arg_head, arg_start, arg_after); - - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - start"); -} /* end Test_CF_CList_InsertAfter_AssertsBecause_start_Is_NULL */ - -void Test_CF_CList_InsertAfter_AssertsBecause_start_IsEqTo_after(void) -{ - /* Arrange */ - // CF_CListNode_t dummy_head_node; - // CF_CListNode_t * dummy_head = &dummy_head_node; - // CF_CListNode_t ** arg_head = &dummy_head; - // CF_CListNode_t dummy_start_node; - // CF_CListNode_t * arg_start = &dummy_start_node; - // CF_CListNode_t * arg_after = arg_start; - - /* Act */ - // CF_CList_InsertAfter(arg_head, arg_start, arg_after); - - /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - start!=after"); -} /* end Test_CF_CList_InsertAfter_AssertsBecause_start_Is_NULL */ - void Test_CF_CList_InsertAfter_WhenOnlyOneNodeSuccess_after_IsInsertedAfter_start(void) { /* Arrange */ @@ -1104,249 +885,44 @@ void Test_CF_CList_InsertAfter_WhenAnyNodeSuccess_after_IsInsertedAfter_start(vo ** *******************************************************************************/ -void Test_CF_CList_Traverse_When_start_Is_NULL_DoNothing(void) -{ - /* Arrange */ - CF_CListNode_t *arg_start = NULL; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - void * arg_context = NULL; - - /* Act */ - CF_CList_Traverse(arg_start, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 0); -} /* end Test_CF_CList_Traverse_When_start_Is_NULL_DoNothing */ - -void Test_CF_CList_Traverse_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails(void) -{ - /* Arrange */ - CF_CListNode_t dummy_start; - CF_CListNode_t * arg_start = &dummy_start; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t; - - arg_start->next = NULL; - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 1); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), &context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse(arg_start, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 1); - UtAssert_True(context_Dummy_clist_fn_t.node == arg_start, "context_Dummy_clist_fn_t.node == arg_start"); - UtAssert_True(context_Dummy_clist_fn_t.context == arg_context, "context_Dummy_clist_fn_t.context == arg_context"); -} /* end Test_CF_CList_Traverse_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails */ - -void Test_CF_CList_Traverse_WhenListIsOneNodeSuccess(void) -{ - /* Arrange */ - CF_CListNode_t dummy_start; - CF_CListNode_t * arg_start = &dummy_start; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t; - - arg_start->next = arg_start; - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), &context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse(arg_start, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 1); - UtAssert_True(context_Dummy_clist_fn_t.node == arg_start, "context_Dummy_clist_fn_t.node == arg_start"); - UtAssert_True(context_Dummy_clist_fn_t.context == arg_context, "context_Dummy_clist_fn_t.context == arg_context"); -} /* end Test_CF_CList_Traverse_WhenListIsOneNodeSuccess */ - -/* NOTE: Test_CF_CList_Traverse_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt may need redesigned, or - * maybe the production code */ -void Test_CF_CList_Traverse_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt(void) -{ - /* Arrange */ - CF_CListNode_t dummy_start; - CF_CListNode_t * arg_start = &dummy_start; - CF_CListFn_t arg_fn = Hook_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - Hook_clist_fn_t_context_t context_Hook_clist_fn_t; - - arg_start->next = arg_start; - - UT_SetDefaultReturnValue(UT_KEY(Hook_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Hook_clist_fn_t), &context_Hook_clist_fn_t, sizeof(context_Hook_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse(arg_start, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Hook_clist_fn_t, 1); - UtAssert_True(context_Hook_clist_fn_t.node == arg_start, "context_Hook_clist_fn_t.node == arg_start"); - UtAssert_True(context_Hook_clist_fn_t.context == arg_context, "context_Hook_clist_fn_t.context == arg_context"); -} /* end Test_CF_CList_Traverse_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt */ - -void Test_CF_CList_Traverse_WhenListIsManyNodesErrorIn_fn_Call(void) -{ - /* Arrange */ - CF_CListNode_t * arg_start; - CF_CListNode_t * adder_node; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - uint8 list_size = Any_uint8_LessThan(9) + 2; /* 2 - 10 */ - uint8 error_location = Any_uint8_LessThan(list_size); /* 0 to list_size - 1 */ - int i = 0; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t[list_size]; - - arg_start = NULL; - adder_node = NULL; - - /* set up list */ - for (i = 0; i < list_size; ++i) - { - CF_CListNode_t *dummy_clist_node = malloc(sizeof(*dummy_clist_node)); - - if (i == 0) - { - arg_start = dummy_clist_node; - } - else if (i == 1) - { - adder_node = dummy_clist_node; - arg_start->next = adder_node; - adder_node->prev = arg_start; - } - else - { - dummy_clist_node->prev = adder_node; - adder_node->next = dummy_clist_node; - adder_node = dummy_clist_node; - } - - if (i == list_size - 1) - { - adder_node->next = arg_start; - arg_start->prev = adder_node; - } - } - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDeferredRetcode(UT_KEY(Dummy_clist_fn_t), error_location + 1, 1); - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), &context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse(arg_start, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, error_location + 1); - UtAssert_True(context_Dummy_clist_fn_t[0].node == arg_start, "context_Dummy_clist_fn_t[0].node == arg_start"); - UtAssert_True(context_Dummy_clist_fn_t[0].context == arg_context, - "context_Dummy_clist_fn_t[0].context == arg_context"); - - CF_CListNode_t *expected_node = arg_start->next; - for (i = 1; i <= error_location; ++i) - { - UtAssert_True(context_Dummy_clist_fn_t[i].node == expected_node, - "context_Dummy_clist_fn_t[i].node == expected_node"); - UtAssert_True(context_Dummy_clist_fn_t[i].context == arg_context, - "context_Dummy_clist_fn_t[i].context == arg_context"); - expected_node = expected_node->next; - } - - /* removes all malloc nodes */ - CF_CListNode_t *free_up_node = arg_start; - - for (i = 0; i < list_size; ++i) - { - CF_CListNode_t *old_free_up_node = free_up_node; - free_up_node = old_free_up_node->next; - free(old_free_up_node); - } -} /* end Test_CF_CList_Traverse_WhenListIsManyNodesErrorIn_fn_Call */ - -void Test_CF_CList_Traverse_WhenListIsManyNodesSuccess(void) -{ - /* Arrange */ - CF_CListNode_t * arg_start; - CF_CListNode_t * adder_node; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - uint8 list_size = Any_uint8_LessThan(9) + 2; /* 2 - 10 */ - int i = 0; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t[list_size + 1]; - - arg_start = NULL; - adder_node = NULL; - - /* set up list */ - for (i = 0; i < list_size; ++i) - { - CF_CListNode_t *dummy_clist_node = malloc(sizeof(*dummy_clist_node)); - - if (i == 0) - { - arg_start = dummy_clist_node; - } - else if (i == 1) - { - adder_node = dummy_clist_node; - arg_start->next = adder_node; - adder_node->prev = arg_start; - } - else - { - dummy_clist_node->prev = adder_node; - adder_node->next = dummy_clist_node; - adder_node = dummy_clist_node; - } - - if (i == list_size - 1) - { - adder_node->next = arg_start; - arg_start->prev = adder_node; - } - } - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), &context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse(arg_start, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, list_size); - UtAssert_True(context_Dummy_clist_fn_t[0].node == arg_start, "context_Dummy_clist_fn_t[0].node == arg_start"); - UtAssert_True(context_Dummy_clist_fn_t[0].context == arg_context, - "context_Dummy_clist_fn_t[0].context == arg_context"); - - CF_CListNode_t *expected_node = arg_start->next; - for (i = 1; i < list_size; ++i) - { - UtAssert_True(context_Dummy_clist_fn_t[i].node == expected_node, - "context_Dummy_clist_fn_t[i].node == expected_node"); - UtAssert_True(context_Dummy_clist_fn_t[i].context == arg_context, - "context_Dummy_clist_fn_t[i].context == arg_context"); - expected_node = expected_node->next; - } - - /* removes all malloc nodes */ - CF_CListNode_t *free_up_node = arg_start; - - for (i = 0; i < list_size; ++i) - { - CF_CListNode_t *old_free_up_node = free_up_node; - free_up_node = old_free_up_node->next; - free(old_free_up_node); - } -} /* end Test_CF_CList_Traverse_WhenListIsManyNodesSuccess */ +void Test_CF_CList_Traverse(void) +{ + CF_CListNode_t node[2]; + int context; + + memset(node, 0, sizeof(node)); + + /* Null won't call function */ + context = 0; + UtAssert_VOIDCALL(CF_CList_Traverse(NULL, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 0); + + /* Single node success */ + context = 0; + node[0].next = &node[0]; + UtAssert_VOIDCALL(CF_CList_Traverse(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 1); + + /* Two nodes nominal */ + context = 0; + node[0].next = &node[1]; + node[1].next = &node[0]; + UtAssert_VOIDCALL(CF_CList_Traverse(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 2); + + /* Two nodes, force exit on first call */ + context = -1; + node[0].next = &node[1]; + UtAssert_VOIDCALL(CF_CList_Traverse(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 0); + + /* Two nodes, self delete */ + context = 0; + node[0].next = &node[1]; + node[1].next = &node[1]; /* This would be the state after a real remove */ + UtAssert_VOIDCALL(CF_CList_Traverse(node, UT_CListFn_Rm, &context)); + UtAssert_INT32_EQ(context, -2); +} /******************************************************************************* ** @@ -1354,144 +930,50 @@ void Test_CF_CList_Traverse_WhenListIsManyNodesSuccess(void) ** *******************************************************************************/ -void Test_CF_CList_Traverse_R_When_end_Is_NULL_DoNothing(void) -{ - /* Arrange */ - CF_CListNode_t *arg_end = NULL; - CF_CListFn_t arg_fn = NULL; - void * arg_context = NULL; - - /* Act */ - CF_CList_Traverse_R(arg_end, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 0); -} /* end Test_CF_CList_Traverse_R_When_end_Is_NULL_DoNothing */ - -void Test_CF_CList_Traverse_R_When_end_prev_Is_NULLDoNothing(void) -{ - /* Arrange */ - CF_CListNode_t dummy_end; - CF_CListNode_t *arg_end = &dummy_end; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - - arg_end->prev = NULL; - - /* Act */ - CF_CList_Traverse_R(arg_end, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 0); -} /* end Test_CF_CList_Traverse_R_When_end_prev_Is_NULLDoNothing */ - -void Test_CF_CList_Traverse_R_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails(void) -{ - /* Arrange */ - CF_CListNode_t dummy_end; - CF_CListNode_t * arg_end = &dummy_end; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - CF_CListNode_t dummy_end_prev_node; - CF_CListNode_t * dummy_end_prev = &dummy_end_prev_node; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t; - - memset(&dummy_end, 0, sizeof(dummy_end)); - memset(&dummy_end_prev_node, 0, sizeof(dummy_end_prev_node)); - - arg_end->prev = dummy_end_prev; - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 1); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), &context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse_R(arg_end, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 1); - UtAssert_True(context_Dummy_clist_fn_t.node == dummy_end_prev, "context_Dummy_clist_fn_t.node == dummy_end_prev"); - UtAssert_True(context_Dummy_clist_fn_t.context == arg_context, "context_Dummy_clist_fn_t.context == arg_context"); -} /* end Test_CF_CList_Traverse_R_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails */ - -void Test_CF_CList_Traverse_R_PassedIn_end_IsTheOnlyNode_fn_Returned_non0(void) -{ - /* Arrange */ - CF_CListNode_t dummy_end; - CF_CListNode_t * arg_end = &dummy_end; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t; - - arg_end->prev = arg_end; - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), &context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse_R(arg_end, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 1); - UtAssert_True(context_Dummy_clist_fn_t.node == arg_end, "context_Dummy_clist_fn_t.node == arg_end"); - UtAssert_True(context_Dummy_clist_fn_t.context == arg_context, "context_Dummy_clist_fn_t.context == arg_context"); -} /* end Test_CF_CList_Traverse_R_PassedIn_end_IsTheOnlyNode_fn_Returned_non0 */ - -void Test_CF_CList_Traverse_R_PassedIn_end_IsNotTheOnlyNode_fn_Returned_non0_Original_end_UsedLast(void) -{ - /* Arrange */ - CF_CListNode_t dummy_node; - CF_CListNode_t dummy_end; - CF_CListNode_t * arg_end = &dummy_end; - CF_CListFn_t arg_fn = Dummy_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - Dummy_clist_fn_t_context_t context_Dummy_clist_fn_t[2]; - - arg_end->prev = &dummy_node; - dummy_node.prev = arg_end; - - UT_SetDefaultReturnValue(UT_KEY(Dummy_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Dummy_clist_fn_t), context_Dummy_clist_fn_t, sizeof(context_Dummy_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse_R(arg_end, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Dummy_clist_fn_t, 2); - UtAssert_True(context_Dummy_clist_fn_t[0].node == &dummy_node, "context_Dummy_clist_fn_t[0].node == &dummy_node"); - UtAssert_True(context_Dummy_clist_fn_t[0].context == arg_context, - "context_Dummy_clist_fn_t[0].context == arg_context"); - UtAssert_True(context_Dummy_clist_fn_t[1].node == arg_end, "context_Dummy_clist_fn_t[1].node == arg_end"); - UtAssert_True(context_Dummy_clist_fn_t[1].context == arg_context, - "context_Dummy_clist_fn_t[1].context == arg_context"); -} /* end Test_CF_CList_Traverse_R_PassedIn_end_IsNotTheOnlyNode_fn_Returned_non0_Original_end_UsedLast */ - -void Test_CF_CList_Traverse_R_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt(void) -{ - /* Arrange */ - CF_CListNode_t dummy_end; - CF_CListNode_t * arg_end = &dummy_end; - CF_CListFn_t arg_fn = Hook_clist_fn_t; - int dummy_context; - void * arg_context = &dummy_context; - Hook_clist_fn_t_context_t context_Hook_clist_fn_t; - - arg_end->prev = arg_end; - - UT_SetDefaultReturnValue(UT_KEY(Hook_clist_fn_t), 0); /* 0 is pass, 1 is fail */ - UT_SetDataBuffer(UT_KEY(Hook_clist_fn_t), &context_Hook_clist_fn_t, sizeof(context_Hook_clist_fn_t), false); - - /* Act */ - CF_CList_Traverse_R(arg_end, arg_fn, arg_context); - - /* Assert */ - UtAssert_STUB_COUNT(Hook_clist_fn_t, 1); - UtAssert_True(context_Hook_clist_fn_t.node == arg_end, "context_Hook_clist_fn_t.node == arg_end"); - UtAssert_True(context_Hook_clist_fn_t.context == arg_context, "context_Hook_clist_fn_t.context == arg_context"); -} /* end Test_CF_CList_Traverse_R_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt */ +void Test_CF_CList_Traverse_R(void) +{ + CF_CListNode_t node[3]; + int context; + + memset(node, 0, sizeof(node)); + + /* Null won't call function */ + context = 0; + UtAssert_VOIDCALL(CF_CList_Traverse_R(NULL, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 0); + + /* Null previous also skips logic */ + context = 0; + UtAssert_VOIDCALL(CF_CList_Traverse_R(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 0); + + /* Single node success */ + context = 0; + node[0].prev = &node[0]; + UtAssert_VOIDCALL(CF_CList_Traverse_R(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 1); + + /* Two nodes nominal */ + context = 0; + node[0].prev = &node[1]; + node[1].prev = &node[0]; + UtAssert_VOIDCALL(CF_CList_Traverse_R(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 2); + + /* Two nodes, force exit on first call */ + context = -1; + node[0].prev = &node[1]; + UtAssert_VOIDCALL(CF_CList_Traverse_R(node, UT_CListFn, &context)); + UtAssert_INT32_EQ(context, 0); + + /* Two nodes, self delete */ + context = 0; + node[0].prev = &node[2]; + node[1].prev = &node[1]; /* Self point to cause end */ + node[2].prev = &node[1]; + UtAssert_VOIDCALL(CF_CList_Traverse_R(node, UT_CListFn_Rm, &context)); + UtAssert_INT32_EQ(context, -2); +} /******************************************************************************* ** @@ -1507,14 +989,6 @@ void add_CF_CList_InitNode_tests(void) void add_CF_CList_InsertFront_tests(void) { - UtTest_Add(Test_CF_CList_InsertFront_AssertsBecauseHeadIs_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_InsertFront_AssertsBecauseHeadIs_NULL"); - UtTest_Add(Test_CF_CList_InsertFront_AssertsBecauseNodeIs_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_InsertFront_AssertsBecauseNodeIs_NULL"); - UtTest_Add(Test_CF_CList_InsertFront_AssertsBecauseNodeNextDoesNotPointToItself, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_InsertFront_AssertsBecauseNodeNextDoesNotPointToItself"); - UtTest_Add(Test_CF_CList_InsertFront_AssertsBecauseNodePrevDoesNotPointToItself, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_InsertFront_AssertsBecauseNodePrevDoesNotPointToItself"); UtTest_Add(Test_CF_CList_InsertFront_InsertNodeIntoEmptyList, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_InsertFront_InsertNodeIntoEmptyList"); UtTest_Add(Test_CF_CList_InsertFront_WhenHeadIsOnlyNodeAndTheyPointToEachOtherInsertNode, cf_clist_tests_Setup, @@ -1530,14 +1004,6 @@ void add_CF_CList_InsertFront_tests(void) void add_CF_CList_InsertBack_tests(void) { - UtTest_Add(Test_CF_CList_InsertBack_AssertsBecauseHeadIs_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_InsertBack_AssertsBecauseHeadIs_NULL"); - UtTest_Add(Test_CF_CList_InsertBack_AssertsBecauseNodeIs_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_InsertBack_AssertsBecauseNodeIs_NULL"); - UtTest_Add(Test_CF_CList_InsertBack_AssertsBecauseNodeNextDoesNotPointToItself, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_InsertBack_AssertsBecauseNodeNextDoesNotPointToItself"); - UtTest_Add(Test_CF_CList_InsertBack_AssertsBecauseNodePrevDoesNotPointToItself, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_InsertBack_AssertsBecauseNodePrevDoesNotPointToItself"); UtTest_Add(Test_CF_CList_InsertBack_InsertNodeIntoEmptyList, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_InsertBack_InsertNodeIntoEmptyList"); UtTest_Add(Test_CF_CList_InsertBack_WhenHeadIsOnlyNodeAndTheyPointToEachOtherInsertNode, cf_clist_tests_Setup, @@ -1552,8 +1018,6 @@ void add_CF_CList_InsertBack_tests(void) void add_CF_CList_Pop_tests(void) { - UtTest_Add(Test_CF_CList_Pop_AssertsBecause_head_Is_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Pop_AssertsBecause_head_Is_NULL"); UtTest_Add(Test_CF_CList_Pop_WhenListIsEmptySuccessReturn_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_Pop_WhenListIsEmptySuccessReturn_NULL"); UtTest_Add(Test_CF_CList_Pop_WhenItIsOnlyNodePopHeadNodeAndReturn_head_, cf_clist_tests_Setup, @@ -1565,14 +1029,6 @@ void add_CF_CList_Pop_tests(void) void add_CF_CList_Remove_tests(void) { - UtTest_Add(Test_CF_CList_Remove_AssertsBecauseHeadIs_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Remove_AssertsBecauseHeadIs_NULL"); - UtTest_Add(Test_CF_CList_Remove_AssertsBecauseNodeIs_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Remove_AssertsBecauseNodeIs_NULL"); - UtTest_Add(Test_CF_CList_Remove_AssertsBecauseHeadPointedAtValueIs_NULL, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_Remove_AssertsBecauseHeadPointedAtValueIs_NULL"); - UtTest_Add(Test_CF_ClistRemove_AssertsBecauseHeadPointedAtValueIsNotNode, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_ClistRemove_AssertsBecauseHeadPointedAtValueIsNotNode"); UtTest_Add(Test_CF_ClistRemove_WhenOnlyNodeSetHeadTo_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_ClistRemove_WhenOnlyNodeSetHeadTo_NULL"); UtTest_Add(Test_CF_ClistRemove_WhenOnlyTwoNodesAndLastIsRemovedSetHeadToPointToItself, cf_clist_tests_Setup, @@ -1583,62 +1039,16 @@ void add_CF_CList_Remove_tests(void) cf_clist_tests_Teardown, "Test_CF_ClistRemove_RemovingLastPointHeadAndNextToLastToEachOther"); UtTest_Add(Test_CF_ClistRemove_RemovingAnyNodeHasNodesPrevAndNextPointToEachOther, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_ClistRemove_RemovingAnyNodeHasNodesPrevAndNextPointToEachOther"); - UtTest_Add(Test_CF_CList_Remove_ReceivesBad_node_Because_next_PointsTo_node_But_prev_DoesNot, cf_clist_tests_Setup, - cf_clist_tests_Teardown, - "Test_CF_CList_Remove_ReceivesBad_node_Because_next_PointsTo_node_But_prev_DoesNot"); } /* end add_CF_CList_Remove_tests */ void add_CF_CList_InsertAfter_tests(void) { - UtTest_Add(Test_CF_CList_InsertAfter_AssertsBecause_head_Is_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_InsertAfter_AssertsBecause_head_Is_NULL"); - UtTest_Add(Test_CF_CList_InsertAfter_AssertsBecauseValueAt_head_Is_NULL, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_InsertAfter_AssertsBecause_head_Is_NULL"); - UtTest_Add(Test_CF_CList_InsertAfter_AssertsBecause_start_Is_NULL, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_InsertAfter_AssertsBecause_head_Is_NULL"); - UtTest_Add(Test_CF_CList_InsertAfter_AssertsBecause_start_IsEqTo_after, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_InsertAfter_AssertsBecause_head_Is_NULL"); UtTest_Add(Test_CF_CList_InsertAfter_WhenOnlyOneNodeSuccess_after_IsInsertedAfter_start, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_InsertAfter_WhenOnlyOneNodeSuccess_after_IsInsertedAfter_start"); UtTest_Add(Test_CF_CList_InsertAfter_WhenAnyNodeSuccess_after_IsInsertedAfter_start, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_InsertAfter_WhenAnyNodeSuccess_after_IsInsertedAfter_start"); } /* end add_CF_CList_InsertAfter_tests */ -void add_CF_CList_Traverse_tests(void) -{ - UtTest_Add(Test_CF_CList_Traverse_When_start_Is_NULL_DoNothing, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_When_start_Is_NULL_DoNothing"); - UtTest_Add(Test_CF_CList_Traverse_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_Traverse_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails"); - UtTest_Add(Test_CF_CList_Traverse_WhenListIsOneNodeSuccess, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_WhenListIsOneNodeSuccess"); - UtTest_Add(Test_CF_CList_Traverse_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt, - cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt"); - UtTest_Add(Test_CF_CList_Traverse_WhenListIsManyNodesErrorIn_fn_Call, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_WhenListIsManyNodesErrorIn_fn_Call"); - UtTest_Add(Test_CF_CList_Traverse_WhenListIsManyNodesSuccess, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_WhenListIsManyNodesSuccess"); -} /* end add_CF_CList_Traverse_tests */ - -void add_CF_CList_Traverse_R_tests(void) -{ - UtTest_Add(Test_CF_CList_Traverse_R_When_end_Is_NULL_DoNothing, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_R_When_end_Is_NULL_DoNothing"); - UtTest_Add(Test_CF_CList_Traverse_R_When_end_prev_Is_NULLDoNothing, cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_R_When_end_prev_Is_NULLDoNothing"); - UtTest_Add(Test_CF_CList_Traverse_R_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_Traverse_R_WhenListIsMoreThanOneNodeErrorOutFirst_fn_CallFails"); - UtTest_Add(Test_CF_CList_Traverse_R_PassedIn_end_IsTheOnlyNode_fn_Returned_non0, cf_clist_tests_Setup, - cf_clist_tests_Teardown, "Test_CF_CList_Traverse_R_PassedIn_end_IsTheOnlyNode_fn_Returned_non0"); - UtTest_Add(Test_CF_CList_Traverse_R_PassedIn_end_IsNotTheOnlyNode_fn_Returned_non0_Original_end_UsedLast, - cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_R_PassedIn_end_IsNotTheOnlyNode_fn_Returned_non0_Original_end_UsedLast"); - UtTest_Add(Test_CF_CList_Traverse_R_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt, - cf_clist_tests_Setup, cf_clist_tests_Teardown, - "Test_CF_CList_Traverse_R_CanActuallyGet_n_next_NotEqTo_nn_ButOnlyWithAn_fn_ThatForcesIt"); -} /* end add_CF_CList_Traverse_R_tests */ - /******************************************************************************* ** ** cf_clist_tests UtTest_Setup @@ -1661,9 +1071,8 @@ void UtTest_Setup(void) add_CF_CList_InsertAfter_tests(); - add_CF_CList_Traverse_tests(); - - add_CF_CList_Traverse_R_tests(); + UtTest_Add(Test_CF_CList_Traverse, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_Traverse"); + UtTest_Add(Test_CF_CList_Traverse_R, cf_clist_tests_Setup, cf_clist_tests_Teardown, "Test_CF_CList_Traverse_R"); } /* end UtTest_Setup for cf_clist_tests.c */ /* end cf_clist_tests.c */ diff --git a/unit-test/cf_cmd_tests.c b/unit-test/cf_cmd_tests.c index ee3ba4ab..f416f80d 100644 --- a/unit-test/cf_cmd_tests.c +++ b/unit-test/cf_cmd_tests.c @@ -1329,16 +1329,6 @@ void Test_CF_TsnChanAction_cmd_FailBecause_cmd_chan_IsInvalid(void) ** *******************************************************************************/ -void Test_CF_DoSuspRes_Txn_Asserts_t_Is_NULL(void) -{ - // /* Arrange */ - - // /* Act */ - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert"); -} /* end Test_CF_DoSuspRes_Txn_Asserts_t_Is_NULL */ - void Test_CF_DoSuspRes_Txn_Set_context_same_To_1_suspended_Eq_action(void) { /* Arrange */ @@ -4206,8 +4196,6 @@ void add_CF_TsnChanAction_tests(void) void add_CF_DoSuspRes_Txn_tests(void) { - UtTest_Add(Test_CF_DoSuspRes_Txn_Asserts_t_Is_NULL, cf_cmd_tests_Setup, cf_cmd_tests_Teardown, - "Test_CF_DoSuspRes_Txn_Asserts_t_Is_NULL"); UtTest_Add(Test_CF_DoSuspRes_Txn_Set_context_same_To_1_suspended_Eq_action, cf_cmd_tests_Setup, cf_cmd_tests_Teardown, "Test_CF_DoSuspRes_Txn_Set_context_same_To_1_suspended_Eq_action"); UtTest_Add(Test_CF_DoSuspRes_Txn_When_suspended_NotEqTo_action_Set_suspended_To_action, cf_cmd_tests_Setup, diff --git a/unit-test/cf_timer_tests.c b/unit-test/cf_timer_tests.c index 4c6e080a..d1eb0b61 100644 --- a/unit-test/cf_timer_tests.c +++ b/unit-test/cf_timer_tests.c @@ -145,16 +145,6 @@ void Test_CF_Timer_Expired_When_t_tick_IsAnyIntegerExcept_0_Return_0(void) ** *******************************************************************************/ -void Test_CF_Timer_TickAssertsBecause_t_tick_Is_0(void) -{ - // /* Arrange */ - - // /* Act */ - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->tick"); -} /* Test_CF_Timer_TickAssertsBecause_t_tick_Is_0 */ - void Test_CF_Timer_Tick_When_t_tick_Is_non0_Decrement_t_tick(void) { /* Arrange */ @@ -206,8 +196,6 @@ void add_CF_Timer_Expired_tests(void) void add_CF_Timer_Tick_tests(void) { - UtTest_Add(Test_CF_Timer_TickAssertsBecause_t_tick_Is_0, cf_timer_tests_Setup, cf_timer_tests_Teardown, - "Test_CF_Timer_TickAssertsBecause_t_tick_Is_0"); UtTest_Add(Test_CF_Timer_Tick_When_t_tick_Is_non0_Decrement_t_tick, cf_timer_tests_Setup, cf_timer_tests_Teardown, "Test_CF_Timer_Tick_When_t_tick_Is_non0_Decrement_t_tick"); } @@ -234,4 +222,4 @@ void UtTest_Setup(void) } /* end UtTest_Setup cf_timer_tests.c */ -/* end cf_timer_tests.c */ \ No newline at end of file +/* end cf_timer_tests.c */ diff --git a/unit-test/cf_utils_tests.c b/unit-test/cf_utils_tests.c index bb740f41..405269db 100644 --- a/unit-test/cf_utils_tests.c +++ b/unit-test/cf_utils_tests.c @@ -258,51 +258,6 @@ void Test_CF_FindTransactionBySequenceNumber(void) /* CF_DequeueTransaction tests */ -void Test_cf_dequeue_transaction_AssertsBecause_t_IsNull(void) -{ - // /* Arrange */ - // CF_Transaction_t *arg_t = NULL; - - // /* Act */ - // CF_DequeueTransaction(arg_t); - - // /* Assert */ - // UtAssert_STUB_COUNT(CF_HandleAssert, 1); - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t"); -} /* end Test_cf_dequeue_transaction_AssertsBecause_t_IsNull */ - -void Test_cf_dequeue_transaction_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS(void) -{ - // /* Arrange */ - // CF_Transaction_t arg_t; - // CF_CListNode_t * *expected_qs = - // &CF_AppData.engine.channels[arg_t.chan_num].qs[arg_t.flags.com.q_index]; - // uint8 dummy_chan_num = - // Any_uint8_GreaterThan_or_EqualTo(CF_NUM_CHANNELS); - - // arg_t.chan_num = dummy_chan_num; - - // /* Act */ - // CF_DequeueTransaction(&arg_t); - - // /* Assert */ - // UtAssert_STUB_COUNT(CF_HandleAssert, 1); - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->chan_numchan_num].q_size[t->flags.com.q_index]"); -} /* end Test_cf_dequeue_transaction_AssertsBecause_q_size_Eq0 */ - void Test_cf_dequeue_transaction_Call_CF_CList_Remove_AndDecrement_q_size(void) { /* Arrange */ @@ -341,36 +296,6 @@ void Test_cf_dequeue_transaction_Call_CF_CList_Remove_AndDecrement_q_size(void) /* CF_MoveTransaction tests */ -void Test_cf_move_transaction_AssertsBecause_t_IsNull(void) -{ - // /* Arrange */ - - // /* Act */ - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t"); -} /* end Test_cf_move_transaction_AssertsBecause_t_IsNull */ - -void Test_cf_move_transaction_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS(void) -{ - // /* Arrange */ - - // /* Act */ - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->chan_numchan_num].q_size[t->flags.com.q_index]"); -} /* end Test_cf_move_transaction_AssertsBecause_channel_hk_Has_q_size_Eq0 */ - void Test_cf_move_transaction_Call_CF_CList_InsertBack_AndSet_q_index_ToGiven_q(void) { /* Arrange */ @@ -421,31 +346,6 @@ void Test_cf_move_transaction_Call_CF_CList_InsertBack_AndSet_q_index_ToGiven_q( /* CF_CList_Remove_Ex tests */ -void Test_CF_CList_Remove_Ex_AssertsBecause_q_size_Eq0(void) -{ - // /* Arrange */ - // CF_Channel_t dummy_c; - // CF_Channel_t* arg_c = &dummy_c; - // CF_QueueIdx_t arg_index = Any_cf_queue_index_t(); - // CF_CListNode_t * arg_node; - // CF_CListNode_t ** expected_remove_head; - // CF_CListNode_t * expected_remove_node; - - // CF_Clist_Remove_context_t context_clist_remove; - // UT_SetDataBuffer(UT_KEY(CF_CList_Remove), &context_clist_remove, - // sizeof(context_clist_remove), false); - // - // expected_remove_head = &arg_c->qs[arg_index]; - - // CF_AppData.hk.channel_hk[arg_c-CF_AppData.engine.channels].q_size[arg_index] = 0; - - // /* Act */ - // CF_CList_Remove_Ex(arg_c, arg_index, arg_node); - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - CF_AppData.hk.channel_hk[c-CF_AppData.engine.channels].q_size[index]"); -} /* end Test_CF_CList_Remove_Ex_AssertsBecause_q_size_Eq0 */ - void Test_CF_CList_Remove_Ex_Call_CF_CList_Remove_AndDecrement_q_size(void) { /* Arrange */ @@ -807,26 +707,6 @@ void Test_CF_PrioSearch_When_t_PrioIsLessThanContextPrio_Set_context_t_To_t_AndR ** *******************************************************************************/ -void Test_CF_InsertSortPrio_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS(void) -{ - // /* Arrange */ - - // /* Act */ - - // /* Assert */ - UtAssert_MIR("JIRA: GSFCCFS-1733 CF_Assert - t->chan_numstate!=CF_TxnState_IDLE"); -} /* end Test_CF_InsertSortPrio_AssertsBecause_t_state_IsNot_CFDP_IDLE */ - void Test_CF_InsertSortPrio_Call_CF_CList_InsertBack_Ex_ListIsEmpty_AndSet_q_index_To_q(void) { /* Arrange */ @@ -1257,31 +1137,16 @@ void add_cf_utils_h_tests(void) "CF_FindTransactionBySequenceNumber"); /* CF_DequeueTransaction tests */ - UtTest_Add(Test_cf_dequeue_transaction_AssertsBecause_t_IsNull, cf_utils_tests_Setup, cf_utils_tests_Teardown, - "Test_cf_dequeue_transaction_AssertsBecause_t_IsNull"); - UtTest_Add(Test_cf_dequeue_transaction_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS, cf_utils_tests_Setup, - cf_utils_tests_Teardown, - "Test_cf_dequeue_transaction_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS"); - UtTest_Add(Test_cf_dequeue_transaction_AssertsBecause_q_size_Eq0, cf_utils_tests_Setup, cf_utils_tests_Teardown, - "Test_cf_dequeue_transaction_AssertsBecause_q_size_Eq0"); UtTest_Add(Test_cf_dequeue_transaction_Call_CF_CList_Remove_AndDecrement_q_size, cf_utils_tests_Setup, cf_utils_tests_Teardown, "Test_cf_dequeue_transaction_Call_CF_CList_Remove_AndDecrement_q_size"); /* end CF_DequeueTransaction tests */ /* CF_MoveTransaction tests */ - UtTest_Add(Test_cf_move_transaction_AssertsBecause_t_IsNull, cf_utils_tests_Setup, cf_utils_tests_Teardown, - "Test_cf_move_transaction_AssertsBecause_t_IsNull"); - UtTest_Add(Test_cf_move_transaction_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS, cf_utils_tests_Setup, - cf_utils_tests_Teardown, "Test_cf_move_transaction_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS"); - UtTest_Add(Test_cf_move_transaction_AssertsBecause_channel_hk_Has_q_size_Eq0, cf_utils_tests_Setup, - cf_utils_tests_Teardown, "Test_cf_move_transaction_AssertsBecause_channel_hk_Has_q_size_Eq0"); UtTest_Add(Test_cf_move_transaction_Call_CF_CList_InsertBack_AndSet_q_index_ToGiven_q, cf_utils_tests_Setup, cf_utils_tests_Teardown, "Test_cf_move_transaction_Call_CF_CList_InsertBack_AndSet_q_index_ToGiven_q"); /* end CF_MoveTransaction tests */ /* CF_CList_Remove_Ex tests */ - UtTest_Add(Test_CF_CList_Remove_Ex_AssertsBecause_q_size_Eq0, cf_utils_tests_Setup, cf_utils_tests_Teardown, - "Test_CF_CList_Remove_Ex_AssertsBecause_q_size_Eq0"); UtTest_Add(Test_CF_CList_Remove_Ex_Call_CF_CList_Remove_AndDecrement_q_size, cf_utils_tests_Setup, cf_utils_tests_Teardown, "Test_CF_CList_Remove_Ex_Call_CF_CList_Remove_AndDecrement_q_size"); /* end CF_CList_Remove_Ex tests */ @@ -1335,10 +1200,6 @@ void add_CF_PrioSearch_tests(void) void add_CF_InsertSortPrio_tests(void) { - UtTest_Add(Test_CF_InsertSortPrio_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS, cf_utils_tests_Setup, - cf_utils_tests_Teardown, "Test_CF_InsertSortPrio_AssertsBecause_t_chan_num_LessThan_CF_NUM_CHANNELS"); - UtTest_Add(Test_CF_InsertSortPrio_AssertsBecause_t_state_IsNot_CFDP_IDLE, cf_utils_tests_Setup, - cf_utils_tests_Teardown, "Test_CF_InsertSortPrio_AssertsBecause_t_state_IsNot_CFDP_IDLE"); UtTest_Add(Test_CF_InsertSortPrio_Call_CF_CList_InsertBack_Ex_ListIsEmpty_AndSet_q_index_To_q, cf_utils_tests_Setup, cf_utils_tests_Teardown, "Test_CF_InsertSortPrio_Call_CF_CList_InsertBack_Ex_ListIsEmpty_AndSet_q_index_To_q"); From 14ec982ae93c04a6b756f85f2b24ee817046b7b3 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 17 Jun 2022 14:50:22 -0600 Subject: [PATCH 4/6] Fix #27, Remove CF_CList_Remove redundant conditional --- fsw/src/cf_clist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsw/src/cf_clist.c b/fsw/src/cf_clist.c index 0bd8390d..45e908e9 100644 --- a/fsw/src/cf_clist.c +++ b/fsw/src/cf_clist.c @@ -142,7 +142,7 @@ void CF_CList_Remove(CF_CListNode_t **head, CF_CListNode_t *node) CF_Assert(node); CF_Assert(*head); - if ((node->next == node) && (node->prev == node)) + if (node->next == node) { /* only node in the list, so this one is easy */ CF_Assert(node == *head); /* sanity check */ From 25ccae18576ffc3af00922f7314f82eb7d3bfef5 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 17 Jun 2022 14:53:53 -0600 Subject: [PATCH 5/6] Fix #266, Explicit default case in CF_WriteHistoryEntryToFile for coverage --- fsw/src/cf_utils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fsw/src/cf_utils.c b/fsw/src/cf_utils.c index d36b969e..eefa709c 100644 --- a/fsw/src/cf_utils.c +++ b/fsw/src/cf_utils.c @@ -201,6 +201,7 @@ int CF_WriteHistoryEntryToFile(osal_id_t fd, const CF_History_t *h) snprintf(linebuf, sizeof(linebuf), "SRC: %s\t", h->fnames.src_filename); break; case 2: + default: snprintf(linebuf, sizeof(linebuf), "DST: %s\n", h->fnames.dst_filename); break; } From 022c496ef577ee040a3f947bf345e1a7234f434a Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 17 Jun 2022 14:57:09 -0600 Subject: [PATCH 6/6] Fix #215, Update workflow for full coverage enforcement --- .github/workflows/unit-test-coverage.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/unit-test-coverage.yml b/.github/workflows/unit-test-coverage.yml index 84ddf7b8..d67e62ba 100644 --- a/.github/workflows/unit-test-coverage.yml +++ b/.github/workflows/unit-test-coverage.yml @@ -8,6 +8,3 @@ jobs: unit-test-coverage: name: Run unit test and coverage uses: nasa/cFS/.github/workflows/unit-test-coverage.yml@main - with: - max-missed-branches: 8 - max-missed-lines: 2