Skip to content

Commit

Permalink
Update CMakeList & Coverity configuration (#109)
Browse files Browse the repository at this point in the history
* Update CMakeList to optionally build UT/Coverity; Update coverity configuration

* Update version

* Add filepath

* Fix broken links
  • Loading branch information
moninom1 authored Aug 8, 2024
1 parent afdd4d5 commit 5f454ac
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_CLONE_SUBMODULES=ON \
-DUNITTEST=1 \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG'
make -C build/ all
Expand Down Expand Up @@ -90,7 +91,7 @@ jobs:
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
mkdir -p source/dependency/coreMQTT/docs/doxygen/output
wget -O source/dependency/coreMQTT/docs/doxygen/output/mqtt.tag \
"https://freertos.org/Documentation/api-ref/coreMQTT/docs/doxygen/output/mqtt.tag"
"https://freertos.github.io/coreMQTT/main/mqtt.tag"
echo -e "::endgroup::"
echo -e "${{env.bashPass}} ${{ env.stepName }} ${{ env.bashEnd }}"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ git submodule update --init --recursive

## coreMQTT Agent Library Configurations

The MQTT Agent library uses the same `core_mqtt_config.h` configuration file as coreMQTT, with the addition of configuration constants listed at the top of [core_mqtt_agent.h](source/include/core_mqtt_agent.h) and [core_mqtt_agent_command_functions.h](source/include/core_mqtt_agent_command_functions.h). Documentation for these configurations can be found [here](https://freertos.org/Documentation/api-ref/coreMQTT-Agent/docs/doxygen/output/html/core_mqtt_agent_config.html).
The MQTT Agent library uses the same `core_mqtt_config.h` configuration file as coreMQTT, with the addition of configuration constants listed at the top of [core_mqtt_agent.h](source/include/core_mqtt_agent.h) and [core_mqtt_agent_command_functions.h](source/include/core_mqtt_agent_command_functions.h). Documentation for these configurations can be found [here](https://freertos.github.io/coreMQTT-Agent/main/core_mqtt_agent_config.html).

To provide values for these configuration values, they must be either:
* Defined in `core_mqtt_config.h` used by coreMQTT
Expand Down Expand Up @@ -131,7 +131,7 @@ Please refer to the demos of the MQTT Agent library in the following locations f

## Documentation

The MQTT Agent API documentation can be found [here](https://freertos.org/Documentation/api-ref/coreMQTT-Agent/docs/doxygen/output/html/index.html).
The MQTT Agent API documentation can be found [here](https://freertos.github.io/coreMQTT-Agent/main/index.html).

### Generating documentation

Expand All @@ -143,7 +143,7 @@ doxygen docs/doxygen/config.doxyfile
```

## Getting help
You can use your Github login to get support from both the FreeRTOS community and directly from the primary FreeRTOS developers on our [active support forum](https://forums.freertos.org). You can find a list of [frequently asked questions](https://www.freertos.org/FAQ.html) here.
You can use your Github login to get support from both the FreeRTOS community and directly from the primary FreeRTOS developers on our [active support forum](https://forums.freertos.org). You can find a list of [frequently asked questions](https://www.freertos.org/Why-FreeRTOS/FAQs) here.

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions source/include/core_mqtt_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ typedef struct MQTTAgentCommandInfo
* @param[in] pMqttAgentContext Pointer to struct to initialize.
* @param[in] pMsgInterface Command interface to use for allocating and sending commands.
* @param[in] pNetworkBuffer Pointer to network buffer to use.
* @param[in] pTransportInterface Transport interface to use with the MQTT
* library. See https://www.freertos.org/network-interface.html
* @param[in] pTransportInterface Transport interface to use with the MQTT library.
* See https://www.freertos.org/Documentation/03-Libraries/03-FreeRTOS-core/06-Transport-Interface/01-Transport-interface
* @param[in] getCurrentTimeMs Pointer to a function that returns a count value
* that increments every millisecond.
* @param[in] incomingCallback The callback to execute when receiving publishes.
Expand Down
109 changes: 62 additions & 47 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 ( "MQTTAgent unit test"
VERSION 1.0.0
cmake_minimum_required ( VERSION 3.22.0 )
project ( "MQTTAgent tests"
VERSION 1.2.0
LANGUAGES C )

# Allow the project to be organized into folders.
Expand All @@ -14,6 +14,12 @@ if( NOT DEFINED CMAKE_C_STANDARD_REQUIRED )
set( CMAKE_C_STANDARD_REQUIRED ON )
endif()

# 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 @@ -35,61 +41,70 @@ set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )

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

# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )
# Target for Coverity analysis that builds the library.
add_library( coverity_analysis
${MQTT_AGENT_SOURCES}
${MQTT_SOURCES}
${MQTT_SERIALIZER_SOURCES} )
if( COV_ANALYSIS )
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )
# Target for Coverity analysis that builds the library.
add_library( coverity_analysis
${MQTT_AGENT_SOURCES}
${MQTT_SOURCES}
${MQTT_SERIALIZER_SOURCES} )

# Build MQTT library target without custom config dependency.
target_compile_definitions( coverity_analysis PUBLIC MQTT_DO_NOT_USE_CUSTOM_CONFIG=1 MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG=1 )
# Build MQTT library target without custom config dependency.
target_compile_definitions( coverity_analysis PUBLIC MQTT_DO_NOT_USE_CUSTOM_CONFIG=1 MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG=1 )

# MQTT AGENT public include path.
target_include_directories( coverity_analysis PUBLIC ${MQTT_AGENT_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} )
# MQTT AGENT public include path.
target_include_directories( coverity_analysis PUBLIC ${MQTT_AGENT_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} )

# ==================================== Test Configuration ========================================
# Remove inclusion of assert.
add_compile_definitions( NDEBUG=1 )

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

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

# 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}/source/dependency/coreMQTT/tools/cmock/create_test.cmake )
# Add function to enable CMock based tests and coverage.
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/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 mqtt_agent_utest mqtt_agent_command_functions_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 mqtt_agent_utest mqtt_agent_command_functions_utest
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
4 changes: 4 additions & 0 deletions test/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )

# ==================== Define your project name (edit) ========================
set(project_name "mqtt_agent")

Expand Down
42 changes: 20 additions & 22 deletions tools/coverity/misra.config
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
// MISRA C-2012 Rules

{
version : "2.0",
standard : "c2012",
title: "Coverity MISRA Configuration",
deviations : [
"version" : "2.0",
"standard" : "c2012",
"title": "Coverity MISRA Configuration",
"deviations" : [
// Disable the following rules.
{
deviation: "Directive 4.5",
reason: "Allow names that MISRA considers ambiguous."
"deviation": "Directive 4.5",
"reason": "Allow names that MISRA considers ambiguous."
},
{
deviation: "Directive 4.8",
reason: "Allow inclusion of unused types. Header files for coreMQTT, which are needed by all files, define types that are not used by the agent."
"deviation": "Directive 4.8",
"reason": "Allow inclusion of unused types. Header files for coreMQTT, which are needed by all files, define types that are not used by the agent."
},
{
deviation: "Directive 4.9",
reason: "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
"deviation": "Directive 4.9",
"reason": "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
},
{
deviation: "Rule 2.3",
reason: "Allow unused types. coreMQTT Library headers define types intended for the application's use, but are not used by the agent files."
"deviation": "Rule 2.3",
"reason": "Allow unused types. coreMQTT Library headers define types intended for the application's use, but are not used by the agent files."
},
{
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. coreMQTT Library headers define macros intended for the application's use, but are not used by the agent."
"deviation": "Rule 2.5",
"reason": "Allow unused macros. coreMQTT Library headers define macros intended for the application's use, but are not used by the agent."
},
{
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 11.5",
reason: "Allow casts from void *. Contexts are passed as void * and must be cast to the correct data type before use."
"deviation": "Rule 11.5",
"reason": "Allow casts from void *. Contexts are passed as void * and must be cast to the correct data type before use."
}
]
}

0 comments on commit 5f454ac

Please sign in to comment.