Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MISRA config #121

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/.cSpellWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Coverity
CSDK
ctest
DCMOCK
DCOV
DDisable
decihours
Decihours
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_CLONE_SUBMODULES=ON \
-DUNITTEST=1 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This question may be out of the scope of this PR.
Do we need to add UNITTEST variable in other library as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which other library are you talking about?

-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror -DNDEBUG'
make -C build/ all
- name: Test
Expand Down
4 changes: 2 additions & 2 deletions MISRA.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# MISRA Compliance

The Device Shadow Library files conform to the [MISRA C:2012](https://www.misra.org.uk)
guidelines, with some noted exceptions. Compliance is checked with Coverity static analysis.
The specific deviations, suppressed inline, are listed below.
guidelines, with some noted exceptions. Compliance is checked with Coverity static analysis
version 2023.6.1. The specific deviations, suppressed inline, are listed below.

Additionally, [MISRA configuration file](https://github.com/aws/Device-Shadow-for-AWS-IoT-embedded-sdk/blob/main/tools/coverity/misra.config) contains the project wide deviations.

Expand Down
103 changes: 55 additions & 48 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 ( "Shadow unit test"
VERSION 1.0.0
VERSION 1.3.0
LANGUAGES C )

# Allow the project to be organized into folders.
Expand All @@ -10,6 +10,12 @@ set_property( GLOBAL PROPERTY USE_FOLDERS ON )
set( CMAKE_C_STANDARD 90 )
set( CMAKE_C_STANDARD_REQUIRED ON )

# If no configuration is defined, turn everything on.
if( NOT DEFINED COV_ANALYSIS AND NOT DEFINED UNITTEST )
set( COV_ANALYSIS TRUE )
set( UNITTEST TRUE )
endif()

# Do not allow in-source build.
if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
Expand All @@ -31,64 +37,65 @@ set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )

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

# Coverity can run off the unit test targets, but this avoids calling unnecessary
# unit testing tools like gcov and CMock.
if( COV_ANALYSIS )
AniruddhaKanhere marked this conversation as resolved.
Show resolved Hide resolved
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/shadowFilePaths.cmake )

# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/shadowFilePaths.cmake )
# Target for Coverity analysis that builds the library.
add_library( coverity_analysis
${SHADOW_SOURCES} )

# Target for Coverity analysis that builds the library.
add_library( coverity_analysis
${SHADOW_SOURCES} )
# Shadow public include path.
target_include_directories( coverity_analysis
PUBLIC
${SHADOW_INCLUDE_PUBLIC_DIRS}
"${CMAKE_CURRENT_LIST_DIR}/include" )

# Shadow public include path.
target_include_directories( coverity_analysis
PUBLIC
${SHADOW_INCLUDE_PUBLIC_DIRS}
"${CMAKE_CURRENT_LIST_DIR}/include" )

target_compile_options(coverity_analysis PUBLIC -DNDEBUG -DDISABLE_LOGGING )
target_compile_options(coverity_analysis PUBLIC -DNDEBUG -DDISABLE_LOGGING )
endif()

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

# Define a CMock resource path.
set( CMOCK_DIR ${MODULE_ROOT_DIR}/test/unit-test/CMock CACHE INTERNAL "CMock library source directory." )

# Include CMock build configuration.
include( unit-test/cmock_build.cmake )

# Check if the CMock source directory exists, and if not present, clone the submodule
# if BUILD_CLONE_SUBMODULES configuration is enabled.
if( NOT EXISTS ${CMOCK_DIR}/src )
# Attempt to clone CMock.
if( ${BUILD_CLONE_SUBMODULES} )
clone_cmock()
else()
message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
if( UNITTEST )
# Define a CMock resource path.
set( CMOCK_DIR ${MODULE_ROOT_DIR}/test/unit-test/CMock CACHE INTERNAL "CMock library source directory." )

# Include CMock build configuration.
include( unit-test/cmock_build.cmake )

# Check if the CMock source directory exists, and if not present, clone the submodule
# if BUILD_CLONE_SUBMODULES configuration is enabled.
if( NOT EXISTS ${CMOCK_DIR}/src )
# Attempt to clone CMock.
if( ${BUILD_CLONE_SUBMODULES} )
clone_cmock()
else()
message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
endif()
endif()
endif()

# Add unit test and coverage configuration.
# Add unit test and coverage configuration.

# Use CTest utility for managing test runs. This has to be added BEFORE
# defining test targets with add_test()
enable_testing()
# Use CTest utility for managing test runs. This has to be added BEFORE
# defining test targets with add_test()
enable_testing()

# Add build targets for CMock and Unit, required for unit testing.
add_cmock_targets()
# Add build targets for CMock and Unit, required for unit testing.
add_cmock_targets()

# Add function to enable CMock based tests and coverage.
include( ${MODULE_ROOT_DIR}/tools/cmock/create_test.cmake )
# Add function to enable CMock based tests and coverage.
include( ${MODULE_ROOT_DIR}/tools/cmock/create_test.cmake )

# Include build configuration for unit tests.
add_subdirectory( unit-test )
# Include build configuration for unit tests.
add_subdirectory( unit-test )

# ==================================== Coverage Analysis configuration ============================
# ==================================== Coverage Analysis configuration ============================

# Add a target for running coverage on tests.
add_custom_target( coverage
COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR}
-P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake
DEPENDS cmock unity shadow_utest
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Add a target for running coverage on tests.
add_custom_target( coverage
COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR}
-P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake
DEPENDS cmock unity shadow_utest
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
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/a
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/aws/Device-Shadow-for-AWS-IoT-embedded-sdk/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 -DCOV_ANALYSIS
~~~
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;
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: "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 2.5",
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
"deviation": "Rule 2.5",
"reason": "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
},
{
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."
}
]
}
Loading