diff --git a/cmake/arch_build.cmake b/cmake/arch_build.cmake index 9569956bb..9917af106 100644 --- a/cmake/arch_build.cmake +++ b/cmake/arch_build.cmake @@ -429,6 +429,11 @@ function(process_arch SYSVAR) message(STATUS "Building App: ${APP} install=${APP_INSTALL_LIST}") add_subdirectory(${${APP}_MISSION_DIR} apps/${APP}) endforeach() + + # If unit test is enabled, build a generic ut stub library for CFE + if (ENABLE_UNIT_TESTS) + add_subdirectory(${cfe-core_MISSION_DIR}/ut-stubs ut_cfe_core_stubs) + endif (ENABLE_UNIT_TESTS) # Process each target that shares this system architecture # Second Pass: Build cfe-core and link final target executable diff --git a/fsw/cfe-core/unit-test/CMakeLists.txt b/fsw/cfe-core/unit-test/CMakeLists.txt index fbab718f2..4949e7846 100644 --- a/fsw/cfe-core/unit-test/CMakeLists.txt +++ b/fsw/cfe-core/unit-test/CMakeLists.txt @@ -7,56 +7,65 @@ # ################################################################## -add_definitions(-DCFE_LINUX) include_directories(${osal_MISSION_DIR}/ut_assert/inc) -# The parent build may have specified extra C flags for use when unit testing -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${UT_C_FLAGS}") +# allow direct inclusion of module-private header files by UT code +# NOTE: this should be minimized and moved to a more targeted +# approach, where only each specific UT module does this. +include_directories( + ${cfe-core_MISSION_DIR}/src/es + ${cfe-core_MISSION_DIR}/src/evs + ${cfe-core_MISSION_DIR}/src/sb + ${cfe-core_MISSION_DIR}/src/tbl + ${cfe-core_MISSION_DIR}/src/time + ${cfe-core_MISSION_DIR}/src/fs +) -# Because the object code is dependent on settings in cfe_platform_cfg.h, -# we must include the LIBNAME in all binary targets, as they must be rebuilt -# for each different platform config. -set (STUBNAME stub) -if (CFE_CORE_TARGET) - set(STUBNAME "${CFE_CORE_TARGET}_${STUBNAME}") -endif (CFE_CORE_TARGET) - -set(STUBFILES configdata osprintf ${CFE_CORE_MODULES}) - -# Allow direct inclusion of all private CFE header files -foreach(MODULE ${CFE_CORE_MODULES}) - get_filename_component(CFEDIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/${MODULE} ABSOLUTE) - if (IS_DIRECTORY "${CFEDIR}") - include_directories(${CFEDIR}) - endif() -endforeach() - -set(CFE_MODULE_FILES) -foreach(MODULE ${CFE_CORE_MODULES}) - list(APPEND CFE_MODULE_FILES ut_${MODULE}_stubs.c) -endforeach(MODULE ${CFE_CORE_MODULES}) - -# -# Create the generic stubs library that ANY other UT target can link to -# to provide stubs for all CFE API calls. -# -add_library(ut_${CFE_CORE_TARGET}_stubs STATIC ${CFE_MODULE_FILES}) +# CFE needs a supplemental test support hook library +add_library(ut_${CFE_CORE_TARGET}_support STATIC + ut_support.c + ut_osprintf_stubs.c +) # For each core module, generate the associated unit test # This is done by linking the stubs of every OTHER module with the # UT version of the real module (compiled with coverage flags) foreach(MODULE ${CFE_CORE_MODULES}) - set(CFE_MODULE_FILES - ut_support.c - ut_osprintf_stubs.c) - aux_source_directory(../src/${MODULE} CFE_MODULE_FILES) - aux_source_directory(../src/shared CFE_MODULE_FILES) - add_executable(${CFE_CORE_TARGET}_${MODULE}_UT ${MODULE}_UT.c ${CFE_MODULE_FILES}) + + set(CFE_MODULE_FILES) + aux_source_directory(${cfe-core_MISSION_DIR}/src/${MODULE} CFE_MODULE_FILES) + + # Compile the unit(s) under test as an object library + # this allows easy configuration of special flags and include paths + # in particular this should use the UT_C_FLAGS for coverage instrumentation + add_library(ut_cfe_${MODULE}_object OBJECT + ${CFE_MODULE_FILES}) + + # Apply the UT_C_FLAGS to the units under test + # This should enable coverage analysis on platforms that support this + set_target_properties(ut_cfe_${MODULE}_object PROPERTIES + COMPILE_FLAGS "${UT_C_FLAGS}") + + # For this object target only, the "override" includes should be injected + # into the include path BEFORE any other include path. This is so the + # override will take precedence over any system-provided version. + target_include_directories(ut_cfe_${MODULE}_object BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/modules/inc/overrides) + + add_executable(${CFE_CORE_TARGET}_${MODULE}_UT + ${MODULE}_UT.c + $) + target_link_libraries(${CFE_CORE_TARGET}_${MODULE}_UT - ut_${CFE_CORE_TARGET}_stubs - ut_psp-${CFE_SYSTEM_PSPNAME}_stubs - ut_osapi_stubs + ut_${CFE_CORE_TARGET}_support + ut_cfe-core_stubs ut_bsp) + + # Also add the C FLAGS to the link command + # This should enable coverage analysis on platforms that support this + set_target_properties(${CFE_CORE_TARGET}_${MODULE}_UT PROPERTIES + LINK_FLAGS "${UT_C_FLAGS}") + add_test(${CFE_CORE_TARGET}_${MODULE}_UT ${CFE_CORE_TARGET}_${MODULE}_UT) install(TARGETS ${CFE_CORE_TARGET}_${MODULE}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) endforeach(MODULE ${CFE_CORE_MODULES}) diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index ed5799516..bef9d6f9f 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -10416,10 +10416,10 @@ void Test_RcvMsg_UnsubResubPath(void) */ void Test_MessageString(void) { - char *SrcString = "abcdefg"; + const char *SrcString = "abcdefg"; char DestString[20]; char *DestStringPtr = DestString; - char *DefString = "default"; + const char *DefString = "default"; SB_ResetUnitTest(); diff --git a/fsw/cfe-core/unit-test/ut_arinc653_stubs.c b/fsw/cfe-core/unit-test/ut_arinc653_stubs.c deleted file mode 100644 index c8f548ca5..000000000 --- a/fsw/cfe-core/unit-test/ut_arinc653_stubs.c +++ /dev/null @@ -1,160 +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. -*/ - -/* -** File: ut_arinc653_stubs.c -** -** Purpose: -** Unit test stubs for ARINC653 routines -** -** Notes: -** Minimal work is done, only what is required for unit testing -** -*/ -/* Define CFE_ARINC653 when compiling using the ARINC653 version of the cFE */ -#ifdef CFE_ARINC653 - -/* -** Includes -*/ -#include "ut_stubs.h" -#include "ut_arinc653_stubs.h" -#include "common_types.h" - -#ifndef CFE_LINUX -#include -#endif - -/* -** Global variables -*/ -int32 UT_LibInitRtn; - -/* -** Functions -*/ -/* -** Set the library initialization return code -*/ -void UT_SetLibInitRtn(int32 LibInitRtn) -{ - UT_LibInitRtn = LibInitRtn; -} - -/* -** Return the library initialization return code -*/ -uint32 UT_LibInit(void) -{ - return UT_LibInitRtn; -} - -/* -** CFS Library Initialization Routine -*/ -int32 CFS_LibInit(void) -{ - return CFE_SUCCESS; -} - -/* -** Initializes the SCH Library -*/ -int32 SCH_LibInit(void) -{ - return CFE_SUCCESS; -} - -/* -** Initialize the Scheduler CFS application -*/ -int32 SCH_AppInit(void) -{ - return CFE_SUCCESS; -} - -/* -** CFS Scheduler (SCH) Application Entry Point -*/ -void SCH_AppMain(void) -{ -} - -/* -** Initialize the housekeeping application -*/ -int32 HK_AppInit(void) -{ - return CFE_SUCCESS; -} - -/* -** CFS Housekeeping (HK) application entry point -*/ -void HK_AppMain(void) -{ -} - -/* -** CI initialization -*/ -int32 CI_TaskInit(void) -{ - return CFE_SUCCESS; -} - -/* -** Application entry point and main process loop -*/ -void CI_AppMain(void) -{ -} - -/* -** TO initialization -*/ -int32 TO_init(void) -{ - return CFE_SUCCESS; -} - -/* -** Application entry point and main process loop -*/ -void TO_AppMain(void) -{ -} - -/* -** Initialize all data used by SBN653 application -*/ -int32 SBN653_InitApp(void) -{ - return CFE_SUCCESS; -} - -/* -** SBN653 application's entry point and main loop -*/ -void SBN653_AppMain(void) -{ -} - -#endif diff --git a/fsw/cfe-core/unit-test/ut_arinc653_stubs.h b/fsw/cfe-core/unit-test/ut_arinc653_stubs.h deleted file mode 100644 index e9d007252..000000000 --- a/fsw/cfe-core/unit-test/ut_arinc653_stubs.h +++ /dev/null @@ -1,61 +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. -*/ - -#ifndef __UT_ARINC653_STUBS_H_ -#define __UT_ARINC653_STUBS_H_ - -#ifdef CFE_ARINC653 -/*****************************************************************************/ -/** -** \brief Set the library initialization return code -** -** \par Description -** Set the library initialization return code. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \param[in] LibInitRtn Library init return code -** -** \returns -** This function does not return a value. -** -******************************************************************************/ -void UT_SetLibInitRtn(int32 LibInitRtn); - -/*****************************************************************************/ -/** -** \brief Return the library initialization return code -** -** \par Description -** Return the library initialization return code. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \returns -** Returns the library initialization return code. -** -******************************************************************************/ -uint32 UT_LibInit(void); - -#endif - -#endif /* __UT_ARINC653_STUBS_H_ */ diff --git a/fsw/cfe-core/unit-test/ut_configdata_stubs.c b/fsw/cfe-core/unit-test/ut_configdata_stubs.c deleted file mode 100644 index c7ec2705e..000000000 --- a/fsw/cfe-core/unit-test/ut_configdata_stubs.c +++ /dev/null @@ -1,60 +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. -*/ - -/* -** Purpose: -** Unit test stub for Configuration Data structure -** -*/ - -/* -** Includes -*/ -#include -#include "cfe.h" -#include "osapi.h" - -#include - -Target_PspConfigData GLOBAL_PSP_CONFIGDATA = { 0 }; -Target_CfeConfigData GLOBAL_CFE_CONFIGDATA = { 0 }; - -/** - * Instantiation of global system-wide configuration struct - * This contains build info plus pointers to the PSP and CFE - * configuration structures. Everything will be linked together - * in the final executable. - */ -Target_ConfigData GLOBAL_CONFIGDATA = -{ - .MissionVersion = "MissionUnitTest", - .CfeVersion = "CfeUnitTest", - .OsalVersion = "OsalUnitTest", - .Config = "MissionConfig", - .Date = "MissionBuildDate", - .User = "MissionBuildUser", - .Default_CpuName = "UnitTestCpu", - .Default_CpuId = 1, - .Default_SpacecraftId = 42, - .CfeConfig = &GLOBAL_CFE_CONFIGDATA, - .PspConfig = &GLOBAL_PSP_CONFIGDATA -}; - - diff --git a/fsw/cfe-core/unit-test/ut_support.c b/fsw/cfe-core/unit-test/ut_support.c index 5059ac584..00ecfbf48 100644 --- a/fsw/cfe-core/unit-test/ut_support.c +++ b/fsw/cfe-core/unit-test/ut_support.c @@ -149,16 +149,6 @@ void UT_InitData(void) */ UT_SetCDSSize(UT_LastCDSSize); - /* - * NOTE: The CDS is not wiped as part of the reset operations - * because some test sequences rely on this being persistent. - * - * Test cases that want to clear CDS should use UT_ResetCDS() - */ -#ifdef UT_RESET_CDS - memset(UT_CDS_Data, 0xEE, sizeof(UT_CDS_Data)); -#endif - /* * Set up for the CFE_SB_RcvMsg() call. * @@ -206,9 +196,6 @@ void UT_ResetPoolBufferIndex(void) * Set the whole memory space to a pattern. */ UT_ResetState(UT_KEY(CFE_ES_GetPoolBuf)); -#ifdef UT_CLEAR_MEMORY_POOL - memset(&UT_CFE_ES_MemoryPool, 0xAA, sizeof(UT_CFE_ES_MemoryPool)); -#endif UT_SetDataBuffer(UT_KEY(CFE_ES_GetPoolBuf), &UT_CFE_ES_MemoryPool, sizeof(UT_CFE_ES_MemoryPool), false); } diff --git a/fsw/cfe-core/ut-stubs/CMakeLists.txt b/fsw/cfe-core/ut-stubs/CMakeLists.txt new file mode 100644 index 000000000..f11209015 --- /dev/null +++ b/fsw/cfe-core/ut-stubs/CMakeLists.txt @@ -0,0 +1,33 @@ +################################################################## +# +# cFE stub function build recipe +# +# This CMake file contains the recipe for building the stub function +# libraries that correlate with the CFE public API. This library supports +# unit testing of OTHER modules, where the test cases for those modules +# are linked with the stubs supplied here, rather than the normal CFE. +# +################################################################## + +# Reference the UT assert include directory +include_directories(${osal_MISSION_DIR}/ut_assert/inc) + +# +# Create the generic stubs library +# +add_library(ut_cfe-core_stubs STATIC + ut_es_stubs.c + ut_evs_stubs.c + ut_sb_stubs.c + ut_tbl_stubs.c + ut_time_stubs.c + ut_fs_stubs.c) + +# linking with the CFE stubs implies also linking +# with the OSAL and PSP stubs. This is in line with +# how the real application is linked, in that cfe-core +# executable also provides OSAL and PSP functions. +target_link_libraries(ut_cfe-core_stubs + ut_psp-${CFE_SYSTEM_PSPNAME}_stubs + ut_osapi_stubs +) diff --git a/fsw/cfe-core/unit-test/ut_es_stubs.c b/fsw/cfe-core/ut-stubs/ut_es_stubs.c similarity index 100% rename from fsw/cfe-core/unit-test/ut_es_stubs.c rename to fsw/cfe-core/ut-stubs/ut_es_stubs.c diff --git a/fsw/cfe-core/unit-test/ut_evs_stubs.c b/fsw/cfe-core/ut-stubs/ut_evs_stubs.c similarity index 100% rename from fsw/cfe-core/unit-test/ut_evs_stubs.c rename to fsw/cfe-core/ut-stubs/ut_evs_stubs.c diff --git a/fsw/cfe-core/unit-test/ut_fs_stubs.c b/fsw/cfe-core/ut-stubs/ut_fs_stubs.c similarity index 100% rename from fsw/cfe-core/unit-test/ut_fs_stubs.c rename to fsw/cfe-core/ut-stubs/ut_fs_stubs.c diff --git a/fsw/cfe-core/unit-test/ut_sb_stubs.c b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c similarity index 100% rename from fsw/cfe-core/unit-test/ut_sb_stubs.c rename to fsw/cfe-core/ut-stubs/ut_sb_stubs.c diff --git a/fsw/cfe-core/unit-test/ut_tbl_stubs.c b/fsw/cfe-core/ut-stubs/ut_tbl_stubs.c similarity index 92% rename from fsw/cfe-core/unit-test/ut_tbl_stubs.c rename to fsw/cfe-core/ut-stubs/ut_tbl_stubs.c index fc3092d5b..fc57a0501 100644 --- a/fsw/cfe-core/unit-test/ut_tbl_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_tbl_stubs.c @@ -150,3 +150,20 @@ UT_DEFAULT_STUB(CFE_TBL_DumpToBuffer, ( CFE_TBL_Handle_t TblHandle )) UT_DEFAULT_STUB(CFE_TBL_Validate, ( CFE_TBL_Handle_t TblHandle )) UT_DEFAULT_STUB(CFE_TBL_Update, ( CFE_TBL_Handle_t TblHandle )) + +int32 CFE_TBL_GetInfo( CFE_TBL_Info_t *TblInfoPtr, const char *TblName ) +{ + int32 status; + + status = UT_DEFAULT_IMPL(CFE_TBL_GetInfo); + if (status >= 0 && + UT_Stub_CopyToLocal(UT_KEY(CFE_TBL_GetInfo), TblInfoPtr, sizeof(*TblInfoPtr)) < sizeof(*TblInfoPtr)) + { + /* just clear the output struct */ + memset(TblInfoPtr, 0, sizeof(*TblInfoPtr)); + } + + return status; +} + + diff --git a/fsw/cfe-core/unit-test/ut_time_stubs.c b/fsw/cfe-core/ut-stubs/ut_time_stubs.c similarity index 99% rename from fsw/cfe-core/unit-test/ut_time_stubs.c rename to fsw/cfe-core/ut-stubs/ut_time_stubs.c index 8e2ef8682..b960487ab 100644 --- a/fsw/cfe-core/unit-test/ut_time_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_time_stubs.c @@ -32,10 +32,9 @@ /* ** Includes */ +#include #include #include "cfe_time.h" -#include "cfe_time_utils.h" -#include "ut_support.h" #include "utstubs.h" /*