Skip to content

Commit 7bb7585

Browse files
author
Jacob Hageman
committed
Fix #928, Update SB unit test for SBR module with direct link
- Linking SBR with SB unit test, not stubbed - Confirms matching functionality (with updates for intended changes)
1 parent b67b11f commit 7bb7585

File tree

2 files changed

+58
-108
lines changed

2 files changed

+58
-108
lines changed

fsw/cfe-core/unit-test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ foreach(MODULE ${CFE_CORE_MODULES})
7171
${UT_COVERAGE_LINK_FLAGS}
7272
ut_cfe-core_support
7373
ut_cfe-core_stubs
74+
sbr # TODO remove this
7475
ut_assert)
7576

7677
add_test(${UT_TARGET_NAME}_UT ${UT_TARGET_NAME}_UT)

fsw/cfe-core/unit-test/sb_UT.c

Lines changed: 57 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,16 @@ void Test_SB_Cmds_SendPrevSubs(void)
12871287
CFE_SB_ProcessCmdPipePkt();
12881288

12891289
NumEvts += 8; /* +2 for the subscribe, +6 for the SEND_PREV_SUBS_CC */
1290-
EVTCNT(NumEvts);
1290+
1291+
/* Event count is only exact if there were no collisions */
1292+
if (UT_EventIsInHistory(CFE_SB_HASHCOLLISION_EID))
1293+
{
1294+
ASSERT_TRUE(UT_GetNumEventsSent() > NumEvts);
1295+
}
1296+
else
1297+
{
1298+
EVTCNT(NumEvts);
1299+
}
12911300

12921301
/* Round out the number to three full pkts in order to test branch path
12931302
* coverage, MSGID 0x0D was skipped in previous subscription loop
@@ -1321,7 +1330,15 @@ void Test_SB_Cmds_SendPrevSubs(void)
13211330

13221331
NumEvts += 8; /* +2 for the subscribe, +6 for the SEND_PREV_SUBS_CC */
13231332

1324-
EVTCNT(NumEvts);
1333+
/* Event count is only exact if there were no collisions */
1334+
if (UT_EventIsInHistory(CFE_SB_HASHCOLLISION_EID))
1335+
{
1336+
ASSERT_TRUE(UT_GetNumEventsSent() > NumEvts);
1337+
}
1338+
else
1339+
{
1340+
EVTCNT(NumEvts);
1341+
}
13251342

13261343
EVTSENT(CFE_SB_SUBSCRIPTION_RCVD_EID);
13271344
EVTSENT(CFE_SB_SEND_NO_SUBS_EID);
@@ -1704,7 +1721,7 @@ void Test_DeletePipe_WithSubs(void)
17041721
SETUP(CFE_SB_Subscribe(MsgId3, PipedId));
17051722
ASSERT(CFE_SB_DeletePipe(PipedId));
17061723

1707-
EVTCNT(14);
1724+
EVTCNT(10);
17081725

17091726
EVTSENT(CFE_SB_PIPE_ADDED_EID);
17101727
EVTSENT(CFE_SB_PIPE_DELETED_EID);
@@ -1772,7 +1789,7 @@ void Test_DeletePipe_WithAppid(void)
17721789

17731790
ASSERT(CFE_SB_DeletePipeWithAppId(PipedId, AppId));
17741791

1775-
EVTCNT(14);
1792+
EVTCNT(10);
17761793

17771794
} /* end Test_DeletePipe_WithAppid */
17781795

