pytest_parttool_example.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. import os
  4. import subprocess
  5. import sys
  6. import pytest
  7. from pytest_embedded import Dut
  8. @pytest.mark.esp32
  9. def test_examples_parttool(dut: Dut) -> None:
  10. # Verify factory firmware
  11. dut.expect('Partitions Tool Example')
  12. dut.expect('Example end')
  13. # Close connection to DUT
  14. dut.pexpect_proc.terminate()
  15. dut.serial.stop_redirect_thread()
  16. # Run the example python script
  17. idf_path = os.getenv('IDF_PATH')
  18. assert idf_path is not None
  19. script_path = os.path.join(idf_path, 'examples', 'storage', 'parttool', 'parttool_example.py')
  20. binary_path = os.path.join(dut.app.binary_path, 'parttool.bin')
  21. subprocess.check_call([sys.executable, script_path, '--binary', binary_path, '--port', dut.serial.port])
  22. # following tests check the external interface (parsing) of the parttool commands
  23. with open('custom.bin', 'wb') as f:
  24. f.write(b'0' * 1024 * 4)
  25. PARTTOOL = os.path.join(idf_path, 'components', 'partition_table', 'parttool.py')
  26. BASE_CMD = [sys.executable, PARTTOOL, '--port', dut.serial.port]
  27. cmds = ['read_partition --partition-type=data --partition-subtype=nvs --output custom1.bin',
  28. 'erase_partition --partition-name=custom',
  29. 'write_partition --partition-name=custom --input custom.bin',
  30. 'get_partition_info --partition-boot-default --info size']
  31. for cmd in cmds:
  32. subprocess.check_call(BASE_CMD + cmd.split())
  33. clean_files = ['custom.bin', 'custom1.bin']
  34. for clean_file in clean_files:
  35. os.unlink(clean_file)