ci(build_system): add a test case for bootloader override

This commit is contained in:
Omar Chebib 2023-07-21 11:14:03 +08:00
parent c98d1f1619
commit 7b5c0fb96b
3 changed files with 38 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import shutil
from pathlib import Path
from typing import Union
from test_build_system_helpers import EnvDict, IdfPyFunc, file_contains
from test_build_system_helpers import EnvDict, IdfPyFunc, bin_file_contains, file_contains, replace_in_file
def get_two_header_bytes(file_path: Union[str, Path]) -> str:
@ -31,6 +31,29 @@ def test_bootloader_custom_overrides_original(test_app_copy: Path, idf_py: IdfPy
str(test_app_copy / 'components' / 'bootloader' / 'subproject' / 'main' / 'bootloader_start.c'))
def test_bootloader_custom_ignores_extra_component(test_app_copy: Path, idf_py: IdfPyFunc, default_idf_env: EnvDict) -> None:
logging.info('Custom bootloader can ignore extra components')
idf_path = Path(default_idf_env.get('IDF_PATH'))
# Import the main bootloader component that overrides the default one
shutil.copytree(idf_path / 'examples' / 'custom_bootloader' / 'bootloader_override' / 'bootloader_components',
test_app_copy / 'bootloader_components')
# Compile it normally and make sure the bootloader is overridden for now
idf_py('bootloader')
# Search for 'Custom bootloader message defined in the KConfig file.' in the resulting binary
# which is the default value for EXAMPLE_BOOTLOADER_WELCOME_MESSAGE Kconfig option.
default_message = bytes('Custom bootloader message defined in the KConfig file.', 'ascii')
assert bin_file_contains(test_app_copy / 'build' / 'bootloader' / 'bootloader.bin', default_message)
# Clean the project
idf_py('fullclean')
# Ignore bootloader component and rebuild
replace_in_file(test_app_copy / 'CMakeLists.txt',
'# placeholder_after_include_project_cmake',
'set(BOOTLOADER_IGNORE_EXTRA_COMPONENT "main")')
idf_py('bootloader')
# The overridden message must not be present anymore
assert not bin_file_contains(test_app_copy / 'build' / 'bootloader' / 'bootloader.bin', default_message)
def test_bootloader_correctly_set_image_header(test_app_copy: Path, idf_py: IdfPyFunc) -> None:
logging.info('Flash size is correctly set in the bootloader image header')
# Build with the default 2MB setting

View File

@ -2,8 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
from .build_constants import ALL_ARTIFACTS, APP_BINS, BOOTLOADER_BINS, JSON_METADATA, PARTITION_BIN
from .editing import append_to_file, replace_in_file
from .idf_utils import (EXT_IDF_PATH, EnvDict, IdfPyFunc, file_contains, find_python, get_idf_build_env, run_cmake,
run_cmake_and_build, run_idf_py)
from .idf_utils import (EXT_IDF_PATH, EnvDict, IdfPyFunc, bin_file_contains, file_contains, find_python,
get_idf_build_env, run_cmake, run_cmake_and_build, run_idf_py)
from .snapshot import Snapshot, get_snapshot
__all__ = [
@ -11,5 +11,5 @@ __all__ = [
'get_idf_build_env', 'run_idf_py', 'EXT_IDF_PATH', 'EnvDict', 'IdfPyFunc',
'Snapshot', 'get_snapshot', 'run_cmake', 'APP_BINS', 'BOOTLOADER_BINS',
'PARTITION_BIN', 'JSON_METADATA', 'ALL_ARTIFACTS',
'run_cmake_and_build', 'find_python', 'file_contains'
'run_cmake_and_build', 'find_python', 'file_contains', 'bin_file_contains'
]

View File

@ -149,3 +149,14 @@ def file_contains(filename: Union[str, Path], what: Union[str, Pattern]) -> bool
return what in data
else:
return re.search(what, data) is not None
def bin_file_contains(filename: Union[str, Path], what: bytearray) -> bool:
"""
Returns true if the binary file contains the given string
:param filename: path to file where lookup is executed
:param what: searched bytes
"""
with open(filename, 'rb') as f:
data = f.read()
return data.find(what) != -1