@@ -2030,7 +2047,6 @@ void Test_Subscribe_API(void)
20302047
SB_UT_ADD_SUBTEST(Test_Subscribe_MaxDestCount);
20312048
SB_UT_ADD_SUBTEST(Test_Subscribe_MaxMsgIdCount);
20322049
SB_UT_ADD_SUBTEST(Test_Subscribe_SendPrevSubs);
2033-
SB_UT_ADD_SUBTEST(Test_Subscribe_FindGlobalMsgIdCnt);
20342050
SB_UT_ADD_SUBTEST(Test_Subscribe_PipeNonexistent);
20352051
SB_UT_ADD_SUBTEST(Test_Subscribe_SubscriptionReporting);
20362052
SB_UT_ADD_SUBTEST(Test_Subscribe_InvalidPipeOwner);
@@ -2274,9 +2290,6 @@ void Test_Subscribe_SendPrevSubs(void)
22742290
SETUP(CFE_SB_Subscribe(MsgId2, PipeId1));
22752291
SETUP(CFE_SB_Subscribe(MsgId0, PipeId2));
22762292

2277-
/* Set the last list header pointer to NULL to get branch path coverage */
2278-
CFE_SB.RoutingTbl[2].ListHeadPtr = NULL;
2279-
22802293
/* For internal SendMsg call */
22812294
MsgIdCmd = CFE_SB_ValueToMsgId(CFE_SB_ALLSUBS_TLM_MID);
22822295
Size = sizeof(CFE_SB.PrevSubMsg);
@@ -2295,46 +2308,6 @@ void Test_Subscribe_SendPrevSubs(void)
22952308

22962309
} /* end Test_Subscribe_SendPrevSubs */
22972310

2298-
/*
2299-
** Test function to get a count of the global message ids in use
2300-
*/
2301-
void Test_Subscribe_FindGlobalMsgIdCnt(void)
2302-
{
2303-
CFE_SB_PipeId_t PipeId0;
2304-
CFE_SB_PipeId_t PipeId1;
2305-
CFE_SB_PipeId_t PipeId2;
2306-
CFE_SB_MsgId_t MsgId0 = SB_UT_TLM_MID1;
2307-
CFE_SB_MsgId_t MsgId1 = SB_UT_TLM_MID2;
2308-
CFE_SB_MsgId_t MsgId2 = SB_UT_TLM_MID3;
2309-
uint16 PipeDepth = 50;
2310-
uint16 MsgLim = 4;
2311-
2312-
SETUP(CFE_SB_CreatePipe(&PipeId0, PipeDepth, "TestPipe0"));
2313-
SETUP(CFE_SB_CreatePipe(&PipeId1, PipeDepth, "TestPipe1"));
2314-
SETUP(CFE_SB_CreatePipe(&PipeId2, PipeDepth, "TestPipe2"));
2315-
SETUP(CFE_SB_Subscribe(MsgId0, PipeId0));
2316-
SETUP(CFE_SB_Subscribe(MsgId1, PipeId0));
2317-
SETUP(CFE_SB_Subscribe(MsgId2, PipeId0));
2318-
SETUP(CFE_SB_Subscribe(MsgId0, PipeId1));
2319-
SETUP(CFE_SB_Subscribe(MsgId1, PipeId1));
2320-
SETUP(CFE_SB_Subscribe(MsgId2, PipeId1));
2321-
SETUP(CFE_SB_SubscribeLocal(MsgId0, PipeId2, MsgLim));
2322-
2323-
/* Set the last list head pointer to NULL for branch path coverage */
2324-
CFE_SB.RoutingTbl[2].ListHeadPtr = NULL;
2325-
2326-
ASSERT_EQ(CFE_SB_FindGlobalMsgIdCnt(), 2); /* 2 unique msg ids; the third is set to skip */
2327-
2328-
EVTCNT(17);
2329-
2330-
EVTSENT(CFE_SB_PIPE_ADDED_EID);
2331-
2332-
TEARDOWN(CFE_SB_DeletePipe(PipeId0));
2333-
TEARDOWN(CFE_SB_DeletePipe(PipeId1));
2334-
TEARDOWN(CFE_SB_DeletePipe(PipeId2));
2335-
2336-
} /* end Test_Subscribe_FindGlobalMsgIdCnt */
2337-
23382311
/*
23392312
** Test message subscription response to nonexistent pipe
23402313
*/
@@ -2366,29 +2339,29 @@ void Test_Subscribe_SubscriptionReporting(void)
23662339
SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe"));
23672340

