sd_card_example_test.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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): # type: (ttfw_idf.Env.Env, None ) -> None
  6. dut = env.get_dut('sd_card', 'examples/storage/sd_card/sdmmc')
  7. dut.start_app()
  8. dut.expect('example: Initializing SD card', timeout=20)
  9. dut.expect('example: Using SDMMC peripheral', timeout=10)
  10. # Provide enough time for possible SD card formatting
  11. dut.expect('Filesystem mounted', timeout=60)
  12. # These lines are matched separately because of ASCII color codes in the output
  13. name = dut.expect(re.compile(r'Name: (\w+)'), timeout=10)[0]
  14. _type = dut.expect(re.compile(r'Type: (\S+)'), timeout=10)[0]
  15. speed = dut.expect(re.compile(r'Speed: (\S+)'), timeout=10)[0]
  16. size = dut.expect(re.compile(r'Size: (\S+)'), timeout=10)[0]
  17. Utility.console_log('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
  18. dut.expect_all('Opening file /sdcard/hello.txt',
  19. 'File written',
  20. 'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
  21. 'Reading file /sdcard/foo.txt',
  22. "Read from file: 'Hello {}!'".format(name),
  23. 'Card unmounted',
  24. timeout=10)
  25. if __name__ == '__main__':
  26. test_examples_sd_card()