diff --git a/components/mqtt/CMakeLists.txt b/components/mqtt/CMakeLists.txt index 15aea3d745..29aa3497d5 100644 --- a/components/mqtt/CMakeLists.txt +++ b/components/mqtt/CMakeLists.txt @@ -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() diff --git a/components/mqtt/host_test/CMakeLists.txt b/components/mqtt/host_test/CMakeLists.txt index 7137910836..b52ed87613 100644 --- a/components/mqtt/host_test/CMakeLists.txt +++ b/components/mqtt/host_test/CMakeLists.txt @@ -1,10 +1,22 @@ 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/" - "$ENV{IDF_PATH}/tools/mocks/esp_timer/" - ) -option(TEST_BUILD "" ON) + +set(COMPONENTS linux mqtt main) + +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/" + ) project(host_mqtt_client_test) + +idf_component_get_property(mqtt mqtt COMPONENT_LIB) +idf_component_get_property(linux linux COMPONENT_LIB) +target_link_libraries(${mqtt} PUBLIC ${linux}) diff --git a/components/mqtt/host_test/main/CMakeLists.txt b/components/mqtt/host_test/main/CMakeLists.txt index 90692f6cce..5ad6024b06 100644 --- a/components/mqtt/host_test/main/CMakeLists.txt +++ b/components/mqtt/host_test/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "test_mqtt_client.cpp" - INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch" - REQUIRES cmock mqtt esp_timer) + INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch" "mocks/include" + REQUIRES cmock mqtt esp_timer esp_hw_support http_parser log) diff --git a/components/mqtt/host_test/mocks/include/sys/queue.h b/components/mqtt/host_test/main/mocks/include/sys/queue.h similarity index 54% rename from components/mqtt/host_test/mocks/include/sys/queue.h rename to components/mqtt/host_test/main/mocks/include/sys/queue.h index 5ec7fec019..fad53cae17 100644 --- a/components/mqtt/host_test/mocks/include/sys/queue.h +++ b/components/mqtt/host_test/main/mocks/include/sys/queue.h @@ -1,3 +1,38 @@ +/* + * SPDX-FileCopyrightText: The Regents of the University of California + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD$ + */ #pragma once /* Implementation from BSD headers*/ diff --git a/components/mqtt/host_test/main/test_mqtt_client.cpp b/components/mqtt/host_test/main/test_mqtt_client.cpp index 4979c194f1..8ebbf1eefc 100644 --- a/components/mqtt/host_test/main/test_mqtt_client.cpp +++ b/components/mqtt/host_test/main/test_mqtt_client.cpp @@ -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(&mtx)); xEventGroupCreate_IgnoreAndReturn(reinterpret_cast(&event_group)); - esp_log_timestamp_IgnoreAndReturn(0); esp_transport_list_init_IgnoreAndReturn(reinterpret_cast(&transport_list)); esp_transport_tcp_init_IgnoreAndReturn(reinterpret_cast(&transport)); esp_transport_ssl_init_IgnoreAndReturn(reinterpret_cast(&transport)); diff --git a/components/mqtt/host_test/mocks/config.yaml b/components/mqtt/host_test/mocks/config.yaml deleted file mode 100644 index cdaab2ae2b..0000000000 --- a/components/mqtt/host_test/mocks/config.yaml +++ /dev/null @@ -1,25 +0,0 @@ - :cmock: - :plugins: - - expect - - expect_any_args - - return_thru_ptr - - ignore - - array - - callback - :includes_h_pre_orig_header: - - local_FreeRTOS_config.h - - esp_attr.h - - FreeRTOS.h - - net/if.h - :strippables: - - '(?:__attribute__\s*\(+.*?\)+)' - - '(?:vQueueAddToRegistry\s*\(+.*?\)+)' - - '(?:vQueueUnregisterQueue\s*\(+.*?\)+)' - - '(?:pcQueueGetName\s*\(+.*?\)+)' - - '(?:xQueueTakeMutexRecursive\s*\(+.*?\)+)' - - '(?:xQueueGiveMutexRecursive\s*\(+.*?\)+)' - - '(?:vTaskSetThreadLocalStoragePointerAndDelCallback\s*\(+.*?\)+)' - - '(?:esp_log_writev\s*\(+.*?\)+)' - - '(?:esp_restart\s*\(+.*?\)+)' - - '(?:esp_system_abort\s*\(+.*?\)+)' - - PRIVILEGED_FUNCTION diff --git a/components/mqtt/host_test/mocks/include/freertos/FreeRTOSConfig.h b/components/mqtt/host_test/mocks/include/freertos/FreeRTOSConfig.h deleted file mode 100644 index 0492f81847..0000000000 --- a/components/mqtt/host_test/mocks/include/freertos/FreeRTOSConfig.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd. - All rights reserved - - VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. - - *************************************************************************** - >>! NOTE: The modification to the GPL is included to allow you to !<< - >>! distribute a combined work that includes FreeRTOS without being !<< - >>! obliged to provide the source code for proprietary components !<< - >>! outside of the FreeRTOS kernel. !<< - *************************************************************************** - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. Full license text is available on the following - link: http://www.freertos.org/a00114.html - - *************************************************************************** - * * - * FreeRTOS provides completely free yet professionally developed, * - * robust, strictly quality controlled, supported, and cross * - * platform software that is more than just the market leader, it * - * is the industry's de facto standard. * - * * - * Help yourself get started quickly while simultaneously helping * - * to support the FreeRTOS project by purchasing a FreeRTOS * - * tutorial book, reference manual, or both: * - * http://www.FreeRTOS.org/Documentation * - * * - *************************************************************************** - - http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading - the FAQ page "My application does not run, what could be wrong?". Have you - defined configASSERT()? - - http://www.FreeRTOS.org/support - In return for receiving this top quality - embedded software for free we request you assist our global community by - participating in the support forum. - - http://www.FreeRTOS.org/training - Investing in training allows your team to - be as productive as possible as early as possible. Now you can receive - FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers - Ltd, and the world's leading authority on the world's leading RTOS. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, a DOS - compatible FAT file system, and our tiny thread aware UDP/IP stack. - - http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. - Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. - - http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High - Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS - licenses offer ticketed support, indemnification and commercial middleware. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. - - 1 tab == 4 spaces! -*/ - -#ifndef FREERTOS_CONFIG_H -#define FREERTOS_CONFIG_H - -#include "esp_attr.h" - -/*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. - * - * See http://www.freertos.org/a00110.html. - *----------------------------------------------------------*/ - -#define configUSE_PREEMPTION 1 -#define configUSE_IDLE_HOOK 1 -#define configUSE_TICK_HOOK 1 -#define configTICK_RATE_HZ ((TickType_t)1000) -#define configMINIMAL_STACK_SIZE ((unsigned short)256) /* This can be made smaller if required. */ -#define configTOTAL_HEAP_SIZE ((size_t)(32 * 1024)) -#define configMAX_TASK_NAME_LEN (16) -#define configUSE_TRACE_FACILITY 1 -#define configUSE_16_BIT_TICKS 1 -#define configIDLE_SHOULD_YIELD 1 -#define configUSE_CO_ROUTINES 1 -#define configUSE_MUTEXES 1 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configUSE_ALTERNATIVE_API 0 -#define configUSE_RECURSIVE_MUTEXES 1 -#define configCHECK_FOR_STACK_OVERFLOW 0 /* Do not use this option on the PC port. */ -#define configUSE_APPLICATION_TASK_TAG 1 -#define configQUEUE_REGISTRY_SIZE 0 - -#define configMAX_PRIORITIES (10) -#define configMAX_CO_ROUTINE_PRIORITIES (2) - -/* Set the following definitions to 1 to include the API function, or zero -to exclude the API function. */ - -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 1 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_uxTaskGetStackHighWaterMark 0 /* Do not use this option on the PC port. */ - -/* This demo makes use of one or more example stats formatting functions. These -format the raw data provided by the uxTaskGetSystemState() function in to human -readable ASCII form. See the notes in the implementation of vTaskList() within -FreeRTOS/Source/tasks.c for limitations. */ -#define configUSE_STATS_FORMATTING_FUNCTIONS 1 - -/* An example "task switched in" hook macro definition. */ -#define traceTASK_SWITCHED_IN() xTaskCallApplicationTaskHook(NULL, (void*)0xabcd) - -extern void vMainQueueSendPassed(void); -#define traceQUEUE_SEND(pxQueue) vMainQueueSendPassed() - -#endif /* FREERTOS_CONFIG_H */ diff --git a/components/mqtt/host_test/mocks/include/freertos/portmacro.h b/components/mqtt/host_test/mocks/include/freertos/portmacro.h deleted file mode 100644 index 23c3d6eaf6..0000000000 --- a/components/mqtt/host_test/mocks/include/freertos/portmacro.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * FreeRTOS Kernel V10.4.3 - * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ -#ifndef PORTMACRO_H -#define PORTMACRO_H - -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef __ASSEMBLER__ - -/*----------------------------------------------------------- - * Port specific definitions. - * - * The settings in this file configure FreeRTOS correctly for the - * given hardware and compiler. - * - * These settings should not be altered. - *----------------------------------------------------------- - */ - -/* Type definitions. */ -#define portCHAR uint8_t -#define portFLOAT float -#define portDOUBLE double -#define portLONG int32_t -#define portSHORT int16_t -#define portSTACK_TYPE uint8_t -#define portBASE_TYPE int -// interrupt module will mask interrupt with priority less than threshold -#define RVHAL_EXCM_LEVEL 4 - -typedef portSTACK_TYPE StackType_t; -typedef portBASE_TYPE BaseType_t; -typedef unsigned portBASE_TYPE UBaseType_t; - -#if (configUSE_16_BIT_TICKS == 1) -typedef uint16_t TickType_t; -#define portMAX_DELAY (TickType_t)0xffff -#else -typedef uint32_t TickType_t; -#define portMAX_DELAY (TickType_t)0xffffffffUL -#endif -/*------------------------------------------------------*/ - -/* Architecture specifics. */ -#define portSTACK_GROWTH (-1) -#define portTICK_PERIOD_MS ((TickType_t)(1000 / configTICK_RATE_HZ)) -#define portBYTE_ALIGNMENT 16 -/*-----------------------------------------------------------*/ - -#define portCRITICAL_NESTING_IN_TCB 0 - -/* - * Send an interrupt to another core in order to make the task running - * on it yield for a higher-priority task. - */ -void vPortYieldOtherCore(BaseType_t coreid); - -/* - Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack - watchpoint around. - */ -void vPortSetStackWatchpoint(void *pxStackStart); - -/* - * Returns true if the current core is in ISR context; low prio ISR, med prio ISR or timer tick ISR. High prio ISRs - * aren't detected here, but they normally cannot call C code, so that should not be an issue anyway. - */ -BaseType_t xPortInIsrContext(void); - -/* - * This function will be called in High prio ISRs. Returns true if the current core was in ISR context - * before calling into high prio ISR context. - */ -BaseType_t xPortInterruptedFromISRContext(void); - -/* "mux" data structure (spinlock) */ -typedef struct { - /* owner field values: - * 0 - Uninitialized (invalid) - * portMUX_FREE_VAL - Mux is free, can be locked by either CPU - * CORE_ID_REGVAL_PRO / CORE_ID_REGVAL_APP - Mux is locked to the particular core - * - * - * Any value other than portMUX_FREE_VAL, CORE_ID_REGVAL_PRO, CORE_ID_REGVAL_APP indicates corruption - */ - uint32_t owner; - /* count field: - * If mux is unlocked, count should be zero. - * If mux is locked, count is non-zero & represents the number of recursive locks on the mux. - */ - uint32_t count; -} portMUX_TYPE; - -#define portMUX_FREE_VAL SPINLOCK_FREE - -/* Special constants for vPortCPUAcquireMutexTimeout() */ -#define portMUX_NO_TIMEOUT SPINLOCK_WAIT_FOREVER /* When passed for 'timeout_cycles', spin forever if necessary */ -#define portMUX_TRY_LOCK SPINLOCK_NO_WAIT /* Try to acquire the spinlock a single time only */ - -// Keep this in sync with the portMUX_TYPE struct definition please. -#define portMUX_INITIALIZER_UNLOCKED \ - { .owner = portMUX_FREE_VAL, .count = 0, } - -/* Scheduler utilities. */ -extern void vPortYield(void); -extern void vPortYieldFromISR(void); - -#define portYIELD() vPortYield() -#define portYIELD_FROM_ISR() vPortYieldFromISR() - -/* Yielding within an API call (when interrupts are off), means the yield should be delayed - until interrupts are re-enabled. - To do this, we use the "cross-core" interrupt as a trigger to yield on this core when interrupts are re-enabled.This - is the same interrupt & code path which is used to trigger a yield between CPUs, although in this case the yield is - happening on the same CPU. -*/ -#define portYIELD_WITHIN_API() portYIELD() -/*-----------------------------------------------------------*/ - -/* Critical section management. */ -extern int vPortSetInterruptMask(void); -extern void vPortClearInterruptMask(int); - -extern void vPortEnterCritical(void); -extern void vPortExitCritical(void); - -/* Task function macros as described on the FreeRTOS.org WEB site. */ -#define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void* pvParameters) -#define portTASK_FUNCTION(vFunction, pvParameters) void vFunction(void* pvParameters) - -void vApplicationSleep(TickType_t xExpectedIdleTime); -#define portSUPPRESS_TICKS_AND_SLEEP(idleTime) vApplicationSleep(idleTime) - -#define portNOP() //__asm volatile ( " nop " ) - -#define portVALID_TCB_MEM(ptr) // esp_ptr_byte_accessible(ptr) -#define portVALID_STACK_MEM(ptr) // esp_ptr_byte_accessible(ptr) - -#endif //__ASSEMBLER__ - -#ifdef __cplusplus -} -#endif - -#endif /* PORTMACRO_H */ diff --git a/components/mqtt/host_test/mocks/include/local_FreeRTOS_config.h b/components/mqtt/host_test/mocks/include/local_FreeRTOS_config.h deleted file mode 100644 index e7e1014beb..0000000000 --- a/components/mqtt/host_test/mocks/include/local_FreeRTOS_config.h +++ /dev/null @@ -1,6 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#define configUSE_TRACE_FACILITY 1 diff --git a/components/mqtt/host_test/mocks/include/machine/endian.h b/components/mqtt/host_test/mocks/include/machine/endian.h deleted file mode 100644 index 228316d612..0000000000 --- a/components/mqtt/host_test/mocks/include/machine/endian.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -#include_next diff --git a/components/mqtt/test/test_mqtt.c b/components/mqtt/test/test_mqtt.c index 4f2341caca..41a5516f7d 100644 --- a/components/mqtt/test/test_mqtt.c +++ b/components/mqtt/test/test_mqtt.c @@ -105,4 +105,5 @@ TEST_CASE("mqtt broker tests", "[mqtt][test_env=UT_T2_Ethernet]") connect_test_fixture_teardown(); } + #endif // SOC_EMAC_SUPPORTED diff --git a/components/tcp_transport/include/esp_transport_tcp.h b/components/tcp_transport/include/esp_transport_tcp.h index 6941820f0e..e5b0a46638 100644 --- a/components/tcp_transport/include/esp_transport_tcp.h +++ b/components/tcp_transport/include/esp_transport_tcp.h @@ -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 +#include #ifdef __cplusplus extern "C" { diff --git a/tools/ci/check_copyright_config.yaml b/tools/ci/check_copyright_config.yaml index bb99c7d0b6..65cb7c10f5 100644 --- a/tools/ci/check_copyright_config.yaml +++ b/tools/ci/check_copyright_config.yaml @@ -68,6 +68,16 @@ lwip_component: - BSD-3-Clause license_for_new_files: Apache-2.0 +mqtt_component: + include: + - 'components/mqtt/**' + allowed_licenses: + - Apache-2.0 + - BSD-3-Clause + - Unlicense + - CC0-1.0 + license_for_new_files: Apache-2.0 + newlib_component: include: - 'components/newlib/platform_include/**' diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index aa7375ad8c..0385b369f4 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1283,7 +1283,6 @@ 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_ssl.h -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 diff --git a/tools/cmake/component.cmake b/tools/cmake/component.cmake index cea0084bf7..9dac5fe409 100644 --- a/tools/cmake/component.cmake +++ b/tools/cmake/component.cmake @@ -564,6 +564,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" diff --git a/tools/mocks/esp-tls/CMakeLists.txt b/tools/mocks/esp-tls/CMakeLists.txt new file mode 100644 index 0000000000..ffe9866874 --- /dev/null +++ b/tools/mocks/esp-tls/CMakeLists.txt @@ -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) diff --git a/tools/mocks/esp-tls/mock/mock_config.yaml b/tools/mocks/esp-tls/mock/mock_config.yaml new file mode 100644 index 0000000000..60a445dc0c --- /dev/null +++ b/tools/mocks/esp-tls/mock/mock_config.yaml @@ -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*\(+.*?\)+)' diff --git a/tools/mocks/esp_event/CMakeLists.txt b/tools/mocks/esp_event/CMakeLists.txt new file mode 100644 index 0000000000..24629a6ef6 --- /dev/null +++ b/tools/mocks/esp_event/CMakeLists.txt @@ -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 + ) diff --git a/tools/mocks/esp_event/mock/mock_config.yaml b/tools/mocks/esp_event/mock/mock_config.yaml new file mode 100644 index 0000000000..596255b0ce --- /dev/null +++ b/tools/mocks/esp_event/mock/mock_config.yaml @@ -0,0 +1,9 @@ + :cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - array + - ignore + - ignore_arg + - callback diff --git a/tools/mocks/esp_hw_support/CMakeLists.txt b/tools/mocks/esp_hw_support/CMakeLists.txt new file mode 100644 index 0000000000..724c3b42a4 --- /dev/null +++ b/tools/mocks/esp_hw_support/CMakeLists.txt @@ -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 + ) diff --git a/tools/mocks/esp_hw_support/mock/mock_config.yaml b/tools/mocks/esp_hw_support/mock/mock_config.yaml new file mode 100644 index 0000000000..e250ea354d --- /dev/null +++ b/tools/mocks/esp_hw_support/mock/mock_config.yaml @@ -0,0 +1,7 @@ + :cmock: + :plugins: + - expect + - expect_any_args + - ignore + - ignore_arg + - return_thru_ptr diff --git a/tools/mocks/freertos/CMakeLists.txt b/tools/mocks/freertos/CMakeLists.txt index 4409be36f3..410855eace 100644 --- a/tools/mocks/freertos/CMakeLists.txt +++ b/tools/mocks/freertos/CMakeLists.txt @@ -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) diff --git a/tools/mocks/freertos/include/FreeRTOSConfig.h b/tools/mocks/freertos/include/FreeRTOSConfig.h new file mode 100644 index 0000000000..eb1f4defe2 --- /dev/null +++ b/tools/mocks/freertos/include/FreeRTOSConfig.h @@ -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 diff --git a/tools/mocks/freertos/mock/mock_config.yaml b/tools/mocks/freertos/mock/mock_config.yaml index dad1a6e2a4..9b7eab92eb 100644 --- a/tools/mocks/freertos/mock/mock_config.yaml +++ b/tools/mocks/freertos/mock/mock_config.yaml @@ -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 diff --git a/tools/mocks/http_parser/CMakeLists.txt b/tools/mocks/http_parser/CMakeLists.txt new file mode 100644 index 0000000000..7050914da3 --- /dev/null +++ b/tools/mocks/http_parser/CMakeLists.txt @@ -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) diff --git a/tools/mocks/http_parser/mock/mock_config.yaml b/tools/mocks/http_parser/mock/mock_config.yaml new file mode 100644 index 0000000000..1923353c61 --- /dev/null +++ b/tools/mocks/http_parser/mock/mock_config.yaml @@ -0,0 +1,9 @@ +:cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - array + - ignore + - ignore_arg + - callback diff --git a/tools/mocks/lwip/CMakeLists.txt b/tools/mocks/lwip/CMakeLists.txt new file mode 100644 index 0000000000..ea9f075886 --- /dev/null +++ b/tools/mocks/lwip/CMakeLists.txt @@ -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 ) diff --git a/tools/mocks/lwip/mock/mock_config.yaml b/tools/mocks/lwip/mock/mock_config.yaml new file mode 100644 index 0000000000..596255b0ce --- /dev/null +++ b/tools/mocks/lwip/mock/mock_config.yaml @@ -0,0 +1,9 @@ + :cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - array + - ignore + - ignore_arg + - callback diff --git a/tools/mocks/tcp_transport/CMakeLists.txt b/tools/mocks/tcp_transport/CMakeLists.txt new file mode 100644 index 0000000000..9ff6b93510 --- /dev/null +++ b/tools/mocks/tcp_transport/CMakeLists.txt @@ -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 + ) diff --git a/tools/mocks/tcp_transport/mock/mock_config.yaml b/tools/mocks/tcp_transport/mock/mock_config.yaml new file mode 100644 index 0000000000..fcf2722bc1 --- /dev/null +++ b/tools/mocks/tcp_transport/mock/mock_config.yaml @@ -0,0 +1,9 @@ +:cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - ignore + - ignore_arg + - callback + :when_ptr: :compare_ptr