Skip to content

Commit a74d35a

Browse files
DakshitBabbarDakshit Babbaraggarg
authored
Updating the coreMQTT submodule pointer (#124)
* Update the coreMQTT submodule pointer * Update the manifest.yml file * Include he core_mqtt_config_defaults.h file in the core_mqtt_agent_config_defaults.h file * Update readme for correct command to build unit tests on mac and linux * Added a definition of the qpaque pointer MQTTVec_t for CMock * Remove weak symbols for the mocked implementation to run unit-tests correctly on Mac machines * Modify coverage.cmake to run coverage succefully on mac machines * Modify the CI command for making coverage report * Modify unit tests for full coverage * Resolve formatting, spellcheck and memory size * Update coreMQTT Submodule Pointer to the Latest commmit with coverity updates * Update indentation in .cmake file Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]> --------- Co-authored-by: Dakshit Babbar <[email protected]> Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
1 parent ddae26c commit a74d35a

File tree

13 files changed

+152
-26
lines changed

13 files changed

+152
-26
lines changed

.github/.cSpellWords.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,7 @@ utest
172172
vect
173173
writev
174174
xlarge
175+
DCMAKE
176+
Wextra
177+
Wsign
178+
Werror

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
5858
echo -e "::group::${{ env.bashInfo }} Generate Coverage Report ${{ env.bashEnd }}"
5959
# Generate coverage report, excluding extra directories
60-
lcov --rc lcov_branch_coverage=1 -r build/coverage.info -o build/coverage.info '*test*' '*CMakeCCompilerId*' '*mocks*' '*dependency*'
60+
lcov --rc lcov_branch_coverage=1 -r build/coverage.info -o build/coverage.info
6161
6262
echo "::endgroup::"
6363
lcov --rc lcov_branch_coverage=1 --list build/coverage.info

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,28 @@ git submodule update --checkout --init --recursive test/unit-test/CMock
103103

