test_common.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. import shutil
  4. import subprocess
  5. from pathlib import Path
  6. import pytest
  7. from _pytest.monkeypatch import MonkeyPatch
  8. from test_build_system_helpers import IdfPyFunc, get_snapshot, replace_in_file
  9. @pytest.mark.usefixtures('test_app_copy')
  10. @pytest.mark.test_app_copy('examples/get-started/blink')
  11. def test_compile_commands_json_updated_by_reconfigure(idf_py: IdfPyFunc) -> None:
  12. output = idf_py('reconfigure')
  13. assert 'Building ESP-IDF components for target esp32' in output.stdout
  14. snapshot_1 = get_snapshot(['build/compile_commands.json'])
  15. snapshot_2 = get_snapshot(['build/compile_commands.json'])
  16. snapshot_2.assert_same(snapshot_1)
  17. idf_py('reconfigure')
  18. snapshot_3 = get_snapshot(['build/compile_commands.json'])
  19. snapshot_3.assert_different(snapshot_2)
  20. @pytest.mark.usefixtures('test_app_copy')
  21. def test_of_test_app_copy(idf_py: IdfPyFunc) -> None:
  22. p = Path('main/idf_component.yml')
  23. p.write_text('syntax_error\n')
  24. try:
  25. with (pytest.raises(subprocess.CalledProcessError)) as exc_info:
  26. idf_py('reconfigure')
  27. assert 'ERROR: Unknown format of the manifest file:' in exc_info.value.stderr
  28. finally:
  29. p.unlink()
  30. @pytest.mark.usefixtures('test_app_copy')
  31. def test_hints_no_color_output_when_noninteractive(idf_py: IdfPyFunc) -> None:
  32. """Check that idf.py hints don't include color escape codes in non-interactive builds"""
  33. # make the build fail in such a way that idf.py shows a hint
  34. replace_in_file('main/build_test_app.c', '// placeholder_inside_main',
  35. 'esp_chip_info_t chip_info; esp_chip_info(&chip_info);')
  36. with (pytest.raises(subprocess.CalledProcessError)) as exc_info:
  37. idf_py('build')
  38. # Should not actually include a color escape sequence!
  39. # Change the assert to the correct value once the bug is fixed.
  40. assert '\x1b[0;33mHINT: esp_chip_info.h' in exc_info.value.stderr
  41. @pytest.mark.usefixtures('test_app_copy')
  42. def test_idf_copy(idf_copy: Path, idf_py: IdfPyFunc) -> None:
  43. # idf_copy is the temporary IDF copy.
  44. # For example, we can check if idf.py build can work without the .git directory:
  45. shutil.rmtree(idf_copy / '.git', ignore_errors=True)
  46. idf_py('build')
  47. def test_idf_build_with_env_var_sdkconfig_defaults(
  48. test_app_copy: Path,
  49. idf_py: IdfPyFunc,
  50. monkeypatch: MonkeyPatch,
  51. ) -> None:
  52. with open(test_app_copy / 'sdkconfig.test', 'w') as fw:
  53. fw.write('CONFIG_BT_ENABLED=y')
  54. monkeypatch.setenv('SDKCONFIG_DEFAULTS', 'sdkconfig.test')
  55. idf_py('build')
  56. with open(test_app_copy / 'sdkconfig') as fr:
  57. assert 'CONFIG_BT_ENABLED=y' in fr.read()
  58. @pytest.mark.usefixtures('test_app_copy')
  59. @pytest.mark.test_app_copy('examples/system/efuse')
  60. def test_efuse_symmary_cmake_functions(
  61. idf_py: IdfPyFunc,
  62. monkeypatch: MonkeyPatch
  63. ) -> None:
  64. monkeypatch.setenv('IDF_CI_BUILD', '1')
  65. output = idf_py('efuse-summary')
  66. assert 'FROM_CMAKE: MAC: 00:00:00:00:00:00' in output.stdout
  67. assert 'FROM_CMAKE: WR_DIS: 0' in output.stdout