Merge branch 'feature/mqtt_cmakefile_cleanup' into 'master'

Mqtt:  Cmakelists.txt file simplification.

See merge request espressif/esp-idf!19966
pull/9842/head
Rocha Euripedes 2022-09-21 15:21:07 +08:00
commit 819dae8008
24 zmienionych plików z 192 dodań i 165 usunięć

Wyświetl plik

@ -7,122 +7,7 @@ endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS esp-mqtt/include
PRIV_INCLUDE_DIRS "esp-mqtt/lib/include"
PRIV_REQUIRES esp_timer
REQUIRES esp_event tcp_transport
PRIV_REQUIRES esp_timer http_parser esp_hw_support
)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
if(TEST_BUILD)
message(STATUS "building MOCKS")
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_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_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)
idf_component_get_property(esp_rom_dir esp_rom COMPONENT_DIR)
idf_component_get_property(esp_system_dir esp_system COMPONENT_DIR)
idf_component_get_property(mbedtls_dir mbedtls COMPONENT_DIR)
idf_component_get_property(cmock_lib cmock COMPONENT_LIB)
set(IDF_PATH $ENV{IDF_PATH})
set(CMOCK_DIR "${IDF_PATH}/components/cmock/CMock")
set(MOCK_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/mocks")
set(ENV{UNITY_DIR} "$ENV{IDF_PATH}/components/cmock/CMock")
file(MAKE_DIRECTORY ${MOCK_GEN_DIR})
set(MOCK_OUTPUT
"${MOCK_GEN_DIR}/Mockesp_transport.c" "${MOCK_GEN_DIR}/Mockesp_transport.h"
"${MOCK_GEN_DIR}/Mockesp_transport_ssl.c" "${MOCK_GEN_DIR}/Mockesp_transport_ssl.h"
"${MOCK_GEN_DIR}/Mockesp_transport_ws.c" "${MOCK_GEN_DIR}/Mockesp_transport_ws.h"
"${MOCK_GEN_DIR}/Mockesp_transport_tcp.c" "${MOCK_GEN_DIR}/Mockesp_transport_tcp.h"
"${MOCK_GEN_DIR}/Mockesp_event.c" "${MOCK_GEN_DIR}/Mockesp_event.h"
"${MOCK_GEN_DIR}/Mockesp_mac.c" "${MOCK_GEN_DIR}/Mockesp_mac.h"
"${MOCK_GEN_DIR}/Mockesp_random.c" "${MOCK_GEN_DIR}/Mockesp_random.h"
"${MOCK_GEN_DIR}/Mockesp_system.c" "${MOCK_GEN_DIR}/Mockesp_system.h"
"${MOCK_GEN_DIR}/Mockesp_tls.c" "${MOCK_GEN_DIR}/Mockesp_tls.h"
"${MOCK_GEN_DIR}/Mockevent_groups.c" "${MOCK_GEN_DIR}/Mockevent_groups.h"
"${MOCK_GEN_DIR}/Mockqueue.c" "${MOCK_GEN_DIR}/Mockqueue.h"
"${MOCK_GEN_DIR}/Mocktask.c" "${MOCK_GEN_DIR}/Mocktask.h"
"${MOCK_GEN_DIR}/Mockesp_log.c" "${MOCK_GEN_DIR}/Mockesp_log.h"
"${MOCK_GEN_DIR}/Mockhttp_parser.c" "${MOCK_GEN_DIR}/Mockhttp_parser.h"
)
set(HEADERS_TO_MOCK
${tcp_transport_dir}/include/esp_transport_tcp.h
${tcp_transport_dir}/include/esp_transport_ws.h
${tcp_transport_dir}/include/esp_transport_ssl.h
${tcp_transport_dir}/include/esp_transport.h
${esp_event_dir}/include/esp_event.h
${esp_hw_support_dir}/include/esp_mac.h
${esp_hw_support_dir}/include/esp_random.h
${freertos_dir}/FreeRTOS-Kernel/include/freertos/event_groups.h
${log_dir}/include/esp_log.h
${http_parser_dir}/http_parser.h
)
set(srcs
${MOCK_GEN_DIR}/Mockesp_transport.c
${MOCK_GEN_DIR}/Mockesp_transport_ws.c
${MOCK_GEN_DIR}/Mockesp_transport_ssl.c
${MOCK_GEN_DIR}/Mockesp_transport_tcp.c
${MOCK_GEN_DIR}/Mockesp_transport_tcp.c
${MOCK_GEN_DIR}/Mockesp_event.c
${MOCK_GEN_DIR}/Mockesp_mac.c
${MOCK_GEN_DIR}/Mockesp_random.c
${MOCK_GEN_DIR}/Mockesp_log.c
${MOCK_GEN_DIR}/Mockhttp_parser.c
${MOCK_GEN_DIR}/Mockevent_groups.c
)
add_custom_command(
OUTPUT ruby_found SYMBOLIC
COMMAND "ruby" "-v"
COMMENT "Try to find ruby. If this fails, you need to install ruby"
)
add_custom_command(
OUTPUT ${MOCK_OUTPUT}
DEPENDS ruby_found
COMMAND ${CMAKE_COMMAND} -E env "UNITY_DIR=${IDF_PATH}/components/unity/unity"
ruby
${CMOCK_DIR}/lib/cmock.rb
-o${CMAKE_CURRENT_SOURCE_DIR}/host_test/mocks/config.yaml
${HEADERS_TO_MOCK}
)
add_library(mocks ${srcs})
target_include_directories(mocks PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/host_test/mocks/include
${tcp_transport_dir}/include
${esp_tls_dir}
${freertos_dir}/FreeRTOS-Kernel/include
${esp_event_dir}/include
${esp_system_dir}/include
${esp_common_dir}/include
${esp_wifi_dir}/include
${esp_hw_support_dir}/include
${esp_netif_dir}/include
${log_dir}/include
${esp_rom_dir}/include
${mbedtls_dir}/port/include
${http_parser_dir}
${mbedtls_dir}/mbedtls/include
${freertos_dir}/FreeRTOS-Kernel/include/freertos
esp-mqtt/lib/include
${MOCK_GEN_DIR}
)
target_link_libraries(mocks PUBLIC ${cmock_lib})
target_compile_definitions(mocks PUBLIC
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS)
target_link_options(${COMPONENT_LIB} INTERFACE -fsanitize=address)
target_link_libraries(${COMPONENT_LIB} PUBLIC mocks)
else()
idf_component_optional_requires(PUBLIC esp_event tcp_transport)
idf_component_optional_requires(PRIVATE http_parser)
endif()

Wyświetl plik

@ -2,9 +2,15 @@ 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/"
list(APPEND EXTRA_COMPONENT_DIRS
"$ENV{IDF_PATH}/tools/mocks/esp_hw_support/"
"$ENV{IDF_PATH}/tools/mocks/freertos/"
"$ENV{IDF_PATH}/tools/mocks/esp_timer/"
"$ENV{IDF_PATH}/tools/mocks/esp_event/"
"$ENV{IDF_PATH}/tools/mocks/lwip/"
"$ENV{IDF_PATH}/tools/mocks/esp-tls/"
"$ENV{IDF_PATH}/tools/mocks/http_parser/"
"$ENV{IDF_PATH}/tools/mocks/tcp_transport/"
)
option(TEST_BUILD "" ON)
project(host_mqtt_client_test)

Wyświetl plik

@ -1,3 +1,3 @@
idf_component_register(SRCS "test_mqtt_client.cpp"
INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch"
REQUIRES cmock mqtt esp_timer)
REQUIRES cmock mqtt esp_timer esp_hw_support http_parser log)

