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

Updating the coreMQTT submodule pointer #124

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
4 changes: 4 additions & 0 deletions .github/.cSpellWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ utest
vect
writev
xlarge
DCMAKE
Wextra
Wsign
Werror
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
echo -e "::group::${{ env.bashInfo }} Generate Coverage Report ${{ env.bashEnd }}"
# Generate coverage report, excluding extra directories
lcov --rc lcov_branch_coverage=1 -r build/coverage.info -o build/coverage.info '*test*' '*CMakeCCompilerId*' '*mocks*' '*dependency*'
lcov --rc lcov_branch_coverage=1 -r build/coverage.info -o build/coverage.info
echo "::endgroup::"
lcov --rc lcov_branch_coverage=1 --list build/coverage.info
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,28 @@ git submodule update --checkout --init --recursive test/unit-test/CMock

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

1. Run the *cmake* command: `cmake -S test -B build`
1. Run the *cmake* command:

For Linux machines:
```
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_CLONE_SUBMODULES=ON \
-DUNITTEST=1 \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Wsign-compare -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG'
```
For Mac machines:

```
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_CLONE_SUBMODULES=ON \
-DUNITTEST=1 \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Wsign-compare -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG' \
-DCMAKE_C_STANDARD=99
```

1. Run this command to build the library and unit tests: `make -C build all`

Expand Down
12 changes: 6 additions & 6 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</tr>
<tr>
<td>core_mqtt.c (coreMQTT)</td>
<td><center>4.1K</center></td>
<td><center>3.5K</center></td>
<td><center>4.9K</center></td>
<td><center>4.2K</center></td>
</tr>
<tr>
<td>core_mqtt_state.c (coreMQTT)</td>
Expand All @@ -29,12 +29,12 @@
</tr>
<tr>
<td>core_mqtt_serializer.c (coreMQTT)</td>
<td><center>2.8K</center></td>
<td><center>2.2K</center></td>
<td><center>2.9K</center></td>
<td><center>2.3K</center></td>
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>10.6K</center></b></td>
<td><b><center>8.7K</center></b></td>
<td><b><center>11.5K</center></b></td>
<td><b><center>9.5K</center></b></td>
</tr>
</table>
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |
license: "MIT"
dependencies:
- name : "coreMQTT"
version: "v2.3.1"
version: "86a5750bb31e05fa69ef3f4e2f5e69d9317fae44"
license: "MIT"
repository:
type: "git"
Expand Down
2 changes: 0 additions & 2 deletions source/core_mqtt_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ static void mqttEventCallback( MQTTContext_t * pMqttContext,
break;

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

case PUBLISH:
default:
/* Publish, does not need to be cast since we do not check it. */
ret = ( pParams != NULL );
Expand Down
2 changes: 1 addition & 1 deletion source/dependency/coreMQTT
Submodule coreMQTT updated 61 files
+7 −0 .github/.cSpellWords.txt
+4 −2 .github/workflows/ci.yml
+91 −45 .github/workflows/release.yml
+31 −7 README.md
+2 −2 docs/doxygen/config.doxyfile
+6 −6 docs/doxygen/include/size_table.md
+1 −1 manifest.yml
+0 −45 sbom.spdx
+563 −190 source/core_mqtt.c
+38 −13 source/core_mqtt_serializer.c
+10 −16 source/core_mqtt_state.c
+234 −4 source/include/core_mqtt.h
+1 −1 source/include/core_mqtt_config_defaults.h
+35 −15 source/include/core_mqtt_serializer.h
+1 −1 source/include/core_mqtt_state.h
+1 −1 source/interface/transport_interface.h
+1 −1 test/cbmc/include/core_mqtt_config.h
+1 −1 test/cbmc/include/event_callback_stub.h
+1 −1 test/cbmc/include/get_time_stub.h
+1 −1 test/cbmc/include/mqtt_cbmc_state.h
+1 −1 test/cbmc/include/network_interface_stubs.h
+1 −1 test/cbmc/proofs/MQTT_Connect/MQTT_Connect_harness.c
+1 −1 test/cbmc/proofs/MQTT_DeserializeAck/MQTT_DeserializeAck_harness.c
+1 −1 test/cbmc/proofs/MQTT_DeserializePublish/MQTT_DeserializePublish_harness.c
+1 −1 test/cbmc/proofs/MQTT_Disconnect/MQTT_Disconnect_harness.c
+1 −1 test/cbmc/proofs/MQTT_GetIncomingPacketTypeAndLength/MQTT_GetIncomingPacketTypeAndLength_harness.c
+1 −1 test/cbmc/proofs/MQTT_GetPacketId/MQTT_GetPacketId_harness.c
+1 −1 test/cbmc/proofs/MQTT_GetSubAckStatusCodes/MQTT_GetSubAckStatusCodes_harness.c
+1 −1 test/cbmc/proofs/MQTT_Init/MQTT_Init_harness.c
+1 −1 test/cbmc/proofs/MQTT_MatchTopic/MQTT_MatchTopic_harness.c
+1 −1 test/cbmc/proofs/MQTT_Ping/MQTT_Ping_harness.c
+10 −1 test/cbmc/proofs/MQTT_ProcessLoop/MQTT_ProcessLoop_harness.c
+1 −1 test/cbmc/proofs/MQTT_Publish/MQTT_Publish_harness.c
+10 −1 test/cbmc/proofs/MQTT_ReceiveLoop/MQTT_ReceiveLoop_harness.c
+2 −2 test/cbmc/proofs/MQTT_SerializeAck/MQTT_SerializeAck_harness.c
+1 −1 test/cbmc/proofs/MQTT_SerializeConnect/MQTT_SerializeConnect_harness.c
+2 −2 test/cbmc/proofs/MQTT_SerializeDisconnect/MQTT_SerializeDisconnect_harness.c
+2 −2 test/cbmc/proofs/MQTT_SerializePingreq/MQTT_SerializePingreq_harness.c
+1 −1 test/cbmc/proofs/MQTT_SerializePublish/MQTT_SerializePublish_harness.c
+1 −1 test/cbmc/proofs/MQTT_SerializePublishHeader/MQTT_SerializePublishHeader_harness.c
+1 −1 test/cbmc/proofs/MQTT_SerializeSubscribe/MQTT_SerializeSubscribe_harness.c
+1 −1 test/cbmc/proofs/MQTT_SerializeUnsubscribe/MQTT_SerializeUnsubscribe_harness.c
+1 −1 test/cbmc/proofs/MQTT_Subscribe/MQTT_Subscribe_harness.c
+1 −1 test/cbmc/proofs/MQTT_Unsubscribe/MQTT_Unsubscribe_harness.c
+212 −184 test/cbmc/proofs/Makefile.common
+1 −1 test/cbmc/sources/mqtt_cbmc_state.c
+1 −1 test/cbmc/stubs/event_callback_stub.c
+1 −1 test/cbmc/stubs/get_time_stub.c
+1 −1 test/cbmc/stubs/memmove.c
+1 −1 test/cbmc/stubs/network_interface_stubs.c
+1 −1 test/unit-test/cmock_opaque_types.h
+1 −1 test/unit-test/core_mqtt_config.h
+41 −1 test/unit-test/core_mqtt_serializer_utest.c
+1 −1 test/unit-test/core_mqtt_state_utest.c
+1,538 −80 test/unit-test/core_mqtt_utest.c
+1 −1 test/unit-test/logging/logging_levels.h
+2 −8 test/unit-test/logging/logging_stack.h
+8 −7 tools/cmock/coverage.cmake
+17 −15 tools/cmock/create_test.cmake
+0 −1 tools/cmock/project.yml
+1 −1 tools/coverity/README.md
2 changes: 2 additions & 0 deletions source/include/core_mqtt_agent_config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#endif
/* *INDENT-ON* */

#include "core_mqtt_config_defaults.h"

/* MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG allows building the MQTT library
* without a custom config. If a custom config is provided, the
* MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG macro should be defined. */
Expand Down
36 changes: 36 additions & 0 deletions test/unit-test/cmock_opaque_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef CMOCK_OPAQUE_TYPES_H_
#define CMOCK_OPAQUE_TYPES_H_

/* CMock does not support opaque types so needs concrete definitions for them.
* This file is included in CMock .c files. */

struct MQTTVec
{
void * a;
int b;
};

#endif /* ifndef CMOCK_OPAQUE_TYPES_H_ */
58 changes: 58 additions & 0 deletions test/unit-test/mqtt_agent_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ static bool stubReleaseCommand( MQTTAgentCommand_t * pCommandToRelease )
return true;
}

