pytest_sdmmc_card_example.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. import logging
  4. import re
  5. import pytest
  6. from pytest_embedded import Dut
  7. @pytest.mark.esp32
  8. @pytest.mark.sdcard_sdmode
  9. def test_examples_sd_card_sdmmc(dut: Dut) -> None:
  10. dut.expect('example: Initializing SD card', timeout=20)
  11. dut.expect('example: Using SDMMC peripheral', timeout=10)
  12. # Provide enough time for possible SD card formatting
  13. dut.expect('Filesystem mounted', timeout=60)
  14. # These lines are matched separately because of ASCII color codes in the output
  15. name = dut.expect(re.compile(rb'Name: (\w+)\r'), timeout=10).group(1).decode()
  16. _type = dut.expect(re.compile(rb'Type: (\S+)'), timeout=10).group(1).decode()
  17. speed = dut.expect(re.compile(rb'Speed: (\S+)'), timeout=10).group(1).decode()
  18. size = dut.expect(re.compile(rb'Size: (\S+)'), timeout=10).group(1).decode()
  19. logging.info('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
  20. message_list1 = ('Opening file /sdcard/hello.txt',
  21. 'File written',
  22. 'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
  23. 'Reading file /sdcard/foo.txt',
  24. "Read from file: 'Hello {}!'".format(name))
  25. sd_card_format = re.compile(str.encode('Formatting card, allocation unit size=\\S+'))
  26. message_list2 = ('file doesnt exist, format done',
  27. 'Opening file /sdcard/nihao.txt',
  28. 'File written',
  29. 'Reading file /sdcard/nihao.txt',
  30. "Read from file: 'Nihao {}!'".format(name),
  31. 'Card unmounted')
  32. for msg in message_list1:
  33. dut.expect_exact(msg, timeout=30)
  34. dut.expect(sd_card_format, timeout=180) # Provide enough time for SD card FATFS format operation
  35. for msg in message_list2:
  36. dut.expect_exact(msg, timeout=30)