|
AWS IoT Device SDK C:
MQTT
MQTT 3.1.1 client library
|
| Return to main page ↑ |
Tests for the user-facing API functions (declared in iot_mqtt.h). More...
#include "iot_config.h"#include <string.h>#include "iot_init.h"#include "private/iot_mqtt_internal.h"#include "iot_mqtt_protocol.h"#include "platform/iot_clock.h"#include "platform/iot_threads.h"#include "unity_fixture.h"#include "iot_test_access_mqtt.h"#include "iot_mqtt_lightweight.h"#include "iot_tests_mqtt_mock.h"#include "iot_atomic.h"Macros | |
| #define | AWS_IOT_MQTT_SERVER true |
| Determine which MQTT server mode to test (AWS IoT or Mosquitto). | |
| #define | TIMEOUT_MS ( 400 ) |
| Timeout to use for the tests. This can be short, but should allow time for other threads to run. | |
| #define | SHORT_KEEP_ALIVE_MS ( 100 ) |
| A short keep-alive interval to use for the keep-alive tests. It may be shorter than the minimum 1 second specified by the MQTT spec. | |
| #define | KEEP_ALIVE_COUNT ( 10 ) |
| The number of times the periodic keep-alive should run. | |
| #define | CLIENT_IDENTIFIER ( "test" ) |
| Client identifier. | |
| #define | CLIENT_IDENTIFIER_LENGTH ( ( uint16_t ) ( sizeof( CLIENT_IDENTIFIER ) - 1 ) ) |
| Length of client identifier. | |
| #define | TEST_TOPIC_NAME ( "/test/topic" ) |
| An arbitrary topic name. | |
| #define | TEST_TOPIC_NAME_LENGTH ( ( uint16_t ) ( sizeof( TEST_TOPIC_NAME ) - 1 ) ) |
| Length of topic name. | |
| #define | SUBSCRIPTION_CALLBACK |
| A non-NULL function pointer to use for subscription callback. This "function" should cause a crash if actually called. More... | |
| #define | DISCONNECT_MALLOC_LIMIT ( 20 ) |
| How many times TEST_MQTT_Unit_API_DisconnectMallocFail_ will test malloc failures. More... | |
| #define | DUP_CHECK_RETRY_MS ( 100 ) |
| When to start sending duplicate packets. | |
| #define | DUP_CHECK_RETRY_LIMIT ( 3 ) |
| How many duplicate packets to send. | |
| #define | DUP_CHECK_TIMEOUT ( 3000 ) |
| Total time allowed to send all duplicate packets. Duplicates are sent using an exponential backoff strategy. | |
| #define | DUP_CHECK_MINIMUM_WAIT |
| The minimum amount of time the test can take. More... | |
| #define | PACKET_LENGTH ( 32 ) |
| Length of an arbitrary packet for testing. A buffer will be allocated for it, but its contents don't matter. | |
| #define | OPERATION_COUNT ( 2 ) |
| How many operations to use for the OperationFindMatch test. | |
Functions | |
| static void | _incomingPingresp (void *pArgument) |
| A thread routine that simulates an incoming PINGRESP. | |
| static void | _publishSetDup (uint8_t *pPublishPacket, uint8_t *pPacketIdentifierHigh, uint16_t *pNewPacketIdentifier) |
| PUBLISH set DUP function override. | |
| static size_t | _sendSuccess (IotNetworkConnection_t pSendContext, const uint8_t *pMessage, size_t messageLength) |
| A send function that always "succeeds". May report that it was invoked through a semaphore. | |
| static size_t | _sendPingreq (IotNetworkConnection_t pSendContext, const uint8_t *pMessage, size_t messageLength) |
| A send function for PINGREQ that responds with a PINGRESP. | |
| static size_t | _sendDelay (IotNetworkConnection_t pSendContext, const uint8_t *pMessage, size_t messageLength) |
| A send function that delays. | |
| static size_t | _dupChecker (IotNetworkConnection_t pSendContext, const uint8_t *pMessage, size_t messageLength) |
| This send function checks that a duplicate outgoing message differs from the original. | |
| static size_t | _receivePingresp (IotNetworkConnection_t pReceiveContext, uint8_t *pBuffer, size_t bytesRequested) |
| A network receive function that simulates receiving a PINGRESP. | |
| static IotNetworkError_t | _setReceiveCallback (IotNetworkConnection_t pConnection, IotNetworkReceiveCallback_t receiveCallback, void *pReceiveContext) |
| A function for setting the receive callback that just returns success. | |
| static IotNetworkError_t | _close (IotNetworkConnection_t pCloseContext) |
| A network close function that counts how many times it was invoked. | |
| static void | _disconnectCallback (void *pCallbackContext, IotMqttCallbackParam_t *pCallbackParam) |
| An MQTT disconnect callback that counts how many times it was invoked. | |
| static void | _decrementReferencesJob (IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pContext) |
| A task pool job routine that decrements an MQTT operation's job reference count. | |
| static IotMqttError_t | _getNextByte (IotNetworkConnection_t pNetworkInterface, uint8_t *nextByte) |
| Get next byte mock function to test MQTT serializer API. | |
| static IotMqttError_t | _getNextByteFailure (IotNetworkConnection_t pNetworkInterface, uint8_t *nextByte) |
| Get next byte mock function to test MQTT serializer API that fails when reading the remaining length. | |
| static IotMqttError_t | _serializePingreq (uint8_t **pPingreqPacket, size_t *pPacketSize) |
| A PINGREQ serializer that attempts to allocate memory (unlike the default). | |
| static void | _completionCallback (void *pContext, IotMqttCallbackParam_t *pCallbackParam) |
| A completion callback that does nothing. | |
| TEST_GROUP (MQTT_Unit_API) | |
| Test group for MQTT API tests. | |
| TEST_SETUP (MQTT_Unit_API) | |
| Test setup for MQTT API tests. | |
| TEST_TEAR_DOWN (MQTT_Unit_API) | |
| Test tear down for MQTT API tests. | |
| TEST_GROUP_RUNNER (MQTT_Unit_API) | |
| Test group runner for MQTT API tests. | |
| void | TEST_MQTT_Unit_API_Init_ (void) |
| Tests the function IotMqtt_Init. | |
| void | TEST_MQTT_Unit_API_StringCoverage_ (void) |
| Provides code coverage of the MQTT enum-to-string functions, IotMqtt_strerror and IotMqtt_OperationType. | |
| void | TEST_MQTT_Unit_API_OperationCreateDestroy_ (void) |
| Test reference counts as MQTT operations are created and destroyed. | |
| void | TEST_MQTT_Unit_API_OperationWaitTimeout_ (void) |
| Test that an operation is correctly cleaned up if IotMqtt_Wait times out while its job is executing. | |
| void | TEST_MQTT_Unit_API_OperationFindMatch_ (void) |
| Test edge cases when searching for operations. | |
| void | TEST_MQTT_Unit_API_OperationLists_ (void) |
| Tests the behavior of send and notify with different link statuses. | |
| void | TEST_MQTT_Unit_API_ConnectParameters_ (void) |
| Tests the behavior of IotMqtt_Connect with various invalid parameters. | |
| void | TEST_MQTT_Unit_API_ConnectMallocFail_ (void) |
| Tests the behavior of IotMqtt_Connect when memory allocation fails at various points. | |
| void | TEST_MQTT_Unit_API_ConnectRestoreSessionMallocFail_ (void) |
| Tests the behavior of IotMqtt_Connect when memory allocation fails at various points for a persistent session. | |
| void | TEST_MQTT_Unit_API_DisconnectMallocFail_ (void) |
| Tests the behavior of IotMqtt_Disconnect when memory allocation fails at various points. | |
| void | TEST_MQTT_Unit_API_DisconnectAlreadyDisconnected_ (void) |
| Tests the behavior of IotMqtt_Disconnect when disconnected mqtt connection is passed. | |
| void | TEST_MQTT_Unit_API_PublishQoS0Parameters_ (void) |
| Tests the behavior of IotMqtt_PublishAsync (QoS 0) with various valid and invalid parameters. | |
| void | TEST_MQTT_Unit_API_PublishQoS0MallocFail_ (void) |
| Tests the behavior of IotMqtt_PublishAsync (QoS 0) when memory allocation fails at various points. | |
| void | TEST_MQTT_Unit_API_PublishQoS1_ (void) |
| Tests the behavior of IotMqtt_PublishAsync (QoS 1) with various invalid parameters. Also tests the behavior of IotMqtt_PublishAsync (QoS 1) when memory allocation fails at various points. | |
| void | TEST_MQTT_Unit_API_PublishRetryPeriod_ (void) |
| Tests that PUBLISH retry periods are calculated correctly. | |
| void | TEST_MQTT_Unit_API_PublishDuplicates_ (void) |
| Tests that duplicate QoS 1 PUBLISH packets are different from the original. More... | |
| void | TEST_MQTT_Unit_API_SubscribeUnsubscribeParameters_ (void) |
| Tests the behavior of IotMqtt_SubscribeAsync and IotMqtt_UnsubscribeAsync with various invalid parameters. | |
| void | TEST_MQTT_Unit_API_SubscribeMallocFail_ (void) |
| Tests the behavior of IotMqtt_SubscribeAsync when memory allocation fails at various points. | |
| void | TEST_MQTT_Unit_API_UnsubscribeMallocFail_ (void) |
| Tests the behavior of IotMqtt_UnsubscribeAsync when memory allocation fails at various points. | |
| void | TEST_MQTT_Unit_API_KeepAlivePeriodic_ (void) |
| Tests keep-alive handling and ensures that it is periodic. | |
| void | TEST_MQTT_Unit_API_KeepAliveJobCleanup_ (void) |
| Tests that the keep-alive job cleans up the MQTT connection after a call to IotMqtt_Disconnect. | |
| void | TEST_MQTT_Unit_API_GetConnectPacketSizeChecks_ (void) |
| Tests that IotMqtt_GetConnectPacketSize works as intended. to IotMqtt_GetConnectPacketSize. | |
| void | TEST_MQTT_Unit_API_SerializeConnectChecks_ (void) |
| Tests that IotMqtt_SerializeConnect works as intended. to IotMqtt_SerializeConnect. | |
| void | TEST_MQTT_Unit_API_GetSubscribePacketSizeChecks_ (void) |
| Tests that IotMqtt_GetSubscribePacketSize works as intended. to IotMqtt_GetSubscriptionPacketSize. | |
| void | TEST_MQTT_Unit_API_SerializeSubscribeChecks_ (void) |
| Tests that IotMqtt_SerializeSubscribe works as intended. to IotMqtt_SerializeSubscribe. | |
| void | TEST_MQTT_Unit_API_SerializeUnsubscribeChecks_ (void) |
| Tests that IotMqtt_SerializeUnsubscribe works as intended. to IotMqtt_SerializeUnsubscribe. | |
| void | TEST_MQTT_Unit_API_GetPublishPacketSizeChecks_ (void) |
| Tests that IotMqtt_GetPublishPacketSize works as intended. to IotMqtt_GetPublishPacketSize. | |
| void | TEST_MQTT_Unit_API_SerializePublishChecks_ (void) |
| Tests that IotMqtt_GetPublishPacketSize works as intended. to IotMqtt_SerializePublish. | |
| void | TEST_MQTT_Unit_API_SerializeDisconnectChecks_ (void) |
| Tests that IotMqtt_SerializeDisconnect works as intended. to IotMqtt_SerializeDisconnect. | |
| void | TEST_MQTT_Unit_API_SerializePingReqChecks_ (void) |
| Tests that IotMqtt_SerializePingReq works as intended. to IotMqtt_SerializePingreq. | |
| void | TEST_MQTT_Unit_API_GetIncomingMQTTPacketTypeAndLengthChecks_ (void) |
| Tests that IotMqtt_GetIncomingMQTTPacketTypeAndLength works as intended. | |
| void | TEST_MQTT_Unit_API_LightweightConnack_ (void) |
| Tests that IotMqtt_DeserializeResponse works as intended with a CONNACK. | |
| void | TEST_MQTT_Unit_API_LightweightSuback_ (void) |
| Tests that IotMqtt_DeserializeResponse works as intended with a SUBACK. | |
| void | TEST_MQTT_Unit_API_LightweightUnsuback_ (void) |
| Tests that IotMqtt_DeserializeResponse works as intended with an UNSUBACK. | |
| void | TEST_MQTT_Unit_API_LightweightPingresp_ (void) |
| Tests that IotMqtt_DeserializeResponse works as intended with a PINGRESP. | |
| void | TEST_MQTT_Unit_API_LightweightPuback_ (void) |
| Tests that IotMqtt_DeserializeResponse works as intended with a PUBACK. | |
| void | TEST_MQTT_Unit_API_DeserializePublishChecks_ (void) |
| Tests that IotMqtt_DeserializePublish works as intended. | |
Variables | |
| static bool | _publishSetDupCalled = false |
| Tracks whether _publishSetDup has been called. | |
| static uint32_t | _pingreqSendCount = 0 |
| Counts how many time _sendPingreq has been called. | |
| static uint32_t | _closeCount = 0 |
| Counts how many times _close has been called. | |
| static uint32_t | _disconnectCallbackCount = 0 |
| Counts how many times _disconnectCallback has been called. | |
| static _mqttConnection_t * | _pMqttConnection = IOT_MQTT_CONNECTION_INITIALIZER |
| An MQTT connection to share among the tests. | |
| static IotMqttNetworkInfo_t | _networkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER |
| An IotMqttNetworkInfo_t to share among the tests. | |
| static IotNetworkInterface_t | _networkInterface = { 0 } |
| An IotNetworkInterface_t to share among the tests. | |
| static uint8_t * | _pAllocatedPingreq = NULL |
| A packet allocated by _serializePingreq. | |
Tests for the user-facing API functions (declared in iot_mqtt.h).
| #define SUBSCRIPTION_CALLBACK |
A non-NULL function pointer to use for subscription callback. This "function" should cause a crash if actually called.
| #define DISCONNECT_MALLOC_LIMIT ( 20 ) |
How many times TEST_MQTT_Unit_API_DisconnectMallocFail_ will test malloc failures.
The DISCONNECT function provides no mechanism to wait on its successful completion. Therefore, this function simply uses the value below as an estimate for the maximum number of times DISCONNECT will use malloc.
| #define DUP_CHECK_MINIMUM_WAIT |
The minimum amount of time the test can take.
| void TEST_MQTT_Unit_API_PublishDuplicates_ | ( | void | ) |
Tests that duplicate QoS 1 PUBLISH packets are different from the original.
For non-AWS IoT MQTT servers, checks that the DUP flag is set. For AWS IoT MQTT servers, checks that the packet identifier is different.