From 87a118361fb46efd9b8b49eef5175b24b02ec5cb Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Thu, 20 Mar 2025 17:07:33 +0100 Subject: [PATCH 1/4] test(tools): skip custom cmake project test for host on Win --- tools/test_build_system/test_cmake.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/test_build_system/test_cmake.py b/tools/test_build_system/test_cmake.py index e43f090a77..90dc3797af 100644 --- a/tools/test_build_system/test_cmake.py +++ b/tools/test_build_system/test_cmake.py @@ -4,8 +4,10 @@ import logging import os import re import shutil +import sys from pathlib import Path +import pytest from test_build_system_helpers import append_to_file from test_build_system_helpers import EnvDict from test_build_system_helpers import file_contains @@ -24,7 +26,11 @@ def test_build_custom_cmake_project(test_app_copy: Path) -> None: assert file_contains((test_app_copy / 'build' / 'compile_commands.json'), '"command"') shutil.rmtree(test_app_copy / 'build') + +@pytest.mark.skipif(sys.platform == 'win32', reason='On Win project is not buildable without system compiler on the host machine. (Win CI runners)') +def test_build_custom_cmake_project_host() -> None: logging.info(f'Test build ESP-IDF as a library to a custom CMake projects for host') + idf_path = Path(os.environ['IDF_PATH']) run_cmake_and_build(str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'), '-G', 'Ninja') From c288935305a1efb706aa17af7e84f669d375a3c8 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Mon, 24 Mar 2025 15:08:57 +0100 Subject: [PATCH 2/4] ci(tools): Run Win build system tests when patterns-build_system changed --- .gitlab/ci/dependencies/dependencies.yml | 2 ++ .gitlab/ci/rules.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitlab/ci/dependencies/dependencies.yml b/.gitlab/ci/dependencies/dependencies.yml index 4f87a9ab3b..1bc47df4f5 100644 --- a/.gitlab/ci/dependencies/dependencies.yml +++ b/.gitlab/ci/dependencies/dependencies.yml @@ -90,3 +90,5 @@ - windows specific_rules: - if-schedule-test-build-system-windows + patterns: + - build_system diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index eb2488a844..6cb01c6558 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -408,6 +408,8 @@ when: never - <<: *if-schedule-test-build-system-windows - <<: *if-label-windows + - <<: *if-dev-push + changes: *patterns-build_system .rules:test:host_test: rules: From 58b3c60f598be49310ee44a1f458f73d61d89eb3 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Tue, 15 Apr 2025 15:05:32 +0200 Subject: [PATCH 3/4] fix(tools): Update ruff-format changes --- tools/test_build_system/test_cmake.py | 96 ++++++++++++++++++--------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/tools/test_build_system/test_cmake.py b/tools/test_build_system/test_cmake.py index 90dc3797af..3ca5bd8200 100644 --- a/tools/test_build_system/test_cmake.py +++ b/tools/test_build_system/test_cmake.py @@ -8,10 +8,10 @@ import sys from pathlib import Path import pytest -from test_build_system_helpers import append_to_file from test_build_system_helpers import EnvDict -from test_build_system_helpers import file_contains from test_build_system_helpers import IdfPyFunc +from test_build_system_helpers import append_to_file +from test_build_system_helpers import file_contains from test_build_system_helpers import run_cmake from test_build_system_helpers import run_cmake_and_build @@ -19,61 +19,91 @@ from test_build_system_helpers import run_cmake_and_build def test_build_custom_cmake_project(test_app_copy: Path) -> None: # Test is compatible with any target. Random targets in the list are selected for performance reasons idf_path = Path(os.environ['IDF_PATH']) - for target in ['esp32','esp32c2','esp32c3','esp32c6','esp32h2','esp32p4','esp32s2','esp32s3']: + for target in ['esp32', 'esp32c2', 'esp32c3', 'esp32c6', 'esp32h2', 'esp32p4', 'esp32s2', 'esp32s3']: logging.info(f'Test build ESP-IDF as a library to a custom CMake projects for {target}') - run_cmake_and_build(str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'), '-G', 'Ninja', - '-DCMAKE_TOOLCHAIN_FILE={}'.format(idf_path / 'tools' / 'cmake' / f'toolchain-{target}.cmake'), f'-DTARGET={target}') + run_cmake_and_build( + str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'), + '-G', + 'Ninja', + '-DCMAKE_TOOLCHAIN_FILE={}'.format(idf_path / 'tools' / 'cmake' / f'toolchain-{target}.cmake'), + f'-DTARGET={target}', + ) assert file_contains((test_app_copy / 'build' / 'compile_commands.json'), '"command"') shutil.rmtree(test_app_copy / 'build') -@pytest.mark.skipif(sys.platform == 'win32', reason='On Win project is not buildable without system compiler on the host machine. (Win CI runners)') +@pytest.mark.skipif( + sys.platform == 'win32', + reason='On Win project is not buildable without system compiler on the host machine. (Win CI runners)', +) def test_build_custom_cmake_project_host() -> None: - logging.info(f'Test build ESP-IDF as a library to a custom CMake projects for host') + logging.info('Test build ESP-IDF as a library to a custom CMake projects for host') idf_path = Path(os.environ['IDF_PATH']) run_cmake_and_build(str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'), '-G', 'Ninja') def test_build_cmake_library_psram_workaround(test_app_copy: Path) -> None: - logging.info('Building a project with CMake library imported and PSRAM workaround, all files compile with workaround') + logging.info( + 'Building a project with CMake library imported and PSRAM workaround, all files compile with workaround' + ) idf_path = Path(os.environ['IDF_PATH']) - (test_app_copy / 'sdkconfig.defaults').write_text('\n'.join(['CONFIG_SPIRAM=y', - 'CONFIG_SPIRAM_CACHE_WORKAROUND=y'])) - run_cmake('-G', 'Ninja', '-DCOMPONENTS=main;esp_psram', - '-DSDKCONFIG_DEFAULTS={}'.format(test_app_copy / 'sdkconfig.defaults'), - str(idf_path / 'examples' / 'build_system' / 'cmake' / 'import_lib')) + (test_app_copy / 'sdkconfig.defaults').write_text( + '\n'.join(['CONFIG_SPIRAM=y', 'CONFIG_SPIRAM_CACHE_WORKAROUND=y']) + ) + run_cmake( + '-G', + 'Ninja', + '-DCOMPONENTS=main;esp_psram', + '-DSDKCONFIG_DEFAULTS={}'.format(test_app_copy / 'sdkconfig.defaults'), + str(idf_path / 'examples' / 'build_system' / 'cmake' / 'import_lib'), + ) with open((test_app_copy / 'build' / 'compile_commands.json'), 'r', encoding='utf-8') as f: data = f.read() res = re.findall(r'.*\"command\".*', data) for r in res: - assert 'mfix-esp32-psram-cache-issue' in r, 'All commands in compile_commands.json should use PSRAM cache workaround' + assert 'mfix-esp32-psram-cache-issue' in r, ( + 'All commands in compile_commands.json should use PSRAM cache workaround' + ) def test_build_cmake_library_psram_strategies(idf_py: IdfPyFunc, test_app_copy: Path) -> None: for strategy in ['DUPLDST', 'NOPS', 'MEMW']: logging.info(f'Test for external libraries in custom CMake projects with PSRAM strategy {strategy}') - (test_app_copy / 'sdkconfig.defaults').write_text('\n'.join(['CONFIG_SPIRAM=y', - f'CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_{strategy}=y', - 'CONFIG_SPIRAM_CACHE_WORKAROUND=y'])) + (test_app_copy / 'sdkconfig.defaults').write_text( + '\n'.join( + [ + 'CONFIG_SPIRAM=y', + f'CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_{strategy}=y', + 'CONFIG_SPIRAM_CACHE_WORKAROUND=y', + ] + ) + ) idf_py('reconfigure') with open((test_app_copy / 'build' / 'compile_commands.json'), 'r', encoding='utf-8') as f: data = f.read() res = re.findall(r'.*\"command\".*', data) for r in res: - assert f'mfix-esp32-psram-cache-strategy={strategy.lower()}' in r, ('All commands in compile_commands.json ' - 'should use PSRAM cache workaround strategy') + assert f'mfix-esp32-psram-cache-strategy={strategy.lower()}' in r, ( + 'All commands in compile_commands.json should use PSRAM cache workaround strategy' + ) (test_app_copy / 'sdkconfig').unlink() def test_defaults_unspecified_build_args(idf_copy: Path) -> None: logging.info('Defaults set properly for unspecified idf_build_process args') idf_as_lib_path = idf_copy / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib' - append_to_file(idf_as_lib_path / 'CMakeLists.txt', '\n'.join(['idf_build_get_property(project_dir PROJECT_DIR)', - 'message("Project directory: ${project_dir}")'])) - ret = run_cmake('..', '-G', 'Ninja', - '-DCMAKE_TOOLCHAIN_FILE={}'.format(str(idf_copy / 'tools' / 'cmake' / 'toolchain-esp32.cmake')), - '-DTARGET=esp32', - workdir=idf_as_lib_path) + append_to_file( + idf_as_lib_path / 'CMakeLists.txt', + '\n'.join(['idf_build_get_property(project_dir PROJECT_DIR)', 'message("Project directory: ${project_dir}")']), + ) + ret = run_cmake( + '..', + '-G', + 'Ninja', + '-DCMAKE_TOOLCHAIN_FILE={}'.format(str(idf_copy / 'tools' / 'cmake' / 'toolchain-esp32.cmake')), + '-DTARGET=esp32', + workdir=idf_as_lib_path, + ) assert 'Project directory: {}'.format(str(idf_as_lib_path.as_posix())) in ret.stderr @@ -83,14 +113,14 @@ def test_build_example_on_host(default_idf_env: EnvDict) -> None: idf_as_lib_path = Path(idf_path, 'examples', 'build_system', 'cmake', 'idf_as_lib') try: target = 'esp32' - run_cmake('..', - f'-DCMAKE_TOOLCHAIN_FILE={idf_path}/tools/cmake/toolchain-{target}.cmake', - f'-DTARGET={target}', - '-GNinja', - workdir=idf_as_lib_path) + run_cmake( + '..', + f'-DCMAKE_TOOLCHAIN_FILE={idf_path}/tools/cmake/toolchain-{target}.cmake', + f'-DTARGET={target}', + '-GNinja', + workdir=idf_as_lib_path, + ) - run_cmake('--build', - '.', - workdir=idf_as_lib_path) + run_cmake('--build', '.', workdir=idf_as_lib_path) finally: shutil.rmtree(idf_as_lib_path / 'build', ignore_errors=True) From 1507ec746627f1bf62647496d22a81da3ac9a86f Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Mon, 7 Apr 2025 15:41:18 +0200 Subject: [PATCH 4/4] fix(test): Proper cleanup after build_custom_cmake pytest The test create build folder in current directory which in this case is defined by (test_app_copy). It also creates sdkconfig file in cmake source directory, which is defined as $IDF_PATH/examples/build_system/cmake/idf_as_lib The fixtures ensures proper cleanup even when test fails. --- tools/test_build_system/test_cmake.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/test_build_system/test_cmake.py b/tools/test_build_system/test_cmake.py index 3ca5bd8200..4464a3d12e 100644 --- a/tools/test_build_system/test_cmake.py +++ b/tools/test_build_system/test_cmake.py @@ -16,6 +16,9 @@ from test_build_system_helpers import run_cmake from test_build_system_helpers import run_cmake_and_build +# This test checks multiple targets in one test function. It would be better to have each target +# tested in a isolated test case, but that would mean doing idf_copy each time, and copying takes most of the time +@pytest.mark.usefixtures('idf_copy') def test_build_custom_cmake_project(test_app_copy: Path) -> None: # Test is compatible with any target. Random targets in the list are selected for performance reasons idf_path = Path(os.environ['IDF_PATH']) @@ -30,12 +33,15 @@ def test_build_custom_cmake_project(test_app_copy: Path) -> None: ) assert file_contains((test_app_copy / 'build' / 'compile_commands.json'), '"command"') shutil.rmtree(test_app_copy / 'build') + os.remove(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib' / 'sdkconfig') @pytest.mark.skipif( sys.platform == 'win32', reason='On Win project is not buildable without system compiler on the host machine. (Win CI runners)', ) +@pytest.mark.usefixtures('idf_copy') +@pytest.mark.usefixtures('test_app_copy') def test_build_custom_cmake_project_host() -> None: logging.info('Test build ESP-IDF as a library to a custom CMake projects for host') idf_path = Path(os.environ['IDF_PATH'])