Skip to content

Commit

Permalink
Fix #415: Separate the CFE stubs from UT test cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jphickey committed Nov 21, 2019
1 parent 5d7d766 commit de7c761
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 336 deletions.
5 changes: 5 additions & 0 deletions cmake/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 49 additions & 40 deletions fsw/cfe-core/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_OBJECTS:ut_cfe_${MODULE}_object>)

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})
Expand Down
160 changes: 0 additions & 160 deletions fsw/cfe-core/unit-test/ut_arinc653_stubs.c

This file was deleted.

61 changes: 0 additions & 61 deletions fsw/cfe-core/unit-test/ut_arinc653_stubs.h

This file was deleted.

Loading

0 comments on commit de7c761

Please sign in to comment.