23682341
/* Enable subscription reporting */
2369-
CFE_SB_SetSubscriptionReporting(CFE_SB_ENABLE);
2342+
CFE_SB_SetSubscriptionReporting(CFE_SB_ENABLE);
23702343

23712344
/* For internal SendMsg call that will report subscription */
23722345
MsgIdRpt = CFE_SB_ValueToMsgId(CFE_SB_ONESUB_TLM_MID);
23732346
Size = sizeof(CFE_SB.SubRprtMsg);
23742347
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgIdRpt, sizeof(MsgIdRpt), false);
23752348
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false);
23762349

2377-
/* Subscribe to message: GLOBAL */
2378-
SETUP(CFE_SB_Subscribe(MsgId, PipeId));
2350+
/* Subscribe to message: GLOBAL */
2351+
SETUP(CFE_SB_Subscribe(MsgId, PipeId));
23792352

2380-
/* Unsubscribe so that a local subscription can be tested */
2381-
SETUP(CFE_SB_Unsubscribe(MsgId, PipeId));
2353+
/* Unsubscribe so that a local subscription can be tested */
2354+
SETUP(CFE_SB_Unsubscribe(MsgId, PipeId));
23822355

2383-
/* Subscribe to message: LOCAL */
2384-
ASSERT(CFE_SB_SubscribeFull(MsgId, PipeId, Quality, CFE_PLATFORM_SB_DEFAULT_MSG_LIMIT, CFE_SB_LOCAL));
2356+
/* Subscribe to message: LOCAL */
2357+
ASSERT(CFE_SB_SubscribeFull(MsgId, PipeId, Quality, CFE_PLATFORM_SB_DEFAULT_MSG_LIMIT, CFE_SB_LOCAL));
23852358

2386-
EVTCNT(8);
2359+
EVTCNT(8);
23872360

2388-
EVTSENT(CFE_SB_SUBSCRIPTION_RPT_EID);
2361+
EVTSENT(CFE_SB_SUBSCRIPTION_RPT_EID);
23892362

2390-
/* Disable subscription reporting */
2391-
CFE_SB_SetSubscriptionReporting(CFE_SB_DISABLE);
2363+
/* Disable subscription reporting */
2364+
CFE_SB_SetSubscriptionReporting(CFE_SB_DISABLE);
23922365

23932366
TEARDOWN(CFE_SB_DeletePipe(PipeId));
23942367

