Merge branch 'refactor/remove_unnecessary_mock_headers' into 'master'

refactor(ci): removed unnecessary hal and soc mock header files

Closes IDF-8511

See merge request espressif/esp-idf!27047
This commit is contained in:
Jakob Hasse 2023-11-16 09:37:21 +08:00
commit bf6a904a44
12 changed files with 95 additions and 164 deletions

View File

@ -11,7 +11,6 @@ if(target STREQUAL "linux")
"${target}/esp_rom_crc.c"
"${target}/esp_rom_md5.c"
"${target}/esp_rom_efuse.c")
list(APPEND include_dirs "${IDF_PATH}/tools/mocks/soc/include")
else()
list(APPEND include_dirs "${target}")
list(APPEND sources "patches/esp_rom_crc.c"

View File

@ -10,3 +10,11 @@ config SOC_GPIO_IN_RANGE_MAX
config SOC_GPIO_OUT_RANGE_MAX
int
default 65535
config SOC_I2C_SUPPORT_SLAVE
bool
default y
config SOC_I2C_SUPPORT_10BIT_ADDR
bool
default y

View File

@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
/**
* Mock definitions for running on the host.
*/
/**
* @brief Supported clock sources for modules (CPU, peripherals, RTC, etc.)
*
* @note enum starts from 1, to save 0 for special purpose
*/
typedef enum {
SOC_MOD_CLK_APB = 1,
} soc_module_clk_t;
/**
* @brief Type of SPI clock source.
*/
typedef enum {
SPI_CLK_SRC_DEFAULT = SOC_MOD_CLK_APB,
SPI_CLK_SRC_APB = SOC_MOD_CLK_APB,
} soc_periph_spi_clk_src_t;

View File

@ -0,0 +1,9 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* NOTE: this is a stripped-down copy to support building on host when using mocking (CMock).
*/

View File

@ -22,8 +22,17 @@
*
*/
/*
* NOTE: These definitions are only meant to allow host-based unit testing of some features using CMock.
* They DO NOT imply any functionality on the host.
*/
#pragma once
// No meaning to define GPIO number for Linux target, only to avoid build warning on Kconfig ESP_CONSOLE_UART_TX_GPIO, ESP_CONSOLE_UART_RX_GPIO
/*-------------------------- GPIO CAPS ---------------------------------------*/
#define SOC_GPIO_IN_RANGE_MAX (65535)
#define SOC_GPIO_OUT_RANGE_MAX (65535)
/*-------------------------- I2C CAPS ----------------------------------------*/
#define SOC_I2C_SUPPORT_SLAVE (1)
#define SOC_I2C_SUPPORT_10BIT_ADDR (1)

View File

@ -14,11 +14,12 @@ set(include_dirs
"${original_driver_dir}/usb_serial_jtag/include/driver"
"${original_driver_dir}/i2c/include"
"${original_driver_dir}/rmt/include"
"${original_driver_dir}/usb_serial_jtag/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../hal/include")
"${original_driver_dir}/usb_serial_jtag/include")
# Note: "hal" and "soc" are only required for corresponding header files and their definitions
# here, they don't provide functionality when built for running on the host.
idf_component_mock(INCLUDE_DIRS ${include_dirs}
REQUIRES freertos
REQUIRES freertos hal soc
MOCK_HEADER_FILES
${IDF_PATH}/components/esp_driver_gpio/include/driver/gpio.h
${IDF_PATH}/components/esp_driver_spi/include/driver/spi_master.h
@ -29,5 +30,3 @@ idf_component_mock(INCLUDE_DIRS ${include_dirs}
${original_driver_dir}/rmt/include/driver/rmt_common.h
${original_driver_dir}/rmt/include/driver/rmt_encoder.h
${original_driver_dir}/usb_serial_jtag/include/driver/usb_serial_jtag.h)
target_compile_definitions(${COMPONENT_LIB} PUBLIC SOC_I2C_NUM=2)

View File

@ -1,63 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* NOTE: this is not the original header file from the hal component. It is a stripped-down copy to support mocking.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief I2C port number, can be I2C_NUM_0 ~ (I2C_NUM_MAX-1).
*/
typedef enum {
I2C_NUM_0 = 0, /*!< I2C port 0 */
#if SOC_I2C_NUM >= 2
I2C_NUM_1, /*!< I2C port 1 */
#endif
I2C_NUM_MAX, /*!< I2C port max */
} i2c_port_t;
typedef enum{
I2C_MODE_SLAVE = 0, /*!< I2C slave mode */
I2C_MODE_MASTER, /*!< I2C master mode */
I2C_MODE_MAX,
} i2c_mode_t;
typedef enum {
I2C_MASTER_WRITE = 0, /*!< I2C write data */
I2C_MASTER_READ, /*!< I2C read data */
} i2c_rw_t;
typedef enum {
I2C_DATA_MODE_MSB_FIRST = 0, /*!< I2C data msb first */
I2C_DATA_MODE_LSB_FIRST = 1, /*!< I2C data lsb first */
I2C_DATA_MODE_MAX
} i2c_trans_mode_t;
typedef enum {
I2C_ADDR_BIT_7 = 0, /*!< I2C 7bit address for slave mode */
I2C_ADDR_BIT_10, /*!< I2C 10bit address for slave mode */
I2C_ADDR_BIT_MAX,
} i2c_addr_mode_t;
typedef enum {
I2C_MASTER_ACK = 0x0, /*!< I2C ack for each byte read */
I2C_MASTER_NACK = 0x1, /*!< I2C nack for each byte read */
I2C_MASTER_LAST_NACK = 0x2, /*!< I2C nack for the last byte*/
I2C_MASTER_ACK_MAX,
} i2c_ack_type_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,31 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* NOTE: this is not the original header file from the hal component. It is a stripped-down copy to support mocking.
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef int rmt_clock_source_t;
typedef union {
struct {
unsigned int duration0 : 15; /*!< Duration of level0 */
unsigned int level0 : 1; /*!< Level of the first part */
unsigned int duration1 : 15; /*!< Duration of level1 */
unsigned int level1 : 1; /*!< Level of the second part */
};
unsigned int val; /*!< Equivalent unsigned value for the RMT symbol */
} rmt_symbol_word_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,34 +0,0 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* NOTE: this is not the original header file from the hal component. It is a stripped-down copy to support mocking.
*/
#pragma once
/**
* @brief Enum with the three SPI peripherals that are software-accessible in it
*/
typedef enum {
// SPI_HOST (SPI1_HOST) is not supported by the SPI Master and SPI Slave driver on ESP32-S2
SPI1_HOST=0, ///< SPI1
SPI2_HOST=1, ///< SPI2
SPI3_HOST=2, ///< SPI3
SPI_HOST_MAX=3, ///< invalid host value
} spi_host_device_t;
/**
* @brief Type of SPI clock source.
*/
typedef enum {
SPI_CLK_SRC_DEFAULT, /*!< Select PLL as SPI source clock */
SPI_CLK_SRC_PLL_F40M, /*!< Select PLL as SPI source clock */
SPI_CLK_SRC_PLL_F80M, /*!< Select PLL as SPI source clock */
SPI_CLK_SRC_APB, /*!< Select APB as SPI source clock */
SPI_CLK_SRC_XTAL, /*!< Select XTAL as SPI source clock */
SPI_CLK_SRC_RC_FAST, /*!< Select RC_FAST as SPI source clock */
} spi_clock_source_t;

View File

@ -1,19 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Type of SPI clock source.
*/
typedef int soc_periph_spi_clk_src_t;
#ifdef __cplusplus
}
#endif