/**
* @brief A mocked function to release an allocated command.
*/
static bool stubReleaseCommandFailed( MQTTAgentCommand_t * pCommandToRelease )
{
( void ) pCommandToRelease;
commandReleaseCallCount++;
return false;
}

/**
* @brief A mock publish callback function.
*/
Expand Down Expand Up @@ -802,6 +812,29 @@ void test_MQTTAgent_Ping_Command_Send_Failure( void )
TEST_ASSERT_EQUAL( PING, command.commandType );
}

/**
* @brief Test error case when a command cannot be enqueued and the release also fails.
*/
void test_MQTTAgent_Ping_Command_Send_Failure_Release_Failed( void )
{
MQTTAgentContext_t agentContext = { 0 };
MQTTStatus_t mqttStatus;
MQTTAgentCommandInfo_t commandInfo = { 0 };
MQTTAgentCommand_t command = { 0 };

setupAgentContext( &agentContext );

pCommandToReturn = &command;
agentContext.agentInterface.send = stubSendFail;
agentContext.agentInterface.releaseCommand = stubReleaseCommandFailed;
mqttStatus = MQTTAgent_Ping( &agentContext, &commandInfo );
TEST_ASSERT_EQUAL( MQTTSendFailed, mqttStatus );
/* Test that the command was released. */
TEST_ASSERT_EQUAL_INT( 1, commandReleaseCallCount );
/* Also test that the command was set. */
TEST_ASSERT_EQUAL( PING, command.commandType );
}

