Skip to content

Commit eed8c3a

Browse files
author
Jacob Hageman
committed
WIP - unit test now multiple executables to cover all code, full coverage on msg map implementations
1 parent fafac8e commit eed8c3a

File tree

7 files changed

+93
-172
lines changed

7 files changed

+93
-172
lines changed

modules/sbr/unit-test-coverage/CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@
77
#
88
##################################################################
99

10+
# Set tests once so name changes are in one location
11+
set(SBR_TEST_MAP_DIRECT "sbr_map_direct")
12+
set(SBR_TEST_MAP_HASH "sbr_map_hash")
13+
set(SBR_TEST_ROUTE_UNSORTED "sbr_route_unsorted")
14+
1015
# All coverage tests always built
11-
set(SBR_TEST_SET "map_direct" "map_hash" "route_unsorted")
16+
set(SBR_TEST_SET ${SBR_TEST_MAP_DIRECT} ${SBR_TEST_MAP_HASH} ${SBR_TEST_ROUTE_UNSORTED})
1217

1318
# Add configured map implementation to routing test source
1419
if (MISSION_MSGMAP_IMPLEMENTATION STREQUAL "DIRECT")
15-
set(route_unsorted_SRC test_cfe_sbr_map_direct.c)
20+
set(${SBR_TEST_ROUTE_UNSORTED}_SRC ../src/cfe_sbr_map_direct.c)
1621
elseif (MISSION_MSGMAP_IMPLEMENTATION STREQUAL "HASH")
17-
set(route_unsorted_SRC test_cfe_sbr_map_hash.c)
22+
set(${SBR_TEST_ROUTE_UNSORTED}_SRC ../src/cfe_sbr_map_hash.c)
1823
endif()
1924

25+
# Add route implementation to map hash
26+
set(${SBR_TEST_MAP_HASH}_SRC ../src/cfe_sbr_route_unsorted.c)
27+
2028
foreach(SBR_TEST ${SBR_TEST_SET})
2129

2230
# Unit test object library sources, options, and includes
23-
add_library(ut_${SBR_TEST}_objs OBJECT ${${SBR_TEST}_SRC} cfe_sbr_${SBR_TEST}.c)
31+
add_library(ut_${SBR_TEST}_objs OBJECT ${${SBR_TEST}_SRC} ../src/cfe_${SBR_TEST}.c)
2432
target_compile_options(ut_${SBR_TEST}_objs PRIVATE ${UT_COVERAGE_COMPILE_FLAGS})
2533
target_include_directories(ut_${SBR_TEST}_objs PRIVATE
2634
$<TARGET_PROPERTY:${DEP},INCLUDE_DIRECTORIES>)
2735

2836
set (ut_${SBR_TEST}_tests
29-
test_cfe_sbr_${SBR_TEST}.c
37+
test_cfe_${SBR_TEST}.c
3038
$<TARGET_OBJECTS:ut_${SBR_TEST}_objs>)
3139

3240
# Add executable

modules/sbr/unit-test-coverage/sbr_UT.c

Lines changed: 0 additions & 51 deletions
This file was deleted.

modules/sbr/unit-test-coverage/test_cfe_sbr_map.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

modules/sbr/unit-test-coverage/test_cfe_sbr_map_direct.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
#include "ut_support.h"
3030
#include "private/cfe_sbr.h"
3131
#include "cfe_sbr_priv.h"
32+
#include <stdlib.h>
3233

3334
void Test_SBR_Map_Direct(void)
3435
{
3536

36-
CFE_SB_MsgId_Atom_t idx;
37+
CFE_SB_MsgId_Atom_t msgidx;
3738
CFE_SBR_RouteId_t routeid;
3839
CFE_SB_MsgId_t msgid;
39-
uint32 invalidcnt;
40+
uint32 count;
41+
uint32 i;
4042

4143
UtPrintf("Invalid msg checks");
4244
ASSERT_EQ(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0);
@@ -49,15 +51,15 @@ void Test_SBR_Map_Direct(void)
4951
UT_SetForceFail(UT_KEY(CFE_SB_IsValidMsgId), true);
5052

5153
UtPrintf("Check that all entries are set invalid");
52-
invalidcnt = 0;
53-
for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++)
54+
count = 0;
55+
for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++)
5456
{
55-
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx))))
57+
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
5658
{
57-
invalidcnt++;
59+
count++;
5860
}
5961
}
60-
ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
62+
ASSERT_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
6163

6264
UtPrintf("Set/Get a range of ids ");
6365
routeid = CFE_SBR_ValueToRouteId(CFE_PLATFORM_SB_MAX_MSG_IDS + 1);
@@ -71,21 +73,32 @@ void Test_SBR_Map_Direct(void)
7173
ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
7274

7375
UtPrintf("Check there is now 1 valid entry in map");
74-
invalidcnt = 0;
75-
for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++)
76+
count = 0;
77+
for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++)
7678
{
77-
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx))))
79+
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
7880
{
79-
invalidcnt++;
81+
count++;
8082
}
8183
}
82-
ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
84+
ASSERT_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
8385

8486
UtPrintf("Set back to invalid and check again");
8587
routeid = CFE_SBR_INVALID_ROUTE_ID;
8688
ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
8789
ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
8890
ASSERT_EQ(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(msgid)), false);
91+
92+
/* Performance check, 0xFFFFFF on 3.2GHz linux box is around 8-9 seconds */
93+
count = 0;
94+
for (i = 0; i <= 0xFFFF; i++)
95+
{
96+
msgidx = rand() % CFE_PLATFORM_SB_HIGHEST_VALID_MSGID;
97+
if (CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
98+
{
99+
count++;
100+
}
101+
}
89102
}
90103

