diff --git a/tools/test_build_system/test_build.py b/tools/test_build_system/test_build.py index 5529aab277..bcc2d73527 100644 --- a/tools/test_build_system/test_build.py +++ b/tools/test_build_system/test_build.py @@ -1,17 +1,25 @@ -# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 - import logging import os +import shutil import stat import sys import textwrap from pathlib import Path -from typing import List, Union +from typing import List +from typing import Union import pytest -from test_build_system_helpers import (APP_BINS, BOOTLOADER_BINS, PARTITION_BIN, IdfPyFunc, append_to_file, - file_contains, get_idf_build_env, replace_in_file, run_cmake_and_build) +from test_build_system_helpers import APP_BINS +from test_build_system_helpers import append_to_file +from test_build_system_helpers import BOOTLOADER_BINS +from test_build_system_helpers import file_contains +from test_build_system_helpers import get_idf_build_env +from test_build_system_helpers import IdfPyFunc +from test_build_system_helpers import PARTITION_BIN +from test_build_system_helpers import replace_in_file +from test_build_system_helpers import run_cmake_and_build def assert_built(paths: Union[List[str], List[Path]]) -> None: @@ -22,11 +30,16 @@ def assert_built(paths: Union[List[str], List[Path]]) -> None: def test_build_alternative_directories(idf_py: IdfPyFunc, func_work_dir: Path, test_app_copy: Path) -> None: logging.info('Moving BUILD_DIR_BASE out of tree') alt_build_dir = func_work_dir / 'alt_build' - idf_py('-B', str(alt_build_dir), 'build') - assert os.listdir(alt_build_dir) != [], 'No files found in new build directory!' - default_build_dir = test_app_copy / 'build' - if default_build_dir.exists(): - assert os.listdir(default_build_dir) == [], f'Some files were incorrectly put into the default build directory: {default_build_dir}' + try: + idf_py('-B', str(alt_build_dir), 'build') + assert os.listdir(alt_build_dir) != [], 'No files found in new build directory!' + default_build_dir = test_app_copy / 'build' + if default_build_dir.exists(): + assert os.listdir(default_build_dir) == [], f'Some files were incorrectly put into the default build directory: {default_build_dir}' + except Exception: + raise + else: + shutil.rmtree(alt_build_dir) logging.info('BUILD_DIR_BASE inside default build directory') build_subdir_inside_build_dir = default_build_dir / 'subdirectory' @@ -120,7 +133,7 @@ def test_build_compiler_flag_in_source_file(idf_py: IdfPyFunc, test_app_copy: Pa @pytest.mark.usefixtures('test_app_copy') def test_build_compiler_flags_no_overwriting(idf_py: IdfPyFunc) -> None: logging.info('Compiler flags cannot be overwritten') - # If the compiler flags are overriden, the following build command will + # If the compiler flags are overridden, the following build command will # cause issues at link time. idf_py('build', '-DCMAKE_C_FLAGS=', '-DCMAKE_CXX_FLAGS=') diff --git a/tools/test_build_system/test_common.py b/tools/test_build_system/test_common.py index 515acce6f9..affc60bdf8 100644 --- a/tools/test_build_system/test_common.py +++ b/tools/test_build_system/test_common.py @@ -46,18 +46,6 @@ def test_compile_commands_json_updated_by_reconfigure(idf_py: IdfPyFunc) -> None snapshot_3.assert_different(snapshot_2) -@pytest.mark.usefixtures('test_app_copy') -def test_of_test_app_copy(idf_py: IdfPyFunc) -> None: - p = Path('main/idf_component.yml') - p.write_text('syntax_error\n') - try: - with (pytest.raises(subprocess.CalledProcessError)) as exc_info: - idf_py('reconfigure') - assert 'ERROR: Unknown format of the manifest file:' in exc_info.value.stderr - finally: - p.unlink() - - @pytest.mark.usefixtures('test_app_copy') def test_hints_no_color_output_when_noninteractive(idf_py: IdfPyFunc) -> None: """Check that idf.py hints don't include color escape codes in non-interactive builds""" @@ -252,11 +240,20 @@ def test_create_project_with_idf_readonly(idf_copy: Path) -> None: for name in files: path = os.path.join(root, name) if '/bin/' in path: - continue # skip excutables + continue # skip executables os.chmod(os.path.join(root, name), 0o444) # readonly logging.info('Check that command for creating new project will success if the IDF itself is readonly.') change_to_readonly(idf_copy) - run_idf_py('create-project', '--path', str(idf_copy / 'example_proj'), 'temp_test_project') + try: + run_idf_py('create-project', '--path', str(idf_copy / 'example_proj'), 'temp_test_project') + except Exception: + raise + else: + def del_rw(function, path, excinfo): # type: ignore + os.chmod(path, stat.S_IWRITE) + os.remove(path) + + shutil.rmtree(idf_copy, onerror=del_rw) @pytest.mark.usefixtures('test_app_copy')