From 4f6814739b33c6e542744726f60e3b859b9b16a7 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 4 Mar 2021 16:18:41 -0500 Subject: [PATCH 1/3] Fix #46, 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 | 17 +++----- unit-test/CMakeLists.txt | 90 +++++++++++++--------------------------- ut-stubs/CMakeLists.txt | 12 +----- 3 files changed, 36 insertions(+), 83 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d023093..7478c75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,12 @@ -cmake_minimum_required(VERSION 2.6.4) project(CFE_SAMPLE_LIB C) -include_directories(fsw/public_inc) - -# The shared OSAL and cFE include directories should always be used -# Note that this intentionally does NOT include PSP-specific includes, just the generic -include_directories(${CFECORE_SOURCE_DIR}/src/inc) -include_directories(${CFEPSP_SOURCE_DIR}/fsw/inc) - -aux_source_directory(fsw/src LIB_SRC_FILES) - # Create the app module -add_cfe_app(sample_lib ${LIB_SRC_FILES}) +add_cfe_app(sample_lib fsw/src/sample_lib.c) + +# The API to this library (which may be invoked/referenced from other apps) +# is stored in fsw/public_inc. Using "target_include_directories" is the +# preferred method of indicating this (vs. directory-scope "include_directories"). +target_include_directories(sample_lib PUBLIC fsw/public_inc) if (ENABLE_UNIT_TESTS) add_subdirectory(ut-stubs) diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index 91b720b..68070c5 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -15,9 +15,6 @@ # - "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. # - "overrides" provides implementation of LOCAL stub functions to # that replace external calls. This is for use cases where the # normal link-time replacements is not sufficient/possible, and @@ -28,73 +25,44 @@ # it is primarily for cases where a C library function needs to be # overridden. It's use-case is included here as an example. - -set(UT_NAME sample_lib) - -# Use the UT_Assert public API # This is also allowed to directly include files in the "fsw/src" # directory that are normally private to the implementation -include_directories(${osal_MISSION_DIR}/ut_assert/inc) include_directories(${PROJECT_SOURCE_DIR}/fsw/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) # The "overrides" target provides replacements for C library # calls that cannot be handled at link time. Most UT test # cases will NOT need this feature. -add_library(ut_${UT_NAME}_overrides STATIC +add_cfe_coverage_stubs(sample_lib_overrides override_src/libc_string_stubs.c ) -# The LIB_SRC_FILES variable should contain the list of source files for the FSW build -# This assumes a 1:1 relationship between FSW source units and coverage tests -# Generate a dedicated "testrunner" executable that executes the tests for each FSW code unit -# Although sample_lib 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 ${LIB_SRC_FILES}) - get_filename_component(UNITNAME "${SRCFILE}" NAME_WE) - - set(TESTNAME "${UT_NAME}-${UNITNAME}") - set(UNIT_SOURCE_FILE "${CFE_SAMPLE_LIB_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}) - - # For this object target only, the "override" includes should be injected - # into the include path BEFORE any other include path. This is so the - # override will take precedence over any system-provided version. - target_include_directories(ut_${TESTNAME}_object PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/override_inc) - - # 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_${UT_NAME}_stubs - ut_${UT_NAME}_overrides - 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_lib-ALL" that +# covers all of the functions in sample_lib. +# +# 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_lib ALL + "coveragetest/coveragetest_sample_lib.c" + "${CFE_SAMPLE_LIB_SOURCE_DIR}/fsw/src/sample_lib.c" +) + +# For the object target only, the "override" includes should be injected +# into the include path. Note it is important that this is only included +# for the specific unit under test (object lib) not the coverage +# test executable or test cases, since these typically need the real +# version of these functions. +add_cfe_coverage_unit_include(sample_lib ALL + ${CMAKE_CURRENT_SOURCE_DIR}/override_inc +) + + +# The sample_lib stubs out a C library function so must be linked +# with the local "overrides" library (this is mainly just an example of how this +# can be done). +add_cfe_coverage_dependency(sample_lib ALL + sample_lib_overrides +) diff --git a/ut-stubs/CMakeLists.txt b/ut-stubs/CMakeLists.txt index c48b49f..0934c9b 100644 --- a/ut-stubs/CMakeLists.txt +++ b/ut-stubs/CMakeLists.txt @@ -9,15 +9,5 @@ # ################################################################## -# Use the UT assert public headers -include_directories(${osal_MISSION_DIR}/ut_assert/inc) - -# Create a static library containing all stubs. -# -# There should be a 1:1 relationship between application source files -# and the stub files. Each stub file should provide the same set of -# functions that the application source file provides. -add_library(ut_sample_lib_stubs STATIC - sample_lib_stubs.c -) +add_cfe_coverage_stubs(sample_lib sample_lib_stubs.c) From 7cd79cb3512c5703d4f9968a07f1b2ef7c6fec28 Mon Sep 17 00:00:00 2001 From: Ariel Adams Date: Fri, 5 Mar 2021 09:23:40 -0600 Subject: [PATCH 2/3] Fix #48, Add Testing Tools to the Security Policy --- SECURITY.md | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index b7ef723..1167fa5 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,12 +4,38 @@ To report a vulnerability for the sample_lib subsystem please [submit an issue](https://github.com/nasa/sample_lib/issues/new/choose). -For general cFS vulnerabilities please [open a cFS framework issue](https://github.com/nasa/cfs/issues/new/choose) and see our [top-level security policy](https://github.com/nasa/cFS/security/policy). +For general cFS vulnerabilities please [open a cFS framework issue](https://github.com/nasa/cfs/issues/new/choose) and see our [top-level security policy](https://github.com/nasa/cFS/security/policy) for additional information. In either case please use the "Bug Report" template and provide as much information as possible. Apply appropraite labels for each report. For security related reports, tag the issue with the "security" label. +## Testing + +**Disclaimer: nasa/sample_lib is not responsible for any liability incurred under the [Apache License 2.0](https://github.com/nasa/sample_lib/blob/main/LICENSE).** + +Testing is an important aspect our team values to improve sample_lib. + +To view tools used for the cFS bundle, see our [top-level security policy](https://github.com/nasa/cFS/security/policy). + +### CodeQL + +The [sample_lib CodeQL GitHub Actions workflow](https://github.com/nasa/sample_lib/actions/workflows/codeql-build.yml) is available to the public. To review the results, fork the sample_lib repository and run the CodeQL workflow. + +CodeQL is ran for every push and pull-request on all branches of sample_lib in GitHub Actions. + +For the CodeQL GitHub Actions setup, visit https://github.com/github/codeql-action. + +### Cppcheck + +The [sample_lib Cppcheck GitHub Actions workflow and results](https://github.com/nasa/sample_lib/actions/workflows/static-analysis.yml) are available to the public. To view the results, select a workflow and download the artifacts. + +Cppcheck is ran for every push on the main branch and every pull request on all branches of sample_lib in Github Actions. + +For more information about Cppcheck, visit http://cppcheck.sourceforge.net/. + ## Additional Support -For additional support, email us at cfs-program@lists.nasa.gov. For help using OSAL and cFS, [subscribe to our mailing list](https://lists.nasa.gov/mailman/listinfo/cfs-community) that includes all the community members/users of the NASA core Flight Software (cFS) product line. The mailing list is used to communicate any information related to the cFS product such as current releases, bug findings and fixes, enhancement requests, community meeting notifications, sending out meeting minutes, etc. +For additional support, submit a GitHub issue. You can also email the cfs community at cfs-community@lists.nasa.gov. + +You can subscribe to the mailing list [here](https://lists.nasa.gov/mailman/listinfo/cfs-community) that includes all the community members/users of the NASA core Flight Software (cFS) product line. The mailing list is used to communicate any information related to the cFS product such as current releases, bug findings and fixes, enhancement requests, community meeting notifications, sending out meeting minutes, etc. -If you wish to report a cybersecurity incident or concern please contact the NASA Security Operations Center either by phone at 1-877-627-2732 or via email address soc@nasa.gov. +If you wish to report a cybersecurity incident or concern, please contact the NASA Security Operations Center either by phone at 1-877-627-2732 or via email address soc@nasa.gov. From 5ded3815644e4d7366ce390526c5e9e222b28fdb Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 5 Mar 2021 17:00:01 -0500 Subject: [PATCH 3/3] IC-20210305a, Update readme and version --- README.md | 6 ++++++ fsw/src/sample_lib_version.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7597a89..7e8bae4 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,12 @@ sample_lib implements SAMPLE_Function, as an example for how to build and link a ## Version History +### Development Build: v1.2.0-rc1+dev24 + +- Fix #46, simplify build to use wrappers and interface libs +- Fix #48, Add Testing Tools to the Security Policy +- See + ### Development Build: v1.2.0-rc1+dev10 - Rename `UT_SetForceFail` to `UT_SetDefaultReturnValue` since some functions that retain more than 1 value are not necessarily failing diff --git a/fsw/src/sample_lib_version.h b/fsw/src/sample_lib_version.h index 34f6c32..65b131f 100644 --- a/fsw/src/sample_lib_version.h +++ b/fsw/src/sample_lib_version.h @@ -32,7 +32,7 @@ /* Development Build Macro Definitions */ -#define SAMPLE_LIB_BUILD_NUMBER 10 /*!< Development Build: Number of commits since baseline */ +#define SAMPLE_LIB_BUILD_NUMBER 24 /*!< Development Build: Number of commits since baseline */ #define SAMPLE_LIB_BUILD_BASELINE \ "v1.2.0-rc1" /*!< Development Build: git tag that is the base for the current development */