91104
/* Main unit test routine */

modules/sbr/unit-test-coverage/test_cfe_sbr_map_hash.c

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "ut_support.h"
3030
#include "private/cfe_sbr.h"
3131
#include "cfe_sbr_priv.h"
32-
#include "test_cfe_sbr_map.h"
3332

3433
/*
3534
* Defines
@@ -50,60 +49,69 @@ CFE_SB_MsgId_t Test_SBR_Unhash(CFE_SB_MsgId_Atom_t Hash) {
5049
return CFE_SB_ValueToMsgId(Hash);
5150
}
5251

53-
void Test_SBR_Map(void)
52+
void Test_SBR_Map_Hash(void)
5453
{
5554

56-
CFE_SB_MsgId_Atom_t idx;
57-
CFE_SBR_RouteId_t routeid;
58-
CFE_SB_MsgId_t msgid;
59-
uint32 invalidcnt;
55+
CFE_SB_MsgId_Atom_t msgidx;
56+
CFE_SBR_RouteId_t routeid[3];
57+
CFE_SB_MsgId_t msgid[3];
58+
uint32 count;
59+
uint32 collisions;
6060

6161
UtPrintf("Invalid msg checks");
6262
ASSERT_EQ(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0);
6363
ASSERT_EQ(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(0))), false);
6464

65-
UtPrintf("Initialize map");
66-
CFE_SBR_Init_Map();
65+
UtPrintf("Initialize routing and map");
66+
CFE_SBR_Init();
6767

6868
/* Force valid msgid responses */
6969
UT_SetForceFail(UT_KEY(CFE_SB_IsValidMsgId), true);
7070

7171
UtPrintf("Check that all entries are set invalid");
72-
invalidcnt = 0;
73-
for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++)
72+
count = 0;
73+
for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++)
7474
{
75-
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx))))
75+
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
7676
{
77-
invalidcnt++;
77+
count++;
7878
}
7979
}
80-
ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
81-
82-
UtPrintf("Set/Get a range of ids ");
83-
routeid = CFE_SBR_ValueToRouteId(CFE_PLATFORM_SB_MAX_MSG_IDS + 1);
84-
msgid = CFE_SB_ValueToMsgId(0);
85-
ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
86-
ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
87-
88-
routeid = CFE_SBR_ValueToRouteId(0);
89-
msgid = CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
90-
ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
91-
ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
92-
93-
UtPrintf("Check there is now 1 valid entry in map");
94-
invalidcnt = 0;
95-
for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++)
80+
ASSERT_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1);
81+
82+
/* Note AddRoute required for hash logic to work since it depends on MsgId in routing table */
83+
UtPrintf("Add routes and check with a rollover and a skip");
84+
msgid[0] = CFE_SB_ValueToMsgId(0);
85+
msgid[1] = Test_SBR_Unhash(0xFFFFFFFF);
86+
msgid[2] = Test_SBR_Unhash(0x7FFFFFFF);
87+
routeid[0] = CFE_SBR_AddRoute(msgid[0], &collisions);
88+
ASSERT_EQ(collisions, 0);
89+
routeid[1] = CFE_SBR_AddRoute(msgid[1], &collisions);
90+
ASSERT_EQ(collisions, 0);
91+
routeid[2] = CFE_SBR_AddRoute(msgid[2], &collisions);
92+
ASSERT_EQ(collisions, 2);
93+
94+
ASSERT_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[0])), CFE_SBR_RouteIdToValue(routeid[0]));
95+
ASSERT_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[1])), CFE_SBR_RouteIdToValue(routeid[1]));
96+
ASSERT_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[2])), CFE_SBR_RouteIdToValue(routeid[2]));
97+
98+
/* Performance check, 0xFFFFFF on 3.2GHz linux box is around 8-9 seconds */
99+
count = 0;
100+
for (msgidx = 0; msgidx <= 0xFFFF; msgidx++)
96101
{
97-
if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx))))
102+
if (CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx))))
98103
{
99-
invalidcnt++;
104+
count++;
100105
}
101106
}
102-
ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
107+
}
108+
109+
/* Main unit test routine */
110+
void UtTest_Setup(void)
111+
{
112+
UT_Init("map_hash");
113+
UtPrintf("Software Bus Routing hash map coverage test...");
103114

104-
UtPrintf("Set back to invalid and check again");
105-
routeid = CFE_SBR_INVALID_ROUTE_ID;
106-
ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0);
107-
ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId);
108-
ASSERT_EQ(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(msgid)), false);
115+
UT_ADD_TEST(Test_SBR_Map_Hash);
109116
}
117+

modules/sbr/unit-test-coverage/test_cfe_sbr_route.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

modules/sbr/unit-test-coverage/test_cfe_sbr_route_unsorted.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
#include "ut_support.h"
3030
#include "private/cfe_sbr.h"
3131
#include "cfe_sbr_priv.h"
32-
#include "test_cfe_sbr_route.h"
3332

34-
void Test_SBR_Route(void)
33+
void Test_SBR_Route_Unsort(void)
3534
{
3635

3736
/* TODO
@@ -102,3 +101,13 @@ void CFE_SBR_ForEachRouteId(CFE_SBR_CallbackPtr_t CallbackPtr, void *ArgPtr, CFE
102101

103102
#endif
104103
}
104+
105+
/* Main unit test routine */
106+
void UtTest_Setup(void)
107+
{
108+
UT_Init("route_unsort");
109+
UtPrintf("Software Bus Routing unsorted coverage test...");
110+
111+
UT_ADD_TEST(Test_SBR_Route_Unsort);
112+
}
113+

0 commit comments

Comments
 (0)