Skip to content

Commit

Permalink
Fix #305, do not override add_psp_module for coverage test
Browse files Browse the repository at this point in the history
Implements a differently-named function instead, which does mostly the same thing,
but does not directly re-add the original subdirectory.  This does repeat some
info (e.g. the list of FSW source files) that was not repeated otherwise, but
it works in general.
  • Loading branch information
jphickey committed Sep 3, 2021
1 parent 6d40816 commit 3d2624b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
39 changes: 20 additions & 19 deletions unit-test-coverage/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@
#
######################################################################

include_directories("${PSPCOVERAGE_SOURCE_DIR}/shared/inc")
include_directories("${PSPCOVERAGE_SOURCE_DIR}/modules/inc")

# redefine the add_psp_module to make a unit test variant
# this needs to name the target differently, so it doesn't conflict with the FSW target.
# this is similar to add_cfe_coverage_test() on the CFE side, but the set of interfaces
# and link libraries is different from that of a CFS app
function(add_psp_module MODULE_NAME)
# Function to simplify adding a coverage test for a PSP module
# This is very similar to the CFE "add_cfe_coverage" function, but
# include directories and link libraries are set up differently for PSP code,
# and it does not depend on having a FSW module by the same name.
function(add_psp_covtest MODULE_NAME TESTCASE_SRC UT_SRCS)

# A consistent name convention for all targets generated by this funtion
set(TEST_NAME "coverage-pspmod-${MODULE_NAME}")
set(OBJECT_TARGET "${TEST_NAME}-object")
set(RUNNER_TARGET "${TEST_NAME}-testrunner")
# Create the module

add_library(${OBJECT_TARGET} OBJECT ${ARGN})
# Compile the source unit(s) under test as a separate library
# This is done so that special coverage-specific compile flags can be used on these files
add_library(${OBJECT_TARGET} OBJECT
${UT_SRCS} ${ARGN}
)

# Apply the UT_COVERAGE_COMPILE_FLAGS to the units under test
# This should enable coverage analysis on platforms that support this
target_compile_options(${OBJECT_TARGET} PRIVATE
${UT_COVERAGE_COMPILE_FLAGS}
)

target_include_directories(${OBJECT_TARGET} PRIVATE
${PSPCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc # overrides for system headers
${PSPCOVERAGE_SOURCE_DIR}/shared/inc
${CFEPSP_SOURCE_DIR}/fsw/inc # PSP public API
${CFEPSP_SOURCE_DIR}/fsw/shared/inc # all PSP shared headers
${CFE_SOURCE_DIR}/cmake/target/inc # for sysconfig headers
Expand All @@ -34,7 +40,7 @@ function(add_psp_module MODULE_NAME)
# Compile a test runner application, which contains the
# actual coverage test code (test cases) and the unit under test
add_executable(${RUNNER_TARGET}
${PSPCOVERAGE_SOURCE_DIR}/modules/src/coveragetest-${MODULE_NAME}.c
${TESTCASE_SRC}
$<TARGET_OBJECTS:${OBJECT_TARGET}>
)

Expand All @@ -49,19 +55,14 @@ function(add_psp_module MODULE_NAME)
ut_assert
)

# Add it to the set of tests to run as part of "make test"
add_test(${TEST_NAME} ${RUNNER_TARGET})
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${RUNNER_TARGET} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
endforeach()

endfunction(add_psp_module)
endfunction(add_psp_covtest)

# a list of modules for which there is a coverage test implemented
set(UT_PSPMODLIST
timebase_vxworks
)

foreach(UT_PSPMOD ${UT_PSPMODLIST})
add_subdirectory(${CFEPSP_SOURCE_DIR}/fsw/modules/${UT_PSPMOD} ${UT_PSPMOD})
endforeach()

# a list of modules for which there is a coverage test implemented
add_subdirectory(timebase_vxworks)
11 changes: 11 additions & 0 deletions unit-test-coverage/modules/timebase_vxworks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
######################################################################
#
# CMAKE build recipe for white-box coverage tests of VxWorks timebase module
#
######################################################################

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")

add_psp_covtest(timebase_vxworks src/coveragetest-timebase_vxworks.c
${CFEPSP_SOURCE_DIR}/fsw/modules/timebase_vxworks/cfe_psp_timebase_vxworks.c
)

0 comments on commit 3d2624b

Please sign in to comment.