Skip to content

Commit fede9a8

Browse files
authored
Update MISRA check information (#51)
* 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
1 parent 81b8348 commit fede9a8

File tree

5 files changed

+49
-37
lines changed

5 files changed

+49
-37
lines changed

.github/.cSpellWords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Coverity
1212
CSDK
1313
ctest
1414
DCMOCK
15+
DCOV
1516
decihours
1617
Decihours
1718
DECIHOURS

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
-G "Unix Makefiles" \
1919
-DCMAKE_BUILD_TYPE=Debug \
2020
-DUNITTEST=ON \
21+
-DBUILD_CLONE_SUBMODULES=ON \
2122
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror'
2223
make -C build/ all
2324
- name: Test
@@ -111,7 +112,7 @@ jobs:
111112
cp source/include/stdint.readme override-include/stdint.h
112113
cmake -S test -B build/ \
113114
-G "Unix Makefiles" \
114-
-DBUILD_CLONE_SUBMODULES=ON \
115+
-DCOV_ANALYSIS=ON \
115116
-DCMAKE_C_FLAGS='-Wall -Wextra -Werror -I../override-include'
116117
make -C build/ coverity_analysis
117118

test/CMakeLists.txt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required( VERSION 3.13.0 )
22
project( "backoffAlgorithm unit test"
3-
VERSION 1.0.0
3+
VERSION 1.3.0
44
LANGUAGES C )
55

66
# Allow the project to be organized into folders.
@@ -25,44 +25,52 @@ set( UNITY_DIR ${UNIT_TEST_DIR}/Unity CACHE INTERNAL "Unity library source direc
2525
option( UNITTEST
2626
"Set this to ON to build unit tests. This will clone the required Unity test framework submodule if it is not cloned already."
2727
OFF )
28+
option( COV_ANALYSIS
29+
"Set this to ON to build coverity analysis project."
30+
OFF )
2831

2932
# Set output directories.
3033
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
3134
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
3235
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
3336

34-
# ================================ Coverity Analysis Configuration =================================
35-
3637
# Include filepaths for source and include.
3738
include( ${MODULE_ROOT_DIR}/backoffAlgorithmFilePaths.cmake )
3839

39-
# Target for Coverity analysis that builds the library.
40-
add_library( coverity_analysis
41-
${BACKOFF_ALGORITHM_SOURCES} )
40+
# ================================ Coverity Analysis Configuration =================================
41+
if( COV_ANALYSIS )
4242

43-
# Backoff Algorithm library public include path.
44-
target_include_directories( coverity_analysis
45-
PUBLIC
46-
${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} )
43+
# Target for Coverity analysis that builds the library.
44+
add_library( coverity_analysis
45+
${BACKOFF_ALGORITHM_SOURCES} )
4746

48-
# Disable logging/assert() calls when building the Coverity analysis target
49-
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
47+
# Backoff Algorithm library public include path.
48+
target_include_directories( coverity_analysis
49+
PUBLIC
50+
${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} )
51+
52+
# Disable logging/assert() calls when building the Coverity analysis target
53+
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
54+
endif()
5055

5156
# ==================================== Unit Test Configuration ====================================
5257

5358
if(${BUILD_CODE_EXAMPLE})
5459

5560
# Target for code example binary.
5661
add_executable( code_example_posix
57-
${MODULE_ROOT_DIR}/docs/doxygen/code_examples/backoff_algorithm_posix.c )
58-
59-
target_link_libraries( code_example_posix coverity_analysis )
62+
${MODULE_ROOT_DIR}/docs/doxygen/code_examples/backoff_algorithm_posix.c
63+
${BACKOFF_ALGORITHM_SOURCES} )
6064

65+
# Backoff Algorithm library public include path.
66+
target_include_directories( code_example_posix
67+
PUBLIC
68+
${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS} )
6169
endif()
6270

6371
# ==================================== Unit Test Configuration ====================================
6472

65-
if(${UNITTEST})
73+
if( UNITTEST )
6674

6775
# Include Unity build configuration.
6876
include( unit-test/unity_build.cmake )
@@ -71,7 +79,12 @@ if(${UNITTEST})
7179
# if BUILD_CLONE_SUBMODULES configuration is enabled.
7280
if( NOT EXISTS ${UNITY_DIR}/src )
7381
# Attempt to clone Unity.
74-
clone_unity()
82+
if( ${BUILD_CLONE_SUBMODULES} )
83+
clone_unity()
84+
else()
85+
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." )
86+
endif()
87+
7588
endif()
7689

7790
# Add unit test and coverage configuration.

tools/coverity/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ To that end, this directory provides a [configuration file](https://github.com/F
55
building a binary for the tool to analyze.
66

77
> **Note**
8-
For generating the report as outlined below, we have used Coverity version 2018.09.
8+
For generating the report as outlined below, we have used Coverity version 2023.6.1.
99

1010
For details regarding the suppressed violations in the report (which can be generated using the instructions described below), please
1111
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
3131
~~~
3232
2. Create the build files using CMake in a `build` directory
3333
~~~
34-
cmake -B build -S test
34+
cmake -B build -S test -DCOV_ANALYSIS=1
3535
~~~
3636
3. Go to the build directory and copy the coverity configuration file
3737
~~~
@@ -62,7 +62,7 @@ Go to the root directory of the library and run the following commands in termin
6262
For your convenience the commands above are below to be copy/pasted into a UNIX command friendly terminal.
6363
~~~
6464
cov-configure --force --compiler cc --comptype gcc;
65-
cmake -B build -S test;
65+
cmake -B build -S test -DCOV_ANALYSIS=1;
6666
cd build/;
6767
cov-build --emit-complementary-info --dir cov-out make coverity_analysis;
6868
cd cov-out/

tools/coverity/misra.config

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
// MISRA C-2012 Rules
2-
31
{
4-
version : "2.0",
5-
standard : "c2012",
6-
title: "Coverity MISRA Configuration",
7-
deviations : [
8-
// Disable the following rules.
2+
"version" : "2.0",
3+
"standard" : "c2012",
4+
"title" : "Coverity MISRA Configuration",
5+
"deviations" : [
96
{
10-
deviation: "Directive 4.9",
11-
reason: "Allow inclusion of function like macros. Logging is done using function like macros."
7+
"deviation" : "Directive 4.9",
8+
"reason" : "Allow inclusion of function like macros. Logging is done using function like macros."
129
},
1310
{
14-
deviation: "Rule 2.4",
15-
reason: "Allow unused tags. Some compilers warn if types are not tagged."
11+
"deviation" : "Rule 2.4",
12+
"reason" : "Allow unused tags. Some compilers warn if types are not tagged."
1613
},
1714
{
18-
deviation: "Rule 3.1",
19-
reason: "Allow nested comments. Documentation blocks contain comments for example code."
15+
"deviation" : "Rule 3.1",
16+
"reason" : "Allow nested comments. Documentation blocks contain comments for example code."
2017
},
2118
{
22-
deviation: "Rule 8.7",
23-
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
24-
},
19+
"deviation" : "Rule 8.7",
20+
"reason" : "API functions are not used by library. They must be externally visible in order to be used by the application."
21+
}
2522
]
2623
}

0 commit comments

Comments
 (0)