Skip to content

Commit 5f454ac

Browse files
authored
Update CMakeList & Coverity configuration (#109)
* Update CMakeList to optionally build UT/Coverity; Update coverity configuration * Update version * Add filepath * Fix broken links
1 parent afdd4d5 commit 5f454ac

File tree

6 files changed

+93
-75
lines changed

6 files changed

+93
-75
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
-G "Unix Makefiles" \
3838
-DCMAKE_BUILD_TYPE=Debug \
3939
-DBUILD_CLONE_SUBMODULES=ON \
40+
-DUNITTEST=1 \
4041
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG'
4142
make -C build/ all
4243
@@ -90,7 +91,7 @@ jobs:
9091
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
9192
mkdir -p source/dependency/coreMQTT/docs/doxygen/output
9293
wget -O source/dependency/coreMQTT/docs/doxygen/output/mqtt.tag \
93-
"https://freertos.org/Documentation/api-ref/coreMQTT/docs/doxygen/output/mqtt.tag"
94+
"https://freertos.github.io/coreMQTT/main/mqtt.tag"
9495
echo -e "::endgroup::"
9596
echo -e "${{env.bashPass}} ${{ env.stepName }} ${{ env.bashEnd }}"
9697

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ git submodule update --init --recursive
2525

2626
## coreMQTT Agent Library Configurations
2727

28-
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).
28+
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).
2929

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

132132
## Documentation
133133

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

136136
### Generating documentation
137137

