From 60d2b99a70a5b0833339a4319bb8f2e70d65998c Mon Sep 17 00:00:00 2001 From: Zhihui Xia Date: Mon, 9 Oct 2023 15:46:18 -0700 Subject: [PATCH 1/6] unit test for adapter operation callback --- crt/aws-c-mqtt | 2 +- tests/CMakeLists.txt | 1 + tests/Mqtt5ClientTest.cpp | 47 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index 9fc57a13b..7fe084126 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit 9fc57a13bce0fbcc50d1fdb4cc52c9107d4c7dc9 +Subproject commit 7fe084126d17dc27c5fcb80265fd7c1d207b9df8 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 702cc4f82..dd2bb79f0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -236,6 +236,7 @@ if(NOT BYO_CRYPTO) add_net_test_case(Mqtt5to3AdapterWithIoTConnectionThroughMqtt5) add_net_test_case(Mqtt5to3AdapterDirectConnectionWithMutualTLSThroughMqtt5) add_net_test_case(Mqtt5to3AdapterOperations) + add_net_test_case(Mqtt5to3AdapterNullPubAck) add_net_test_case(Mqtt5to3AdapterMultipleAdapters) endif() diff --git a/tests/Mqtt5ClientTest.cpp b/tests/Mqtt5ClientTest.cpp index d4510156e..a54bf3991 100644 --- a/tests/Mqtt5ClientTest.cpp +++ b/tests/Mqtt5ClientTest.cpp @@ -3166,6 +3166,53 @@ static int s_TestMqtt5to3AdapterOperations(Aws::Crt::Allocator *allocator, void } AWS_TEST_CASE(Mqtt5to3AdapterOperations, s_TestMqtt5to3AdapterOperations) +/* + * [Mqtt5to3Adapter-UC11] Test s_TestMqtt5to3AdapterNullPubAck + * The unit test would have memory leak if the callback data for incomplete publish was not released. + */ +static int s_TestMqtt5to3AdapterNullPubAck(Aws::Crt::Allocator *allocator, void *) +{ + Mqtt5TestEnvVars mqtt5TestVars(allocator, MQTT5CONNECT_IOT_CORE); + if (!mqtt5TestVars) + { + printf("Environment Variables are not set for the test, skip the test"); + return AWS_OP_SKIP; + } + + ApiHandle apiHandle(allocator); + + Aws::Iot::Mqtt5ClientBuilder *builder = Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath( + mqtt5TestVars.m_hostname_string, + mqtt5TestVars.m_certificate_path_string.c_str(), + mqtt5TestVars.m_private_key_path_string.c_str(), + allocator); + ASSERT_TRUE(builder); + uint8_t received = 0; + std::mutex mutex; + std::condition_variable cv; + + String testUUID = Aws::Crt::UUID().ToString(); + String testTopic = "test/MQTT5to3Adapter_" + testUUID; + ByteBuf testPayload = Aws::Crt::ByteBufFromCString("PUBLISH ME!"); + + std::shared_ptr mqtt5Client = builder->Build(); + ASSERT_TRUE(mqtt5Client); + // Created a Mqtt311 Connection from mqtt5Client. The options are setup by the builder. + std::shared_ptr mqttConnection = + Mqtt::MqttConnection::NewConnectionFromMqtt5Client(mqtt5Client); + ASSERT_TRUE(mqttConnection); + + // Publish an offline message to create an incomplete publish operation + mqttConnection->Publish(testTopic.c_str(), Mqtt::QOS::AWS_MQTT_QOS_AT_LEAST_ONCE, false, testPayload, NULL); + + delete builder; + + // If the incomplete operation callback was not called, there would be a memory leak as the callback data was not + // released + return AWS_OP_SUCCESS; +} +AWS_TEST_CASE(Mqtt5to3AdapterNullPubAck, s_TestMqtt5to3AdapterNullPubAck) + /* * [Mqtt5to3Adapter-UC11] Test one mqtt5 client with multiple adapters */ From 9f58358169e12ad867ba30c1b3d2eaff380f4c68 Mon Sep 17 00:00:00 2001 From: Zhihui Xia Date: Mon, 9 Oct 2023 15:51:50 -0700 Subject: [PATCH 2/6] remove unused var --- tests/Mqtt5ClientTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Mqtt5ClientTest.cpp b/tests/Mqtt5ClientTest.cpp index a54bf3991..20504dd02 100644 --- a/tests/Mqtt5ClientTest.cpp +++ b/tests/Mqtt5ClientTest.cpp @@ -3187,7 +3187,6 @@ static int s_TestMqtt5to3AdapterNullPubAck(Aws::Crt::Allocator *allocator, void mqtt5TestVars.m_private_key_path_string.c_str(), allocator); ASSERT_TRUE(builder); - uint8_t received = 0; std::mutex mutex; std::condition_variable cv; From 3211d3c2f399bff8d3bd1f83d6f4efad71b1d804 Mon Sep 17 00:00:00 2001 From: Zhihui Xia Date: Mon, 9 Oct 2023 16:06:25 -0700 Subject: [PATCH 3/6] fix compile error: remove unused vars --- tests/Mqtt5ClientTest.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Mqtt5ClientTest.cpp b/tests/Mqtt5ClientTest.cpp index 20504dd02..0d3ae46fd 100644 --- a/tests/Mqtt5ClientTest.cpp +++ b/tests/Mqtt5ClientTest.cpp @@ -3187,8 +3187,6 @@ static int s_TestMqtt5to3AdapterNullPubAck(Aws::Crt::Allocator *allocator, void mqtt5TestVars.m_private_key_path_string.c_str(), allocator); ASSERT_TRUE(builder); - std::mutex mutex; - std::condition_variable cv; String testUUID = Aws::Crt::UUID().ToString(); String testTopic = "test/MQTT5to3Adapter_" + testUUID; From d35f854e3db8eebace9a46dee7f97c31e65afbb9 Mon Sep 17 00:00:00 2001 From: Zhihui Xia Date: Thu, 19 Oct 2023 10:38:11 -0700 Subject: [PATCH 4/6] update mqtt submodule --- crt/aws-c-mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index 7fe084126..c475ef1bf 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit 7fe084126d17dc27c5fcb80265fd7c1d207b9df8 +Subproject commit c475ef1bfcc31f815e46558864161728a15a70ae From 2ab1706ca9aa297aa2da7735379484c2921c21d8 Mon Sep 17 00:00:00 2001 From: Zhihui Xia Date: Fri, 20 Oct 2023 15:12:50 -0700 Subject: [PATCH 5/6] setup mqtt to test branch --- crt/aws-c-mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index c475ef1bf..ed5a7001e 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit c475ef1bfcc31f815e46558864161728a15a70ae +Subproject commit ed5a7001e2abebadae9a5f3d72a0458b6b7ab476 From 1201e4cd6a8408da2f0609a9775858c2e76912a6 Mon Sep 17 00:00:00 2001 From: Zhihui Xia Date: Mon, 23 Oct 2023 16:46:38 -0700 Subject: [PATCH 6/6] update mqtt --- crt/aws-c-mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index ed5a7001e..c475ef1bf 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit ed5a7001e2abebadae9a5f3d72a0458b6b7ab476 +Subproject commit c475ef1bfcc31f815e46558864161728a15a70ae