View File

@ -1,9 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* NOTE: this is not the original header file from the soc component. It is a stripped-down copy to support mocking.
*/

View File

@ -17,7 +17,7 @@
#include "Mockrmt_tx.h"
#include "Mockrmt_rx.h"
/*Test that mock functions exist*/
/* Test that mock functions exist and that required definitions are available */
void app_main(void)
{
i2c_driver_delete(0);
@ -26,6 +26,42 @@ void app_main(void)
int gpio_num = GPIO_NUM_39;
(void)gpio_num;
spi_host_device_t spi_dev = SPI1_HOST;
spi_dev = SPI2_HOST;
(void)spi_dev;
spi_clock_source_t spi_default_clock = SPI_CLK_SRC_DEFAULT;
(void)spi_default_clock;
soc_periph_spi_clk_src_t soc_periph_spi_clk_src = 0;
(void)soc_periph_spi_clk_src;
rmt_clock_source_t rmt_clk_source = 0;
(void)rmt_clk_source;
rmt_symbol_word_t rm_symbol_word = { .duration0 = 47, .level0 = 0, .duration1 = 47, .level1 = 1 };
(void)rm_symbol_word;
i2c_port_t i2c_port = I2C_NUM_0;
(void)i2c_port;
i2c_mode_t i2c_mode = I2C_MODE_MASTER;
i2c_mode = I2C_MODE_SLAVE;
(void)i2c_mode;
i2c_rw_t i2c_rw = I2C_MASTER_WRITE;
i2c_rw = I2C_MASTER_READ;
(void)i2c_rw;
i2c_trans_mode_t i2c = I2C_DATA_MODE_MSB_FIRST;
i2c = I2C_DATA_MODE_LSB_FIRST;
(void)i2c;
i2c_addr_bit_len_t i2c_addr_bit_len = I2C_ADDR_BIT_LEN_7;
#if SOC_I2C_SUPPORT_10BIT_ADDR
i2c_addr_bit_len = I2C_ADDR_BIT_LEN_10;
#endif
(void)i2c_addr_bit_len;
i2c_ack_type_t i2c_ack = I2C_MASTER_ACK;
i2c_ack = I2C_MASTER_NACK;
i2c_ack = I2C_MASTER_LAST_NACK;
(void)i2c_ack;
rmt_channel_handle_t channel = 0;
rmt_new_bytes_encoder(NULL, NULL);
rmt_new_rx_channel(NULL, NULL);