Skip to content

Commit

Permalink
Partial nasa#596, UtAssert macros for SBR test
Browse files Browse the repository at this point in the history
Update SBR coverage test to use preferred macros
  • Loading branch information
jphickey committed Jun 22, 2021
1 parent 09736d5 commit 687b715
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
22 changes: 11 additions & 11 deletions modules/sbr/ut-coverage/test_cfe_sbr_map_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void Test_SBR_Map_Direct(void)
uint32 i;

UtPrintf("Invalid msg checks");
CFE_UtAssert_EQUAL(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0);
CFE_UtAssert_EQUAL(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(0))), false);
UtAssert_INT32_EQ(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0);
CFE_UtAssert_FALSE(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(0))));

UtPrintf("Initialize map");
CFE_SBR_Init_Map();
Expand All @@ -59,18 +59,18 @@ void Test_SBR_Map_Direct(void)
count++;
}
}
CFE_UtAssert_EQUAL(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);

UtPrintf("Set/Get a range of ids ");
routeid = CFE_SBR_ValueToRouteId(CFE_PLATFORM_SB_MAX_MSG_IDS + 1);
msgid = CFE_SB_ValueToMsgId(0);
CFE_UtAssert_EQUAL(CFE_SBR_SetRouteId(msgid, routeid), 0);
CFE_UtAssert_EQUAL(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
UtAssert_INT32_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
UtAssert_INT32_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);

routeid = CFE_SBR_ValueToRouteId(0);
msgid = CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
CFE_UtAssert_EQUAL(CFE_SBR_SetRouteId(msgid, routeid), 0);
CFE_UtAssert_EQUAL(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
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");
count = 0;
Expand All @@ -81,13 +81,13 @@ void Test_SBR_Map_Direct(void)
count++;
}
}
CFE_UtAssert_EQUAL(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);

UtPrintf("Set back to invalid and check again");
routeid = CFE_SBR_INVALID_ROUTE_ID;
CFE_UtAssert_EQUAL(CFE_SBR_SetRouteId(msgid, routeid), 0);
CFE_UtAssert_EQUAL(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
CFE_UtAssert_EQUAL(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(msgid)), false);
UtAssert_INT32_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
UtAssert_INT32_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
CFE_UtAssert_FALSE(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(msgid)));

/* Performance check, 0xFFFFFF on 3.2GHz linux box is around 8-9 seconds */
count = 0;
Expand Down
18 changes: 9 additions & 9 deletions modules/sbr/ut-coverage/test_cfe_sbr_map_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void Test_SBR_Map_Hash(void)
uint32 collisions;

UtPrintf("Invalid msg checks");
CFE_UtAssert_EQUAL(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0);
CFE_UtAssert_EQUAL(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(0))), false);
UtAssert_INT32_EQ(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0);
CFE_UtAssert_FALSE(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(0))));

UtPrintf("Initialize routing and map");
CFE_SBR_Init();
Expand All @@ -78,23 +78,23 @@ void Test_SBR_Map_Hash(void)
count++;
}
}
CFE_UtAssert_EQUAL(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 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");
msgid[0] = CFE_SB_ValueToMsgId(0);
msgid[1] = Test_SBR_Unhash(0xFFFFFFFF);
msgid[2] = Test_SBR_Unhash(0x7FFFFFFF);
routeid[0] = CFE_SBR_AddRoute(msgid[0], &collisions);
CFE_UtAssert_EQUAL(collisions, 0);
UtAssert_INT32_EQ(collisions, 0);
routeid[1] = CFE_SBR_AddRoute(msgid[1], &collisions);
CFE_UtAssert_EQUAL(collisions, 0);
UtAssert_INT32_EQ(collisions, 0);
routeid[2] = CFE_SBR_AddRoute(msgid[2], &collisions);
CFE_UtAssert_EQUAL(collisions, 2);
UtAssert_INT32_EQ(collisions, 2);

CFE_UtAssert_EQUAL(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[0])), CFE_SBR_RouteIdToValue(routeid[0]));
CFE_UtAssert_EQUAL(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[1])), CFE_SBR_RouteIdToValue(routeid[1]));
CFE_UtAssert_EQUAL(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[2])), CFE_SBR_RouteIdToValue(routeid[2]));
UtAssert_INT32_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[0])), CFE_SBR_RouteIdToValue(routeid[0]));
UtAssert_INT32_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[1])), CFE_SBR_RouteIdToValue(routeid[1]));
UtAssert_INT32_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[2])), CFE_SBR_RouteIdToValue(routeid[2]));

