|
|
@@ -8,6 +8,9 @@ from pathlib import Path
|
|
|
import pytest
|
|
|
from test_build_system_helpers import EnvDict, IdfPyFunc, check_file_contains, run_cmake
|
|
|
|
|
|
+ESP32C3_TARGET = 'esp32c3'
|
|
|
+ESP32C2_TARGET = 'esp32c2'
|
|
|
+ESP32S3_TARGET = 'esp32s3'
|
|
|
ESP32S2_TARGET = 'esp32s2'
|
|
|
ESP32_TARGET = 'esp32'
|
|
|
|
|
|
@@ -36,9 +39,12 @@ def test_target_from_environment_idf_py(idf_py: IdfPyFunc, default_idf_env: EnvD
|
|
|
idf_py('set-target', ESP32S2_TARGET)
|
|
|
default_idf_env.update({'IDF_TARGET': ESP32_TARGET})
|
|
|
|
|
|
+ cfg_path = test_app_copy.joinpath('sdkconfig')
|
|
|
+
|
|
|
logging.info("idf.py fails if IDF_TARGET settings don't match the environment")
|
|
|
- reconfigure_and_check_return_values("Project sdkconfig was generated for target '{}', but environment "
|
|
|
- "variable IDF_TARGET is set to '{}'.".format(ESP32S2_TARGET, ESP32_TARGET))
|
|
|
+ reconfigure_and_check_return_values("Project sdkconfig '{}' was generated for target '{}', but environment "
|
|
|
+ "variable IDF_TARGET is set to '{}'.".format(cfg_path, ESP32S2_TARGET,
|
|
|
+ ESP32_TARGET))
|
|
|
|
|
|
logging.info("idf.py fails if IDF_TARGET settings in CMakeCache.txt don't match the environment")
|
|
|
(test_app_copy / 'sdkconfig').write_text('CONFIG_IDF_TARGET="{}"'.format(ESP32_TARGET))
|
|
|
@@ -47,8 +53,8 @@ def test_target_from_environment_idf_py(idf_py: IdfPyFunc, default_idf_env: EnvD
|
|
|
|
|
|
logging.info("idf.py fails if IDF_TARGET settings in CMakeCache.txt don't match the sdkconfig")
|
|
|
default_idf_env.pop('IDF_TARGET')
|
|
|
- reconfigure_and_check_return_values("Project sdkconfig was generated for target '{}', but CMakeCache.txt "
|
|
|
- "contains '{}'.".format(ESP32_TARGET, ESP32S2_TARGET))
|
|
|
+ reconfigure_and_check_return_values("Project sdkconfig '{}' was generated for target '{}', but CMakeCache.txt "
|
|
|
+ "contains '{}'.".format(cfg_path, ESP32_TARGET, ESP32S2_TARGET))
|
|
|
|
|
|
|
|
|
def test_target_precedence(idf_py: IdfPyFunc, default_idf_env: EnvDict, test_app_copy: Path) -> None:
|
|
|
@@ -102,3 +108,41 @@ def test_target_using_sdkconfig(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
|
|
|
idf_py('reconfigure')
|
|
|
check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32S2_TARGET))
|
|
|
check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET_{}=y'.format(ESP32S2_TARGET.upper()))
|
|
|
+
|
|
|
+
|
|
|
+def test_target_guessing(idf_py: IdfPyFunc, test_app_copy: Path, default_idf_env: EnvDict) -> None:
|
|
|
+ """
|
|
|
+ Tests are performed from the lowest to the highest priority, while
|
|
|
+ configs, except from the sdkconfig, and parameters of previous tests are
|
|
|
+ preserved.
|
|
|
+ """
|
|
|
+
|
|
|
+ logging.info('Can guess target from sdkconfig.defaults')
|
|
|
+ (test_app_copy / 'sdkconfig.defaults').write_text('CONFIG_IDF_TARGET="{}"'.format(ESP32_TARGET))
|
|
|
+ idf_py('reconfigure')
|
|
|
+ check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32_TARGET))
|
|
|
+ check_file_contains('build/CMakeCache.txt', 'IDF_TARGET:STRING={}'.format(ESP32_TARGET))
|
|
|
+
|
|
|
+ logging.info('Can guess target from SDKCONFIG_DEFAULTS environment variable')
|
|
|
+ (test_app_copy / 'sdkconfig1').write_text('NOTHING HERE')
|
|
|
+ (test_app_copy / 'sdkconfig2').write_text('CONFIG_IDF_TARGET="{}"'.format(ESP32S2_TARGET))
|
|
|
+ clean_app(test_app_copy)
|
|
|
+ default_idf_env.update({'SDKCONFIG_DEFAULTS': 'sdkconfig1;sdkconfig2'})
|
|
|
+ idf_py('reconfigure')
|
|
|
+ check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32S2_TARGET))
|
|
|
+ check_file_contains('build/CMakeCache.txt', 'IDF_TARGET:STRING={}'.format(ESP32S2_TARGET))
|
|
|
+
|
|
|
+ logging.info('Can guess target from SDKCONFIG_DEFAULTS using -D')
|
|
|
+ (test_app_copy / 'sdkconfig3').write_text('CONFIG_IDF_TARGET="{}"'.format(ESP32S2_TARGET))
|
|
|
+ (test_app_copy / 'sdkconfig4').write_text('CONFIG_IDF_TARGET="{}"'.format(ESP32S3_TARGET))
|
|
|
+ clean_app(test_app_copy)
|
|
|
+ idf_py('-D', 'SDKCONFIG_DEFAULTS=sdkconfig4;sdkconfig3', 'reconfigure')
|
|
|
+ check_file_contains('sdkconfig', 'CONFIG_IDF_TARGET="{}"'.format(ESP32S3_TARGET))
|
|
|
+ check_file_contains('build/CMakeCache.txt', 'IDF_TARGET:STRING={}'.format(ESP32S3_TARGET))
|
|
|
+
|
|
|
+ logging.info('Can guess target from custom sdkconfig')
|
|
|
+ (test_app_copy / 'sdkconfig5').write_text('CONFIG_IDF_TARGET="{}"'.format(ESP32C3_TARGET))
|
|
|
+ clean_app(test_app_copy)
|
|
|
+ idf_py('-D', 'SDKCONFIG=sdkconfig5', '-D', 'SDKCONFIG_DEFAULTS=sdkconfig4;sdkconfig3', 'reconfigure')
|
|
|
+ check_file_contains('sdkconfig5', 'CONFIG_IDF_TARGET="{}"'.format(ESP32C3_TARGET))
|
|
|
+ check_file_contains('build/CMakeCache.txt', 'IDF_TARGET:STRING={}'.format(ESP32C3_TARGET))
|