/**
* @brief Test that an MQTTNoMemory error is returned when there
* is no more space to store a pending acknowledgment for
Expand Down Expand Up @@ -1577,6 +1610,31 @@ void test_MQTTAgent_CommandLoop_with_eventCallback( void )
TEST_ASSERT_EQUAL( 0, mqttAgentContext.pPendingAcks[ 0 ].packetId );
TEST_ASSERT_EQUAL( NULL, mqttAgentContext.pPendingAcks[ 0 ].pOriginalCommand );

/* Invoking mqttEventCallback with MQTT_PACKET_TYPE_PUBACK packet type with release command failed.
* MQTT_PACKET_TYPE_PUBCOMP, MQTT_PACKET_TYPE_SUBACK, MQTT_PACKET_TYPE_UNSUBACK
* packet types code path will also be covered by this test case. */
packetType = MQTT_PACKET_TYPE_PUBACK;
commandCompleteCallbackCount = 0;

mqttAgentContext.pPendingAcks[ 0 ].packetId = 1U;
command.pCommandCompleteCallback = stubCompletionCallback;
mqttAgentContext.pPendingAcks[ 0 ].pOriginalCommand = &command;

MQTTAgentCommand_Publish_ExpectAnyArgsAndReturn( MQTTSuccess );
MQTTAgentCommand_Publish_ReturnThruPtr_pReturnFlags( &returnFlags );
mqttAgentContext.agentInterface.releaseCommand = stubReleaseCommandFailed;

MQTT_ProcessLoop_Stub( MQTT_ProcessLoop_CustomStub );

mqttStatus = MQTTAgent_CommandLoop( &mqttAgentContext );

TEST_ASSERT_EQUAL( MQTTSuccess, mqttStatus );
/* Ensure that callback is invoked. */
TEST_ASSERT_EQUAL( 2, commandCompleteCallbackCount );
/* Ensure that acknowledgment is cleared. */
TEST_ASSERT_EQUAL( 0, mqttAgentContext.pPendingAcks[ 0 ].packetId );
TEST_ASSERT_EQUAL( NULL, mqttAgentContext.pPendingAcks[ 0 ].pOriginalCommand );

/* mqttEventcallback behavior when the command for the pending ack is NULL for the received PUBACK. */
commandCompleteCallbackCount = 0;
mqttAgentContext.pPendingAcks[ 0 ].packetId = 1U;
Expand Down
7 changes: 4 additions & 3 deletions tools/cmock/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
--initial
--capture
--rc lcov_branch_coverage=1
--rc genhtml_branch_coverage=1
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info
--include "*source*"

)
file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*")

Expand Down Expand Up @@ -46,10 +47,10 @@ execute_process(COMMAND ruby
execute_process(
COMMAND lcov --capture
--rc lcov_branch_coverage=1
--rc genhtml_branch_coverage=1
--base-directory ${CMAKE_BINARY_DIR}
--directory ${CMAKE_BINARY_DIR}
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info
--include "*source*"
)

# combile baseline results (zeros) with the one after running the tests
Expand All @@ -59,8 +60,8 @@ execute_process(
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
--output-file ${CMAKE_BINARY_DIR}/coverage.info
--no-external
--rc lcov_branch_coverage=1
--include "*source*"
)
execute_process(
COMMAND genhtml --rc lcov_branch_coverage=1
Expand Down
25 changes: 15 additions & 10 deletions tools/cmock/create_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function(create_test test_name
add_dependencies(${test_name} ${dependency})
target_link_libraries(${test_name} ${dependency})
endforeach()
target_link_libraries(${test_name} -lgcov unity)
target_link_libraries(${test_name} unity)
target_link_directories(${test_name} PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/lib
)
Expand Down Expand Up @@ -129,11 +129,20 @@ function(create_mock_list mock_name
${mocks_dir}
${mock_include_list}
)
set_target_properties(${mock_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
POSITION_INDEPENDENT_CODE ON
)
target_compile_definitions(${mock_name} PUBLIC
if (APPLE)
set_target_properties(${mock_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
POSITION_INDEPENDENT_CODE ON
LINK_FLAGS "-Wl,-undefined,dynamic_lookup"
)
else()
set_target_properties(${mock_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
POSITION_INDEPENDENT_CODE ON
)
endif()

target_compile_definitions(${mock_name} PUBLIC
${mock_define_list}
)
target_link_libraries(${mock_name} cmock unity)
Expand All @@ -160,9 +169,5 @@ function(create_real_library target
)
if(NOT(mock_name STREQUAL ""))
add_dependencies(${target} ${mock_name})
target_link_libraries(${target}
-l${mock_name}
-lgcov
)
endif()
endfunction()
3 changes: 2 additions & 1 deletion tools/cmock/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:includes: # This will add these includes to each mock.
- <stdbool.h>
- <stdint.h>
:includes_c_post_header:
- <cmock_opaque_types.h>
:treat_externs: :exclude # Now the extern-ed functions will be mocked.
:weak: __attribute__((weak))
:treat_externs: :include
Loading