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 #60, Adds HK_ValidateHkCopyTable size check #61

Merged
merged 1 commit into from
Oct 23, 2023
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
7 changes: 4 additions & 3 deletions docs/dox_src/cfs_hk.dox
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@
tables were chosen so that checksumming can be executed on the more-static copy
table.

<B>HK Copy Table Validation</B> - The HK copy table currently has an empty validation
call-back function that always returns success. At the time of development,
a validation process that would apply to all projects was not perceived.
<B>HK Copy Table Validation</B> - The HK copy table currently has a validation
call-back function that returns success when the size of the resulting combined
packet is less than or equal to the platform/project defined maximum value. Otherwise,
this function returns error and sends and error event.

<B>HK Copy Table Entries</B> - Entries follow the concept of:
<I>Copy A bytes from input message B, byte-offset C to output message Y,
Expand Down
1 change: 1 addition & 0 deletions docs/hk_FunctionalRequirements.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ HK1002,HK1002,"For all HK commands, if the length contained in the message heade
HK1003,HK1003,"If HK accepts any command as valid, HK shall execute the command, increment the HK Valid Command Counter and issue an event message",Provides basic verification of each HK command (i.e. HK command parameters are acceptable)
HK1004,HK1004,"If HK rejects any command, HK shall abort the command execution, increment the HK Command Rejected Counter and issue an error event message",Provides indicator of erroneous command
HK2000,HK2000,HK shall collect flight software housekeeping data from table-specified input messages,Use of tables makes it easier to modify/maintain
HK2000.1,HK2000.1,"If the HK Copy Table fails validation, HK shall issue an event message.",This is the case when the total memory stored in the combined copy packet is greater than the <PLATFORM_DEFINED> allowable size.
HK2001,HK2001,"HK shall output table-defined messages, at the scheduled rate, by combining input message data starting at the table-defined offset and table-defined number of bytes to the table-defined offset in the output message.",Useful to group telemetry from multiple apps into a single message
HK2001.1,HK2001.1,"Upon a table update, HK shall update the output message formats specified in the table during normal execution.",Supports the capability to adding and removing applications at runtime (or modifying messages)
HK2001.2,HK2001.2,"If the <PLATFORM_DEFINED> parameter Discard Combo Packets is set to NO and HK does not receive a message from an application, HK shall use all values associated with last received message for that application in the combined message for that telemetry collection period.",Zeroing data could have undesirable effects.
Expand Down
12 changes: 12 additions & 0 deletions fsw/inc/hk_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@
*/
#define HK_MISSION_REV 0

/**
* \brief Maximum size allowed for HK combined packet
*
* \par Description:
* Defines the maximum allowed size (in bytes) of a combined packet.
*
* \par Limits:
* Must be defined as a numeric value that is greater than
* or equal to zero.
*/
#define HK_MAX_COMBINED_PACKET_SIZE 1500

/**\}*/

