AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
iot_tests_mqtt_system.c File Reference

Full system tests for the MQTT library. More...

#include "iot_config.h"
#include <stdio.h>
#include <string.h>
#include "iot_init.h"
#include "private/iot_mqtt_internal.h"
#include "platform/iot_clock.h"
#include "platform/iot_threads.h"
#include <IOT_TEST_NETWORK_HEADER>
#include "unity_fixture.h"

Data Structures

struct  _operationCompleteParams_t
 Parameter 1 of _operationComplete. More...
 

Macros

#define AWS_IOT_MQTT_SERVER   true
 Determine which MQTT server mode to test (AWS IoT or Mosquitto).
 
#define CLIENT_IDENTIFIER_MAX_LENGTH   ( 24 )
 The maximum length of an MQTT client identifier. More...
 
#define GENERATE_TOPIC_WITH_SUFFIX(bufferName, suffix)
 Generates a topic by suffixing the client identifier with a suffix. More...
 

Functions

static IotMqttError_t _mqttConnect (const IotMqttNetworkInfo_t *pNetworkInfo, const IotMqttConnectInfo_t *pConnectInfo, uint32_t timeoutMs, IotMqttConnection_t *const pMqttConnection)
 Establish an MQTT connection. Retry if enabled.
 
static void _freePacket (uint8_t *pPacket)
 Packet free function override.
 
static IotMqttError_t _serializeConnect (const IotMqttConnectInfo_t *pConnectInfo, uint8_t **pConnectPacket, size_t *pPacketSize)
 Serializer override for CONNECT.
 
static IotMqttError_t _serializePublish (const IotMqttPublishInfo_t *pPublishInfo, uint8_t **pPublishPacket, size_t *pPacketSize, uint16_t *pPacketIdentifier, uint8_t **pPacketIdentifierHigh)
 Serializer override for PUBLISH.
 
static IotMqttError_t _serializePuback (uint16_t packetIdentifier, uint8_t **pPubackPacket, size_t *pPacketSize)
 Serializer override for PUBACK.
 
static IotMqttError_t _serializeSubscribe (const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint8_t **pSubscribePacket, size_t *pPacketSize, uint16_t *pPacketIdentifier)
 Serializer override for SUBSCRIBE.
 
static IotMqttError_t _serializeUnsubscribe (const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint8_t **pSubscribePacket, size_t *pPacketSize, uint16_t *pPacketIdentifier)
 Serializer override for UNSUBSCRIBE.
 
static IotMqttError_t _serializeDisconnect (uint8_t **pDisconnectPacket, size_t *pPacketSize)
 Serializer override for DISCONNECT.
 
static void _publishReceived (void *pArgument, IotMqttCallbackParam_t *pPublish)
 Subscription callback function. Checks for valid parameters and unblocks the main test thread.
 
static void _operationComplete (void *pArgument, IotMqttCallbackParam_t *pOperation)
 Operation completion callback function. Checks for valid parameters and unblocks the main test thread.
 
static void _subscribePublishWait (IotMqttQos_t qos)
 Run the subscribe-publish-wait tests at various QoS.
 
 TEST_GROUP (MQTT_System)
 Test group for MQTT system tests.
 
 TEST_SETUP (MQTT_System)
 Test setup for MQTT system tests.
 
 TEST_TEAR_DOWN (MQTT_System)
 Test tear down for MQTT system tests.
 
 TEST_GROUP_RUNNER (MQTT_System)
 Test group runner for MQTT system tests.
 
void TEST_MQTT_System_SubscribePublishWaitQoS0_ (void)
 Subscribe-publish-wait (QoS 0).
 
void TEST_MQTT_System_SubscribePublishWaitQoS1_ (void)
 Subscribe-publish-wait (QoS 1).
 
void TEST_MQTT_System_SubscribePublishAsync_ (void)
 Subscribe-publish asynchronous (QoS 1).
 
void TEST_MQTT_System_LastWillAndTestament_ (void)
 Test that a LWT is published if an MQTT connection is unexpectedly closed.
 
void TEST_MQTT_System_RestorePreviousSession_ (void)
 Test that subscriptions from a previous session are restored.
 
