diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index de75b9df94..8089688ed5 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -340,7 +340,7 @@ test_nvs_page: script: - cd ${IDF_PATH}/components/nvs_flash/host_test/nvs_page_test - idf.py build - - build/host_nvs_page_test.elf + - build/test_nvs_page_host.elf test_log: extends: .host_test_template diff --git a/components/nvs_flash/CMakeLists.txt b/components/nvs_flash/CMakeLists.txt index 7134f8eb16..063ffc0832 100644 --- a/components/nvs_flash/CMakeLists.txt +++ b/components/nvs_flash/CMakeLists.txt @@ -13,13 +13,9 @@ set(srcs "src/nvs_api.cpp" "src/nvs_partition_manager.cpp" "src/nvs_types.cpp") -set(public_req "spi_flash") - -set(include_dirs "include") - idf_component_register(SRCS "${srcs}" - REQUIRES "${public_req}" - INCLUDE_DIRS "${include_dirs}") + REQUIRES "spi_flash" + INCLUDE_DIRS "include") # If we use the linux target, we need to redirect the crc functions to the linux if(${target} STREQUAL "linux") @@ -27,9 +23,6 @@ if(${target} STREQUAL "linux") # mbedtls isn't configured for building with linux or as mock target. It will draw in all kind of dependencies message(FATAL_ERROR "NVS currently doesn't support encryption if built for Linux.") endif() - idf_component_get_property(spi_flash_dir spi_flash COMPONENT_DIR) - target_include_directories(${COMPONENT_LIB} PUBLIC - "${spi_flash_dir}/sim/stubs/freertos/include") target_compile_options(${COMPONENT_LIB} PUBLIC "-DLINUX_TARGET") else() # TODO: this is a workaround until IDF-2085 is fixed diff --git a/components/nvs_flash/host_test/nvs_page_test/CMakeLists.txt b/components/nvs_flash/host_test/nvs_page_test/CMakeLists.txt index 976484eb85..797ef37d40 100644 --- a/components/nvs_flash/host_test/nvs_page_test/CMakeLists.txt +++ b/components/nvs_flash/host_test/nvs_page_test/CMakeLists.txt @@ -1,12 +1,15 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + set(COMPONENTS main) -idf_component_set_property(spi_flash USE_MOCK 1) list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/driver/") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/") +list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/spi_flash/") + idf_build_set_property(COMPILE_DEFINITIONS "-DNO_DEBUG_STORAGE" APPEND) -project(host_nvs_page_test) +project(test_nvs_page_host) + add_custom_command( OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/build/coverage.info" diff --git a/components/nvs_flash/host_test/nvs_page_test/sdkconfig.defaults b/components/nvs_flash/host_test/nvs_page_test/sdkconfig.defaults index d7ae4dee46..209c6da062 100644 --- a/components/nvs_flash/host_test/nvs_page_test/sdkconfig.defaults +++ b/components/nvs_flash/host_test/nvs_page_test/sdkconfig.defaults @@ -1,4 +1,4 @@ CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n CONFIG_COMPILER_HIDE_PATHS_MACROS=n CONFIG_IDF_TARGET="linux" -CONFIG_CXX_EXCEPTIONS=y +CONFIG_COMPILER_CXX_EXCEPTIONS=y diff --git a/components/spi_flash/CMakeLists.txt b/components/spi_flash/CMakeLists.txt index 69a2a604f1..5648ed5980 100644 --- a/components/spi_flash/CMakeLists.txt +++ b/components/spi_flash/CMakeLists.txt @@ -1,121 +1,58 @@ -idf_component_get_property(spi_flash_mock ${COMPONENT_NAME} USE_MOCK) idf_build_get_property(target IDF_TARGET) -if(${spi_flash_mock}) - message(STATUS "building SPI FLASH MOCKS") - - set(IDF_PATH $ENV{IDF_PATH}) - set(CMOCK_DIR "${IDF_PATH}/components/cmock/CMock") - set(MOCK_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/mocks") - - file(MAKE_DIRECTORY ${MOCK_GEN_DIR}) - - set(MOCK_OUTPUT - "${MOCK_GEN_DIR}/Mockesp_partition.c" "${MOCK_GEN_DIR}/Mockesp_partition.h" - "${MOCK_GEN_DIR}/Mockesp_flash.c" "${MOCK_GEN_DIR}/Mockesp_flash.h" - "${MOCK_GEN_DIR}/Mockesp_spi_flash.c" "${MOCK_GEN_DIR}/Mockesp_spi_flash.h") - - set(MOCK_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/include/esp_partition.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/esp_flash.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/esp_spi_flash.h - ) - - set(ENV{UNITY_DIR} "$ENV{IDF_PATH}/components/cmock/CMock") - - set(include_dirs - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${MOCK_GEN_DIR}") - - set(srcs "${MOCK_GEN_DIR}/Mockesp_partition.c" - "${MOCK_GEN_DIR}/Mockesp_spi_flash.c" - "${MOCK_GEN_DIR}/Mockesp_flash.c") - - if(${target} STREQUAL "linux") - list(APPEND include_dirs - "${CMAKE_CURRENT_SOURCE_DIR}/../spi_flash/sim/stubs/soc/include") - endif() - - idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS "${include_dirs}" - REQUIRES "cmock") - - add_custom_command( - OUTPUT ruby_found SYMBOLIC - COMMAND "ruby" "-v" - COMMENT "Try to find ruby. If this fails, you need to install ruby" +if(BOOTLOADER_BUILD) + set(srcs "${target}/spi_flash_rom_patch.c") + set(cache_srcs "") + set(priv_requires bootloader_support soc) +else() + set(cache_srcs + "cache_utils.c" + "flash_mmap.c" + "flash_ops.c" + "${target}/flash_ops_${target}.c" + ) + set(srcs + "partition.c" + "${target}/spi_flash_rom_patch.c" ) - # This command builds the mocks. - # First, environment variable UNITY_DIR is set. This is necessary to prevent unity from looking in its own submodule - # which doesn't work in our CI yet... - # The rest is a straight forward call to cmock.rb, consult cmock's documentation for more information. - 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}/mock/mock_config.yaml - ${MOCK_HEADERS} - ) - -else() - if(BOOTLOADER_BUILD) - set(srcs "${target}/spi_flash_rom_patch.c") - set(cache_srcs "") - set(priv_requires bootloader_support soc) - else() - set(cache_srcs - "cache_utils.c" - "flash_mmap.c" - "flash_ops.c" - "${target}/flash_ops_${target}.c" - ) - set(srcs - "partition.c" - "${target}/spi_flash_rom_patch.c" - ) - - if(CONFIG_ESPTOOLPY_OCT_FLASH) - list(APPEND srcs "${target}/spi_flash_oct_flash_init.c") - endif() - - if(CONFIG_IDF_TARGET_ESP32S3) - list(APPEND srcs - "esp32s3/spi_timing_config.c" - "spi_flash_timing_tuning.c") - endif() - - # New implementation after IDF v4.0 - list(APPEND srcs - "spi_flash_chip_drivers.c" - "spi_flash_chip_generic.c" - "spi_flash_chip_issi.c" - "spi_flash_chip_mxic.c" - "spi_flash_chip_gd.c" - "spi_flash_chip_winbond.c" - "spi_flash_chip_boya.c" - "memspi_host_driver.c") - - list(APPEND cache_srcs - "esp_flash_api.c" - "esp_flash_spi_init.c" - "spi_flash_os_func_app.c" - "spi_flash_os_func_noos.c") - - list(APPEND srcs ${cache_srcs}) - set(priv_requires bootloader_support app_update soc esp_ipc driver) + if(CONFIG_ESPTOOLPY_OCT_FLASH) + list(APPEND srcs "${target}/spi_flash_oct_flash_init.c") endif() - idf_component_register(SRCS "${srcs}" - REQUIRES hal - PRIV_REQUIRES "${priv_requires}" - INCLUDE_DIRS include - PRIV_INCLUDE_DIRS include/spi_flash - LDFRAGMENTS linker.lf) + if(CONFIG_IDF_TARGET_ESP32S3) + list(APPEND srcs + "esp32s3/spi_timing_config.c" + "spi_flash_timing_tuning.c") + endif() - # Avoid cache miss by unexpected inlineing when built by -Os - set_source_files_properties(${cache_srcs} PROPERTIES COMPILE_FLAGS - "-fno-inline-functions -fno-inline-small-functions -fno-inline-functions-called-once") + # New implementation after IDF v4.0 + list(APPEND srcs + "spi_flash_chip_drivers.c" + "spi_flash_chip_generic.c" + "spi_flash_chip_issi.c" + "spi_flash_chip_mxic.c" + "spi_flash_chip_gd.c" + "spi_flash_chip_winbond.c" + "spi_flash_chip_boya.c" + "memspi_host_driver.c") + list(APPEND cache_srcs + "esp_flash_api.c" + "esp_flash_spi_init.c" + "spi_flash_os_func_app.c" + "spi_flash_os_func_noos.c") + + list(APPEND srcs ${cache_srcs}) + set(priv_requires bootloader_support app_update soc esp_ipc driver) endif() + +idf_component_register(SRCS "${srcs}" + REQUIRES hal + PRIV_REQUIRES "${priv_requires}" + INCLUDE_DIRS include + PRIV_INCLUDE_DIRS include/spi_flash + LDFRAGMENTS linker.lf) + +# Avoid cache miss by unexpected inlineing when built by -Os +set_source_files_properties(${cache_srcs} PROPERTIES COMPILE_FLAGS + "-fno-inline-functions -fno-inline-small-functions -fno-inline-functions-called-once") diff --git a/tools/mocks/spi_flash/CMakeLists.txt b/tools/mocks/spi_flash/CMakeLists.txt new file mode 100644 index 0000000000..91b008cf3a --- /dev/null +++ b/tools/mocks/spi_flash/CMakeLists.txt @@ -0,0 +1,24 @@ +# NOTE: This kind of mocking currently works on Linux targets only. +# On Espressif chips, too many dependencies are missing at the moment. +# Furthermore, this component can only mock the interfaces of +# spi_master.h and gpio.h. +message(STATUS "building SPI FLASH MOCKS (only esp_partition* API)") + +idf_component_get_property(original_spi_flash_dir spi_flash COMPONENT_OVERRIDEN_DIR) + +idf_build_get_property(target IDF_TARGET) + +set(include_dirs + "${original_spi_flash_dir}/include") + +if(${target} STREQUAL "linux") + list(APPEND include_dirs + "${original_spi_flash_dir}/sim/stubs/soc/include") +endif() + +idf_component_mock(INCLUDE_DIRS ${include_dirs} + REQUIRES esp_common + MOCK_HEADER_FILES + ${original_spi_flash_dir}/include/esp_partition.h + ${original_spi_flash_dir}/include/esp_flash.h + ${original_spi_flash_dir}/include/esp_spi_flash.h) diff --git a/tools/mocks/spi_flash/mock/mock_config.yaml b/tools/mocks/spi_flash/mock/mock_config.yaml new file mode 100644 index 0000000000..ceeda099ee --- /dev/null +++ b/tools/mocks/spi_flash/mock/mock_config.yaml @@ -0,0 +1,8 @@ + :cmock: + :plugins: + - expect + - expect_any_args + - return_thru_ptr + - array + - ignore_arg + - callback