1import re
2
3import ttfw_idf
4from tiny_test_fw import Utility
5
6
7@ttfw_idf.idf_example_test(env_tag='UT_T1_SPIMODE', target=['esp32', 'esp32s2', 'esp32c3'])
8def test_examples_sd_card(env, extra_data):  # type: (ttfw_idf.Env.Env, None ) -> None
9
10    dut = env.get_dut('sd_card', 'examples/storage/sd_card/sdspi')
11    dut.start_app()
12    dut.expect('example: Initializing SD card', timeout=20)
13    dut.expect('example: Using SPI peripheral', timeout=20)
14
15    # Provide enough time for possible SD card formatting
16    dut.expect('Filesystem mounted', timeout=60)
17
18    # These lines are matched separately because of ASCII color codes in the output
19    name = dut.expect(re.compile(r'Name: (\w+)'), timeout=20)[0]
20    _type = dut.expect(re.compile(r'Type: (\S+)'), timeout=20)[0]
21    speed = dut.expect(re.compile(r'Speed: (\S+)'), timeout=20)[0]
22    size = dut.expect(re.compile(r'Size: (\S+)'), timeout=20)[0]
23
24    Utility.console_log('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
25
26    dut.expect_all('Opening file /sdcard/hello.txt',
27                   'File written',
28                   'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
29                   'Reading file /sdcard/foo.txt',
30                   "Read from file: 'Hello {}!'".format(name),
31                   'Card unmounted',
32                   timeout=20)
33
34
35if __name__ == '__main__':
36    test_examples_sd_card()
37