/* Performance check, 0xFFFFFF on 3.2GHz linux box is around 8-9 seconds */
count = 0;
Expand Down
40 changes: 20 additions & 20 deletions modules/sbr/ut-coverage/test_cfe_sbr_route_unsorted.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ void Test_SBR_Route_Unsort_General(void)
CFE_SBR_Init();

UtPrintf("Invalid msg checks");
CFE_UtAssert_TRUE(!CFE_SBR_IsValidRouteId(CFE_SBR_AddRoute(CFE_SB_ValueToMsgId(0), NULL)));
CFE_UtAssert_TRUE(!CFE_SBR_IsValidRouteId(CFE_SBR_AddRoute(CFE_SB_ValueToMsgId(0), &collisions)));
CFE_UtAssert_EQUAL(collisions, 0);
CFE_UtAssert_FALSE(CFE_SBR_IsValidRouteId(CFE_SBR_AddRoute(CFE_SB_ValueToMsgId(0), NULL)));
CFE_UtAssert_FALSE(CFE_SBR_IsValidRouteId(CFE_SBR_AddRoute(CFE_SB_ValueToMsgId(0), &collisions)));
UtAssert_INT32_EQ(collisions, 0);

/*
* Force valid msgid responses
Expand All @@ -65,18 +65,18 @@ void Test_SBR_Route_Unsort_General(void)
UtPrintf("Callback test with no routes");
count = 0;
CFE_SBR_ForEachRouteId(Test_SBR_Callback, &count, NULL);
CFE_UtAssert_EQUAL(count, 0);
UtAssert_INT32_EQ(count, 0);

UtPrintf("Add maximum mesage id value");
msgid = CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
routeid = CFE_SBR_AddRoute(msgid, &collisions);
CFE_UtAssert_EQUAL(collisions, 0);
UtAssert_INT32_EQ(collisions, 0);
CFE_UtAssert_TRUE(CFE_SBR_IsValidRouteId(routeid));

UtPrintf("Callback test with one route");
count = 0;
CFE_SBR_ForEachRouteId(Test_SBR_Callback, &count, NULL);
CFE_UtAssert_EQUAL(count, 1);
UtAssert_INT32_EQ(count, 1);

UtPrintf("Fill routing table");
count = 0;
Expand All @@ -86,30 +86,30 @@ void Test_SBR_Route_Unsort_General(void)
}

/* Check for expected count indicating full routing table */
CFE_UtAssert_EQUAL(count + 1, CFE_PLATFORM_SB_MAX_MSG_IDS);
UtAssert_INT32_EQ(count + 1, CFE_PLATFORM_SB_MAX_MSG_IDS);

/* Try one more for good luck */
CFE_UtAssert_TRUE(!CFE_SBR_IsValidRouteId(CFE_SBR_AddRoute(CFE_SB_ValueToMsgId(count), NULL)));
CFE_UtAssert_FALSE(CFE_SBR_IsValidRouteId(CFE_SBR_AddRoute(CFE_SB_ValueToMsgId(count), NULL)));

