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 #2022, Limit SBR UT loops #2023

Merged
merged 1 commit into from
Jan 21, 2022
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
47 changes: 40 additions & 7 deletions modules/sbr/ut-coverage/test_cfe_sbr_map_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@
#include "cfe_sbr_priv.h"
#include <stdlib.h>

/*
* Reasonable limit on loops in case CFE_PLATFORM_SB_HIGHEST_VALID_MSGID is large
* Can be set equal to the configured highest if user requires it
*/
#define CFE_SBR_UT_LIMIT_HIGHEST_MSGID 0x1FFF

void Test_SBR_Map_Direct(void)
{

CFE_SB_MsgId_Atom_t msgidx;
CFE_SB_MsgId_Atom_t msgid_limit;
CFE_SBR_RouteId_t routeid;
CFE_SB_MsgId_t msgid;
uint32 count;
Expand All @@ -50,16 +57,29 @@ void Test_SBR_Map_Direct(void)
/* Force valid msgid responses */
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_IsValidMsgId), true);

UtPrintf("Check that all entries are set invalid");
/* Limit message id loops */
if (CFE_PLATFORM_SB_HIGHEST_VALID_MSGID > CFE_SBR_UT_LIMIT_HIGHEST_MSGID)
{
msgid_limit = CFE_SBR_UT_LIMIT_HIGHEST_MSGID;
UtPrintf("Limiting msgid ut loops to 0x%08X of 0x%08X", (unsigned int)msgid_limit,
(unsigned int)CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
}
else
{
msgid_limit = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID;
UtPrintf("Testing full msgid range in ut up to 0x%08X", (unsigned int)msgid_limit);
}

UtPrintf("Check that entries are set invalid");
count = 0;
for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++)
for (msgidx = 0; msgidx <= msgid_limit; msgidx++)
{
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
{
count++;
}
}
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
UtAssert_INT32_EQ(count, msgid_limit + 1);

UtPrintf("Set/Get a range of ids ");
routeid = CFE_SBR_ValueToRouteId(CFE_PLATFORM_SB_MAX_MSG_IDS + 1);
Expand All @@ -72,16 +92,29 @@ void Test_SBR_Map_Direct(void)
UtAssert_INT32_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
UtAssert_INT32_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);

UtPrintf("Check there is now 1 valid entry in map");
/* Get number of valid routes in range */
count = 0;
for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++)
for (msgidx = 0; msgidx <= msgid_limit; msgidx++)
{
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
if (CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
{
count++;
}
}
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);

/* Check result based on range checked */
if (msgid_limit == CFE_PLATFORM_SB_HIGHEST_VALID_MSGID)
{
/* Full range, 1 valid */
UtPrintf("Check there is 1 valid entry in map");
UtAssert_INT32_EQ(count, 1);
}
else
{
/* Limited range, up to 1 valid */
UtPrintf("Up to 1 valid entry in limited range check");
UtAssert_INT32_LTEQ(count, 1);
}

UtPrintf("Set back to invalid and check again");
routeid = CFE_SBR_INVALID_ROUTE_ID;
Expand Down
26 changes: 23 additions & 3 deletions modules/sbr/ut-coverage/test_cfe_sbr_map_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
/* Unhash magic number */
#define CFE_SBR_UNHASH_MAGIC (0x119de1f3)

/*
* Reasonable limit on loops in case CFE_PLATFORM_SB_HIGHEST_VALID_MSGID is large
* Can be set equal to the configured highest if user requires it
*/
#define CFE_SBR_UT_LIMIT_HIGHEST_MSGID 0x1FFF

/******************************************************************************
* Local helper to unhash
*/
Expand All @@ -54,6 +60,7 @@ void Test_SBR_Map_Hash(void)
{

CFE_SB_MsgId_Atom_t msgidx;
CFE_SB_MsgId_Atom_t msgid_limit;
CFE_SBR_RouteId_t routeid[3];
CFE_SB_MsgId_t msgid[3];
uint32 count;
Expand All @@ -69,16 +76,29 @@ void Test_SBR_Map_Hash(void)
/* Force valid msgid responses */
UT_SetDefaultReturnValue(UT_KEY(CFE_SB_IsValidMsgId), true);

UtPrintf("Check that all entries are set invalid");
/* Limit message id loops */
if (CFE_PLATFORM_SB_HIGHEST_VALID_MSGID > CFE_SBR_UT_LIMIT_HIGHEST_MSGID)
{
msgid_limit = CFE_SBR_UT_LIMIT_HIGHEST_MSGID;
UtPrintf("Limiting msgid ut loops to 0x%08X of 0x%08X", (unsigned int)msgid_limit,
(unsigned int)CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
}
else
{
msgid_limit = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID;
UtPrintf("Testing full msgid range in ut up to 0x%08X", (unsigned int)msgid_limit);
}

UtPrintf("Check that entries are set invalid");
count = 0;
for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++)
for (msgidx = 0; msgidx <= msgid_limit; msgidx++)
{
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
{
count++;
}
}
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
UtAssert_INT32_EQ(count, msgid_limit + 1);

/* Note AddRoute required for hash logic to work since it depends on MsgId in routing table */
UtPrintf("Add routes and check with a rollover and a skip");
Expand Down