Skip to content

Commit 3b2ac89

Browse files
authored
Add process loop timeout configuration and check received topic in MQTT test. (#62)
1 parent 30aafe9 commit 3b2ac89

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

config_template/test_param_config_template.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
* #define MQTT_TEST_NETWORK_BUFFER_SIZE ( 5000 )
6464
*/
6565

66+
/**
67+
* @brief Timeout for MQTT_ProcessLoop() function in milliseconds.
68+
* The timeout value is appropriately chosen for receiving an incoming
69+
* PUBLISH message and ack responses for QoS 1 and QoS 2 communications
70+
* with the broker.
71+
*
72+
* #define MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ( 700 )
73+
*/
74+
6675
/**
6776
* @brief Root certificate of the IoT Core.
6877
*

src/mqtt/mqtt_test.c

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,6 @@
172172
*/
173173
#define MQTT_KEEP_ALIVE_INTERVAL_SECONDS ( 5U )
174174

175-
/**
176-
* @brief Timeout for MQTT_ProcessLoop() function in milliseconds.
177-
* The timeout value is appropriately chosen for receiving an incoming
178-
* PUBLISH message and ack responses for QoS 1 and QoS 2 communications
179-
* with the broker.
180-
*/
181-
#define MQTT_PROCESS_LOOP_TIMEOUT_MS ( 700U )
182-
183175
/**
184176
* @brief The MQTT message published in this example.
185177
*/
@@ -854,7 +846,7 @@ TEST( MqttTest, MQTT_Subscribe_Publish_With_Qos_0 )
854846
{
855847
xMQTTStatus = MQTT_ProcessLoop( &context );
856848

857-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
849+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
858850
{
859851
/* Timeout. */
860852
break;
@@ -883,7 +875,7 @@ TEST( MqttTest, MQTT_Subscribe_Publish_With_Qos_0 )
883875
{
884876
xMQTTStatus = MQTT_ProcessLoop( &context );
885877

886-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
878+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
887879
{
888880
/* Timeout. */
889881
break;
@@ -917,7 +909,7 @@ TEST( MqttTest, MQTT_Subscribe_Publish_With_Qos_0 )
917909
{
918910
xMQTTStatus = MQTT_ProcessLoop( &context );
919911

920-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
912+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
921913
{
922914
/* Timeout. */
923915
break;
@@ -955,7 +947,7 @@ TEST( MqttTest, MQTT_Subscribe_Publish_With_Qos_1 )
955947
{
956948
xMQTTStatus = MQTT_ProcessLoop( &context );
957949

958-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
950+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
959951
{
960952
/* Timeout. */
961953
break;
@@ -997,12 +989,12 @@ TEST( MqttTest, MQTT_Subscribe_Publish_With_Qos_1 )
997989
{
998990
xMQTTStatus = MQTT_ProcessLoop( &context );
999991

1000-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
992+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
1001993
{
1002994
/* Timeout. */
1003995
break;
1004996
}
1005-
else if( ( receivedPubAck != 0 ) && ( incomingInfo.topicNameLength > 0 ) )
997+
else if( ( receivedPubAck != 0 ) && ( incomingInfo.topicNameLength > 0 ) && ( strncmp( TEST_MQTT_TOPIC, incomingInfo.pTopicName, TEST_MQTT_TOPIC_LENGTH ) == 0 ) )
1006998
{
1007999
/* Both the PUBACK and the incoming publish have been received. */
10081000
/* "incomingInfo.topicNameLength > 0" means we got a publish message from MQTT broker.
@@ -1041,7 +1033,7 @@ TEST( MqttTest, MQTT_Subscribe_Publish_With_Qos_1 )
10411033
{
10421034
xMQTTStatus = MQTT_ProcessLoop( &context );
10431035

1044-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1036+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
10451037
{
10461038
/* Timeout. */
10471039
break;
@@ -1096,7 +1088,7 @@ TEST( MqttTest, MQTT_Connect_LWT )
10961088
{
10971089
xMQTTStatus = MQTT_ProcessLoop( &context );
10981090

1099-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1091+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
11001092
{
11011093
/* Timeout. */
11021094
break;
@@ -1126,12 +1118,12 @@ TEST( MqttTest, MQTT_Connect_LWT )
11261118
{
11271119
xMQTTStatus = MQTT_ProcessLoop( &context );
11281120

1129-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1121+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
11301122
{
11311123
/* Timeout. */
11321124
break;
11331125
}
1134-
else if( incomingInfo.topicNameLength > 0 )
1126+
else if( ( incomingInfo.topicNameLength > 0 ) && ( strncmp( TEST_MQTT_LWT_TOPIC, incomingInfo.pTopicName, TEST_MQTT_LWT_TOPIC_LENGTH ) == 0 ) )
11351127
{
11361128
/* Some data was received on the LWT topic. */
11371129
/* "incomingInfo.topicNameLength > 0" means we got a publish message from MQTT broker.
@@ -1169,7 +1161,7 @@ TEST( MqttTest, MQTT_Connect_LWT )
11691161
{
11701162
xMQTTStatus = MQTT_ProcessLoop( &context );
11711163

1172-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1164+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
11731165
{
11741166
/* Timeout. */
11751167
break;
@@ -1272,7 +1264,7 @@ TEST( MqttTest, MQTT_Resend_Unacked_Publish_QoS1 )
12721264
{
12731265
xMQTTStatus = MQTT_ProcessLoop( &context );
12741266

1275-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1267+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
12761268
{
12771269
/* Timeout. */
12781270
break;
@@ -1318,7 +1310,7 @@ TEST( MqttTest, MQTT_Resend_Unacked_Publish_QoS1 )
13181310
{
13191311
xMQTTStatus = MQTT_ProcessLoop( &context );
13201312

1321-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1313+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
13221314
{
13231315
/* Timeout. */
13241316
break;
@@ -1371,7 +1363,7 @@ TEST( MqttTest, MQTT_Restore_Session_Duplicate_Incoming_Publish_Qos1 )
13711363
{
13721364
xMQTTStatus = MQTT_ProcessLoop( &context );
13731365

1374-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1366+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
13751367
{
13761368
/* Timeout. */
13771369
break;
@@ -1409,7 +1401,7 @@ TEST( MqttTest, MQTT_Restore_Session_Duplicate_Incoming_Publish_Qos1 )
14091401
{
14101402
xMQTTStatus = MQTT_ProcessLoop( &context );
14111403

1412-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1404+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
14131405
{
14141406
/* Timeout. */
14151407
break;
@@ -1439,7 +1431,7 @@ TEST( MqttTest, MQTT_Restore_Session_Duplicate_Incoming_Publish_Qos1 )
14391431
{
14401432
xMQTTStatus = MQTT_ProcessLoop( &context );
14411433

1442-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1434+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
14431435
{
14441436
/* Timeout. */
14451437
break;
@@ -1479,7 +1471,7 @@ TEST( MqttTest, MQTT_Publish_With_Retain_Flag )
14791471
{
14801472
xMQTTStatus = MQTT_ProcessLoop( &context );
14811473

1482-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1474+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
14831475
{
14841476
/* Timeout. */
14851477
break;
@@ -1512,7 +1504,7 @@ TEST( MqttTest, MQTT_Publish_With_Retain_Flag )
15121504
{
15131505
xMQTTStatus = MQTT_ProcessLoop( &context );
15141506

1515-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1507+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
15161508
{
15171509
/* Timeout. */
15181510
break;
@@ -1557,7 +1549,7 @@ TEST( MqttTest, MQTT_Publish_With_Retain_Flag )
15571549
{
15581550
xMQTTStatus = MQTT_ProcessLoop( &context );
15591551

1560-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1552+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
15611553
{
15621554
/* Timeout. */
15631555
break;
@@ -1588,7 +1580,7 @@ TEST( MqttTest, MQTT_Publish_With_Retain_Flag )
15881580
{
15891581
xMQTTStatus = MQTT_ProcessLoop( &context );
15901582

1591-
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
1583+
if( FRTest_GetTimeMs() > ( entryTime + ( MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS * 2 ) ) )
15921584
{
15931585
/* Timeout. */
15941586
break;
@@ -1663,7 +1655,7 @@ TEST( MqttTest, MQTT_SubUnsub_Multiple_Topics )
16631655
{
16641656
xMQTTStatus = MQTT_ProcessLoop( &context );
16651657

1666-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1658+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
16671659
{
16681660
/* Timeout. */
16691661
break;
@@ -1705,7 +1697,7 @@ TEST( MqttTest, MQTT_SubUnsub_Multiple_Topics )
17051697
{
17061698
xMQTTStatus = MQTT_ProcessLoop( &context );
17071699

1708-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1700+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
17091701
{
17101702
/* Timeout. */
17111703
break;
@@ -1755,7 +1747,7 @@ TEST( MqttTest, MQTT_SubUnsub_Multiple_Topics )
17551747
{
17561748
xMQTTStatus = MQTT_ProcessLoop( &context );
17571749

1758-
if( FRTest_GetTimeMs() > ( entryTime + MQTT_PROCESS_LOOP_TIMEOUT_MS ) )
1750+
if( FRTest_GetTimeMs() > ( entryTime + MQTT_TEST_PROCESS_LOOP_TIMEOUT_MS ) )
17591751
{
17601752
/* Timeout. */
17611753
break;

0 commit comments

Comments
 (0)