Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix #30, Move variables declared mid-function to the top #31

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fsw/inc/hk_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Dictates the pipe depth of the hk command pipe.
*
* \par Limits
* The minimum size of this paramater is 1
* The minimum size of this parameter is 1
* The maximum size dictated by cFE platform configuration
* parameter CFE_SB_MAX_PIPE_DEPTH
*/
Expand Down
15 changes: 10 additions & 5 deletions unit-test/hk_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ void Test_HK_AppInit_SBCreatePipeFail(void)
int32 ReturnValue;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
int32 ForcedReturnVal = -1;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Error Creating SB Pipe,RC=0x%%08X");

int32 ForcedReturnVal = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_CreatePipe), ForcedReturnVal);

/* Act */
Expand Down Expand Up @@ -370,10 +371,11 @@ void Test_HK_AppInit_SBSubscribe1Fail(void)
int32 ReturnValue;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
int32 ForcedReturnVal = -1;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Error Subscribing to HK Snd Cmb Pkt, MID=0x%%08X, RC=0x%%08X");

int32 ForcedReturnVal = -1;
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 1, ForcedReturnVal);

/* Act */
Expand Down Expand Up @@ -406,10 +408,11 @@ void Test_HK_AppInit_SBSubscribe2Fail(void)
int32 ReturnValue;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
int32 ForcedReturnVal = -1;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Error Subscribing to HK Request, MID=0x%%08X, RC=0x%%08X");

int32 ForcedReturnVal = -1;
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 2, ForcedReturnVal);

/* Act */
Expand Down Expand Up @@ -442,10 +445,11 @@ void Test_HK_AppInit_SBSubscribe3Fail(void)
int32 ReturnValue;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
int32 ForcedReturnVal = -1;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Error Subscribing to HK Gnd Cmds, MID=0x%%08X, RC=0x%%08X");

int32 ForcedReturnVal = -1;
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 3, ForcedReturnVal);

/* Act */
Expand Down Expand Up @@ -478,9 +482,10 @@ void Test_HK_AppInit_PoolCreateFail(void)
int32 ReturnValue;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
int32 ForcedReturnVal = -1;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH, "Error Creating Memory Pool,RC=0x%%08X");

int32 ForcedReturnVal = -1;
UT_SetDefaultReturnValue(UT_KEY(CFE_ES_PoolCreate), ForcedReturnVal);

/* Act */
Expand Down
65 changes: 34 additions & 31 deletions unit-test/hk_utils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ void UT_CFE_TBL_GetAddress_Handler(void *UserObj, UT_EntryKey_t FuncKey, const U
void Test_HK_ProcessIncomingHkData_MidNotFound(void)
{
/* Arrange */
int32 i;
int32 NumEntriesWithDataPresent = 0;
CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; /* not in copy table */
CFE_SB_Buffer_t Buf;

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

int32 i;
int32 NumEntriesWithDataPresent = 0;
CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; /* not in copy table */
CFE_SB_Buffer_t Buf;
hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

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

HK_Test_InitGoodCopyTable(CopyTblPtr);
HK_Test_InitGoodRuntimeTable(RtTblPtr);

Expand Down Expand Up @@ -241,6 +240,8 @@ void Test_HK_ProcessIncomingHkData_MessageError(void)
CFE_SB_Buffer_t Buf;
hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

HK_Test_InitGoodCopyTable(CopyTblPtr);
HK_Test_InitGoodRuntimeTable(RtTblPtr);
Expand All @@ -254,8 +255,6 @@ void Test_HK_ProcessIncomingHkData_MessageError(void)
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false);

int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"HK table definition exceeds packet length. MID:0x%%08lX, Length:%%d, Count:%%d");

Expand Down Expand Up @@ -329,14 +328,15 @@ void Test_HK_ProcessNewCopyTable_NullCpyTbl(void)
/* Arrange */
hk_runtime_tbl_entry_t RtTblPtr;
int32 strCmpResult;
int32 ReturnValue;

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Null pointer detected in new copy tbl processing: CpyTbl = %%p, RtTbl = %%p");

/* Act */
int32 ReturnValue = HK_ProcessNewCopyTable(NULL, &RtTblPtr);
ReturnValue = HK_ProcessNewCopyTable(NULL, &RtTblPtr);

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

Expand Down Expand Up @@ -365,12 +365,13 @@ void Test_HK_ProcessNewCopyTable_NullRtTbl(void)
hk_copy_table_entry_t CpyTblPtr;
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
int32 ReturnValue;

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Null pointer detected in new copy tbl processing: CpyTbl = %%p, RtTbl = %%p");

/* Act */
int32 ReturnValue = HK_ProcessNewCopyTable(&CpyTblPtr, NULL);
ReturnValue = HK_ProcessNewCopyTable(&CpyTblPtr, NULL);

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

Expand Down Expand Up @@ -469,14 +470,14 @@ void Test_HK_ProcessNewCopyTable_SubscribeFail(void)

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"HK Processing New Table:SB_Subscribe for Mid 0x%%08lX returned 0x%%04X");

UT_SetDefaultReturnValue(UT_KEY(CFE_SB_Subscribe), !CFE_SUCCESS);

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitGoodCopyTable(CopyTblPtr);
HK_Test_InitGoodRuntimeTable(RtTblPtr);

