mqtt: Fix and add mqtt host test to CI

pull/9179/head
David Cermak 2022-05-13 16:55:22 +02:00
rodzic e2bc3f865e
commit 1ad3e2db17
6 zmienionych plików z 27 dodań i 26 usunięć

Wyświetl plik

@ -358,6 +358,13 @@ test_nvs_page:
- idf.py build
- build/test_nvs_page_host.elf
test_mqtt_on_host:
extends: .host_test_template
script:
- cd ${IDF_PATH}/components/mqtt/host_test
- idf.py build
- LSAN_OPTIONS=verbosity=1:log_threads=1 build/host_mqtt_client_test.elf
test_log:
extends: .host_test_template
script:

Wyświetl plik

@ -3,9 +3,7 @@ idf_component_register(SRCS "esp-mqtt/mqtt_client.c"
"esp-mqtt/lib/mqtt_outbox.c"
"esp-mqtt/lib/platform_esp32_idf.c"
INCLUDE_DIRS esp-mqtt/include
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include"
PRIV_REQUIRES lwip
)
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include")
if(TEST_BUILD)
message(STATUS "building MOCKS")
@ -13,10 +11,9 @@ idf_component_get_property(tcp_transport_dir tcp_transport COMPONENT_DIR)
idf_component_get_property(esp_hw_support_dir esp_hw_support COMPONENT_DIR)
idf_component_get_property(esp_event_dir esp_event COMPONENT_DIR)
idf_component_get_property(log_dir log COMPONENT_DIR)
idf_component_get_property(freertos_dir freertos COMPONENT_DIR)
idf_component_get_property(freertos_dir freertos COMPONENT_OVERRIDEN_DIR)
idf_component_get_property(http_parser_dir http_parser COMPONENT_DIR)
idf_component_get_property(esp_wifi_dir esp_wifi COMPONENT_DIR)
idf_component_get_property(esp_hw_support_dir esp_hw_support COMPONENT_DIR)
idf_component_get_property(esp_tls_dir esp-tls COMPONENT_DIR)
idf_component_get_property(esp_netif_dir esp_netif COMPONENT_DIR)
idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR)
@ -56,10 +53,6 @@ idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
${esp_event_dir}/include/esp_event.h
${esp_hw_support_dir}/include/esp_mac.h
${esp_hw_support_dir}/include/esp_random.h
${esp_system_dir}/include/esp_system.h
${esp_tls_dir}/esp_tls.h
${freertos_dir}/FreeRTOS-Kernel/include/freertos/queue.h
${freertos_dir}/FreeRTOS-Kernel/include/freertos/task.h
${freertos_dir}/FreeRTOS-Kernel/include/freertos/event_groups.h
${log_dir}/include/esp_log.h
${http_parser_dir}/http_parser.h
@ -74,13 +67,9 @@ idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
${MOCK_GEN_DIR}/Mockesp_event.c
${MOCK_GEN_DIR}/Mockesp_mac.c
${MOCK_GEN_DIR}/Mockesp_random.c
${MOCK_GEN_DIR}/Mockesp_system.c
${MOCK_GEN_DIR}/Mockesp_tls.c
${MOCK_GEN_DIR}/Mockesp_log.c
${MOCK_GEN_DIR}/Mockhttp_parser.c
${MOCK_GEN_DIR}/Mockevent_groups.c
${MOCK_GEN_DIR}/Mockqueue.c
${MOCK_GEN_DIR}/Mocktask.c
)
add_custom_command(
@ -122,10 +111,6 @@ idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
)
target_link_libraries(mocks PUBLIC ${cmock_lib})
target_compile_definitions(mocks PUBLIC
CONFIG_LOG_MAXIMUM_LEVEL=5
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_ESP_TLS_USING_MBEDTLS
CONFIG_ESP_TLS_SERVER
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS)
target_link_options(${COMPONENT_LIB} INTERFACE -fsanitize=address)
@ -134,5 +119,7 @@ idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
else()
idf_component_get_property(http_parser_lib http_parser COMPONENT_LIB)
idf_component_get_property(tcp_transport_lib tcp_transport COMPONENT_LIB)
idf_component_get_property(lwip_lib lwip COMPONENT_LIB)
target_link_libraries(${COMPONENT_LIB} PUBLIC ${http_parser_lib} ${tcp_transport_lib})
target_link_libraries(${COMPONENT_LIB} PRIVATE ${lwip_lib})
endif()

Wyświetl plik

@ -2,5 +2,7 @@ cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(COMPONENTS main)
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
option(TEST_BUILD "" ON)
project(host_mqtt_client_test)

Wyświetl plik

@ -1,11 +1,9 @@
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
#include "catch.hpp"
#include "mqtt_client.h"
extern "C" {
#include "Mockesp_event.h"
#include "Mockesp_log.h"
#include "Mockesp_system.h"
#include "Mockesp_mac.h"
#include "Mockesp_transport.h"
#include "Mockesp_transport_ssl.h"
@ -20,17 +18,14 @@ extern "C" {
* The following functions are not directly called but the generation of them
* from cmock is broken, so we need to define them here.
*/
BaseType_t xQueueTakeMutexRecursive(QueueHandle_t xMutex,
TickType_t xTicksToWait)
esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tls_code, int *esp_tls_flags)
{
return 0;
}
BaseType_t xQueueGiveMutexRecursive(QueueHandle_t xMutex)
{
return 0;
return ESP_OK;
}
}
#include "mqtt_client.h"
struct ClientInitializedFixture {
esp_mqtt_client_handle_t client;
ClientInitializedFixture()
@ -42,6 +37,8 @@ struct ClientInitializedFixture {
int event_group;
uint8_t mac[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
esp_log_write_Ignore();
xQueueTakeMutexRecursive_CMockIgnoreAndReturn(0, true);
xQueueGiveMutexRecursive_CMockIgnoreAndReturn(0, true);
xQueueCreateMutex_ExpectAnyArgsAndReturn(
reinterpret_cast<QueueHandle_t>(&mtx));
xEventGroupCreate_IgnoreAndReturn(reinterpret_cast<EventGroupHandle_t>(&event_group));

Wyświetl plik

@ -7,6 +7,8 @@
- array
- callback
:includes_h_pre_orig_header:
- local_FreeRTOS_config.h
- esp_attr.h
- FreeRTOS.h
- net/if.h
:strippables:

Wyświetl plik

@ -0,0 +1,6 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#define configUSE_TRACE_FACILITY 1