pytest_sdmmc_card_example.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # SPDX-FileCopyrightText: 2022 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_list = ('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. 'Card unmounted')
  26. for msg in message_list:
  27. dut.expect(msg, timeout=10)