mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
feat(tools/kconfig): add initial and current versions of IDF to kconfig
This commit is contained in:
@@ -1,11 +1,33 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from test_build_system_helpers import IdfPyFunc, file_contains
|
||||
|
||||
|
||||
def idf_version_from_cmake() -> Optional[str]:
|
||||
version_path = os.path.join(os.environ['IDF_PATH'], 'tools/cmake/version.cmake')
|
||||
regex = re.compile(r'^\s*set\s*\(\s*IDF_VERSION_([A-Z]{5})\s+(\d+)')
|
||||
ver = {}
|
||||
try:
|
||||
with open(version_path) as f:
|
||||
for line in f:
|
||||
m = regex.match(line)
|
||||
|
||||
if m:
|
||||
ver[m.group(1)] = m.group(2)
|
||||
|
||||
return '%s.%s.%s' % (ver['MAJOR'], ver['MINOR'], ver['PATCH'])
|
||||
except (KeyError, OSError):
|
||||
pytest.fail('Cannot find ESP-IDF version in tools/cmake/version.cmake')
|
||||
return None
|
||||
|
||||
|
||||
def test_sdkconfig_contains_all_files(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
|
||||
logging.info('sdkconfig should have contents of all files: sdkconfig, sdkconfig.defaults, sdkconfig.defaults.IDF_TARGET')
|
||||
(test_app_copy / 'sdkconfig').write_text('CONFIG_PARTITION_TABLE_TWO_OTA=y')
|
||||
@@ -24,3 +46,18 @@ def test_sdkconfig_multiple_default_files(idf_py: IdfPyFunc, test_app_copy: Path
|
||||
idf_py('-DSDKCONFIG_DEFAULTS=sdkconfig.defaults1;sdkconfig.defaults2', 'reconfigure')
|
||||
assert all([file_contains((test_app_copy / 'sdkconfig'), x) for x in ['CONFIG_PARTITION_TABLE_TWO_OTA=y',
|
||||
'CONFIG_PARTITION_TABLE_OFFSET=0x10000']])
|
||||
|
||||
|
||||
def test_keep_idf_init_version(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
|
||||
logging.info('sdkconfig should contain initial IDF version, even after regenerating the config')
|
||||
(test_app_copy / 'sdkconfig').write_text('CONFIG_IDF_INIT_VERSION="1.2.3"')
|
||||
idf_py('reconfigure')
|
||||
assert file_contains((test_app_copy / 'sdkconfig'), 'CONFIG_IDF_INIT_VERSION="1.2.3"')
|
||||
|
||||
|
||||
def test_empty_idf_init_version(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
|
||||
logging.info('sdkconfig should add current IDF version as initial IDF version')
|
||||
(test_app_copy / 'sdkconfig').write_text('CONFIG_IDF_INIT_VERSION=""')
|
||||
idf_py('reconfigure')
|
||||
version = idf_version_from_cmake()
|
||||
assert file_contains((test_app_copy / 'sdkconfig'), f'CONFIG_IDF_INIT_VERSION="{version}"')
|
||||
|
Reference in New Issue
Block a user