From 4b139455a8f4318bb2db93b056045ffdf5ee5a92 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Thu, 16 Apr 2026 16:21:25 +0200 Subject: [PATCH] test(cmakev2): verify IDF_TOOLCHAIN is propagated to sdkconfig Add a buildv2 test that reconfigures the test app with both GCC and clang toolchains and asserts that the selected IDF_TOOLCHAIN value is propagated to sdkconfig. The clang case is skipped when a clang compiler is not available in PATH. --- .../buildv2/test_toolchain.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tools/test_build_system/buildv2/test_toolchain.py diff --git a/tools/test_build_system/buildv2/test_toolchain.py b/tools/test_build_system/buildv2/test_toolchain.py new file mode 100644 index 00000000000..9ef6dd7a80c --- /dev/null +++ b/tools/test_build_system/buildv2/test_toolchain.py @@ -0,0 +1,58 @@ +# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +import logging +import shutil +from pathlib import Path + +import pytest +from test_build_system_helpers import EnvDict +from test_build_system_helpers import file_contains +from test_build_system_helpers import run_idf_py + + +@pytest.mark.usefixtures('test_app_copy') +def test_idf_toolchain_gcc_propagation(default_idf_env: EnvDict) -> None: + """IDF_TOOLCHAIN=gcc is propagated to the CMake cache and to sdkconfig.""" + logging.info('Testing IDF_TOOLCHAIN=gcc propagation') + + default_idf_env.pop('IDF_TOOLCHAIN', None) + run_idf_py('reconfigure', env=default_idf_env) + + assert file_contains('build/CMakeCache.txt', 'IDF_TOOLCHAIN:STRING=gcc'), ( + 'IDF_TOOLCHAIN CMake cache variable must be "gcc" when building with the default toolchain' + ) + + sdkconfig_h = Path('build/config/sdkconfig.h').read_text() + assert '#define CONFIG_IDF_TOOLCHAIN "gcc"' in sdkconfig_h, ( + 'CONFIG_IDF_TOOLCHAIN must be "gcc" in sdkconfig.h for the default toolchain' + ) + assert '#define CONFIG_IDF_TOOLCHAIN_GCC 1' in sdkconfig_h, ( + 'CONFIG_IDF_TOOLCHAIN_GCC must be set in sdkconfig.h for the default toolchain' + ) + + +@pytest.mark.usefixtures('test_app_copy') +def test_idf_toolchain_clang_propagation(default_idf_env: EnvDict) -> None: + """IDF_TOOLCHAIN=clang is propagated to the CMake cache and to sdkconfig, + and selects a libc implementation that is compatible with clang.""" + clang_path = shutil.which('clang') + if clang_path is None or 'esp-clang' not in str(Path(clang_path).resolve()): + pytest.skip('Espressif clang (esp-clang) not available in PATH') + + logging.info('Testing IDF_TOOLCHAIN=clang propagation') + + default_idf_env['IDF_TOOLCHAIN'] = 'clang' + run_idf_py('reconfigure', env=default_idf_env) + + assert file_contains('build/CMakeCache.txt', 'IDF_TOOLCHAIN:STRING=clang'), ( + 'IDF_TOOLCHAIN CMake cache variable must be "clang" when IDF_TOOLCHAIN=clang is set' + ) + + sdkconfig_h = Path('build/config/sdkconfig.h').read_text() + assert '#define CONFIG_IDF_TOOLCHAIN "clang"' in sdkconfig_h, ( + 'CONFIG_IDF_TOOLCHAIN must be "clang" in sdkconfig.h when IDF_TOOLCHAIN=clang is set' + ) + assert '#define CONFIG_IDF_TOOLCHAIN_CLANG 1' in sdkconfig_h, ( + 'CONFIG_IDF_TOOLCHAIN_CLANG must be set in sdkconfig.h when IDF_TOOLCHAIN=clang is set' + ) + assert '#define CONFIG_LIBC_NEWLIB 1' in sdkconfig_h, 'CONFIG_LIBC_NEWLIB must be selected for clang builds'