104104
1. Go to the root directory of this repository. (Make sure that the **CMock** submodule is cloned as described [above](#checkout-cmock-submodule))
105105

106-
1. Run the *cmake* command: `cmake -S test -B build`
106+
1. Run the *cmake* command:
107+
108+
For Linux machines:
109+
```
110+
cmake -S test -B build/ \
111+
-G "Unix Makefiles" \
112+
-DCMAKE_BUILD_TYPE=Debug \
113+
-DBUILD_CLONE_SUBMODULES=ON \
114+
-DUNITTEST=1 \
115+
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Wsign-compare -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG'
116+
```
117+
For Mac machines:
118+
119+
```
120+
cmake -S test -B build/ \
121+
-G "Unix Makefiles" \
122+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
123+
-DBUILD_CLONE_SUBMODULES=ON \
124+
-DUNITTEST=1 \
125+
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Wsign-compare -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG' \
126+
-DCMAKE_C_STANDARD=99
127+
```
107128
108129
1. Run this command to build the library and unit tests: `make -C build all`
109130

docs/doxygen/include/size_table.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
</tr>
2020
<tr>
2121
<td>core_mqtt.c (coreMQTT)</td>
22-
<td><center>4.1K</center></td>
23-
<td><center>3.5K</center></td>
22+
<td><center>4.9K</center></td>
23+
<td><center>4.2K</center></td>
2424
</tr>
2525
<tr>
2626
<td>core_mqtt_state.c (coreMQTT)</td>
@@ -29,12 +29,12 @@
2929
</tr>
3030
<tr>
3131
<td>core_mqtt_serializer.c (coreMQTT)</td>
32-
<td><center>2.8K</center></td>
33-
<td><center>2.2K</center></td>
32+
<td><center>2.9K</center></td>
33+
<td><center>2.3K</center></td>
3434
</tr>
3535
<tr>
3636
<td><b>Total estimates</b></td>
37-
<td><b><center>10.6K</center></b></td>
38-
<td><b><center>8.7K</center></b></td>
37+
<td><b><center>11.5K</center></b></td>
38+
<td><b><center>9.5K</center></b></td>
3939
</tr>
4040
</table>

manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
license: "MIT"
66
dependencies:
77
- name : "coreMQTT"
8-
version: "v2.3.1"
8+
version: "86a5750bb31e05fa69ef3f4e2f5e69d9317fae44"
99
license: "MIT"
1010
repository:
1111
type: "git"

source/core_mqtt_agent.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,6 @@ static void mqttEventCallback( MQTTContext_t * pMqttContext,
710710
break;
711711

712712
/* Any other packet type is invalid. */
713-
case MQTT_PACKET_TYPE_PINGRESP:
714713
default:
715714
LogError( ( "Unknown packet type received:(%02x).\n",
716715
pPacketInfo->type ) );
@@ -953,7 +952,6 @@ static bool validateParams( MQTTAgentCommandType_t commandType,
953952
( pSubscribeArgs->numSubscriptions != 0U ) );
954953
break;
955954

956-
case PUBLISH:
957955
default:
958956
/* Publish, does not need to be cast since we do not check it. */
959957
ret = ( pParams != NULL );

source/dependency/coreMQTT

Submodule coreMQTT updated 61 files

source/include/core_mqtt_agent_config_defaults.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#endif
4242
/* *INDENT-ON* */
4343

44+
#include "core_mqtt_config_defaults.h"
45+
4446
/* MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG allows building the MQTT library
4547
* without a custom config. If a custom config is provided, the
4648
* MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG macro should be defined. */

test/unit-test/cmock_opaque_types.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
* this software and associated documentation files (the "Software"), to deal in
8+
* the Software without restriction, including without limitation the rights to
9+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
* the Software, and to permit persons to whom the Software is furnished to do so,
11+
* subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
#ifndef CMOCK_OPAQUE_TYPES_H_
25+
#define CMOCK_OPAQUE_TYPES_H_
26+
27+
/* CMock does not support opaque types so needs concrete definitions for them.
28+
* This file is included in CMock .c files. */
29+
30+
struct MQTTVec
31+
{
32+
void * a;
33+
int b;
34+
};
35+
36+
#endif /* ifndef CMOCK_OPAQUE_TYPES_H_ */

test/unit-test/mqtt_agent_utest.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ static bool stubReleaseCommand( MQTTAgentCommand_t * pCommandToRelease )
216216
return true;
217217
}
218218

219+
/**
220+
* @brief A mocked function to release an allocated command.
221+
*/
222+
static bool stubReleaseCommandFailed( MQTTAgentCommand_t * pCommandToRelease )
223+
{
224+
( void ) pCommandToRelease;
225+
commandReleaseCallCount++;
226+
return false;
227+
}
228+
219229
/**
220230
* @brief A mock publish callback function.
221231
*/
@@ -802,6 +812,29 @@ void test_MQTTAgent_Ping_Command_Send_Failure( void )
802812
TEST_ASSERT_EQUAL( PING, command.commandType );
803813
}
804814

815+
/**
816+
* @brief Test error case when a command cannot be enqueued and the release also fails.
817+
*/
818+
void test_MQTTAgent_Ping_Command_Send_Failure_Release_Failed( void )
819+
{
820+
MQTTAgentContext_t agentContext = { 0 };
821+
MQTTStatus_t mqttStatus;
822+
MQTTAgentCommandInfo_t commandInfo = { 0 };
823+
MQTTAgentCommand_t command = { 0 };
824+
825+
setupAgentContext( &agentContext );
826+
827+
pCommandToReturn = &command;
828+
agentContext.agentInterface.send = stubSendFail;
829+
agentContext.agentInterface.releaseCommand = stubReleaseCommandFailed;
830+
mqttStatus = MQTTAgent_Ping( &agentContext, &commandInfo );
831+
TEST_ASSERT_EQUAL( MQTTSendFailed, mqttStatus );
832+
/* Test that the command was released. */
833+
TEST_ASSERT_EQUAL_INT( 1, commandReleaseCallCount );
834+
/* Also test that the command was set. */
835+
TEST_ASSERT_EQUAL( PING, command.commandType );
836+
}
837+
805838
/**
806839
* @brief Test that an MQTTNoMemory error is returned when there
807840
* is no more space to store a pending acknowledgment for
@@ -1577,6 +1610,31 @@ void test_MQTTAgent_CommandLoop_with_eventCallback( void )
15771610
TEST_ASSERT_EQUAL( 0, mqttAgentContext.pPendingAcks[ 0 ].packetId );
15781611
TEST_ASSERT_EQUAL( NULL, mqttAgentContext.pPendingAcks[ 0 ].pOriginalCommand );
15791612

1613+
/* Invoking mqttEventCallback with MQTT_PACKET_TYPE_PUBACK packet type with release command failed.
1614+
* MQTT_PACKET_TYPE_PUBCOMP, MQTT_PACKET_TYPE_SUBACK, MQTT_PACKET_TYPE_UNSUBACK
1615+
* packet types code path will also be covered by this test case. */
1616+
packetType = MQTT_PACKET_TYPE_PUBACK;
1617+
commandCompleteCallbackCount = 0;
1618+
1619+
mqttAgentContext.pPendingAcks[ 0 ].packetId = 1U;
1620+
command.pCommandCompleteCallback = stubCompletionCallback;
1621+
mqttAgentContext.pPendingAcks[ 0 ].pOriginalCommand = &command;
1622+
1623+
MQTTAgentCommand_Publish_ExpectAnyArgsAndReturn( MQTTSuccess );
1624+
MQTTAgentCommand_Publish_ReturnThruPtr_pReturnFlags( &returnFlags );
1625+
mqttAgentContext.agentInterface.releaseCommand = stubReleaseCommandFailed;
1626+
1627+
MQTT_ProcessLoop_Stub( MQTT_ProcessLoop_CustomStub );
1628+
1629+
mqttStatus = MQTTAgent_CommandLoop( &mqttAgentContext );
1630+
1631+
TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
1632+
/* Ensure that callback is invoked. */
1633+
TEST_ASSERT_EQUAL( 2, commandCompleteCallbackCount );
1634+
/* Ensure that acknowledgment is cleared. */
1635+
TEST_ASSERT_EQUAL( 0, mqttAgentContext.pPendingAcks[ 0 ].packetId );
1636+
TEST_ASSERT_EQUAL( NULL, mqttAgentContext.pPendingAcks[ 0 ].pOriginalCommand );
1637+
15801638
/* mqttEventcallback behavior when the command for the pending ack is NULL for the received PUBACK. */
15811639
commandCompleteCallbackCount = 0;
15821640
mqttAgentContext.pPendingAcks[ 0 ].packetId = 1U;

tools/cmock/coverage.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
1515
--initial
1616
--capture
1717
--rc lcov_branch_coverage=1
18-
--rc genhtml_branch_coverage=1
1918
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info
19+
--include "*source*"
20+
2021
)
2122
file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*")
2223