@@ -143,7 +143,7 @@ doxygen docs/doxygen/config.doxyfile
143143
```
144144

145145
## Getting help
146-
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.
146+
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.
147147

148148
## Contributing
149149

source/include/core_mqtt_agent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ typedef struct MQTTAgentCommandInfo
201201
* @param[in] pMqttAgentContext Pointer to struct to initialize.
202202
* @param[in] pMsgInterface Command interface to use for allocating and sending commands.
203203
* @param[in] pNetworkBuffer Pointer to network buffer to use.
204-
* @param[in] pTransportInterface Transport interface to use with the MQTT
205-
* library. See https://www.freertos.org/network-interface.html
204+
* @param[in] pTransportInterface Transport interface to use with the MQTT library.
205+
* See https://www.freertos.org/Documentation/03-Libraries/03-FreeRTOS-core/06-Transport-Interface/01-Transport-interface
206206
* @param[in] getCurrentTimeMs Pointer to a function that returns a count value
207207
* that increments every millisecond.
208208
* @param[in] incomingCallback The callback to execute when receiving publishes.

test/CMakeLists.txt

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
cmake_minimum_required ( VERSION 3.13.0 )
2-
project ( "MQTTAgent unit test"
3-
VERSION 1.0.0
1+
cmake_minimum_required ( VERSION 3.22.0 )
2+
project ( "MQTTAgent tests"
3+
VERSION 1.2.0
44
LANGUAGES C )
55

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

17+
# If no configuration is defined, turn everything on.
18+
if( NOT DEFINED COV_ANALYSIS AND NOT DEFINED UNITTEST )
19+
set( COV_ANALYSIS TRUE )
20+
set( UNITTEST TRUE )
21+
endif()
22+
1723
# Do not allow in-source build.
1824
if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
1925
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
@@ -35,61 +41,70 @@ set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
3541

3642
# ===================================== Coverity Analysis Configuration =================================================
3743

38-
# Include filepaths for source and include.
39-
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
40-
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )
41-
# Target for Coverity analysis that builds the library.
42-
add_library( coverity_analysis
43-
${MQTT_AGENT_SOURCES}
44-
${MQTT_SOURCES}
45-
${MQTT_SERIALIZER_SOURCES} )
44+
if( COV_ANALYSIS )
45+
# Include filepaths for source and include.
46+
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
47+
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )
48+
# Target for Coverity analysis that builds the library.
49+
add_library( coverity_analysis
50+
${MQTT_AGENT_SOURCES}
51+
${MQTT_SOURCES}
52+
${MQTT_SERIALIZER_SOURCES} )
4653

47-
# Build MQTT library target without custom config dependency.
48-
target_compile_definitions( coverity_analysis PUBLIC MQTT_DO_NOT_USE_CUSTOM_CONFIG=1 MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG=1 )
54+
# Build MQTT library target without custom config dependency.
55+
target_compile_definitions( coverity_analysis PUBLIC MQTT_DO_NOT_USE_CUSTOM_CONFIG=1 MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG=1 )
4956

50-
# MQTT AGENT public include path.
51-
target_include_directories( coverity_analysis PUBLIC ${MQTT_AGENT_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} )
57+
# MQTT AGENT public include path.
58+
target_include_directories( coverity_analysis PUBLIC ${MQTT_AGENT_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS} )
5259

53-
# ==================================== Test Configuration ========================================
60+
# Remove inclusion of assert.
61+
add_compile_definitions( NDEBUG=1 )
5462

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

58-
# Include CMock build configuration.
59-
include( unit-test/cmock_build.cmake )
65+
# ==================================== Test Configuration ========================================
6066

61-
# Check if the CMock source directory exists, and if not present, clone the submodule
62-
# if BUILD_CLONE_SUBMODULES configuration is enabled.
63-
if( NOT EXISTS ${CMOCK_DIR}/src )
64-
# Attempt to clone CMock.
65-
if( ${BUILD_CLONE_SUBMODULES} )
66-
clone_cmock()
67-
else()
68-
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." )
67+
if( UNITTEST )
68+
# Define a CMock resource path.
69+
set( CMOCK_DIR ${MODULE_ROOT_DIR}/test/unit-test/CMock CACHE INTERNAL "CMock library source directory." )
70+
71+
# Include CMock build configuration.
72+
include( unit-test/cmock_build.cmake )
73+
74+
# Check if the CMock source directory exists, and if not present, clone the submodule
75+
# if BUILD_CLONE_SUBMODULES configuration is enabled.
76+
if( NOT EXISTS ${CMOCK_DIR}/src )
77+
# Attempt to clone CMock.
78+
if( ${BUILD_CLONE_SUBMODULES} )
79+
clone_cmock()
80+
else()
81+
message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set\
82+
BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
83+
endif()
6984
endif()
70-
endif()
7185

72-
# Add unit test and coverage configuration.
86+
# Add unit test and coverage configuration.
7387

74-
# Use CTest utility for managing test runs. This has to be added BEFORE
75-
# defining test targets with add_test()
76-
enable_testing()
88+
# Use CTest utility for managing test runs. This has to be added BEFORE
89+
# defining test targets with add_test()
90+
enable_testing()
7791

78-
# Add build targets for CMock and Unit, required for unit testing.
79-
add_cmock_targets()
92+
# Add build targets for CMock and Unit, required for unit testing.
93+
add_cmock_targets()
8094

81-
# Add function to enable CMock based tests and coverage.
82-
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/tools/cmock/create_test.cmake )
95+
# Add function to enable CMock based tests and coverage.
96+
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/tools/cmock/create_test.cmake )
8397

84-
# Include build configuration for unit tests.
85-
add_subdirectory( unit-test )
98+
# Include build configuration for unit tests.
99+
add_subdirectory( unit-test )
86100

87-
# ==================================== Coverage Analysis configuration ========================================
101+
# ==================================== Coverage Analysis configuration ========================================
88102

89-
# Add a target for running coverage on tests.
90-
add_custom_target( coverage
91-
COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR}
92-
-P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake
93-
DEPENDS cmock unity mqtt_agent_utest mqtt_agent_command_functions_utest
94-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
95-
)
103+
# Add a target for running coverage on tests.
104+
add_custom_target( coverage
105+
COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR}
106+
-P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake
107+
DEPENDS cmock unity mqtt_agent_utest mqtt_agent_command_functions_utest
108+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
109+
)
110+
endif()

test/unit-test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Include filepaths for source and include.
2+
include( ${MODULE_ROOT_DIR}/source/dependency/coreMQTT/mqttFilePaths.cmake )
3+
include( ${MODULE_ROOT_DIR}/mqttAgentFilePaths.cmake )
4+
15
# ==================== Define your project name (edit) ========================
26
set(project_name "mqtt_agent")
37

tools/coverity/misra.config

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
1-
// MISRA C-2012 Rules
2-
31
{
4-
version : "2.0",
5-
standard : "c2012",
6-
title: "Coverity MISRA Configuration",
7-
deviations : [
2+
"version" : "2.0",
3+
"standard" : "c2012",
4+
"title": "Coverity MISRA Configuration",
5+
"deviations" : [
86
// Disable the following rules.
97
{
10-
deviation: "Directive 4.5",
11-
reason: "Allow names that MISRA considers ambiguous."
8+
"deviation": "Directive 4.5",
9+
"reason": "Allow names that MISRA considers ambiguous."
1210
},
1311
{
14-
deviation: "Directive 4.8",
15-
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."
12+
"deviation": "Directive 4.8",
13+
"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."
1614
},
1715
{
18-
deviation: "Directive 4.9",
19-
reason: "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
16+
"deviation": "Directive 4.9",
17+
"reason": "Allow inclusion of function like macros. Asserts and logging are done using function like macros."
2018
},
2119
{
22-
deviation: "Rule 2.3",
23-
reason: "Allow unused types. coreMQTT Library headers define types intended for the application's use, but are not used by the agent files."
20+
"deviation": "Rule 2.3",
21+
"reason": "Allow unused types. coreMQTT Library headers define types intended for the application's use, but are not used by the agent files."
2422
},
2523
{
26-
deviation: "Rule 2.4",
27-
reason: "Allow unused tags. Some compilers warn if types are not tagged."
24+
"deviation": "Rule 2.4",
25+
"reason": "Allow unused tags. Some compilers warn if types are not tagged."
2826
},
2927
{
30-
deviation: "Rule 2.5",
31-
reason: "Allow unused macros. coreMQTT Library headers define macros intended for the application's use, but are not used by the agent."
28+
"deviation": "Rule 2.5",
29+
"reason": "Allow unused macros. coreMQTT Library headers define macros intended for the application's use, but are not used by the agent."
3230
},
3331
{
34-
deviation: "Rule 3.1",
35-
reason: "Allow nested comments. Documentation blocks contain comments for example code."
32+
"deviation": "Rule 3.1",
33+
"reason": "Allow nested comments. Documentation blocks contain comments for example code."
3634
},
3735
{
38-
deviation: "Rule 11.5",
39-
reason: "Allow casts from void *. Contexts are passed as void * and must be cast to the correct data type before use."
36+
"deviation": "Rule 11.5",
37+
"reason": "Allow casts from void *. Contexts are passed as void * and must be cast to the correct data type before use."
4038
}
4139
]
4240
}

0 commit comments

Comments
 (0)