Skip to content

Commit

Permalink
Adds mqtt host tests to Ci
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
euripedesrocha committed Jun 19, 2023
1 parent aee82c7 commit 4050df4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ build_idf_latest:
extends: .build_template
image: espressif/idf:latest

build_and_host_test:
stage: build
image: espressif/idf:latest
script:
# Replace the IDF's default esp-mqtt with this version
- rm -rf $IDF_PATH/components/mqtt/esp-mqtt && cp -r $MQTT_PATH $IDF_PATH/components/mqtt/
- cd $IDF_PATH/components/mqtt/esp-mqtt/host_test
- idf.py build
- build/host_mqtt_client_test.elf

build_and_test_qemu:
stage: build
image: ${CI_DOCKER_REGISTRY}/qemu-v5.1:1-20220802
Expand Down
12 changes: 11 additions & 1 deletion host_test/main/test_mqtt_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <memory>
#include <net/if.h>
#include <random>
#include <string_view>
#include <type_traits>
Expand Down Expand Up @@ -51,7 +52,6 @@ using unique_mqtt_client = std::unique_ptr < std::remove_pointer_t<esp_mqtt_clie

SCENARIO("MQTT Client Operation")
{
// [[maybe_unused]] auto protect = TEST_PROTECT();
// Set expectations for the mocked calls.
int mtx = 0;
int transport_list = 0;
Expand All @@ -76,6 +76,7 @@ SCENARIO("MQTT Client Operation")
esp_read_mac_IgnoreAndReturn(ESP_OK);
esp_read_mac_ReturnThruPtr_mac(mac);
esp_transport_list_destroy_IgnoreAndReturn(ESP_OK);
esp_transport_destroy_IgnoreAndReturn(ESP_OK);
vEventGroupDelete_Ignore();
vQueueDelete_Ignore();
GIVEN("An a minimal config") {
Expand Down Expand Up @@ -113,6 +114,15 @@ SCENARIO("MQTT Client Operation")
REQUIRE(res == ESP_FAIL);
}
}
SECTION("User set interface to use"){
http_parser_parse_url_ExpectAnyArgsAndReturn(0);
http_parser_parse_url_ReturnThruPtr_u(&ret_uri);
struct ifreq if_name = {.ifr_ifrn = {"custom"}};
config.network.if_name = &if_name;
SECTION("Client is not started"){
REQUIRE(esp_mqtt_set_config(client.get(), &config)== ESP_OK);
}
}
SECTION("After Start Client Is Cleanly destroyed") {
REQUIRE(esp_mqtt_client_start(client.get()) == ESP_OK);
// Only need to start the client, destroy is called automatically at the end of
Expand Down
1 change: 1 addition & 0 deletions mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ void esp_mqtt_destroy_config(esp_mqtt_client_handle_t client)
}
free(client->config->alpn_protos);
free(client->config->clientkey_password);
free(client->config->if_name);
free(client->mqtt_state.connection.information.will_topic);
free(client->mqtt_state.connection.information.will_message);
free(client->mqtt_state.connection.information.client_id);
Expand Down

0 comments on commit 4050df4

Please sign in to comment.