@@ -46,10 +47,10 @@ execute_process(COMMAND ruby
4647
execute_process(
4748
COMMAND lcov --capture
4849
--rc lcov_branch_coverage=1
49-
--rc genhtml_branch_coverage=1
5050
--base-directory ${CMAKE_BINARY_DIR}
5151
--directory ${CMAKE_BINARY_DIR}
5252
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info
53+
--include "*source*"
5354
)
5455

5556
# combile baseline results (zeros) with the one after running the tests
@@ -59,8 +60,8 @@ execute_process(
5960
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
6061
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
6162
--output-file ${CMAKE_BINARY_DIR}/coverage.info
62-
--no-external
6363
--rc lcov_branch_coverage=1
64+
--include "*source*"
6465
)
6566
execute_process(
6667
COMMAND genhtml --rc lcov_branch_coverage=1

tools/cmock/create_test.cmake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function(create_test test_name
4545
add_dependencies(${test_name} ${dependency})
4646
target_link_libraries(${test_name} ${dependency})
4747
endforeach()
48-
target_link_libraries(${test_name} -lgcov unity)
48+
target_link_libraries(${test_name} unity)
4949
target_link_directories(${test_name} PUBLIC
5050
${CMAKE_CURRENT_BINARY_DIR}/lib
5151
)
@@ -129,11 +129,20 @@ function(create_mock_list mock_name
129129
${mocks_dir}
130130
${mock_include_list}
131131
)
132-
set_target_properties(${mock_name} PROPERTIES
133-
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
134-
POSITION_INDEPENDENT_CODE ON
135-
)
136-
target_compile_definitions(${mock_name} PUBLIC
132+
if (APPLE)
133+
set_target_properties(${mock_name} PROPERTIES
134+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
135+
POSITION_INDEPENDENT_CODE ON
136+
LINK_FLAGS "-Wl,-undefined,dynamic_lookup"
137+
)
138+
else()
139+
set_target_properties(${mock_name} PROPERTIES
140+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
141+
POSITION_INDEPENDENT_CODE ON
142+
)
143+
endif()
144+
145+
target_compile_definitions(${mock_name} PUBLIC
137146
${mock_define_list}
138147
)
139148
target_link_libraries(${mock_name} cmock unity)
@@ -160,9 +169,5 @@ function(create_real_library target
160169
)
161170
if(NOT(mock_name STREQUAL ""))
162171
add_dependencies(${target} ${mock_name})
163-
target_link_libraries(${target}
164-
-l${mock_name}
165-
-lgcov
166-
)
167172
endif()
168173
endfunction()

tools/cmock/project.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
:includes: # This will add these includes to each mock.
2222
- <stdbool.h>
2323
- <stdint.h>
24+
:includes_c_post_header:
25+
- <cmock_opaque_types.h>
2426
:treat_externs: :exclude # Now the extern-ed functions will be mocked.
25-
:weak: __attribute__((weak))
2627
:treat_externs: :include

0 commit comments

Comments
 (0)