Expand Down Expand Up @@ -772,14 +773,15 @@ void Test_HK_TearDownOldCopyTable_NullCpyTbl(void)
/* Arrange */
hk_runtime_tbl_entry_t RtTblPtr;
int32 strCmpResult;
int32 ReturnValue;

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Null pointer detected in copy tbl tear down: CpyTbl = %%p, RtTbl = %%p");

/* Act */
int32 ReturnValue = HK_TearDownOldCopyTable(NULL, &RtTblPtr);
ReturnValue = HK_TearDownOldCopyTable(NULL, &RtTblPtr);

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

Expand Down Expand Up @@ -807,14 +809,15 @@ void Test_HK_TearDownOldCopyTable_NullRtTbl(void)
/* Arrange */
hk_copy_table_entry_t CpyTblPtr;
int32 strCmpResult;
int32 ReturnValue;

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Null pointer detected in copy tbl tear down: CpyTbl = %%p, RtTbl = %%p");

/* Act */
int32 ReturnValue = HK_TearDownOldCopyTable(&CpyTblPtr, NULL);
ReturnValue = HK_TearDownOldCopyTable(&CpyTblPtr, NULL);

call_count_CFE_EVS_SendEvent = UT_GetStubCount(UT_KEY(CFE_EVS_SendEvent));

Expand Down Expand Up @@ -846,14 +849,14 @@ void Test_HK_TearDownOldCopyTable_PoolFreeFail(void)

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"HK TearDown: ES_putPoolBuf Err pkt:0x%%08lX ret 0x%%04X, hdl 0x%%08lx");

UT_SetDefaultReturnValue(UT_KEY(CFE_ES_PutPoolBuf), (CFE_SUCCESS - 1));

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitGoodCopyTable(CopyTblPtr);
HK_Test_InitGoodRuntimeTable(RtTblPtr);

Expand Down Expand Up @@ -1017,14 +1020,15 @@ void Test_HK_SendCombinedHkPacket_NoMissingData(void)
int32 call_count_CFE_SB_TimeStampMsg;
int32 call_count_CFE_SB_TransmitMsg;
CFE_SB_MsgId_t SendMid = CFE_SB_ValueToMsgId(HK_COMBINED_PKT1_MID); /* MID in the table */
int32 i;

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitGoodCopyTable(CopyTblPtr);
HK_Test_InitGoodRuntimeTable(RtTblPtr);

for (int i = 0; i < 5; i++)
for (i = 0; i < 5; i++)
{
RtTblPtr[i].DataPresent = HK_DATA_PRESENT;
}
Expand Down Expand Up @@ -1099,6 +1103,9 @@ void Test_HK_SendCombinedHkPacket_MissingData(void)
void Test_HK_SendCombinedHkPacket_EmptyTable(void)
{
/* Arrange */
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

Expand All @@ -1107,10 +1114,6 @@ void Test_HK_SendCombinedHkPacket_EmptyTable(void)
HK_AppData.RuntimeTablePtr = RtTblPtr;
HK_AppData.CopyTablePtr = CopyTblPtr;

int32 strCmpResult;

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Combined HK Packet 0x%%08lX is not found in current HK Copy Table");

Expand Down Expand Up @@ -1141,24 +1144,23 @@ void Test_HK_SendCombinedHkPacket_EmptyTable(void)
void Test_HK_SendCombinedHkPacket_PacketNotFound(void)
{
/* Arrange */
CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; /* does not match provided parameter */
int32 strCmpResult;
char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
CFE_SB_Buffer_t DummyBuffer;

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitEmptyCopyTable(CopyTblPtr);
HK_Test_InitEmptyRuntimeTable(RtTblPtr);

CFE_SB_Buffer_t DummyBuffer;
/* populate one entry in the RT table */
RtTblPtr[1].OutputPktAddr = &DummyBuffer; /* just needs to be non-null */

HK_AppData.RuntimeTablePtr = RtTblPtr;
HK_AppData.CopyTablePtr = CopyTblPtr;

CFE_SB_MsgId_t forced_MsgID = HK_UT_MID_100; /* does not match provided parameter */
int32 strCmpResult;

char ExpectedEventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];

snprintf(ExpectedEventString, CFE_MISSION_EVS_MAX_MESSAGE_LENGTH,
"Combined HK Packet 0x%%08lX is not found in current HK Copy Table");

Expand Down Expand Up @@ -1833,14 +1835,15 @@ void Test_HK_CheckForMissingData_NoMissingData_DataPresent(void)
int32 ReturnValue;
CFE_SB_MsgId_t OutPktToCheck = CFE_SB_ValueToMsgId(HK_COMBINED_PKT1_MID); /* MID in the table */
CFE_SB_MsgId_t MissingInputMid = CFE_SB_INVALID_MSG_ID;
int32 i;

hk_runtime_tbl_entry_t RtTblPtr[HK_COPY_TABLE_ENTRIES];
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitGoodCopyTable(CopyTblPtr);
HK_Test_InitGoodRuntimeTable(RtTblPtr);

for (int i = 0; i < 5; i++)
for (i = 0; i < 5; i++)
{
RtTblPtr[i].DataPresent = HK_DATA_PRESENT;
}
Expand Down