void TEST_MQTT_System_WaitAfterDisconnect_ (void)
 Test that Wait can be safely invoked after Disconnect.
 

Variables

static const struct IotNetworkServerInfo _serverInfo = IOT_TEST_NETWORK_SERVER_INFO_INITIALIZER
 Network server info to share among the tests.
 
static IotMqttNetworkInfo_t _networkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER
 Network credential info to share among the tests. More...
 
static const IotMqttSerializer_t _mqttSerializer
 Function pointers to the default MQTT serializers. More...
 
static const IotMqttSerializer_t_pMqttSerializer = &_mqttSerializer
 The MQTT serializers to use in these tests.
 
static IotMqttConnection_t _mqttConnection = IOT_MQTT_CONNECTION_INITIALIZER
 An MQTT connection to share among the tests.
 
static const char _pSamplePayload []
 Filler text to publish. More...
 
static const size_t _samplePayloadLength = sizeof( _pSamplePayload ) - 1
 Length of _pSamplePayload.
 
static char _pClientIdentifier [CLIENT_IDENTIFIER_MAX_LENGTH] = { 0 }
 Buffer holding the client identifier used for the tests.
 
static bool _freePacketOverride = false
 Tracks if _freePacket was called.
 
static bool _connectSerializerOverride = false
 Tracks if _connectSerializerOverride was called.
 
static bool _publishSerializerOverride = false
 Tracks if _publishSerializerOverride was called.
 
static bool _pubackSerializerOverride = false
 Tracks if _pubackSerializerOverride was called.
 
static bool _subscribeSerializerOverride = false
 Tracks if _subscribeSerializerOverride was called.
 
static bool _unsubscribeSerializerOverride = false
 Tracks if _unsubscribeSerializerOverride was called.
 
static bool _disconnectSerializerOverride = false
 Tracks if _disconnectSerializerOverride was called.
 

Detailed Description

Full system tests for the MQTT library.

Macro Definition Documentation

◆ CLIENT_IDENTIFIER_MAX_LENGTH

#define CLIENT_IDENTIFIER_MAX_LENGTH   ( 24 )

The maximum length of an MQTT client identifier.

When IOT_TEST_MQTT_CLIENT_IDENTIFIER is defined, this value must accommodate the length of IOT_TEST_MQTT_CLIENT_IDENTIFIER plus 4 to accommodate the Last Will and Testament test. Otherwise, this value is set to 24, which is the longest client identifier length an MQTT server is obligated to accept plus a NULL terminator.

◆ GENERATE_TOPIC_WITH_SUFFIX

#define GENERATE_TOPIC_WITH_SUFFIX (   bufferName,
  suffix 
)
Value:
char bufferName[ CLIENT_IDENTIFIER_MAX_LENGTH + sizeof( suffix ) ] = { 0 }; \
( void ) snprintf( bufferName, \
CLIENT_IDENTIFIER_MAX_LENGTH + sizeof( suffix ), \
"%s%s", \
_pClientIdentifier, \
suffix );
#define CLIENT_IDENTIFIER_MAX_LENGTH
The maximum length of an MQTT client identifier.
Definition: iot_tests_mqtt_system.c:98

Generates a topic by suffixing the client identifier with a suffix.

Parameters
[in]bufferNameThe name of the buffer for the topic.
[in]suffixThe suffix to place at the end of the client identifier.

Variable Documentation

◆ _networkInfo

Network credential info to share among the tests.

An MQTT network setup parameter to share among the tests.

◆ _mqttSerializer

