Skip to content

Commit

Permalink
Update MISRA check information (#51)
Browse files Browse the repository at this point in the history
* Update to coverity 2023.6.1 MISRA check
* Rename "BUILD_UNIT_TESTS" to "UNITTEST" to align with other FreeRTOS libraries
* Add "COV_ANALYSIS" cmake variable for coverity_analysis project
  • Loading branch information
chinglee-iot authored Apr 12, 2024
1 parent 81b8348 commit fede9a8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/.cSpellWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Coverity
CSDK
ctest
DCMOCK
DCOV
decihours
Decihours
DECIHOURS
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +112,7 @@ jobs:
cp source/include/stdint.readme override-include/stdint.h
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DBUILD_CLONE_SUBMODULES=ON \
-DCOV_ANALYSIS=ON \
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror -I../override-include'
make -C build/ coverity_analysis
Expand Down
47 changes: 30 additions & 17 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,44 +25,52 @@ set( UNITY_DIR ${UNIT_TEST_DIR}/Unity CACHE INTERNAL "Unity library source direc
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."
OFF )

# Set output directories.
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 )

# ================================ Coverity Analysis Configuration =================================

# 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} )
# ================================ Coverity Analysis Configuration =================================
if( COV_ANALYSIS )

# Backoff Algorithm library public include path.
target_include_directories( coverity_analysis
PUBLIC
${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} )
# Target for Coverity analysis that builds the library.
add_library( coverity_analysis
${BACKOFF_ALGORITHM_SOURCES} )

# Disable logging/assert() calls when building the Coverity analysis target
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
# 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 )
endif()

# ==================================== Unit Test Configuration ====================================

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 ====================================

if(${UNITTEST})
if( UNITTEST )

# Include Unity build configuration.
include( unit-test/unity_build.cmake )
Expand All @@ -71,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.
Expand Down
6 changes: 3 additions & 3 deletions tools/coverity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
~~~
Expand Down Expand Up @@ -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/
Expand Down
29 changes: 13 additions & 16 deletions tools/coverity/misra.config
Original file line number Diff line number Diff line change
@@ -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."
}
]
}

0 comments on commit fede9a8

Please sign in to comment.