mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
ci: improve pytest build system tests
- remove temp dirs - remove idf-component-manager unit test
This commit is contained in:
@@ -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
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union
|
from typing import List
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from test_build_system_helpers import (APP_BINS, BOOTLOADER_BINS, PARTITION_BIN, IdfPyFunc, append_to_file,
|
from test_build_system_helpers import APP_BINS
|
||||||
file_contains, get_idf_build_env, replace_in_file, run_cmake_and_build)
|
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:
|
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, session_work_dir: Path, test_app_copy: Path) -> None:
|
def test_build_alternative_directories(idf_py: IdfPyFunc, session_work_dir: Path, test_app_copy: Path) -> None:
|
||||||
logging.info('Moving BUILD_DIR_BASE out of tree')
|
logging.info('Moving BUILD_DIR_BASE out of tree')
|
||||||
alt_build_dir = session_work_dir / 'alt_build'
|
alt_build_dir = session_work_dir / 'alt_build'
|
||||||
idf_py('-B', str(alt_build_dir), 'build')
|
try:
|
||||||
assert os.listdir(alt_build_dir) != [], 'No files found in new build directory!'
|
idf_py('-B', str(alt_build_dir), 'build')
|
||||||
default_build_dir = test_app_copy / 'build'
|
assert os.listdir(alt_build_dir) != [], 'No files found in new build directory!'
|
||||||
if default_build_dir.exists():
|
default_build_dir = test_app_copy / 'build'
|
||||||
assert os.listdir(default_build_dir) == [], f'Some files were incorrectly put into the default build directory: {default_build_dir}'
|
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')
|
logging.info('BUILD_DIR_BASE inside default build directory')
|
||||||
build_subdir_inside_build_dir = default_build_dir / 'subdirectory'
|
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')
|
@pytest.mark.usefixtures('test_app_copy')
|
||||||
def test_build_compiler_flags_no_overwriting(idf_py: IdfPyFunc) -> None:
|
def test_build_compiler_flags_no_overwriting(idf_py: IdfPyFunc) -> None:
|
||||||
logging.info('Compiler flags cannot be overwritten')
|
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.
|
# cause issues at link time.
|
||||||
idf_py('build', '-DCMAKE_C_FLAGS=', '-DCMAKE_CXX_FLAGS=')
|
idf_py('build', '-DCMAKE_C_FLAGS=', '-DCMAKE_CXX_FLAGS=')
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@@ -12,8 +12,14 @@ from pathlib import Path
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from test_build_system_helpers import (EnvDict, IdfPyFunc, append_to_file, file_contains, find_python, get_snapshot,
|
from test_build_system_helpers import append_to_file
|
||||||
replace_in_file, run_idf_py)
|
from test_build_system_helpers import EnvDict
|
||||||
|
from test_build_system_helpers import file_contains
|
||||||
|
from test_build_system_helpers import find_python
|
||||||
|
from test_build_system_helpers import get_snapshot
|
||||||
|
from test_build_system_helpers import IdfPyFunc
|
||||||
|
from test_build_system_helpers import replace_in_file
|
||||||
|
from test_build_system_helpers import run_idf_py
|
||||||
|
|
||||||
|
|
||||||
def get_subdirs_absolute_paths(path: Path) -> List[str]:
|
def get_subdirs_absolute_paths(path: Path) -> List[str]:
|
||||||
@@ -40,18 +46,6 @@ def test_compile_commands_json_updated_by_reconfigure(idf_py: IdfPyFunc) -> None
|
|||||||
snapshot_3.assert_different(snapshot_2)
|
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')
|
@pytest.mark.usefixtures('test_app_copy')
|
||||||
def test_hints_no_color_output_when_noninteractive(idf_py: IdfPyFunc) -> None:
|
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"""
|
"""Check that idf.py hints don't include color escape codes in non-interactive builds"""
|
||||||
@@ -246,11 +240,20 @@ def test_create_project_with_idf_readonly(idf_copy: Path) -> None:
|
|||||||
for name in files:
|
for name in files:
|
||||||
path = os.path.join(root, name)
|
path = os.path.join(root, name)
|
||||||
if '/bin/' in path:
|
if '/bin/' in path:
|
||||||
continue # skip excutables
|
continue # skip executables
|
||||||
os.chmod(os.path.join(root, name), 0o444) # readonly
|
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.')
|
logging.info('Check that command for creating new project will success if the IDF itself is readonly.')
|
||||||
change_to_readonly(idf_copy)
|
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')
|
@pytest.mark.usefixtures('test_app_copy')
|
||||||
|
Reference in New Issue
Block a user