Skip to content

Commit e5e5219

Browse files
committed
CCB 20191218: Merge #417 #430
Fix #415, #429 Reviewed and approved at 2019-12-18 CCB
2 parents 2b27dfc + d1a1b35 commit e5e5219

14 files changed

+107
-338
lines changed

cmake/arch_build.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ function(process_arch SYSVAR)
429429
message(STATUS "Building App: ${APP} install=${APP_INSTALL_LIST}")
430430
add_subdirectory(${${APP}_MISSION_DIR} apps/${APP})
431431
endforeach()
432+
433+
# If unit test is enabled, build a generic ut stub library for CFE
434+
if (ENABLE_UNIT_TESTS)
435+
add_subdirectory(${cfe-core_MISSION_DIR}/ut-stubs ut_cfe_core_stubs)
436+
endif (ENABLE_UNIT_TESTS)
432437

433438
# Process each target that shares this system architecture
434439
# Second Pass: Build cfe-core and link final target executable

fsw/cfe-core/unit-test/CMakeLists.txt

+49-40
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,65 @@
77
#
88
##################################################################
99

10-
add_definitions(-DCFE_LINUX)
1110
include_directories(${osal_MISSION_DIR}/ut_assert/inc)
1211

13-
# The parent build may have specified extra C flags for use when unit testing
14-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${UT_C_FLAGS}")
12+
# allow direct inclusion of module-private header files by UT code
13+
# NOTE: this should be minimized and moved to a more targeted
14+
# approach, where only each specific UT module does this.
15+
include_directories(
16+
${cfe-core_MISSION_DIR}/src/es
17+
${cfe-core_MISSION_DIR}/src/evs
18+
${cfe-core_MISSION_DIR}/src/sb
19+
${cfe-core_MISSION_DIR}/src/tbl
20+
${cfe-core_MISSION_DIR}/src/time
21+
${cfe-core_MISSION_DIR}/src/fs
22+
)
1523

16-
# Because the object code is dependent on settings in cfe_platform_cfg.h,
17-
# we must include the LIBNAME in all binary targets, as they must be rebuilt
18-
# for each different platform config.
19-
set (STUBNAME stub)
20-
if (CFE_CORE_TARGET)
21-
set(STUBNAME "${CFE_CORE_TARGET}_${STUBNAME}")
22-
endif (CFE_CORE_TARGET)
23-
24-
set(STUBFILES configdata osprintf ${CFE_CORE_MODULES})
25-
26-
# Allow direct inclusion of all private CFE header files
27-
foreach(MODULE ${CFE_CORE_MODULES})
28-
get_filename_component(CFEDIR ${CMAKE_CURRENT_SOURCE_DIR}/../src/${MODULE} ABSOLUTE)
29-
if (IS_DIRECTORY "${CFEDIR}")
30-
include_directories(${CFEDIR})
31-
endif()
32-
endforeach()
33-
34-
set(CFE_MODULE_FILES)
35-
foreach(MODULE ${CFE_CORE_MODULES})
36-
list(APPEND CFE_MODULE_FILES ut_${MODULE}_stubs.c)
37-
endforeach(MODULE ${CFE_CORE_MODULES})
38-
39-
#
40-
# Create the generic stubs library that ANY other UT target can link to
41-
# to provide stubs for all CFE API calls.
42-
#
43-
add_library(ut_${CFE_CORE_TARGET}_stubs STATIC ${CFE_MODULE_FILES})
24+
# CFE needs a supplemental test support hook library
25+
add_library(ut_${CFE_CORE_TARGET}_support STATIC
26+
ut_support.c
27+
ut_osprintf_stubs.c
28+
)
4429

4530
# For each core module, generate the associated unit test
4631
# This is done by linking the stubs of every OTHER module with the
4732
# UT version of the real module (compiled with coverage flags)
4833
foreach(MODULE ${CFE_CORE_MODULES})
49-
set(CFE_MODULE_FILES
50-
ut_support.c
51-
ut_osprintf_stubs.c)
52-
aux_source_directory(../src/${MODULE} CFE_MODULE_FILES)
53-
aux_source_directory(../src/shared CFE_MODULE_FILES)
54-
add_executable(${CFE_CORE_TARGET}_${MODULE}_UT ${MODULE}_UT.c ${CFE_MODULE_FILES})
34+
35+
set(CFE_MODULE_FILES)
36+
aux_source_directory(${cfe-core_MISSION_DIR}/src/${MODULE} CFE_MODULE_FILES)
37+
38+
# Compile the unit(s) under test as an object library
39+
# this allows easy configuration of special flags and include paths
40+
# in particular this should use the UT_C_FLAGS for coverage instrumentation
41+
add_library(ut_cfe_${MODULE}_object OBJECT
42+
${CFE_MODULE_FILES})
43+
44+
# Apply the UT_C_FLAGS to the units under test
45+
# This should enable coverage analysis on platforms that support this
46+
set_target_properties(ut_cfe_${MODULE}_object PROPERTIES
47+
COMPILE_FLAGS "${UT_C_FLAGS}")
48+
49+
# For this object target only, the "override" includes should be injected
50+
# into the include path BEFORE any other include path. This is so the
51+
# override will take precedence over any system-provided version.
52+
target_include_directories(ut_cfe_${MODULE}_object BEFORE PRIVATE
53+
${CMAKE_CURRENT_SOURCE_DIR}/modules/inc/overrides)
54+
55+
add_executable(${CFE_CORE_TARGET}_${MODULE}_UT
56+
${MODULE}_UT.c
57+
$<TARGET_OBJECTS:ut_cfe_${MODULE}_object>)
58+
5559
target_link_libraries(${CFE_CORE_TARGET}_${MODULE}_UT
56-
ut_${CFE_CORE_TARGET}_stubs
57-
ut_psp-${CFE_SYSTEM_PSPNAME}_stubs
58-
ut_osapi_stubs
60+
ut_${CFE_CORE_TARGET}_support
61+
ut_cfe-core_stubs
5962
ut_bsp)
63+
64+
# Also add the C FLAGS to the link command
65+
# This should enable coverage analysis on platforms that support this
66+
set_target_properties(${CFE_CORE_TARGET}_${MODULE}_UT PROPERTIES
67+
LINK_FLAGS "${UT_C_FLAGS}")
68+
6069
add_test(${CFE_CORE_TARGET}_${MODULE}_UT ${CFE_CORE_TARGET}_${MODULE}_UT)
6170
install(TARGETS ${CFE_CORE_TARGET}_${MODULE}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
6271
endforeach(MODULE ${CFE_CORE_MODULES})

fsw/cfe-core/unit-test/sb_UT.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10416,10 +10416,10 @@ void Test_RcvMsg_UnsubResubPath(void)
1041610416
*/
1041710417
void Test_MessageString(void)
1041810418
{
10419-
char *SrcString = "abcdefg";
10419+
const char *SrcString = "abcdefg";
1042010420
char DestString[20];
1042110421
char *DestStringPtr = DestString;
10422-
char *DefString = "default";
10422+
const char *DefString = "default";
1042310423

1042410424
SB_ResetUnitTest();
1042510425

fsw/cfe-core/unit-test/ut_arinc653_stubs.c

-160
This file was deleted.

fsw/cfe-core/unit-test/ut_arinc653_stubs.h

-61
This file was deleted.

0 commit comments

Comments
 (0)