|
| 1 | +################################################################## |
| 2 | +# |
| 3 | +# Coverage Unit Test build recipe |
| 4 | +# |
| 5 | +# This CMake file contains the recipe for building the sample unit tests. |
| 6 | +# It is invoked from the parent directory when unit tests are enabled. |
| 7 | +# |
| 8 | +################################################################## |
| 9 | + |
| 10 | +# |
| 11 | +# |
| 12 | +# NOTE on the subdirectory structures here: |
| 13 | +# |
| 14 | +# - "inc" provides local header files shared between the coveragetest, |
| 15 | +# wrappers, and overrides source code units |
| 16 | +# - "coveragetest" contains source code for the actual unit test cases |
| 17 | +# The primary objective is to get line/path coverage on the FSW |
| 18 | +# code units. |
| 19 | +# - "wrappers" contains wrappers for the FSW code. The wrapper adds |
| 20 | +# any UT-specific scaffolding to facilitate the coverage test, and |
| 21 | +# includes the unmodified FSW source file. |
| 22 | +# |
| 23 | + |
| 24 | +set(UT_NAME sample_app) |
| 25 | + |
| 26 | +# Use the UT assert public API, and allow direct |
| 27 | +# inclusion of source files that are normally private |
| 28 | +include_directories(${osal_MISSION_DIR}/ut_assert/inc) |
| 29 | +include_directories(${PROJECT_SOURCE_DIR}/fsw/src) |
| 30 | +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) |
| 31 | + |
| 32 | +# Generate a dedicated "testrunner" executable that executes the tests for each FSW code unit |
| 33 | +# Although sample_app has only one source file, this is done in a loop such that |
| 34 | +# the general pattern should work for several files as well. |
| 35 | +foreach(SRCFILE sample_app.c) |
| 36 | + get_filename_component(UNITNAME "${SRCFILE}" NAME_WE) |
| 37 | + |
| 38 | + set(TESTNAME "${UT_NAME}-${UNITNAME}") |
| 39 | + set(UNIT_SOURCE_FILE "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/${UNITNAME}.c") |
| 40 | + set(TESTCASE_SOURCE_FILE "coveragetest/coveragetest_${UNITNAME}.c") |
| 41 | + |
| 42 | + # Compile the source unit under test as a OBJECT |
| 43 | + add_library(ut_${TESTNAME}_object OBJECT |
| 44 | + ${UNIT_SOURCE_FILE} |
| 45 | + ) |
| 46 | + |
| 47 | + # Apply the UT_C_FLAGS to the units under test |
| 48 | + # This should enable coverage analysis on platforms that support this |
| 49 | + set_target_properties(ut_${TESTNAME}_object PROPERTIES |
| 50 | + COMPILE_FLAGS "${UT_C_FLAGS}") |
| 51 | + |
| 52 | + # Compile a test runner application, which contains the |
| 53 | + # actual coverage test code (test cases) and the unit under test |
| 54 | + add_executable(${TESTNAME}-testrunner |
| 55 | + ${TESTCASE_SOURCE_FILE} |
| 56 | + $<TARGET_OBJECTS:ut_${TESTNAME}_object> |
| 57 | + ) |
| 58 | + |
| 59 | + # This also needs to be linked with UT_C_FLAGS (for coverage) |
| 60 | + set_target_properties(${TESTNAME}-testrunner PROPERTIES |
| 61 | + LINK_FLAGS "${UT_C_FLAGS}") |
| 62 | + |
| 63 | + # This is also linked with any other stub libraries needed, |
| 64 | + # as well as the UT assert framework |
| 65 | + target_link_libraries(${TESTNAME}-testrunner |
| 66 | + ut_sample_lib_stubs |
| 67 | + ut_cfe-core_stubs |
| 68 | + ut_assert |
| 69 | + ) |
| 70 | + |
| 71 | + # Add it to the set of tests to run as part of "make test" |
| 72 | + add_test(${TESTNAME} ${TESTNAME}-testrunner) |
| 73 | + |
| 74 | +endforeach() |
| 75 | + |
0 commit comments