test_cmake.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. import logging
  4. import os
  5. import re
  6. import shutil
  7. from pathlib import Path
  8. from test_build_system_helpers import IdfPyFunc, file_contains, run_cmake, run_cmake_and_build
  9. def test_build_custom_cmake_project(test_app_copy: Path) -> None:
  10. for target in ['esp32', 'esp32s3', 'esp32c6', 'esp32h2']:
  11. logging.info(f'Test build ESP-IDF as a library to a custom CMake projects for {target}')
  12. idf_path = Path(os.environ['IDF_PATH'])
  13. run_cmake_and_build(str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'),
  14. '-DCMAKE_TOOLCHAIN_FILE={}'.format(idf_path / 'tools' / 'cmake' / f'toolchain-{target}.cmake'), f'-DTARGET={target}')
  15. assert file_contains((test_app_copy / 'build' / 'compile_commands.json'), '"command"')
  16. shutil.rmtree(test_app_copy / 'build')
  17. def test_build_cmake_library_psram_workaround(test_app_copy: Path) -> None:
  18. logging.info('Building a project with CMake library imported and PSRAM workaround, all files compile with workaround')
  19. idf_path = Path(os.environ['IDF_PATH'])
  20. (test_app_copy / 'sdkconfig.defaults').write_text('\n'.join(['CONFIG_SPIRAM=y',
  21. 'CONFIG_SPIRAM_CACHE_WORKAROUND=y']))
  22. run_cmake('-G', 'Ninja', '-DSDKCONFIG_DEFAULTS={}'.format(test_app_copy / 'sdkconfig.defaults'),
  23. str(idf_path / 'examples' / 'build_system' / 'cmake' / 'import_lib'))
  24. with open((test_app_copy / 'build' / 'compile_commands.json'), 'r', encoding='utf-8') as f:
  25. data = f.read()
  26. res = re.findall(r'.*\"command\".*', data)
  27. for r in res:
  28. assert 'mfix-esp32-psram-cache-issue' in r, 'All commands in compile_commands.json should use PSRAM cache workaround'
  29. def test_build_cmake_library_psram_strategies(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
  30. for strategy in ['DUPLDST', 'NOPS', 'MEMW']:
  31. logging.info(f'Test for external libraries in custom CMake projects with PSRAM strategy {strategy}')
  32. (test_app_copy / 'sdkconfig.defaults').write_text('\n'.join(['CONFIG_SPIRAM=y',
  33. f'CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_{strategy}=y',
  34. 'CONFIG_SPIRAM_CACHE_WORKAROUND=y']))
  35. idf_py('reconfigure')
  36. with open((test_app_copy / 'build' / 'compile_commands.json'), 'r', encoding='utf-8') as f:
  37. data = f.read()
  38. res = re.findall(r'.*\"command\".*', data)
  39. for r in res:
  40. assert f'mfix-esp32-psram-cache-strategy={strategy.lower()}' in r, ('All commands in compile_commands.json '
  41. 'should use PSRAM cache workaround strategy')
  42. (test_app_copy / 'sdkconfig').unlink()