Wyświetl plik

@ -3,7 +3,6 @@
extern "C" {
#include "Mockesp_event.h"
#include "Mockesp_log.h"
#include "Mockesp_mac.h"
#include "Mockesp_transport.h"
#include "Mockesp_transport_ssl.h"
@ -37,14 +36,12 @@ struct ClientInitializedFixture {
int transport;
int event_group;
uint8_t mac[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
esp_log_write_Ignore();
esp_timer_get_time_IgnoreAndReturn(0);
xQueueTakeMutexRecursive_IgnoreAndReturn(true);
xQueueGiveMutexRecursive_IgnoreAndReturn(true);
xQueueCreateMutex_ExpectAnyArgsAndReturn(
reinterpret_cast<QueueHandle_t>(&mtx));
xEventGroupCreate_IgnoreAndReturn(reinterpret_cast<EventGroupHandle_t>(&event_group));
esp_log_timestamp_IgnoreAndReturn(0);
esp_transport_list_init_IgnoreAndReturn(reinterpret_cast<esp_transport_list_handle_t>(&transport_list));
esp_transport_tcp_init_IgnoreAndReturn(reinterpret_cast<esp_transport_handle_t>(&transport));
esp_transport_ssl_init_IgnoreAndReturn(reinterpret_cast<esp_transport_handle_t>(&transport));

Wyświetl plik

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

Wyświetl plik

@ -104,4 +104,5 @@ TEST_CASE("mqtt broker tests", "[mqtt][test_env=UT_T2_Ethernet]")
connect_test_fixture_teardown();
}
#endif // SOC_EMAC_SUPPORTED

Wyświetl plik

@ -1,22 +1,15 @@
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _ESP_TRANSPORT_TCP_H_
#define _ESP_TRANSPORT_TCP_H_
#include "esp_transport.h"
#include <sys/socket.h>
#include <net/if.h>
#ifdef __cplusplus
extern "C" {

Wyświetl plik

@ -1254,7 +1254,6 @@ components/spi_flash/test/test_mmap.c
components/spi_flash/test/test_out_of_bounds_write.c
components/spi_flash/test/test_partition_ext.c
components/spi_flash/test/test_spi_flash.c
components/tcp_transport/include/esp_transport_tcp.h
components/tcp_transport/include/esp_transport_ws.h
components/tcp_transport/test/tcp_transport_fixtures.h
components/tcp_transport/test/test_transport_basic.c

Wyświetl plik

@ -558,6 +558,8 @@ function(idf_component_mock)
INCLUDE_DIRS ${__INCLUDE_DIRS}
REQUIRES ${__REQUIRES})
set(COMPONENT_LIB ${COMPONENT_LIB} PARENT_SCOPE)
add_custom_command(
OUTPUT ruby_found SYMBOLIC
COMMAND "ruby" "-v"

Wyświetl plik

@ -0,0 +1,12 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building ESP-TLS MOCKS")
idf_component_get_property(original_esp_tls_dir esp-tls COMPONENT_OVERRIDEN_DIR)
idf_component_mock(INCLUDE_DIRS "${original_esp_tls_dir}"
"${original_esp_tls_dir}/esp-tls-crypto"
MOCK_HEADER_FILES ${original_esp_tls_dir}/esp_tls.h
${original_esp_tls_dir}/esp-tls-crypto/esp_tls_crypto.h
)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-array-parameter)

Wyświetl plik

@ -0,0 +1,16 @@
:cmock:
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- ignore
- ignore_arg
:when_ptr: :compare_ptr
:strippables:
- '(?:esp_tls_cfg_server_session_tickets_init\s*\(+.*?\)+)'
- '(?:esp_tls_cfg_server_session_tickets_free\s*\(+.*?\)+)'
- '(?:esp_tls_server_session_create\s*\(+.*?\)+)'
- '(?:esp_tls_get_global_ca_store\s*\(+.*?\)+)'
- '(?:esp_tls_get_client_session\s*\(+.*?\)+)'
- '(?:esp_tls_free_client_session\s*\(+.*?\)+)'

Wyświetl plik

@ -0,0 +1,10 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building ESP EVENT MOCKS")
idf_component_get_property(original_esp_event_dir esp_event COMPONENT_OVERRIDEN_DIR)
idf_component_mock(INCLUDE_DIRS "${original_esp_event_dir}/include"
MOCK_HEADER_FILES ${original_esp_event_dir}/include/esp_event.h
${original_esp_event_dir}/include/esp_event_base.h
)

Wyświetl plik

@ -0,0 +1,9 @@
:cmock:
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- array
- ignore
- ignore_arg
- callback

Wyświetl plik

@ -0,0 +1,10 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building ESP HW SUPPORT MOCKS")
idf_component_get_property(original_esp_hw_support_dir esp_hw_support COMPONENT_OVERRIDEN_DIR)
idf_component_mock(INCLUDE_DIRS "${original_esp_hw_support_dir}/include"
MOCK_HEADER_FILES ${original_esp_hw_support_dir}/include/esp_mac.h
${original_esp_hw_support_dir}/include/esp_random.h
)

Wyświetl plik

@ -0,0 +1,7 @@
:cmock:
:plugins:
- expect
- expect_any_args
- ignore
- ignore_arg
- return_thru_ptr

Wyświetl plik

@ -1,10 +1,11 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building FREERTOS MOCKS (only task and queue)")
message(STATUS "building FREERTOS MOCKS (only task, event-groups and queue)")
idf_component_get_property(original_freertos_dir freertos COMPONENT_OVERRIDEN_DIR)
set(include_dirs
"include"
"${original_freertos_dir}/FreeRTOS-Kernel/include"
"${original_freertos_dir}/esp_additions/include"
"${original_freertos_dir}/esp_additions/include/freertos"
@ -15,4 +16,5 @@ idf_component_mock(INCLUDE_DIRS ${include_dirs}
REQUIRES esp_common
MOCK_HEADER_FILES
${original_freertos_dir}/FreeRTOS-Kernel/include/freertos/task.h
${original_freertos_dir}/FreeRTOS-Kernel/include/freertos/event_groups.h
${original_freertos_dir}/FreeRTOS-Kernel/include/freertos/queue.h)

Wyświetl plik

@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#define STACK_OVERHEAD_CHECKER 256
#define STACK_OVERHEAD_OPTIMIZATION 320
#define STACK_OVERHEAD_APPTRACE 1280
#define STACK_OVERHEAD_WATCHPOINT 60
#define configSTACK_OVERHEAD_TOTAL ( \
STACK_OVERHEAD_CHECKER + \
STACK_OVERHEAD_OPTIMIZATION + \
STACK_OVERHEAD_APPTRACE + \
STACK_OVERHEAD_WATCHPOINT \
)
#define configMINIMAL_STACK_SIZE ( 768 + configSTACK_OVERHEAD_TOTAL )
#define configMAX_PRIORITIES ( 25 ) //This has impact on speed of search for highest priority
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK CONFIG_FREERTOS_USE_IDLE_HOOK
#define configUSE_TICK_HOOK CONFIG_FREERTOS_USE_TICK_HOOK
#define configUSE_16_BIT_TICKS 0
#define configUSE_TRACE_FACILITY 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1

Wyświetl plik

@ -1,21 +1,22 @@
:cmock:
:includes_h_pre_orig_header:
- FreeRTOS.h
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- array
- ignore
- ignore_arg
- callback
:strippables:
- '(?:__attribute__\s*\(+.*?\)+)'
# following functions are disabled by configQUEUE_REGISTRY_SIZE
- '(?:vQueueAddToRegistry\s*\([\s\w\*_,]*\))'
- '(?:vQueueUnregisterQueue\s*\([\s\w\*_,]*\))'
- '(?:pcQueueGetName\s*\([\s\w\*_,]*\))'
# following function is disabled by configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS
- '(?:vTaskSetThreadLocalStoragePointerAndDelCallback\s*\([\s\w\*_,]*\))'
- PRIVILEGED_FUNCTION
- portDONT_DISCARD
:cmock:
:includes_h_pre_orig_header:
- FreeRTOSConfig.h
- FreeRTOS.h
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- array
- ignore
- ignore_arg
- callback
:strippables:
- '(?:__attribute__\s*\(+.*?\)+)'
# following functions are disabled by configQUEUE_REGISTRY_SIZE
- '(?:vQueueAddToRegistry\s*\([\s\w\*_,]*\))'
- '(?:vQueueUnregisterQueue\s*\([\s\w\*_,]*\))'
- '(?:pcQueueGetName\s*\([\s\w\*_,]*\))'
# following function is disabled by configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS
- '(?:vTaskSetThreadLocalStoragePointerAndDelCallback\s*\([\s\w\*_,]*\))'
- PRIVILEGED_FUNCTION
- portDONT_DISCARD

Wyświetl plik

@ -0,0 +1,8 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building HTTP PARSER MOCKS")
idf_component_get_property(original_http_parser_dir http_parser COMPONENT_OVERRIDEN_DIR)
idf_component_mock(INCLUDE_DIRS "${original_http_parser_dir}"
MOCK_HEADER_FILES ${original_http_parser_dir}/http_parser.h)

Wyświetl plik

@ -0,0 +1,9 @@
:cmock:
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- array
- ignore
- ignore_arg
- callback

Wyświetl plik

@ -0,0 +1,10 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building LWIP MOCKS (only netdb)")
idf_component_get_property(original_lwip_dir lwip COMPONENT_OVERRIDEN_DIR)
idf_component_mock(INCLUDE_DIRS "${original_lwip_dir}/port"
"${original_lwip_dir}/include/lwip"
"${original_lwip_dir}/lwip/src/include"
MOCK_HEADER_FILES ${original_lwip_dir}/lwip/src/include/lwip/netdb.h )

Wyświetl plik

@ -0,0 +1,9 @@
:cmock:
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- array
- ignore
- ignore_arg
- callback

Wyświetl plik

@ -0,0 +1,13 @@
# NOTE: This kind of mocking currently works on Linux targets only.
# On Espressif chips, too many dependencies are missing at the moment.
message(STATUS "building TCP TRANSPORT MOCKS")
idf_component_get_property(original_tcp_transport_dir tcp_transport COMPONENT_OVERRIDEN_DIR)
idf_component_mock(INCLUDE_DIRS "${original_tcp_transport_dir}/include"
MOCK_HEADER_FILES ${original_tcp_transport_dir}/include/esp_transport.h
${original_tcp_transport_dir}/include/esp_transport_tcp.h
${original_tcp_transport_dir}/include/esp_transport_ssl.h
${original_tcp_transport_dir}/include/esp_transport_ws.h
REQUIRES esp-tls
)

Wyświetl plik

@ -0,0 +1,9 @@
:cmock:
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- ignore
- ignore_arg
- callback
:when_ptr: :compare_ptr