Skip to content

Commit 4050df4

Browse files
Adds mqtt host tests to Ci
- New job to run host tests - Fix leak in case of usage of interface name - Fix host tests to expect a call to `transport_destroy` and add an extra case
1 parent aee82c7 commit 4050df4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.gitlab-ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ build_idf_latest:
4949
extends: .build_template
5050
image: espressif/idf:latest
5151

52+
build_and_host_test:
53+
stage: build
54+
image: espressif/idf:latest
55+
script:
56+
# Replace the IDF's default esp-mqtt with this version
57+
- rm -rf $IDF_PATH/components/mqtt/esp-mqtt && cp -r $MQTT_PATH $IDF_PATH/components/mqtt/
58+
- cd $IDF_PATH/components/mqtt/esp-mqtt/host_test
59+
- idf.py build
60+
- build/host_mqtt_client_test.elf
61+
5262
build_and_test_qemu:
5363
stage: build
5464
image: ${CI_DOCKER_REGISTRY}/qemu-v5.1:1-20220802

host_test/main/test_mqtt_client.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
#include <memory>
7+
#include <net/if.h>
78
#include <random>
89
#include <string_view>
910
#include <type_traits>
@@ -51,7 +52,6 @@ using unique_mqtt_client = std::unique_ptr < std::remove_pointer_t<esp_mqtt_clie
5152

5253
SCENARIO("MQTT Client Operation")
5354
{
54-
// [[maybe_unused]] auto protect = TEST_PROTECT();
5555
// Set expectations for the mocked calls.
5656
int mtx = 0;
5757
int transport_list = 0;
@@ -76,6 +76,7 @@ SCENARIO("MQTT Client Operation")
7676
esp_read_mac_IgnoreAndReturn(ESP_OK);
7777
esp_read_mac_ReturnThruPtr_mac(mac);
7878
esp_transport_list_destroy_IgnoreAndReturn(ESP_OK);
79+
esp_transport_destroy_IgnoreAndReturn(ESP_OK);
7980
vEventGroupDelete_Ignore();
8081
vQueueDelete_Ignore();
8182
GIVEN("An a minimal config") {
@@ -113,6 +114,15 @@ SCENARIO("MQTT Client Operation")
113114
REQUIRE(res == ESP_FAIL);
114115
}
115116
}
117+
SECTION("User set interface to use"){
118+
http_parser_parse_url_ExpectAnyArgsAndReturn(0);
119+
http_parser_parse_url_ReturnThruPtr_u(&ret_uri);
120+
struct ifreq if_name = {.ifr_ifrn = {"custom"}};
121+
config.network.if_name = &if_name;
122+
SECTION("Client is not started"){
123+
REQUIRE(esp_mqtt_set_config(client.get(), &config)== ESP_OK);
124+
}
125+
}
116126
SECTION("After Start Client Is Cleanly destroyed") {
117127
REQUIRE(esp_mqtt_client_start(client.get()) == ESP_OK);
118128
// Only need to start the client, destroy is called automatically at the end of

mqtt_client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ void esp_mqtt_destroy_config(esp_mqtt_client_handle_t client)
608608
}
609609
free(client->config->alpn_protos);
610610
free(client->config->clientkey_password);
611+
free(client->config->if_name);
611612
free(client->mqtt_state.connection.information.will_topic);
612613
free(client->mqtt_state.connection.information.will_message);
613614
free(client->mqtt_state.connection.information.client_id);

0 commit comments

Comments
 (0)