|
7 | 7 | #
|
8 | 8 | ##################################################################
|
9 | 9 |
|
10 |
| -add_definitions(-DCFE_LINUX) |
11 | 10 | include_directories(${osal_MISSION_DIR}/ut_assert/inc)
|
12 | 11 |
|
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 | +) |
15 | 23 |
|
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 | +) |
44 | 29 |
|
45 | 30 | # For each core module, generate the associated unit test
|
46 | 31 | # This is done by linking the stubs of every OTHER module with the
|
47 | 32 | # UT version of the real module (compiled with coverage flags)
|
48 | 33 | 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 | + |
55 | 59 | 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 |
59 | 62 | 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 | + |
60 | 69 | add_test(${CFE_CORE_TARGET}_${MODULE}_UT ${CFE_CORE_TARGET}_${MODULE}_UT)
|
61 | 70 | install(TARGETS ${CFE_CORE_TARGET}_${MODULE}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR})
|
62 | 71 | endforeach(MODULE ${CFE_CORE_MODULES})
|
|
0 commit comments