From 2ad02654ec5a85b4afe2b27960e31e33878cca17 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 4 Mar 2021 16:17:19 -0500 Subject: [PATCH] Fix #126, simplify build to use wrappers and interface libs Use the wrapper functions now provided by CFE to simplify the build recipe and work with interface libraries --- CMakeLists.txt | 9 +++--- unit-test/CMakeLists.txt | 66 +++++++++++----------------------------- 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c37119c..bd1d332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,15 @@ -cmake_minimum_required(VERSION 2.6.4) project(CFE_SAMPLE_APP C) include_directories(fsw/mission_inc) include_directories(fsw/platform_inc) -# Include the public API from sample_lib to demonstrate how -# to call library-provided functions -include_directories(${sample_lib_MISSION_DIR}/fsw/public_inc) - # Create the app module add_cfe_app(sample_app fsw/src/sample_app.c) +# Include the public API from sample_lib to demonstrate how +# to call library-provided functions +add_cfe_app_dependency(sample_app sample_lib) + # Add table add_cfe_tables(sampleAppTable fsw/tables/sample_app_tbl.c) diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 4890906..20f8f34 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -16,60 +16,28 @@ # - "coveragetest" contains source code for the actual unit test cases # The primary objective is to get line/path coverage on the FSW # code units. -# - "wrappers" contains wrappers for the FSW code. The wrapper adds -# any UT-specific scaffolding to facilitate the coverage test, and -# includes the unmodified FSW source file. # -set(UT_NAME sample_app) - # Use the UT assert public API, and allow direct # inclusion of source files that are normally private -include_directories(${osal_MISSION_DIR}/ut_assert/inc) include_directories(${PROJECT_SOURCE_DIR}/fsw/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) -# Generate a dedicated "testrunner" executable that executes the tests for each FSW code unit -# Although sample_app has only one source file, this is done in a loop such that -# the general pattern should work for several files as well. -foreach(SRCFILE sample_app.c) - get_filename_component(UNITNAME "${SRCFILE}" NAME_WE) - - set(TESTNAME "${UT_NAME}-${UNITNAME}") - set(UNIT_SOURCE_FILE "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/${UNITNAME}.c") - set(TESTCASE_SOURCE_FILE "coveragetest/coveragetest_${UNITNAME}.c") - - # Compile the source unit under test as a OBJECT - add_library(ut_${TESTNAME}_object OBJECT - ${UNIT_SOURCE_FILE} - ) - - # Apply the UT_COVERAGE_COMPILE_FLAGS to the units under test - # This should enable coverage analysis on platforms that support this - target_compile_options(ut_${TESTNAME}_object PRIVATE ${UT_COVERAGE_COMPILE_FLAGS}) - - # Compile a test runner application, which contains the - # actual coverage test code (test cases) and the unit under test - add_executable(${TESTNAME}-testrunner - ${TESTCASE_SOURCE_FILE} - $ - ) - - # This also needs to be linked with UT_COVERAGE_LINK_FLAGS (for coverage) - # This is also linked with any other stub libraries needed, - # as well as the UT assert framework - target_link_libraries(${TESTNAME}-testrunner - ${UT_COVERAGE_LINK_FLAGS} - ut_sample_lib_stubs - ut_cfe-core_stubs - ut_assert - ) - - # Add it to the set of tests to run as part of "make test" - add_test(${TESTNAME} ${TESTNAME}-testrunner) - foreach(TGT ${INSTALL_TARGET_LIST}) - install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGT}/${UT_INSTALL_SUBDIR}) - endforeach() - -endforeach() + +# Add a coverate test excutable called "sample_app-ALL" that +# covers all of the functions in sample_app. +# +# Also note in a more complex app/lib the coverage test can also +# be broken down into smaller units (in which case one should use +# a unique suffix other than "ALL" for each unit). For example, +# OSAL implements a separate coverage test per source unit. +add_cfe_coverage_test(sample_app ALL + "coveragetest/coveragetest_sample_app.c" + "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app.c" +) + +# The sample_app uses library functions provided by sample_lib so must be linked +# with the sample_lib stub library (this is mainly just an example of how this +# can be done). +add_cfe_coverage_dependency(sample_app ALL sample_lib)