const IotMqttSerializer_t _mqttSerializer
static
Initial value:
=
{
.getPacketType = _IotMqtt_GetPacketType,
.getRemainingLength = _IotMqtt_GetRemainingLength,
.freePacket = _IotMqtt_FreePacket,
.serialize =
{
.publishSetDup = _IotMqtt_PublishSetDup,
},
.deserialize =
{
}
}
IotMqttError_t _IotMqtt_SerializePingreq(uint8_t **pPingreqPacket, size_t *pPacketSize)
Generate a PINGREQ packet.
Definition: iot_mqtt_serialize.c:936
IotMqttError_t _IotMqtt_SerializeDisconnect(uint8_t **pDisconnectPacket, size_t *pPacketSize)
Generate a DISCONNECT packet.
Definition: iot_mqtt_serialize.c:997
IotMqttError_t _IotMqtt_SerializePublish(const IotMqttPublishInfo_t *pPublishInfo, uint8_t **pPublishPacket, size_t *pPacketSize, uint16_t *pPacketIdentifier, uint8_t **pPacketIdentifierHigh)
Generate a PUBLISH packet from the given parameters.
Definition: iot_mqtt_serialize.c:445
IotMqttError_t _IotMqtt_SerializeUnsubscribe(const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint8_t **pUnsubscribePacket, size_t *pPacketSize, uint16_t *pPacketIdentifier)
Generate an UNSUBSCRIBE packet from the given parameters.
Definition: iot_mqtt_serialize.c:825
void _IotMqtt_FreePacket(uint8_t *pPacket)
Free a packet generated by the serializer.
Definition: iot_mqtt_serialize.c:1024
IotMqttError_t _IotMqtt_DeserializeSuback(_mqttPacket_t *pSuback)
Deserialize a SUBACK packet.
Definition: iot_mqtt_serialize.c:776
IotMqttError_t _IotMqtt_DeserializePublish(_mqttPacket_t *pPublish)
Deserialize a PUBLISH packet received from the server.
Definition: iot_mqtt_serialize.c:538
IotMqttError_t _IotMqtt_DeserializePuback(_mqttPacket_t *pPuback)
Deserialize a PUBACK packet.
Definition: iot_mqtt_serialize.c:666
void _IotMqtt_PublishSetDup(uint8_t *pPublishPacket, uint8_t *pPacketIdentifierHigh, uint16_t *pNewPacketIdentifier)
Set the DUP bit in a QoS 1 PUBLISH packet.
Definition: iot_mqtt_serialize.c:503
IotMqttError_t _IotMqtt_DeserializeUnsuback(_mqttPacket_t *pUnsuback)
Deserialize a UNSUBACK packet.
Definition: iot_mqtt_serialize.c:886
uint8_t _IotMqtt_GetPacketType(IotNetworkConnection_t pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface)
Get the MQTT packet type from a stream of bytes off the network.
Definition: iot_mqtt_serialize.c:210
IotMqttError_t _IotMqtt_SerializeSubscribe(const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint8_t **pSubscribePacket, size_t *pPacketSize, uint16_t *pPacketIdentifier)
Generate a SUBSCRIBE packet from the given parameters.
Definition: iot_mqtt_serialize.c:715
IotMqttError_t _IotMqtt_DeserializePingresp(_mqttPacket_t *pPingresp)
Deserialize a PINGRESP packet.
Definition: iot_mqtt_serialize.c:963
size_t _IotMqtt_GetRemainingLength(IotNetworkConnection_t pNetworkConnection, const IotNetworkInterface_t *pNetworkInterface)
Get the remaining length from a stream of bytes off the network.
Definition: iot_mqtt_serialize.c:225
IotMqttError_t _IotMqtt_SerializePuback(uint16_t packetIdentifier, uint8_t **pPubackPacket, size_t *pPacketSize)
Generate a PUBACK packet for the given packet identifier.
Definition: iot_mqtt_serialize.c:630
IotMqttError_t _IotMqtt_DeserializeConnack(_mqttPacket_t *pConnack)
Deserialize a CONNACK packet.
Definition: iot_mqtt_serialize.c:331
IotMqttError_t _IotMqtt_SerializeConnect(const IotMqttConnectInfo_t *pConnectInfo, uint8_t **pConnectPacket, size_t *pPacketSize)
Generate a CONNECT packet from the given parameters.
Definition: iot_mqtt_serialize.c:281

Function pointers to the default MQTT serializers.

◆ _pSamplePayload

const char _pSamplePayload[]
static
Initial value:
=
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
" incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis "
"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu"
" fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in"
" culpa qui officia deserunt mollit anim id est laborum."
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
" incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis "
"nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu"
" fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in"
" culpa qui officia deserunt mollit anim id est laborum."

Filler text to publish.