test_spaces.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. import logging
  4. import os
  5. import shutil
  6. import subprocess
  7. import sys
  8. from pathlib import Path
  9. import pytest
  10. from test_build_system_helpers import run_idf_py
  11. # In this test file the test are grouped into 3 bundels
  12. # It would be better to have every test separate,
  13. # but that would mean doing idf_copy each time, and copying takes most of the time
  14. def clean_app_dir(app_path: Path) -> None:
  15. (app_path / 'sdkconfig').unlink()
  16. shutil.rmtree(app_path / 'build', ignore_errors=True)
  17. @pytest.mark.idf_copy('esp idf with spaces')
  18. def test_spaces_bundle1(idf_copy: Path) -> None:
  19. logging.info('Running test spaces bundle 1')
  20. # test_build
  21. run_idf_py('build', workdir=(idf_copy / 'examples' / 'get-started' / 'hello_world'))
  22. # test build ulp_fsm
  23. run_idf_py('build', workdir=(idf_copy / 'examples' / 'system' / 'ulp' / 'ulp_fsm' / 'ulp'))
  24. # test build ulp_riscv
  25. run_idf_py('-DIDF_TARGET=esp32s2', 'build', workdir=(idf_copy / 'examples' / 'system' / 'ulp' / 'ulp_riscv' / 'gpio'))
  26. # test spiffsgen
  27. run_idf_py('build', workdir=(idf_copy / 'examples' / 'storage' / 'spiffsgen'))
  28. @pytest.mark.idf_copy('esp idf with spaces')
  29. def test_spaces_bundle2(idf_copy: Path) -> None:
  30. logging.info('Running test spaces bundle 2')
  31. # test flash_encryption
  32. run_idf_py('build', workdir=(idf_copy / 'examples' / 'security' / 'flash_encryption'))
  33. # test_x509_cert_bundle
  34. run_idf_py('build', workdir=(idf_copy / 'examples' / 'protocols' / 'https_x509_bundle'))
  35. # test dfu
  36. hello_world_app_path = (idf_copy / 'examples' / 'get-started' / 'hello_world')
  37. run_idf_py('-DIDF_TARGET=esp32s2', 'dfu', workdir=hello_world_app_path)
  38. clean_app_dir(hello_world_app_path)
  39. # test uf2
  40. run_idf_py('uf2', workdir=hello_world_app_path)
  41. @pytest.mark.idf_copy('esp idf with spaces')
  42. def test_spaces_bundle3(idf_copy: Path) -> None:
  43. logging.info('Running test spaces bundle 3')
  44. secure_boot_app_path = (idf_copy / 'tools' / 'test_apps' / 'security' / 'secure_boot')
  45. # test secure_boot_v1
  46. run_idf_py('-DSDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.ci.00', 'build',
  47. workdir=secure_boot_app_path)
  48. clean_app_dir(secure_boot_app_path)
  49. # test secure_boot_v2
  50. run_idf_py('-DSDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.ci.01', 'build',
  51. workdir=secure_boot_app_path)
  52. clean_app_dir(secure_boot_app_path)
  53. # test app_signing
  54. run_idf_py('-DSDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.ci.02', 'build',
  55. workdir=secure_boot_app_path)
  56. clean_app_dir(secure_boot_app_path)
  57. # test secure_boot_release_mode
  58. run_idf_py('-DSDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.ci.04', '-DIDF_TARGET=esp32s2', 'build',
  59. workdir=secure_boot_app_path)
  60. @pytest.mark.skipif(sys.platform == 'win32', reason='Unix test')
  61. @pytest.mark.idf_copy('esp idf with spaces')
  62. def test_install_export_unix(idf_copy: Path) -> None:
  63. logging.info('install and export setup scripts')
  64. env = dict(**os.environ)
  65. install_cmd = './install.sh esp32'
  66. export_cmd = '. ./export.sh'
  67. logging.debug('running {} in {}'.format(install_cmd, idf_copy))
  68. subprocess.check_call(install_cmd, env=env, shell=True, cwd=idf_copy)
  69. logging.debug('running {} in {}'.format(export_cmd, idf_copy))
  70. # The default shell used by subprocess.Popen on POSIX platforms is '/bin/sh',
  71. # which in esp-env Docker image is 'dash'. The export script doesn't support
  72. # IDF_PATH detection when used in dash, so we have to override the shell here.
  73. subprocess.check_call(export_cmd, env=env, shell=True, cwd=idf_copy, executable='/bin/bash')
  74. @pytest.mark.skipif(sys.platform != 'win32', reason='Windows test')
  75. @pytest.mark.idf_copy('esp idf with spaces')
  76. def test_install_export_win(idf_copy: Path) -> None:
  77. logging.info('install and export setup scripts')
  78. env = dict(**os.environ)
  79. install_cmd = 'install.bat esp32'
  80. export_cmd = 'export.bat'
  81. logging.debug('running {} in {}'.format(install_cmd, idf_copy))
  82. subprocess.check_call(install_cmd, env=env, shell=True, cwd=idf_copy)
  83. logging.debug('running {} in {}'.format(export_cmd, idf_copy))
  84. subprocess.check_call(export_cmd, env=env, shell=True, cwd=idf_copy)