@@ -2538,22 +2511,21 @@ void Test_Unsubscribe_NoMatch(void)
25382511
{
25392512
CFE_SB_PipeId_t TestPipe;
25402513
CFE_SB_MsgId_t MsgId = SB_UT_TLM_MID;
2541-
CFE_SB_MsgRouteIdx_t Idx;
25422514
uint16 PipeDepth = 50;
25432515

2516+
/* Create pipe, subscribe, unsubscribe */
25442517
SETUP(CFE_SB_CreatePipe(&TestPipe, PipeDepth, "TestPipe"));
25452518
SETUP(CFE_SB_Subscribe(MsgId, TestPipe));
2519+
SETUP(CFE_SB_Unsubscribe(MsgId, TestPipe));
2520+
UT_ClearEventHistory();
25462521

2522+
/* Check that unsubscribe to msgid that was never subscribed reports error */
25472523
ASSERT(CFE_SB_Unsubscribe(SB_UT_TLM_MID1, TestPipe));
2524+
EVTSENT(CFE_SB_UNSUB_NO_SUBS_EID);
2525+
UT_ClearEventHistory();
25482526

2549-
/* Get index into routing table */
2550-
Idx = CFE_SB_GetRoutingTblIdx(CFE_SB_ConvertMsgIdtoMsgKey(MsgId));
2551-
CFE_SB.RoutingTbl[CFE_SB_RouteIdxToValue(Idx)].ListHeadPtr->PipeId = 1;
2552-
CFE_SB.RoutingTbl[CFE_SB_RouteIdxToValue(Idx)].ListHeadPtr->Next = NULL;
2527+
/* Check that repeated unsubscribe to msgid that was subscribted reports error */
25532528
ASSERT(CFE_SB_Unsubscribe(MsgId, TestPipe));
2554-
2555-
EVTCNT(7);
2556-
25572529
EVTSENT(CFE_SB_UNSUB_NO_SUBS_EID);
25582530

25592531
TEARDOWN(CFE_SB_DeletePipe(TestPipe));
@@ -2681,18 +2653,21 @@ void Test_Unsubscribe_MiddleDestWithMany(void)
26812653
*/
26822654
void Test_Unsubscribe_GetDestPtr(void)
26832655
{
2684-
CFE_SB_MsgId_t MsgId = SB_UT_CMD_MID;
2685-
CFE_SB_PipeId_t TestPipe1;
2686-
CFE_SB_PipeId_t TestPipe2;
2687-
uint16 PipeDepth = 50;
2656+
CFE_SB_MsgId_t MsgId = SB_UT_CMD_MID;
2657+
CFE_SB_PipeId_t TestPipe1;
2658+
CFE_SB_PipeId_t TestPipe2;
2659+
uint16 PipeDepth = 50;
2660+
CFE_SBR_RouteId_t RouteId;
26882661

26892662
SETUP(CFE_SB_CreatePipe(&TestPipe1, PipeDepth, "TestPipe1"));
26902663
SETUP(CFE_SB_CreatePipe(&TestPipe2, PipeDepth, "TestPipe2"));
26912664
SETUP(CFE_SB_Subscribe(MsgId, TestPipe1));
26922665
SETUP(CFE_SB_Subscribe(MsgId, TestPipe2));
26932666
SETUP(CFE_SB_Unsubscribe(MsgId, TestPipe2));
26942667

2695-
ASSERT_TRUE(CFE_SB_GetDestPtr(CFE_SB_ConvertMsgIdtoMsgKey(MsgId), TestPipe2) == NULL);
2668+
/* TODO for now just get route id and use it, will need update when stubbed */
2669+
RouteId = CFE_SBR_GetRouteId(MsgId);
2670+
ASSERT_TRUE(CFE_SB_GetDestPtr(RouteId, TestPipe2) == NULL);
26962671

26972672
EVTCNT(7);
26982673

@@ -3252,12 +3227,15 @@ void Test_SendMsg_DisabledDestination(void)
32523227
int32 PipeDepth;
32533228
CFE_MSG_Type_t Type = CFE_MSG_Type_Tlm;
32543229
CFE_MSG_Size_t Size = sizeof(TlmPkt);
3230+
CFE_SBR_RouteId_t RouteId;
32553231

32563232
PipeDepth = 2;
32573233

32583234
SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe"));
32593235
SETUP(CFE_SB_Subscribe(MsgId, PipeId));
3260-
DestPtr = CFE_SB_GetDestPtr(CFE_SB_ConvertMsgIdtoMsgKey(MsgId), PipeId);
3236+
3237+
RouteId = CFE_SBR_GetRouteId(MsgId);
3238+
DestPtr = CFE_SB_GetDestPtr(RouteId, PipeId);
32613239
DestPtr->Active = CFE_SB_INACTIVE;
32623240

32633241
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
@@ -3857,41 +3835,8 @@ void Test_SB_SpecialCases(void)
38573835
SB_UT_ADD_SUBTEST(Test_SB_SendMsgPaths_IgnoreOpt);
38583836
SB_UT_ADD_SUBTEST(Test_RcvMsg_UnsubResubPath);
38593837
SB_UT_ADD_SUBTEST(Test_MessageString);
3860-
SB_UT_ADD_SUBTEST(Test_SB_IdxPushPop);
38613838
} /* end Test_SB_SpecialCases */
38623839

3863-
/*
3864-
** Test msg key idx push pop
3865-
*/
3866-
void Test_SB_IdxPushPop()
3867-
{
3868-
int32 i;
3869-
CFE_SB_MsgRouteIdx_t Idx;
3870-
3871-
CFE_SB_InitIdxStack();
3872-
3873-
for (i = 0; i < CFE_PLATFORM_SB_MAX_MSG_IDS; i++)
3874-
{
3875-
/* Subscribe to maximum number of messages */
3876-
Idx = CFE_SB_RouteIdxPop_Unsync();
3877-
ASSERT_EQ(CFE_SB_RouteIdxToValue(Idx), i);
3878-
}
3879-
3880-
3881-
Idx = CFE_SB_RouteIdxPop_Unsync();
3882-
ASSERT_EQ(CFE_SB_RouteIdxToValue(Idx), CFE_SB_RouteIdxToValue(CFE_SB_INVALID_ROUTE_IDX));
3883-
3884-
for (i = 0; i < CFE_PLATFORM_SB_MAX_MSG_IDS; i++)
3885-
{
3886-
/* Un-subscribe from all messages */
3887-
CFE_SB_RouteIdxPush_Unsync(CFE_SB_ValueToRouteIdx(i));
3888-
}
3889-
3890-
CFE_SB_RouteIdxPush_Unsync(CFE_SB_ValueToRouteIdx(i));
3891-
3892-
3893-
} /* end Test_SB_IdxPushPop */
3894-
38953840
/*
38963841
** Test pipe creation with semaphore take and give failures
38973842
*/
@@ -4037,10 +3982,10 @@ void Test_CFE_SB_BadPipeInfo(void)
40373982

40383983

40393984
} /* end Test_CFE_SB_BadPipeInfo */
3985+
40403986
/*
40413987
** Test send housekeeping information command
40423988
*/
4043-
40443989
void Test_SB_SendMsgPaths_Nominal(void)
40453990
{
40463991
CFE_SB_CmdHdr_t NoParamCmd;
@@ -4062,12 +4007,17 @@ void Test_SB_SendMsgPaths_Nominal(void)
40624007
MsgId = CFE_SB_ValueToMsgId(CFE_SB_SEND_HK_MID);
40634008
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
40644009

4010+
/* Repress sending the no subscriptions event and process request */
4011+
CFE_SB.HKTlmMsg.Payload.NoSubscribersCounter = 0;
40654012
CFE_SB.CmdPipePktPtr = (CFE_SB_MsgPtr_t) &NoParamCmd;
40664013
CFE_SB.StopRecurseFlags[1] |= CFE_BIT(CFE_SB_SEND_NO_SUBS_EID_BIT);
40674014
CFE_SB_ProcessCmdPipePkt();
40684015

4016+
/* The no subs event should not be in history but count should increment */
40694017
ASSERT_TRUE(!UT_EventIsInHistory(CFE_SB_SEND_NO_SUBS_EID));
4018+
ASSERT_EQ(CFE_SB.HKTlmMsg.Payload.NoSubscribersCounter, 1);
40704019

4020+
/* Repress get buffer error */
40714021
CFE_SB.HKTlmMsg.Payload.MsgSendErrorCounter = 0;
40724022
CFE_SB.StopRecurseFlags[1] |= CFE_BIT(CFE_SB_GET_BUF_ERR_EID_BIT);
40734023

@@ -4081,7 +4031,6 @@ void Test_SB_SendMsgPaths_Nominal(void)
40814031
MsgId = CFE_SB_ValueToMsgId(CFE_SB_SEND_HK_MID);
40824032
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false);
40834033

4084-
CFE_SB.MsgMap[CFE_SB_MsgKeyToValue(CFE_SB_ConvertMsgIdtoMsgKey(CFE_SB_HK_TLM_MID))] = CFE_SB_INVALID_ROUTE_IDX;
40854034
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 1, CFE_ES_ERR_MEM_BLOCK_SIZE);
40864035
CFE_SB_ProcessCmdPipePkt();
40874036
ASSERT_EQ(CFE_SB.HKTlmMsg.Payload.MsgSendErrorCounter, 0);

0 commit comments

Comments
 (0)