/* Check that maximum msgid is still in the table */
CFE_UtAssert_EQUAL(CFE_SB_MsgIdToValue(CFE_SBR_GetMsgId(routeid)), CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
CFE_UtAssert_EQUAL(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
UtAssert_INT32_EQ(CFE_SB_MsgIdToValue(CFE_SBR_GetMsgId(routeid)), CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
UtAssert_INT32_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);

UtPrintf("Callback test with full route");
count = 0;
CFE_SBR_ForEachRouteId(Test_SBR_Callback, &count, NULL);
CFE_UtAssert_EQUAL(count, CFE_PLATFORM_SB_MAX_MSG_IDS);
UtAssert_INT32_EQ(count, CFE_PLATFORM_SB_MAX_MSG_IDS);

UtPrintf("Callback test throttled");
throttle.MaxLoop = CFE_PLATFORM_SB_MAX_MSG_IDS - 1;
throttle.StartIndex = 0;
count = 0;
CFE_SBR_ForEachRouteId(Test_SBR_Callback, &count, &throttle);
CFE_UtAssert_EQUAL(count, CFE_PLATFORM_SB_MAX_MSG_IDS - 1);
UtAssert_UINT32_EQ(count, CFE_PLATFORM_SB_MAX_MSG_IDS - 1);
count = 0;
throttle.StartIndex = throttle.NextIndex;
CFE_SBR_ForEachRouteId(Test_SBR_Callback, &count, &throttle);
CFE_UtAssert_EQUAL(count, 1);
UtAssert_INT32_EQ(count, 1);
}

void Test_SBR_Route_Unsort_GetSet(void)
Expand All @@ -130,7 +130,7 @@ void Test_SBR_Route_Unsort_GetSet(void)
{
CFE_UtAssert_TRUE(CFE_SB_MsgId_Equal(CFE_SBR_GetMsgId(routeid[i]), CFE_SB_INVALID_MSG_ID));
UtAssert_ADDRESS_EQ(CFE_SBR_GetDestListHeadPtr(routeid[i]), NULL);
CFE_UtAssert_EQUAL(CFE_SBR_GetSequenceCounter(routeid[i]), 0);
UtAssert_INT32_EQ(CFE_SBR_GetSequenceCounter(routeid[i]), 0);
}

/*
Expand All @@ -154,7 +154,7 @@ void Test_SBR_Route_Unsort_GetSet(void)
count++;
}
}
CFE_UtAssert_EQUAL(count, 0);
UtAssert_INT32_EQ(count, 0);

UtPrintf("Add routes and initialize values for testing");
msgid[0] = CFE_SB_ValueToMsgId(0);
Expand All @@ -174,19 +174,19 @@ void Test_SBR_Route_Unsort_GetSet(void)
CFE_UtAssert_TRUE(CFE_SB_MsgId_Equal(msgid[i], CFE_SBR_GetMsgId(routeid[i])));
CFE_SBR_IncrementSequenceCounter(routeid[0]);
}
CFE_UtAssert_EQUAL(UT_GetStubCount(UT_KEY(CFE_MSG_GetNextSequenceCount)), 3);
UtAssert_STUB_COUNT(CFE_MSG_GetNextSequenceCount, 3);

/* Increment route 1 once and set dest pointers */
UT_SetDefaultReturnValue(UT_KEY(CFE_MSG_GetNextSequenceCount), seqcntexpected[1]);
CFE_SBR_IncrementSequenceCounter(routeid[1]);
CFE_UtAssert_EQUAL(UT_GetStubCount(UT_KEY(CFE_MSG_GetNextSequenceCount)), 4);
UtAssert_STUB_COUNT(CFE_MSG_GetNextSequenceCount, 4);
CFE_SBR_SetDestListHeadPtr(routeid[1], &dest[1]);
CFE_SBR_SetDestListHeadPtr(routeid[2], &dest[0]);

UtPrintf("Verify remaining set values");
CFE_UtAssert_EQUAL(CFE_SBR_GetSequenceCounter(routeid[0]), seqcntexpected[0]);
CFE_UtAssert_EQUAL(CFE_SBR_GetSequenceCounter(routeid[1]), seqcntexpected[1]);
CFE_UtAssert_EQUAL(CFE_SBR_GetSequenceCounter(routeid[2]), 0);
UtAssert_UINT32_EQ(CFE_SBR_GetSequenceCounter(routeid[0]), seqcntexpected[0]);
UtAssert_UINT32_EQ(CFE_SBR_GetSequenceCounter(routeid[1]), seqcntexpected[1]);
UtAssert_INT32_EQ(CFE_SBR_GetSequenceCounter(routeid[2]), 0);
UtAssert_ADDRESS_EQ(CFE_SBR_GetDestListHeadPtr(routeid[0]), NULL);
UtAssert_ADDRESS_EQ(CFE_SBR_GetDestListHeadPtr(routeid[1]), &dest[1]);
UtAssert_ADDRESS_EQ(CFE_SBR_GetDestListHeadPtr(routeid[2]), &dest[0]);
Expand Down

0 comments on commit 687b715

Please sign in to comment.