diff --git a/modules/sbr/unit-test-coverage/CMakeLists.txt b/modules/sbr/unit-test-coverage/CMakeLists.txt index dd51524cd..95b22232e 100644 --- a/modules/sbr/unit-test-coverage/CMakeLists.txt +++ b/modules/sbr/unit-test-coverage/CMakeLists.txt @@ -7,26 +7,34 @@ # ################################################################## +# Set tests once so name changes are in one location +set(SBR_TEST_MAP_DIRECT "sbr_map_direct") +set(SBR_TEST_MAP_HASH "sbr_map_hash") +set(SBR_TEST_ROUTE_UNSORTED "sbr_route_unsorted") + # All coverage tests always built -set(SBR_TEST_SET "map_direct" "map_hash" "route_unsorted") +set(SBR_TEST_SET ${SBR_TEST_MAP_DIRECT} ${SBR_TEST_MAP_HASH} ${SBR_TEST_ROUTE_UNSORTED}) # Add configured map implementation to routing test source if (MISSION_MSGMAP_IMPLEMENTATION STREQUAL "DIRECT") - set(route_unsorted_SRC test_cfe_sbr_map_direct.c) + set(${SBR_TEST_ROUTE_UNSORTED}_SRC ../src/cfe_sbr_map_direct.c) elseif (MISSION_MSGMAP_IMPLEMENTATION STREQUAL "HASH") - set(route_unsorted_SRC test_cfe_sbr_map_hash.c) + set(${SBR_TEST_ROUTE_UNSORTED}_SRC ../src/cfe_sbr_map_hash.c) endif() +# Add route implementation to map hash +set(${SBR_TEST_MAP_HASH}_SRC ../src/cfe_sbr_route_unsorted.c) + foreach(SBR_TEST ${SBR_TEST_SET}) # Unit test object library sources, options, and includes - add_library(ut_${SBR_TEST}_objs OBJECT ${${SBR_TEST}_SRC} cfe_sbr_${SBR_TEST}.c) + add_library(ut_${SBR_TEST}_objs OBJECT ${${SBR_TEST}_SRC} ../src/cfe_${SBR_TEST}.c) target_compile_options(ut_${SBR_TEST}_objs PRIVATE ${UT_COVERAGE_COMPILE_FLAGS}) target_include_directories(ut_${SBR_TEST}_objs PRIVATE $) set (ut_${SBR_TEST}_tests - test_cfe_sbr_${SBR_TEST}.c + test_cfe_${SBR_TEST}.c $) # Add executable diff --git a/modules/sbr/unit-test-coverage/sbr_UT.c b/modules/sbr/unit-test-coverage/sbr_UT.c deleted file mode 100644 index e27cf4839..000000000 --- a/modules/sbr/unit-test-coverage/sbr_UT.c +++ /dev/null @@ -1,51 +0,0 @@ -/* -** GSC-18128-1, "Core Flight Executive Version 6.7" -** -** Copyright (c) 2006-2019 United States Government as represented by -** the Administrator of the National Aeronautics and Space Administration. -** All Rights Reserved. -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -/* - * Software bus routing unit tests - */ - -/* - * Includes - */ -#include "utassert.h" -#include "ut_support.h" -#include "test_cfe_sbr_map.h" - -/* - * Functions - */ -void UtTest_Setup(void) -{ - UT_Init("sbr"); - UtPrintf("Software Bus Routing coverage test..."); - - UT_ADD_TEST(Test_SBR_Map); - -/* TODO clean - Test_MSG_CCSDSPri(); - Test_MSG_CCSDSExt(); - Test_MSG_MsgId_Shared(); - UT_ADD_TEST(Test_MSG_MsgId); - UT_ADD_TEST(Test_MSG_Checksum); - UT_ADD_TEST(Test_MSG_FcnCode); - UT_ADD_TEST(Test_MSG_Time); -*/ -} diff --git a/modules/sbr/unit-test-coverage/test_cfe_sbr_map.h b/modules/sbr/unit-test-coverage/test_cfe_sbr_map.h deleted file mode 100644 index 1f650c686..000000000 --- a/modules/sbr/unit-test-coverage/test_cfe_sbr_map.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -** GSC-18128-1, "Core Flight Executive Version 6.7" -** -** Copyright (c) 2006-2019 United States Government as represented by -** the Administrator of the National Aeronautics and Space Administration. -** All Rights Reserved. -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -/* - * Software bus routing map test header - */ -#ifndef TEST_CFE_SBR_MAP_H_ -#define TEST_CFE_SBR_MAP_H_ - -/* - * Functions - */ - -void Test_SBR_Map(void); - -#endif /* TEST_CFE_SBR_MAP_H_ */ diff --git a/modules/sbr/unit-test-coverage/test_cfe_sbr_map_direct.c b/modules/sbr/unit-test-coverage/test_cfe_sbr_map_direct.c index 803525a22..32d27c3f7 100644 --- a/modules/sbr/unit-test-coverage/test_cfe_sbr_map_direct.c +++ b/modules/sbr/unit-test-coverage/test_cfe_sbr_map_direct.c @@ -29,14 +29,16 @@ #include "ut_support.h" #include "private/cfe_sbr.h" #include "cfe_sbr_priv.h" +#include void Test_SBR_Map_Direct(void) { - CFE_SB_MsgId_Atom_t idx; + CFE_SB_MsgId_Atom_t msgidx; CFE_SBR_RouteId_t routeid; CFE_SB_MsgId_t msgid; - uint32 invalidcnt; + uint32 count; + uint32 i; UtPrintf("Invalid msg checks"); ASSERT_EQ(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0); @@ -49,15 +51,15 @@ void Test_SBR_Map_Direct(void) UT_SetForceFail(UT_KEY(CFE_SB_IsValidMsgId), true); UtPrintf("Check that all entries are set invalid"); - invalidcnt = 0; - for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++) + count = 0; + for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++) { - if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx)))) + if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx)))) { - invalidcnt++; + count++; } } - ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1); + ASSERT_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); @@ -71,21 +73,32 @@ void Test_SBR_Map_Direct(void) ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId); UtPrintf("Check there is now 1 valid entry in map"); - invalidcnt = 0; - for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++) + count = 0; + for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++) { - if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx)))) + if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx)))) { - invalidcnt++; + count++; } } - ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); + ASSERT_EQ(count, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); UtPrintf("Set back to invalid and check again"); routeid = CFE_SBR_INVALID_ROUTE_ID; ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0); ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId); ASSERT_EQ(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(msgid)), false); + + /* Performance check, 0xFFFFFF on 3.2GHz linux box is around 8-9 seconds */ + count = 0; + for (i = 0; i <= 0xFFFF; i++) + { + msgidx = rand() % CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; + if (CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx)))) + { + count++; + } + } } /* Main unit test routine */ diff --git a/modules/sbr/unit-test-coverage/test_cfe_sbr_map_hash.c b/modules/sbr/unit-test-coverage/test_cfe_sbr_map_hash.c index b04aeae18..f589967ed 100644 --- a/modules/sbr/unit-test-coverage/test_cfe_sbr_map_hash.c +++ b/modules/sbr/unit-test-coverage/test_cfe_sbr_map_hash.c @@ -29,7 +29,6 @@ #include "ut_support.h" #include "private/cfe_sbr.h" #include "cfe_sbr_priv.h" -#include "test_cfe_sbr_map.h" /* * Defines @@ -50,60 +49,69 @@ CFE_SB_MsgId_t Test_SBR_Unhash(CFE_SB_MsgId_Atom_t Hash) { return CFE_SB_ValueToMsgId(Hash); } -void Test_SBR_Map(void) +void Test_SBR_Map_Hash(void) { - CFE_SB_MsgId_Atom_t idx; - CFE_SBR_RouteId_t routeid; - CFE_SB_MsgId_t msgid; - uint32 invalidcnt; + CFE_SB_MsgId_Atom_t msgidx; + CFE_SBR_RouteId_t routeid[3]; + CFE_SB_MsgId_t msgid[3]; + uint32 count; + uint32 collisions; UtPrintf("Invalid msg checks"); ASSERT_EQ(CFE_SBR_SetRouteId(CFE_SB_ValueToMsgId(0), CFE_SBR_ValueToRouteId(0)), 0); ASSERT_EQ(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(0))), false); - UtPrintf("Initialize map"); - CFE_SBR_Init_Map(); + UtPrintf("Initialize routing and map"); + CFE_SBR_Init(); /* Force valid msgid responses */ UT_SetForceFail(UT_KEY(CFE_SB_IsValidMsgId), true); UtPrintf("Check that all entries are set invalid"); - invalidcnt = 0; - for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++) + count = 0; + for (msgidx = 0; msgidx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; msgidx++) { - if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx)))) + if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx)))) { - invalidcnt++; + count++; } } - ASSERT_EQ(invalidcnt, 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); - ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0); - ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId); - - routeid = CFE_SBR_ValueToRouteId(0); - msgid = CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); - ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0); - ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId); - - UtPrintf("Check there is now 1 valid entry in map"); - invalidcnt = 0; - for (idx = 0; idx <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; idx++) + ASSERT_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); + ASSERT_EQ(collisions, 0); + routeid[1] = CFE_SBR_AddRoute(msgid[1], &collisions); + ASSERT_EQ(collisions, 0); + routeid[2] = CFE_SBR_AddRoute(msgid[2], &collisions); + ASSERT_EQ(collisions, 2); + + ASSERT_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[0])), CFE_SBR_RouteIdToValue(routeid[0])); + ASSERT_EQ(CFE_SBR_RouteIdToValue(CFE_SBR_GetRouteId(msgid[1])), CFE_SBR_RouteIdToValue(routeid[1])); + ASSERT_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; + for (msgidx = 0; msgidx <= 0xFFFF; msgidx++) { - if (!CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(idx)))) + if (CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(CFE_SB_ValueToMsgId(msgidx)))) { - invalidcnt++; + count++; } } - ASSERT_EQ(invalidcnt, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); +} + +/* Main unit test routine */ +void UtTest_Setup(void) +{ + UT_Init("map_hash"); + UtPrintf("Software Bus Routing hash map coverage test..."); - UtPrintf("Set back to invalid and check again"); - routeid = CFE_SBR_INVALID_ROUTE_ID; - ASSERT_EQ(CFE_SBR_SetRouteId(msgid, routeid), 0); - ASSERT_EQ(CFE_SBR_GetRouteId(msgid).RouteId, routeid.RouteId); - ASSERT_EQ(CFE_SBR_IsValidRouteId(CFE_SBR_GetRouteId(msgid)), false); + UT_ADD_TEST(Test_SBR_Map_Hash); } + diff --git a/modules/sbr/unit-test-coverage/test_cfe_sbr_route.h b/modules/sbr/unit-test-coverage/test_cfe_sbr_route.h deleted file mode 100644 index 70405ad65..000000000 --- a/modules/sbr/unit-test-coverage/test_cfe_sbr_route.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -** GSC-18128-1, "Core Flight Executive Version 6.7" -** -** Copyright (c) 2006-2019 United States Government as represented by -** the Administrator of the National Aeronautics and Space Administration. -** All Rights Reserved. -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -/* - * Software bus routing test header - */ -#ifndef TEST_CFE_SBR_ROUTE_H_ -#define TEST_CFE_SBR_ROUTE_H_ - -/* - * Functions - */ - -void Test_SBR_Route(void); - -#endif /* TEST_CFE_SBR_ROUTE_H_ */ diff --git a/modules/sbr/unit-test-coverage/test_cfe_sbr_route_unsorted.c b/modules/sbr/unit-test-coverage/test_cfe_sbr_route_unsorted.c index e59fdbda5..9028a4c5f 100644 --- a/modules/sbr/unit-test-coverage/test_cfe_sbr_route_unsorted.c +++ b/modules/sbr/unit-test-coverage/test_cfe_sbr_route_unsorted.c @@ -29,9 +29,8 @@ #include "ut_support.h" #include "private/cfe_sbr.h" #include "cfe_sbr_priv.h" -#include "test_cfe_sbr_route.h" -void Test_SBR_Route(void) +void Test_SBR_Route_Unsort(void) { /* TODO @@ -102,3 +101,13 @@ void CFE_SBR_ForEachRouteId(CFE_SBR_CallbackPtr_t CallbackPtr, void *ArgPtr, CFE #endif } + +/* Main unit test routine */ +void UtTest_Setup(void) +{ + UT_Init("route_unsort"); + UtPrintf("Software Bus Routing unsorted coverage test..."); + + UT_ADD_TEST(Test_SBR_Route_Unsort); +} +