From 87b4215ecd1f79b637cd69ead3d306d6c77d8700 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 3 Apr 2024 03:48:08 +0000 Subject: [PATCH 1/8] Update MISRA check information --- .github/workflows/ci.yml | 2 +- test/CMakeLists.txt | 32 ++++++++++++++++++-------------- test/unit-test/CMakeLists.txt | 4 +++- tools/coverity/README.md | 6 +++--- tools/coverity/misra.config | 29 +++++++++++++---------------- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb303e3..bbd870d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: cmake -S test -B build/ \ -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ - -DBUILD_UNIT_TESTS=ON \ + -DUNITTEST=ON \ -DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror' make -C build/ all - name: Test diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bda37f7..6568edf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,9 +22,12 @@ set( UNIT_TEST_DIR ${MODULE_ROOT_DIR}/test/unit-test CACHE INTERNAL "backoffAlgo set( UNITY_DIR ${UNIT_TEST_DIR}/Unity CACHE INTERNAL "Unity library source directory." ) # Configure options to always show in CMake GUI. -option( BUILD_UNIT_TESTS +option( UNITTEST "Set this to ON to build unit tests. This will clone the required Unity test framework submodule if it is not cloned already." OFF ) +option( COV_ANALYSIS + "Set this to ON to build coverity analysis project." + ON ) # Set output directories. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) @@ -32,21 +35,22 @@ set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) # ================================ Coverity Analysis Configuration ================================= +if( COV_ANALYSIS ) + # Include filepaths for source and include. + include( ${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake ) -# Include filepaths for source and include. -include( ${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake ) + # Target for Coverity analysis that builds the library. + add_library( coverity_analysis + ${BACKOFF_ALGORITHM_SOURCES} ) -# Target for Coverity analysis that builds the library. -add_library( coverity_analysis - ${BACKOFF_ALGORITHM_SOURCES} ) + # Backoff Algorithm library public include path. + target_include_directories( coverity_analysis + PUBLIC + ${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} ) -# Backoff Algorithm library public include path. -target_include_directories( coverity_analysis - PUBLIC - ${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} ) - -# Disable logging/assert() calls when building the Coverity analysis target -target_compile_options(coverity_analysis PUBLIC -DNDEBUG ) + # Disable logging/assert() calls when building the Coverity analysis target + target_compile_options(coverity_analysis PUBLIC -DNDEBUG ) +endif() # ==================================== Unit Test Configuration ==================================== @@ -62,7 +66,7 @@ endif() # ==================================== Unit Test Configuration ==================================== -if(${BUILD_UNIT_TESTS}) +if( UNITTEST ) # Include Unity build configuration. include( unit-test/unity_build.cmake ) diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 8f59148..d3f20bf 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -1,7 +1,9 @@ # Include file path configuration for backoff algorithm library. include(${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake) -project ("backoff algorithm unit test") +project ( "backoff algorithm unit test" + VERSION 1.3.0 + LANGUAGE C ) cmake_minimum_required (VERSION 3.2.0) # ==================== Define your project name (edit) ======================== diff --git a/tools/coverity/README.md b/tools/coverity/README.md index afca338..c1715a7 100644 --- a/tools/coverity/README.md +++ b/tools/coverity/README.md @@ -5,7 +5,7 @@ To that end, this directory provides a [configuration file](https://github.com/F building a binary for the tool to analyze. > **Note** -For generating the report as outlined below, we have used Coverity version 2018.09. +For generating the report as outlined below, we have used Coverity version 2023.6.1. For details regarding the suppressed violations in the report (which can be generated using the instructions described below), please see the [MISRA.md](https://github.com/FreeRTOS/backoffAlgorithm/blob/main/MISRA.md) file. @@ -31,7 +31,7 @@ Go to the root directory of the library and run the following commands in termin ~~~ 2. Create the build files using CMake in a `build` directory ~~~ - cmake -B build -S test + cmake -B build -S test -DCOV_ANALYSIS=1 ~~~ 3. Go to the build directory and copy the coverity configuration file ~~~ @@ -62,7 +62,7 @@ Go to the root directory of the library and run the following commands in termin For your convenience the commands above are below to be copy/pasted into a UNIX command friendly terminal. ~~~ cov-configure --force --compiler cc --comptype gcc; - cmake -B build -S test; + cmake -B build -S test -DCOV_ANALYSIS=1; cd build/; cov-build --emit-complementary-info --dir cov-out make coverity_analysis; cd cov-out/ diff --git a/tools/coverity/misra.config b/tools/coverity/misra.config index 84a6078..eeb29ec 100644 --- a/tools/coverity/misra.config +++ b/tools/coverity/misra.config @@ -1,26 +1,23 @@ -// MISRA C-2012 Rules - { - version : "2.0", - standard : "c2012", - title: "Coverity MISRA Configuration", - deviations : [ - // Disable the following rules. + "version" : "2.0", + "standard" : "c2012", + "title" : "Coverity MISRA Configuration", + "deviations" : [ { - deviation: "Directive 4.9", - reason: "Allow inclusion of function like macros. Logging is done using function like macros." + "deviation" : "Directive 4.9", + "reason" : "Allow inclusion of function like macros. Logging is done using function like macros." }, { - deviation: "Rule 2.4", - reason: "Allow unused tags. Some compilers warn if types are not tagged." + "deviation" : "Rule 2.4", + "reason" : "Allow unused tags. Some compilers warn if types are not tagged." }, { - deviation: "Rule 3.1", - reason: "Allow nested comments. Documentation blocks contain comments for example code." + "deviation" : "Rule 3.1", + "reason" : "Allow nested comments. Documentation blocks contain comments for example code." }, { - deviation: "Rule 8.7", - reason: "API functions are not used by library. They must be externally visible in order to be used by the application." - }, + "deviation" : "Rule 8.7", + "reason" : "API functions are not used by library. They must be externally visible in order to be used by the application." + } ] } From 267ee3507aaed944ef9d82d188c1bc580430e2fc Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 3 Apr 2024 06:15:56 +0000 Subject: [PATCH 2/8] Fix unit test build and spell --- .github/.cSpellWords.txt | 1 + test/CMakeLists.txt | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index f2aa350..384222b 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -12,6 +12,7 @@ Coverity CSDK ctest DCMOCK +DCOV decihours Decihours DECIHOURS diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6568edf..5e5b2f9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,10 +34,11 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) +# Include filepaths for source and include. +include( ${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake ) + # ================================ Coverity Analysis Configuration ================================= if( COV_ANALYSIS ) - # Include filepaths for source and include. - include( ${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake ) # Target for Coverity analysis that builds the library. add_library( coverity_analysis From c3df20481fd1f7a347d46fd8fdc085c5fb94e698 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 3 Apr 2024 06:28:53 +0000 Subject: [PATCH 3/8] Fix unittest --- test/CMakeLists.txt | 2 +- test/unit-test/CMakeLists.txt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5e5b2f9..54c2890 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required( VERSION 3.13.0 ) project( "backoffAlgorithm unit test" - VERSION 1.0.0 + VERSION 1.3.0 LANGUAGES C ) # Allow the project to be organized into folders. diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index d3f20bf..37e1689 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -1,9 +1,7 @@ # Include file path configuration for backoff algorithm library. include(${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake) -project ( "backoff algorithm unit test" - VERSION 1.3.0 - LANGUAGE C ) +project ( "backoff algorithm unit test" ) cmake_minimum_required (VERSION 3.2.0) # ==================== Define your project name (edit) ======================== From 8a6d001423796dc537fe2dd715b53697e3a43344 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 3 Apr 2024 06:30:49 +0000 Subject: [PATCH 4/8] Revert uncessary change --- test/unit-test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 37e1689..8f59148 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -1,7 +1,7 @@ # Include file path configuration for backoff algorithm library. include(${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake) -project ( "backoff algorithm unit test" ) +project ("backoff algorithm unit test") cmake_minimum_required (VERSION 3.2.0) # ==================== Define your project name (edit) ======================== From 6718570dd5d3a88249564da076a3706fc89bf35c Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Apr 2024 06:19:15 +0000 Subject: [PATCH 5/8] Set COV_ANALYSIS default to false --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 54c2890..2bf544e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,7 +27,7 @@ option( UNITTEST OFF ) option( COV_ANALYSIS "Set this to ON to build coverity analysis project." - ON ) + OFF ) # Set output directories. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) From a2e99d49a235923eff418744bc421f5d993dbfd0 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Apr 2024 06:26:07 +0000 Subject: [PATCH 6/8] Update cmake file for code build example --- test/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2bf544e..46c2cbe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,10 +59,13 @@ if(${BUILD_CODE_EXAMPLE}) # Target for code example binary. add_executable( code_example_posix - ${MODULE_ROOT_DIR}/docs/doxygen/code_examples/backoff_algorithm_posix.c ) - - target_link_libraries( code_example_posix coverity_analysis ) + ${MODULE_ROOT_DIR}/docs/doxygen/code_examples/backoff_algorithm_posix.c + ${BACKOFF_ALGORITHM_SOURCES} ) + # Backoff Algorithm library public include path. + target_include_directories( code_example_posix + PUBLIC + ${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} ) endif() # ==================================== Unit Test Configuration ==================================== From 3f036c4104a11990a0b327f7a9e47509d0bc9149 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Apr 2024 06:42:52 +0000 Subject: [PATCH 7/8] Update for custom standard c header --- .github/workflows/ci.yml | 2 +- test/CMakeLists.txt | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbd870d..b8793d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ jobs: -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ -DUNITTEST=ON \ + -DBUILD_CLONE_SUBMODULES=ON \ -DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror' make -C build/ all - name: Test @@ -111,7 +112,6 @@ jobs: cp source/include/stdint.readme override-include/stdint.h cmake -S test -B build/ \ -G "Unix Makefiles" \ - -DBUILD_CLONE_SUBMODULES=ON \ -DCMAKE_C_FLAGS='-Wall -Wextra -Werror -I../override-include' make -C build/ coverity_analysis diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 46c2cbe..5c4db23 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,7 +79,12 @@ if( UNITTEST ) # if BUILD_CLONE_SUBMODULES configuration is enabled. if( NOT EXISTS ${UNITY_DIR}/src ) # Attempt to clone Unity. - clone_unity() + if( ${BUILD_CLONE_SUBMODULES} ) + clone_unity() + else() + message( FATAL_ERROR "The required submodule Unity does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." ) + endif() + endif() # Add unit test and coverage configuration. From 4acf5197f2f43a0d8c89970c16268263b16e1831 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Apr 2024 06:48:35 +0000 Subject: [PATCH 8/8] Fix custom standard c header build --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8793d9..41c290d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -112,6 +112,7 @@ jobs: cp source/include/stdint.readme override-include/stdint.h cmake -S test -B build/ \ -G "Unix Makefiles" \ + -DCOV_ANALYSIS=ON \ -DCMAKE_C_FLAGS='-Wall -Wextra -Werror -I../override-include' make -C build/ coverity_analysis