sd_card_example_test.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import re
  2. import ttfw_idf
  3. from tiny_test_fw import Utility
  4. @ttfw_idf.idf_example_test(env_tag='UT_T1_SDMODE')
  5. def test_examples_sd_card(env, extra_data):
  6. dut = env.get_dut('sd_card', 'examples/storage/sd_card')
  7. dut.start_app()
  8. dut.expect('example: Initializing SD card', timeout=20)
  9. peripheral = dut.expect(re.compile(r'example: Using (\w+) peripheral'), timeout=5)[0]
  10. Utility.console_log('peripheral {} detected'.format(peripheral))
  11. assert peripheral in ('SDMMC', 'SPI')
  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(r'Name: (\w+)'), timeout=5)[0]
  16. _type = dut.expect(re.compile(r'Type: (\S+)'), timeout=5)[0]
  17. speed = dut.expect(re.compile(r'Speed: (\S+)'), timeout=5)[0]
  18. size = dut.expect(re.compile(r'Size: (\S+)'), timeout=5)[0]
  19. Utility.console_log('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
  20. dut.expect_all('Opening file',
  21. 'File written',
  22. 'Renaming file',
  23. 'Reading file',
  24. "Read from file: 'Hello {}!".format(name),
  25. 'Card unmounted',
  26. timeout=5)
  27. if __name__ == '__main__':
  28. test_examples_sd_card()