mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-08-02 20:25:10 +02:00
mqtt: Fix and add mqtt host test to CI
This commit is contained in:
committed by
Euripedes Rocha
parent
62c5545f2d
commit
610db7b934
@@ -3,9 +3,7 @@ idf_component_register(SRCS "esp-mqtt/mqtt_client.c"
|
|||||||
"esp-mqtt/lib/mqtt_outbox.c"
|
"esp-mqtt/lib/mqtt_outbox.c"
|
||||||
"esp-mqtt/lib/platform_esp32_idf.c"
|
"esp-mqtt/lib/platform_esp32_idf.c"
|
||||||
INCLUDE_DIRS esp-mqtt/include
|
INCLUDE_DIRS esp-mqtt/include
|
||||||
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include"
|
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include")
|
||||||
PRIV_REQUIRES lwip
|
|
||||||
)
|
|
||||||
|
|
||||||
if(TEST_BUILD)
|
if(TEST_BUILD)
|
||||||
message(STATUS "building MOCKS")
|
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_hw_support_dir esp_hw_support COMPONENT_DIR)
|
||||||
idf_component_get_property(esp_event_dir esp_event 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(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(http_parser_dir http_parser COMPONENT_DIR)
|
||||||
idf_component_get_property(esp_wifi_dir esp_wifi 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_tls_dir esp-tls COMPONENT_DIR)
|
||||||
idf_component_get_property(esp_netif_dir esp_netif COMPONENT_DIR)
|
idf_component_get_property(esp_netif_dir esp_netif COMPONENT_DIR)
|
||||||
idf_component_get_property(esp_common_dir esp_common 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_event_dir}/include/esp_event.h
|
||||||
${esp_hw_support_dir}/include/esp_mac.h
|
${esp_hw_support_dir}/include/esp_mac.h
|
||||||
${esp_hw_support_dir}/include/esp_random.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
|
${freertos_dir}/FreeRTOS-Kernel/include/freertos/event_groups.h
|
||||||
${log_dir}/include/esp_log.h
|
${log_dir}/include/esp_log.h
|
||||||
${http_parser_dir}/http_parser.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_event.c
|
||||||
${MOCK_GEN_DIR}/Mockesp_mac.c
|
${MOCK_GEN_DIR}/Mockesp_mac.c
|
||||||
${MOCK_GEN_DIR}/Mockesp_random.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}/Mockesp_log.c
|
||||||
${MOCK_GEN_DIR}/Mockhttp_parser.c
|
${MOCK_GEN_DIR}/Mockhttp_parser.c
|
||||||
${MOCK_GEN_DIR}/Mockevent_groups.c
|
${MOCK_GEN_DIR}/Mockevent_groups.c
|
||||||
${MOCK_GEN_DIR}/Mockqueue.c
|
|
||||||
${MOCK_GEN_DIR}/Mocktask.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
@@ -122,10 +111,6 @@ idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
|
|||||||
)
|
)
|
||||||
target_link_libraries(mocks PUBLIC ${cmock_lib})
|
target_link_libraries(mocks PUBLIC ${cmock_lib})
|
||||||
target_compile_definitions(mocks PUBLIC
|
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)
|
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS)
|
||||||
target_link_options(${COMPONENT_LIB} INTERFACE -fsanitize=address)
|
target_link_options(${COMPONENT_LIB} INTERFACE -fsanitize=address)
|
||||||
|
|
||||||
@@ -134,5 +119,7 @@ idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
|
|||||||
else()
|
else()
|
||||||
idf_component_get_property(http_parser_lib http_parser COMPONENT_LIB)
|
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(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} PUBLIC ${http_parser_lib} ${tcp_transport_lib})
|
||||||
|
target_link_libraries(${COMPONENT_LIB} PRIVATE ${lwip_lib})
|
||||||
endif()
|
endif()
|
||||||
|
@@ -2,5 +2,7 @@ cmake_minimum_required(VERSION 3.16)
|
|||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
set(COMPONENTS main)
|
set(COMPONENTS main)
|
||||||
|
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
|
||||||
|
|
||||||
option(TEST_BUILD "" ON)
|
option(TEST_BUILD "" ON)
|
||||||
project(host_mqtt_client_test)
|
project(host_mqtt_client_test)
|
||||||
|
@@ -1,11 +1,9 @@
|
|||||||
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
|
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include "mqtt_client.h"
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "Mockesp_event.h"
|
#include "Mockesp_event.h"
|
||||||
#include "Mockesp_log.h"
|
#include "Mockesp_log.h"
|
||||||
#include "Mockesp_system.h"
|
|
||||||
#include "Mockesp_mac.h"
|
#include "Mockesp_mac.h"
|
||||||
#include "Mockesp_transport.h"
|
#include "Mockesp_transport.h"
|
||||||
#include "Mockesp_transport_ssl.h"
|
#include "Mockesp_transport_ssl.h"
|
||||||
@@ -20,17 +18,14 @@ extern "C" {
|
|||||||
* The following functions are not directly called but the generation of them
|
* The following functions are not directly called but the generation of them
|
||||||
* from cmock is broken, so we need to define them here.
|
* from cmock is broken, so we need to define them here.
|
||||||
*/
|
*/
|
||||||
BaseType_t xQueueTakeMutexRecursive(QueueHandle_t xMutex,
|
esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tls_code, int *esp_tls_flags)
|
||||||
TickType_t xTicksToWait)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return ESP_OK;
|
||||||
}
|
|
||||||
BaseType_t xQueueGiveMutexRecursive(QueueHandle_t xMutex)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "mqtt_client.h"
|
||||||
|
|
||||||
struct ClientInitializedFixture {
|
struct ClientInitializedFixture {
|
||||||
esp_mqtt_client_handle_t client;
|
esp_mqtt_client_handle_t client;
|
||||||
ClientInitializedFixture()
|
ClientInitializedFixture()
|
||||||
@@ -42,6 +37,8 @@ struct ClientInitializedFixture {
|
|||||||
int event_group;
|
int event_group;
|
||||||
uint8_t mac[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
|
uint8_t mac[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
|
||||||
esp_log_write_Ignore();
|
esp_log_write_Ignore();
|
||||||
|
xQueueTakeMutexRecursive_CMockIgnoreAndReturn(0, true);
|
||||||
|
xQueueGiveMutexRecursive_CMockIgnoreAndReturn(0, true);
|
||||||
xQueueCreateMutex_ExpectAnyArgsAndReturn(
|
xQueueCreateMutex_ExpectAnyArgsAndReturn(
|
||||||
reinterpret_cast<QueueHandle_t>(&mtx));
|
reinterpret_cast<QueueHandle_t>(&mtx));
|
||||||
xEventGroupCreate_IgnoreAndReturn(reinterpret_cast<EventGroupHandle_t>(&event_group));
|
xEventGroupCreate_IgnoreAndReturn(reinterpret_cast<EventGroupHandle_t>(&event_group));
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
- array
|
- array
|
||||||
- callback
|
- callback
|
||||||
:includes_h_pre_orig_header:
|
:includes_h_pre_orig_header:
|
||||||
|
- local_FreeRTOS_config.h
|
||||||
|
- esp_attr.h
|
||||||
- FreeRTOS.h
|
- FreeRTOS.h
|
||||||
- net/if.h
|
- net/if.h
|
||||||
:strippables:
|
:strippables:
|
||||||
|
@@ -0,0 +1,6 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#define configUSE_TRACE_FACILITY 1
|
Reference in New Issue
Block a user