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

Add freertos_command_pool.c unit tests #89

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
#include "FreeRTOS.h"
#include "task.h"

#ifdef UNIT_TESTING

/* Transport interface header file.
* Needed to compile UNIT_TESTING function prototypes. */
#include "transport_interface_api.h"
#endif /* UNIT_TESTING */

/* MQTT library includes. */
#include "core_mqtt_config.h"
#include "core_mqtt_agent.h"
Expand Down
84 changes: 48 additions & 36 deletions components/aws_iot/coremqtt_agent/integration/src/mqtt_agent_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,54 @@ extern SubscriptionElement_t xGlobalSubscriptionList[ SUBSCRIPTION_MANAGER_MAX_S

/*-----------------------------------------------------------*/

/**
* @brief Retry logic to establish a connection to the MQTT broker.
*
* If the connection fails, keep retrying with exponentially increasing
* timeout value, until max retries, max timeout or successful connect.
*
* @param[in] pNetworkContext Network context to connect on.
* @return int pdFALSE if connection failed after retries.
*/
STATIC BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext );

/**
* @brief Initializes an MQTT context, including transport interface and
* network buffer.
*
* @return `MQTTSuccess` if the initialization succeeds, else `MQTTBadParameter`.
*/
STATIC MQTTStatus_t prvMQTTInit( void );

/**
* @brief Sends an MQTT Connect packet over the already connected TCP socket.
* This function takes no inputs, but does rely on the global 'xConnectInfo'
* variable, which contains information such as passwords and user identifiers,
* and whether to start a clean MQTT session.
*
* @return `MQTTSuccess` if connection succeeds, else appropriate error code
* from MQTT_Connect.
*/
STATIC MQTTStatus_t prvMQTTConnect( void );

/**
* @brief Disconnects from the MQTT broker.
* Initiates an MQTT disconnect and then teardown underlying TCP connection.
*/
STATIC void prvDisconnectFromMQTTBroker( void );

/**
* @brief Task for MQTT agent.
* Task runs MQTT agent command loop, which returns only when the user disconnects
* MQTT, terminates agent, or the MQTT connection is broken. If the MQTT connection is broken, the task
* tries to reconnect to the broker.
*
* @param[in] pParam Can be used to pass down functionality to the agent task
*/
STATIC void prvMQTTAgentTask( void * pParam );

/*-----------------------------------------------------------*/

STATIC uint32_t prvGetTimeMs( void )
{
TickType_t xTickCount = 0;
Expand Down Expand Up @@ -243,15 +291,6 @@ STATIC UBaseType_t prvGetRandomNumber( void )
return uxRandomValue;
}

/**
* @brief Retry logic to establish a connection to the MQTT broker.
*
* If the connection fails, keep retrying with exponentially increasing
* timeout value, until max retries, max timeout or successful connect.
*
* @param[in] pNetworkContext Network context to connect on.
* @return int pdFALSE if connection failed after retries.
*/
STATIC BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
{
BaseType_t xConnected = pdFAIL;
Expand Down Expand Up @@ -391,12 +430,6 @@ STATIC void prvReSubscriptionCommandCallback( MQTTAgentCommandContext_t * pxComm
}
}

/**
* @brief Initializes an MQTT context, including transport interface and
* network buffer.
*
* @return `MQTTSuccess` if the initialization succeeds, else `MQTTBadParameter`.
*/
STATIC MQTTStatus_t prvMQTTInit( void )
{
TransportInterface_t xTransport = { 0 };
Expand Down Expand Up @@ -512,15 +545,6 @@ STATIC MQTTStatus_t prvHandleResubscribe( void )
return xResult;
}

/**
* @brief Sends an MQTT Connect packet over the already connected TCP socket.
*
* @param[in] pxMQTTContext MQTT context pointer.
* @param[in] xCleanSession If a clean session should be established.
*
* @return `MQTTSuccess` if connection succeeds, else appropriate error code
* from MQTT_Connect.
*/
STATIC MQTTStatus_t prvMQTTConnect( void )
{
MQTTStatus_t xResult;
Expand Down Expand Up @@ -593,10 +617,6 @@ STATIC void prvDisconnectCommandCallback( MQTTAgentCommandContext_t * pxCommandC
}
}

/**
* @brief Disconnects from the MQTT broker.
* Initiates an MQTT disconnect and then teardown underlying TCP connection.
*/
STATIC void prvDisconnectFromMQTTBroker( void )
{
static MQTTAgentCommandContext_t xCommandContext = { 0 };
Expand Down Expand Up @@ -629,14 +649,6 @@ STATIC void prvDisconnectFromMQTTBroker( void )
}
}

/**
* @brief Task for MQTT agent.
* Task runs MQTT agent command loop, which returns only when the user disconnects
* MQTT, terminates agent, or the mqtt connection is broken. If the mqtt connection is broken, the task
* tries to reconnect to the broker.
*
* @param[in] pParam Can be used to pass down functionality to the agent task
*/
STATIC void prvMQTTAgentTask( void * pParam )
{
BaseType_t xResult;
Expand Down
26 changes: 26 additions & 0 deletions components/aws_iot/coremqtt_agent/integration/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,29 @@ target_link_libraries(mqtt-agent-task-test
trusted-firmware-m-mock
)
iot_reference_arm_corstone3xx_add_test(mqtt-agent-task-test)

add_executable(freertos-command-pool-test
test_freertos_command_pool.cpp
../src/freertos_command_pool.c
)
target_include_directories(freertos-command-pool-test
PRIVATE
.
../../library_mocks/inc

../inc
)
target_link_libraries(freertos-command-pool-test
PRIVATE
fff
backoff-algorithm-mock
coremqtt-agent-mock
coremqtt-agent-test-config-mocks
coremqtt-mock
freertos-kernel-mock
freertos-plus-tcp-mock
helpers-logging-mock
mbedtls-mock
trusted-firmware-m-mock
)
iot_reference_arm_corstone3xx_add_test(freertos-command-pool-test)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "fff.h"

DECLARE_FAKE_VOID_FUNC( vAssertCalled,
const char *,
unsigned long );
Expand Down
Loading
Loading