#endif
26 changes: 25 additions & 1 deletion fsw/src/hk_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,31 @@ void HK_ProcessIncomingHkData(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 HK_ValidateHkCopyTable(void *TblPtr)
{
return HK_SUCCESS;
int32 HKStatus;
int32 i = 0;
int32 sumBytes = 0;
hk_copy_table_entry_t *tbl = (hk_copy_table_entry_t *)TblPtr;

/* Loop thru the table and add up all the bytes copied for testing overflow scenario */
for (i = 0; i < HK_COPY_TABLE_ENTRIES; i++)
{
sumBytes += tbl[i].NumBytes;
}

/* Check if the accumulated bytes exceed the allowed packet size, indicating an overflow */
if (sumBytes > HK_MAX_COMBINED_PACKET_SIZE)
{
HKStatus = HK_ERROR;

CFE_EVS_SendEvent(HK_NEWCPYTBL_HK_FAILED_EID, CFE_EVS_EventType_ERROR,
"HK Validate: table contents has size %d > %d\n", sumBytes, HK_MAX_COMBINED_PACKET_SIZE);
}
else
{
HKStatus = HK_SUCCESS;
}

return HKStatus;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
1 change: 1 addition & 0 deletions fsw/src/hk_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void HK_ProcessIncomingHkData(const CFE_SB_Buffer_t *BufPtr);
*
* \return Table Validation Status
* \retval #HK_SUCCESS Valid table
* \retval #HK_ERROR \copydoc HK_ERROR
*
* \sa #HK_TableInit
*/
Expand Down
30 changes: 27 additions & 3 deletions unit-test/hk_utils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,44 @@ void Test_HK_ProcessIncomingHkData_MessageError(void)
* Function under test: HK_ValidateHkCopyTable
*
* Case: Tests that the HK_ValidateHkCopyTable returns HK_SUCCESS
* (that is the only possible outcome - there are no branches in
* the function).
*/

void Test_HK_ValidateHkCopyTable_Success(void)
{
/* Arrange */
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitGoodCopyTable(CopyTblPtr);

/* Act */
int32 ReturnValue = HK_ValidateHkCopyTable(NULL);
int32 ReturnValue = HK_ValidateHkCopyTable(CopyTblPtr);

/* Assert */
UtAssert_True(ReturnValue == HK_SUCCESS, "HK_ValidateHkCopyTable returned %d, expected %d (HK_SUCCESS)",
ReturnValue, HK_SUCCESS);
}

/*
* Function under test: HK_ValidateHkCopyTable
*
* Case: Tests that the HK_ValidateHkCopyTable returns HK_ERROR
*/

void Test_HK_ValidateHkCopyTable_Error(void)
{
/* Arrange */
hk_copy_table_entry_t CopyTblPtr[HK_COPY_TABLE_ENTRIES];

HK_Test_InitOverflowCopyTable(CopyTblPtr);

/* Act */
int32 ReturnValue = HK_ValidateHkCopyTable(CopyTblPtr);

/* Assert */
UtAssert_True(ReturnValue == HK_ERROR, "HK_ValidateHkCopyTable returned %d, expected %d (HK_ERROR)",
ReturnValue, HK_ERROR);
}

/**********************************************************************/
/* */
/* Test functions for HK_ProcessNewCopyTable */
Expand Down Expand Up @@ -1933,6 +1955,8 @@ void UtTest_Setup(void)
/* Test functions for HK_VaidateHkCopyTable */
UtTest_Add(Test_HK_ValidateHkCopyTable_Success, HK_Test_Setup, HK_Test_TearDown,
"Test_HK_ValidateHkCopyTable_Success");
UtTest_Add(Test_HK_ValidateHkCopyTable_Error, HK_Test_Setup, HK_Test_TearDown,
"Test_HK_ValidateHkCopyTable_Error");

/* Test functions for HK_ProcessNewCopyTable */
UtTest_Add(Test_HK_ProcessNewCopyTable_EmptyTable, HK_Test_Setup, HK_Test_TearDown,
Expand Down
16 changes: 16 additions & 0 deletions unit-test/utilities/hk_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ void HK_Test_InitGoodCopyTable(hk_copy_table_entry_t *CpyTbl)
}
}

void HK_Test_InitOverflowCopyTable(hk_copy_table_entry_t *CpyTbl)
{
int32 i;
int32 overflowBytes = (HK_MAX_COMBINED_PACKET_SIZE / HK_COPY_TABLE_ENTRIES) + 1;

/* Set each table entry such that the combined size exceeds HK_MAX_COMBINED_PACKET_SIZE */
for (i = 0; i < HK_COPY_TABLE_ENTRIES; i++)
{
CpyTbl[i].InputMid = CFE_SB_ValueToMsgId(CFE_EVS_HK_TLM_MID);
CpyTbl[i].InputOffset = 12;
CpyTbl[i].OutputMid = CFE_SB_ValueToMsgId(HK_COMBINED_PKT1_MID);
CpyTbl[i].OutputOffset = ((i + 1) * overflowBytes);
CpyTbl[i].NumBytes = overflowBytes; /* Ensures overflow when summed across all entries */
}
}

void HK_Test_InitEmptyCopyTable(hk_copy_table_entry_t *CpyTbl)
{
int32 i = 0;
Expand Down
2 changes: 2 additions & 0 deletions unit-test/utilities/hk_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ extern CFE_ES_WriteToSysLog_context_t context_CFE_ES_WriteToSysLog;

void HK_Test_InitGoodCopyTable(hk_copy_table_entry_t *CpyTbl);

void HK_Test_InitOverflowCopyTable(hk_copy_table_entry_t *CpyTbl);

void HK_Test_InitEmptyCopyTable(hk_copy_table_entry_t *CpyTbl);

void HK_Test_InitGoodRuntimeTable(hk_runtime_tbl_entry_t *RtTbl);
Expand Down