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

aws-iot: Unit test and debug ota_agent_task.c #93

Merged
merged 6 commits into from
Sep 27, 2024
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
6 changes: 6 additions & 0 deletions applications/helpers/events/mocks/inc/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define EVENT_H

#include "fff.h"
#include <stdbool.h>

#define EVENT_MASK_MQTT_INIT 0x02
#define EVENT_MASK_MQTT_CONNECTED 0x04
Expand All @@ -15,6 +16,11 @@ typedef void * EventGroupHandle_t;

extern EventGroupHandle_t xSystemEvents;

DECLARE_FAKE_VALUE_FUNC( bool,
xIsMqttAgentConnected );
DECLARE_FAKE_VOID_FUNC( vWaitUntilNetworkIsUp );
DECLARE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentReady );
DECLARE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentConnected );


#endif /* EVENT_H */
4 changes: 4 additions & 0 deletions applications/helpers/events/mocks/src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@

EventGroupHandle_t xSystemEvents;

DEFINE_FAKE_VALUE_FUNC( bool,
xIsMqttAgentConnected );
DEFINE_FAKE_VOID_FUNC( vWaitUntilNetworkIsUp );
DEFINE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentReady );
DEFINE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentConnected );
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ typedef enum MQTTStatus
{
MQTTSuccess = 0,
MQTTBadParameter,
MQTTSendFailed
MQTTSendFailed,
MQTTRecvFailed
} MQTTStatus_t;

typedef struct MQTTConnectInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
add_library(coremqtt-agent-integration-mock
src/freertos_agent_message.c
src/freertos_command_pool.c
src/mqtt_agent_task.c
src/subscription_manager.c
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* FreeRTOS V202012.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2023-2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* 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.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/

#ifndef MQTT_AGENT_H
#define MQTT_AGENT_H

#include "core_mqtt.h"
#include "core_mqtt_agent.h"
#include "task.h"

struct MQTTAgentCommandContext
{
MQTTStatus_t xReturnStatus;
TaskHandle_t xTaskToNotify;
void * pArgs;
};

extern MQTTAgentContext_t xGlobalMqttAgentContext;

#endif /* MQTT_AGENT_H */
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ typedef struct SubscriptionElement
#define SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS 10U
#endif

typedef void (* IncomingPubCallback_t)( void * pvIncomingPublishCallbackContext,
MQTTPublishInfo_t * pxPublishInfo );

DECLARE_FAKE_VALUE_FUNC( bool,
addSubscription,
const char *,
uint16_t,
IncomingPubCallback_t,
void * );
DECLARE_FAKE_VOID_FUNC( removeSubscription,
const char *,
uint16_t );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* FreeRTOS V202012.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2023-2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* 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.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/

#include "mqtt_agent_task.h"

MQTTAgentContext_t xGlobalMqttAgentContext;
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@
*
*/

#include "fff.h"
#include "subscription_manager.h"

DEFINE_FAKE_VALUE_FUNC( bool,
addSubscription,
const char *,
uint16_t,
IncomingPubCallback_t,
void * );
DEFINE_FAKE_VOID_FUNC( removeSubscription,
const char *,
uint16_t );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ TEST_F( TestMqttAgentTask, Publish_callback_calls_publish_handler )

EXPECT_EQ( handleIncomingPublishes_fake.call_count, 0 );
int dummy = 5;
MQTTAgentContext_t mqttAgentContext = { &dummy };
MQTTAgentContext_t mqttAgentContext = { nullptr, &dummy };
uint16_t dummyId = 10;
MQTTPublishInfo_t xPublishInfo;
xPublishInfo.qos = MQTTQoS0;
Expand All @@ -561,7 +561,7 @@ TEST_F( TestMqttAgentTask, Publish_callback_does_not_error_if_publish_handled )
handleIncomingPublishes_fake.return_val = handled;

int dummy = 5;
MQTTAgentContext_t mqttAgentContext = { &dummy };
MQTTAgentContext_t mqttAgentContext = { nullptr, &dummy };
uint16_t dummyId = 10;
MQTTPublishInfo_t xPublishInfo;
xPublishInfo.qos = MQTTQoS0;
Expand All @@ -581,7 +581,7 @@ TEST_F( TestMqttAgentTask, Publish_callback_generates_log_if_handler_fails )
handleIncomingPublishes_fake.return_val = handled;

int dummy = 5;
MQTTAgentContext_t mqttAgentContext = { &dummy };
MQTTAgentContext_t mqttAgentContext = { nullptr, &dummy };
uint16_t dummyId = 10;
MQTTPublishInfo_t xPublishInfo;
xPublishInfo.qos = MQTTQoS0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct MQTTAgentCommand MQTTAgentCommand_t;

typedef struct MQTTAgentContext
{
MQTTAgentCommand_t * pArgs;
void * mqttContext;
} MQTTAgentContext_t;

Expand Down Expand Up @@ -102,4 +103,16 @@ DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTTAgent_CancelAll,
MQTTAgentContext_t * );

DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTTAgent_Publish,
const MQTTAgentContext_t *,
MQTTPublishInfo_t *,
const MQTTAgentCommandInfo_t * );

DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTTAgent_Unsubscribe,
const MQTTAgentContext_t *,
MQTTAgentSubscribeArgs_t *,
const MQTTAgentCommandInfo_t * );

#endif /* CORE_MQTT_AGENT_H */
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ DEFINE_FAKE_VALUE_FUNC( MQTTStatus_t,
DEFINE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTTAgent_CancelAll,
MQTTAgentContext_t * );

DEFINE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTTAgent_Publish,
const MQTTAgentContext_t *,
MQTTPublishInfo_t *,
const MQTTAgentCommandInfo_t * );

DEFINE_FAKE_VALUE_FUNC( MQTTStatus_t,
MQTTAgent_Unsubscribe,
const MQTTAgentContext_t *,
MQTTAgentSubscribeArgs_t *,
const MQTTAgentCommandInfo_t * );
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# <[email protected]>
# SPDX-License-Identifier: MIT

if(CMAKE_CROSSCOMPILING)
if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
add_subdirectory(library_mocks)
else()
set(ota_for_aws_iot_embedded_sdk_SOURCE_DIR
${CMAKE_CURRENT_LIST_DIR}/library
CACHE INTERNAL
Expand All @@ -14,6 +16,6 @@ if(CMAKE_CROSSCOMPILING)
set(PATCH_FILES_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/integration/patches")
set(PATCH_FILES "${PATCH_FILES_DIRECTORY}/0001-Add-non-constant-appFirmwareVersion-extern.patch")
iot_reference_arm_corstone3xx_apply_patches("${ota_for_aws_iot_embedded_sdk_SOURCE_DIR}" "${PATCH_FILES}")

add_subdirectory(integration)
endif()

add_subdirectory(integration)
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@
# <[email protected]>
# SPDX-License-Identifier: MIT

include(${ota_for_aws_iot_embedded_sdk_SOURCE_DIR}/otaFilePaths.cmake)

add_library(ota-for-aws-iot-embedded-sdk
${OTA_SOURCES}
${OTA_MQTT_SOURCES}
${OTA_OS_FREERTOS_SOURCES}
src/ota_agent_task.c
)
if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
add_subdirectory(tests)
else()
include(${ota_for_aws_iot_embedded_sdk_SOURCE_DIR}/otaFilePaths.cmake)

target_include_directories(ota-for-aws-iot-embedded-sdk
PUBLIC
${OTA_INCLUDE_PUBLIC_DIRS}
${OTA_INCLUDE_OS_FREERTOS_DIRS}
)
add_library(ota-for-aws-iot-embedded-sdk
${OTA_SOURCES}
${OTA_MQTT_SOURCES}
${OTA_OS_FREERTOS_SOURCES}
src/ota_agent_task.c
)

add_library(ota-for-aws-iot-embedded-sdk-config INTERFACE)
target_include_directories(ota-for-aws-iot-embedded-sdk
PUBLIC
${OTA_INCLUDE_PUBLIC_DIRS}
${OTA_INCLUDE_OS_FREERTOS_DIRS}
)

target_link_libraries(ota-for-aws-iot-embedded-sdk
PUBLIC
ota-for-aws-iot-embedded-sdk-config
PRIVATE
corejson
coremqtt
coremqtt-agent
freertos-ota-pal-psa
helpers-events
helpers-logging
tinycbor
)
add_library(ota-for-aws-iot-embedded-sdk-config INTERFACE)

target_link_libraries(ota-for-aws-iot-embedded-sdk
PUBLIC
ota-for-aws-iot-embedded-sdk-config
PRIVATE
corejson
coremqtt
coremqtt-agent
freertos-ota-pal-psa
helpers-events
helpers-logging
tinycbor
)
endif()
Loading
Loading