Skip to content

Commit c8ad3d0

Browse files
RC-Repositoriesurutva
authored andcommitted
aws-iot-mock: Add subset of functionalities
This commit expands mock coverage across the FRI codebase, adding and modifying existing mocks. The mocks added are intended to support testing of `ota_agent_task.c`. Signed-off-by: Reuben Cartwright <[email protected]>
1 parent 295961a commit c8ad3d0

File tree

43 files changed

+1062
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1062
-34
lines changed

applications/helpers/events/mocks/inc/events.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define EVENT_H
88

99
#include "fff.h"
10+
#include <stdbool.h>
1011

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

1617
extern EventGroupHandle_t xSystemEvents;
1718

19+
DECLARE_FAKE_VALUE_FUNC( bool,
20+
xIsMqttAgentConnected );
1821
DECLARE_FAKE_VOID_FUNC( vWaitUntilNetworkIsUp );
22+
DECLARE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentReady );
23+
DECLARE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentConnected );
24+
1925

2026
#endif /* EVENT_H */

applications/helpers/events/mocks/src/events.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77

88
EventGroupHandle_t xSystemEvents;
99

10+
DEFINE_FAKE_VALUE_FUNC( bool,
11+
xIsMqttAgentConnected );
1012
DEFINE_FAKE_VOID_FUNC( vWaitUntilNetworkIsUp );
13+
DEFINE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentReady );
14+
DEFINE_FAKE_VOID_FUNC( vWaitUntilMQTTAgentConnected );

components/aws_iot/coremqtt/library_mocks/inc/core_mqtt_serializer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ typedef enum MQTTStatus
3333
{
3434
MQTTSuccess = 0,
3535
MQTTBadParameter,
36-
MQTTSendFailed
36+
MQTTSendFailed,
37+
MQTTRecvFailed
3738
} MQTTStatus_t;
3839

3940
typedef struct MQTTConnectInfo

components/aws_iot/coremqtt_agent/integration/integration_mocks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
add_library(coremqtt-agent-integration-mock
66
src/freertos_agent_message.c
77
src/freertos_command_pool.c
8+
src/mqtt_agent_task.c
89
src/subscription_manager.c
910
)
1011

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* FreeRTOS V202012.00
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2023-2024 Arm Limited and/or its affiliates
5+
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* https://www.FreeRTOS.org
25+
* https://github.com/FreeRTOS
26+
*
27+
*/
28+
29+
#ifndef MQTT_AGENT_H
30+
#define MQTT_AGENT_H
31+
32+
#include "core_mqtt.h"
33+
#include "core_mqtt_agent.h"
34+
#include "task.h"
35+
36+
struct MQTTAgentCommandContext
37+
{
38+
MQTTStatus_t xReturnStatus;
39+
TaskHandle_t xTaskToNotify;
40+
void * pArgs;
41+
};
42+
43+
extern MQTTAgentContext_t xGlobalMqttAgentContext;
44+
45+
#endif /* MQTT_AGENT_H */

components/aws_iot/coremqtt_agent/integration/integration_mocks/inc/subscription_manager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ typedef struct SubscriptionElement
4444
#define SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS 10U
4545
#endif
4646

47+
typedef void (* IncomingPubCallback_t)( void * pvIncomingPublishCallbackContext,
48+
MQTTPublishInfo_t * pxPublishInfo );
49+
50+
DECLARE_FAKE_VALUE_FUNC( bool,
51+
addSubscription,
52+
const char *,
53+
uint16_t,
54+
IncomingPubCallback_t,
55+
void * );
4756
DECLARE_FAKE_VOID_FUNC( removeSubscription,
4857
const char *,
4958
uint16_t );
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* FreeRTOS V202012.00
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2023-2024 Arm Limited and/or its affiliates
5+
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
* this software and associated documentation files (the "Software"), to deal in
9+
* the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
* the Software, and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
*
24+
* https://www.FreeRTOS.org
25+
* https://github.com/FreeRTOS
26+
*
27+
*/
28+
29+
#include "mqtt_agent_task.h"
30+
31+
MQTTAgentContext_t xGlobalMqttAgentContext;

components/aws_iot/coremqtt_agent/integration/integration_mocks/src/subscription_manager.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626
*
2727
*/
2828

29+
#include "fff.h"
2930
#include "subscription_manager.h"
3031

32+
DEFINE_FAKE_VALUE_FUNC( bool,
33+
addSubscription,
34+
const char *,
35+
uint16_t,
36+
IncomingPubCallback_t,
37+
void * );
3138
DEFINE_FAKE_VOID_FUNC( removeSubscription,
3239
const char *,
3340
uint16_t );

components/aws_iot/coremqtt_agent/integration/tests/test_mqtt_agent_task.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ TEST_F( TestMqttAgentTask, Publish_callback_calls_publish_handler )
541541

542542
EXPECT_EQ( handleIncomingPublishes_fake.call_count, 0 );
543543
int dummy = 5;
544-
MQTTAgentContext_t mqttAgentContext = { &dummy };
544+
MQTTAgentContext_t mqttAgentContext = { nullptr, &dummy };
545545
uint16_t dummyId = 10;
546546
MQTTPublishInfo_t xPublishInfo;
547547
xPublishInfo.qos = MQTTQoS0;
@@ -561,7 +561,7 @@ TEST_F( TestMqttAgentTask, Publish_callback_does_not_error_if_publish_handled )
561561
handleIncomingPublishes_fake.return_val = handled;
562562

563563
int dummy = 5;
564-
MQTTAgentContext_t mqttAgentContext = { &dummy };
564+
MQTTAgentContext_t mqttAgentContext = { nullptr, &dummy };
565565
uint16_t dummyId = 10;
566566
MQTTPublishInfo_t xPublishInfo;
567567
xPublishInfo.qos = MQTTQoS0;
@@ -581,7 +581,7 @@ TEST_F( TestMqttAgentTask, Publish_callback_generates_log_if_handler_fails )
581581
handleIncomingPublishes_fake.return_val = handled;
582582

583583
int dummy = 5;
584-
MQTTAgentContext_t mqttAgentContext = { &dummy };
584+
MQTTAgentContext_t mqttAgentContext = { nullptr, &dummy };
585585
uint16_t dummyId = 10;
586586
MQTTPublishInfo_t xPublishInfo;
587587
xPublishInfo.qos = MQTTQoS0;

components/aws_iot/coremqtt_agent/library_mocks/inc/core_mqtt_agent.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct MQTTAgentCommand MQTTAgentCommand_t;
4141

4242
typedef struct MQTTAgentContext
4343
{
44+
MQTTAgentCommand_t * pArgs;
4445
void * mqttContext;
4546
} MQTTAgentContext_t;
4647

@@ -102,4 +103,16 @@ DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
102103
MQTTAgent_CancelAll,
103104
MQTTAgentContext_t * );
104105

106+
DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
107+
MQTTAgent_Publish,
108+
const MQTTAgentContext_t *,
109+
MQTTPublishInfo_t *,
110+
const MQTTAgentCommandInfo_t * );
111+
112+
DECLARE_FAKE_VALUE_FUNC( MQTTStatus_t,
113+
MQTTAgent_Unsubscribe,
114+
const MQTTAgentContext_t *,
115+
MQTTAgentSubscribeArgs_t *,
116+
const MQTTAgentCommandInfo_t * );
117+
105118
#endif /* CORE_MQTT_AGENT_H */

0 commit comments

Comments
 (0)