From de7c761caf77d2d2924b3266d69bc84dedac0751 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 21 Nov 2019 09:52:39 -0500 Subject: [PATCH] Fix #415: Separate the CFE stubs from UT test cases Build the CFE UT stub library separately from the test cases. This moves the stub files into a separate ut-stubs directory, and the library is now called "ut_cfe_core_stubs" Note: Minor cleanup also done as part of moving. Two stub files were in the source tree but not being built or used by any framework test config. These were: ut_arinc653_stubs.c ut_configdata_stubs.c These are now removed. Also cleaned up some old macros/ifdefs that were never enabled or used in the current tests. --- cmake/arch_build.cmake | 5 + fsw/cfe-core/unit-test/CMakeLists.txt | 89 +++++----- fsw/cfe-core/unit-test/ut_arinc653_stubs.c | 160 ------------------ fsw/cfe-core/unit-test/ut_arinc653_stubs.h | 61 ------- fsw/cfe-core/unit-test/ut_configdata_stubs.c | 60 ------- fsw/cfe-core/unit-test/ut_support.c | 13 -- fsw/cfe-core/ut-stubs/CMakeLists.txt | 33 ++++ .../{unit-test => ut-stubs}/ut_es_stubs.c | 0 .../{unit-test => ut-stubs}/ut_evs_stubs.c | 0 .../{unit-test => ut-stubs}/ut_fs_stubs.c | 0 .../{unit-test => ut-stubs}/ut_sb_stubs.c | 0 .../{unit-test => ut-stubs}/ut_tbl_stubs.c | 17 ++ .../{unit-test => ut-stubs}/ut_time_stubs.c | 3 +- 13 files changed, 105 insertions(+), 336 deletions(-) delete mode 100644 fsw/cfe-core/unit-test/ut_arinc653_stubs.c delete mode 100644 fsw/cfe-core/unit-test/ut_arinc653_stubs.h delete mode 100644 fsw/cfe-core/unit-test/ut_configdata_stubs.c create mode 100644 fsw/cfe-core/ut-stubs/CMakeLists.txt rename fsw/cfe-core/{unit-test => ut-stubs}/ut_es_stubs.c (100%) rename fsw/cfe-core/{unit-test => ut-stubs}/ut_evs_stubs.c (100%) rename fsw/cfe-core/{unit-test => ut-stubs}/ut_fs_stubs.c (100%) rename fsw/cfe-core/{unit-test => ut-stubs}/ut_sb_stubs.c (100%) rename fsw/cfe-core/{unit-test => ut-stubs}/ut_tbl_stubs.c (92%) rename fsw/cfe-core/{unit-test => ut-stubs}/ut_time_stubs.c (99%) diff --git a/cmake/arch_build.cmake b/cmake/arch_build.cmake index e2bce98d9..6d9b3d40a 100644 --- a/cmake/arch_build.cmake +++ b/cmake/arch_build.cmake @@ -425,6 +425,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/ut_arinc653_stubs.c b/fsw/cfe-core/unit-test/ut_arinc653_stubs.c deleted file mode 100644 index c83d0eb31..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.6" -** -** 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 22c70c12f..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.6" -** -** 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 7b19fc23d..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.6" -** -** 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 39179e9d3..d5f5c1130 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 acb6db037..a97fcd7bb 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 8dba04fd0..b4ee78727 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" /*