feat(bootloader_support): added bootloader_support mocks

This commit is contained in:
Jakob Hasse 2024-08-05 18:43:39 +02:00
parent 524d6b143f
commit e565224149
5 changed files with 72 additions and 4 deletions

View File

@ -0,0 +1,18 @@
# 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 BOOTLOADER SUPPORT MOCKS")
idf_component_get_property(original_bootloader_support_dir bootloader_support COMPONENT_OVERRIDEN_DIR)
# Note: bootloader_memory_utils.h, bootloader_util.h and esp_app_format.h are not mocked
# since they only contain inline functions which we cannot mock without changing the build system.
idf_component_mock(INCLUDE_DIRS "${original_bootloader_support_dir}/include"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_clock.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_common.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_mem.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/bootloader_random.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_flash_encrypt.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_flash_partitions.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_image_format.h"
MOCK_HEADER_FILES "${original_bootloader_support_dir}/include/esp_secure_boot.h"
)

View File

@ -0,0 +1,12 @@
:cmock:
:plugins:
- expect
- expect_any_args
- return_thru_ptr
- array
- ignore
- ignore_arg
- callback
:strippables:
# esp_secure_boot_verify_sbv2_signature_block uses an ets type that is not yet available
- ['(?:esp_secure_boot_verify_sbv2_signature_block\s*\(+.*?\)+)']

View File

@ -2,6 +2,7 @@ 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/bootloader_support)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_wifi)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_netif)
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/tools/mocks/esp_event)

View File

@ -1,3 +1,3 @@
idf_component_register(SRCS "mock_build_test.c"
INCLUDE_DIRS "."
PRIV_REQUIRES driver esp_wifi)
PRIV_REQUIRES driver esp_wifi bootloader_support)

View File

@ -30,6 +30,14 @@
#include "Mockrmt_common.h"
#include "Mockrmt_tx.h"
#include "Mockrmt_rx.h"
#include "Mockbootloader_clock.h"
#include "Mockbootloader_common.h"
#include "Mockbootloader_mem.h"
#include "Mockbootloader_random.h"
#include "Mockesp_flash_encrypt.h"
#include "Mockesp_flash_partitions.h"
#include "Mockesp_image_format.h"
#include "Mockesp_secure_boot.h"
/* Test that mock functions exist and that required definitions are available */
void app_main(void)
@ -130,5 +138,34 @@ void app_main(void)
esp_now_init_IgnoreAndReturn(ESP_OK);
ESP_ERROR_CHECK(esp_now_init());
// Bootloader Support
bootloader_clock_configure_Ignore();
bootloader_clock_configure();
bootloader_configure_spi_pins_Ignore();
bootloader_configure_spi_pins(0);
bootloader_init_mem_Ignore();
bootloader_init_mem();
bootloader_random_enable_Ignore();
bootloader_random_enable();
esp_flash_encryption_enabled_IgnoreAndReturn(true);
bool flash_encrypted = esp_flash_encryption_enabled();
(void)flash_encrypted;
esp_partition_main_flash_region_safe_IgnoreAndReturn(true);
bool region_is_safe = esp_partition_main_flash_region_safe(0, 0);
(void) region_is_safe;
esp_image_verify_bootloader_IgnoreAndReturn(ESP_OK);
esp_err_t bootloader_is_ok = esp_image_verify_bootloader(NULL);
(void)bootloader_is_ok;
esp_secure_boot_cfg_verify_release_mode_IgnoreAndReturn(true);
bool release_mode_enabled = esp_secure_boot_cfg_verify_release_mode();
(void)release_mode_enabled;
printf("Mock build test done\n");
}