mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-19 14:26:01 -04:00
storage examples migrated to pytest
This commit is contained in:
parent
37bc05c84d
commit
3271088428
@ -1,19 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_ExtFlash')
|
|
||||||
def test_examples_storage_ext_flash_fatfs(env, extra_data):
|
|
||||||
dut = env.get_dut('ext_flash_fatfs', 'examples/storage/ext_flash_fatfs', dut_class=ttfw_idf.ESP32DUT)
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
dut.expect('Initialized external Flash')
|
|
||||||
dut.expect('partition \'nvs\'')
|
|
||||||
dut.expect('partition \'storage\'')
|
|
||||||
dut.expect('File written')
|
|
||||||
dut.expect('Read from file: \'Written using ESP-IDF')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_storage_ext_flash_fatfs()
|
|
@ -13,6 +13,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "esp_flash.h"
|
#include "esp_flash.h"
|
||||||
#include "esp_flash_spi_init.h"
|
#include "esp_flash_spi_init.h"
|
||||||
#include "esp_partition.h"
|
#include "esp_partition.h"
|
||||||
@ -165,7 +166,12 @@ static const esp_partition_t* example_add_partition(esp_flash_t* ext_flash, cons
|
|||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Adding external Flash as a partition, label=\"%s\", size=%d KB", partition_label, ext_flash->size / 1024);
|
ESP_LOGI(TAG, "Adding external Flash as a partition, label=\"%s\", size=%d KB", partition_label, ext_flash->size / 1024);
|
||||||
const esp_partition_t* fat_partition;
|
const esp_partition_t* fat_partition;
|
||||||
ESP_ERROR_CHECK(esp_partition_register_external(ext_flash, 0, ext_flash->size, partition_label, ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, &fat_partition));
|
const size_t offset = 0;
|
||||||
|
ESP_ERROR_CHECK(esp_partition_register_external(ext_flash, offset, ext_flash->size, partition_label, ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, &fat_partition));
|
||||||
|
|
||||||
|
// Erase space of partition on the external flash chip
|
||||||
|
ESP_LOGI(TAG, "Erasing partition range, offset=%d size=%d KB", offset, ext_flash->size / 1024);
|
||||||
|
ESP_ERROR_CHECK(esp_partition_erase_range(fat_partition, offset, ext_flash->size));
|
||||||
return fat_partition;
|
return fat_partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
examples/storage/ext_flash_fatfs/pytest_ext_flash_fatfs.py
Normal file
19
examples/storage/ext_flash_fatfs/pytest_ext_flash_fatfs.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.external_flash
|
||||||
|
def test_ext_flash_fatfs(dut: Dut) -> None:
|
||||||
|
message_list = ('Initialized external Flash',
|
||||||
|
'partition \'nvs\'',
|
||||||
|
'partition \'storage\'',
|
||||||
|
'File written',
|
||||||
|
'Read from file: \'Written using ESP-IDF')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(msg, timeout=20)
|
@ -1,95 +0,0 @@
|
|||||||
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
|
||||||
import os
|
|
||||||
from datetime import datetime
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
|
||||||
def test_examples_fatfsgen(env: ttfw_idf.TinyFW.Env, _: Optional[list]) -> None:
|
|
||||||
tag = 'fatfsgen'
|
|
||||||
test_path = 'examples/storage/fatfsgen'
|
|
||||||
timeout = 20
|
|
||||||
filename_ln = 'sublongnames/testlongfilenames.txt'
|
|
||||||
filename_sn = 'sub/test.txt'
|
|
||||||
dir_ln = os.path.join(os.path.dirname(__file__), 'fatfs_long_name_image')
|
|
||||||
dir_sn = os.path.join(os.path.dirname(__file__), 'fatfs_image')
|
|
||||||
Path(os.path.join(dir_ln, filename_ln)).touch()
|
|
||||||
Path(os.path.join(dir_sn, filename_sn)).touch()
|
|
||||||
date_modified = datetime.today().strftime('%Y-%m-%d')
|
|
||||||
date_default = '1980-01-01'
|
|
||||||
|
|
||||||
for test_name in ['test_read_write_partition_gen', 'test_read_write_partition_gen_default_dt']:
|
|
||||||
filename = filename_sn
|
|
||||||
filename_expected = f'/spiflash/{filename}'
|
|
||||||
date_ = date_default if test_name == 'test_read_write_partition_gen_default_dt' else date_modified
|
|
||||||
dut = env.get_dut(tag, test_path, app_config_name=test_name)
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect_all('example: Mounting FAT filesystem',
|
|
||||||
'example: Opening file',
|
|
||||||
'example: File written',
|
|
||||||
'example: Reading file',
|
|
||||||
'example: Read from file: \'This is written by the device\'',
|
|
||||||
'example: Reading file',
|
|
||||||
f'The file \'{filename_expected}\' was modified at date: {date_}',
|
|
||||||
'example: Read from file: \'This is generated on the host\'',
|
|
||||||
'example: Unmounting FAT filesystem',
|
|
||||||
'example: Done',
|
|
||||||
timeout=timeout)
|
|
||||||
env.close_dut(dut.name)
|
|
||||||
|
|
||||||
for test_name in ['test_read_only_partition_gen', 'test_read_only_partition_gen_default_dt']:
|
|
||||||
filename = filename_sn
|
|
||||||
filename_expected = f'/spiflash/{filename}'
|
|
||||||
date_ = date_default if test_name == 'test_read_only_partition_gen_default_dt' else date_modified
|
|
||||||
dut = env.get_dut(tag, test_path, app_config_name=test_name)
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect_all('example: Mounting FAT filesystem',
|
|
||||||
'example: Reading file',
|
|
||||||
f'The file \'{filename_expected}\' was modified at date: {date_}',
|
|
||||||
'example: Read from file: \'this is test\'',
|
|
||||||
'example: Unmounting FAT filesystem',
|
|
||||||
'example: Done',
|
|
||||||
timeout=timeout)
|
|
||||||
env.close_dut(dut.name)
|
|
||||||
|
|
||||||
for test_name in ['test_read_write_partition_gen_ln', 'test_read_write_partition_gen_ln_default_dt']:
|
|
||||||
filename = filename_ln
|
|
||||||
filename_expected = f'/spiflash/{filename}'
|
|
||||||
date_ = date_default if test_name == 'test_read_write_partition_gen_ln_default_dt' else date_modified
|
|
||||||
dut = env.get_dut(tag, test_path, app_config_name=test_name)
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect_all('example: Mounting FAT filesystem',
|
|
||||||
'example: Opening file',
|
|
||||||
'example: File written',
|
|
||||||
'example: Reading file',
|
|
||||||
'example: Read from file: \'This is written by the device\'',
|
|
||||||
'example: Reading file',
|
|
||||||
f'The file \'{filename_expected}\' was modified at date: {date_}',
|
|
||||||
'example: Read from file: \'This is generated on the host; long name it has\'',
|
|
||||||
'example: Unmounting FAT filesystem',
|
|
||||||
'example: Done',
|
|
||||||
timeout=timeout)
|
|
||||||
env.close_dut(dut.name)
|
|
||||||
|
|
||||||
for test_name in ['test_read_only_partition_gen_ln', 'test_read_only_partition_gen_ln_default_dt']:
|
|
||||||
filename = filename_ln
|
|
||||||
filename_expected = f'/spiflash/{filename}'
|
|
||||||
date_ = date_default if test_name == 'test_read_only_partition_gen_ln_default_dt' else date_modified
|
|
||||||
dut = env.get_dut(tag, test_path, app_config_name=test_name)
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect_all('example: Mounting FAT filesystem',
|
|
||||||
'example: Reading file',
|
|
||||||
f'The file \'{filename_expected}\' was modified at date: {date_}',
|
|
||||||
'example: Read from file: \'this is test; long name it has\'',
|
|
||||||
'example: Unmounting FAT filesystem',
|
|
||||||
'example: Done',
|
|
||||||
timeout=timeout)
|
|
||||||
env.close_dut(dut.name)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_fatfsgen()
|
|
109
examples/storage/fatfsgen/pytest_fatfsgen_example.py
Normal file
109
examples/storage/fatfsgen/pytest_fatfsgen_example.py
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
# Example_GENERIC
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.parametrize('config', ['test_read_only_partition_gen',
|
||||||
|
'test_read_only_partition_gen_default_dt',
|
||||||
|
'test_read_only_partition_gen_ln',
|
||||||
|
'test_read_only_partition_gen_ln_default_dt',
|
||||||
|
'test_read_write_partition_gen',
|
||||||
|
'test_read_write_partition_gen_default_dt',
|
||||||
|
'test_read_write_partition_gen_ln',
|
||||||
|
'test_read_write_partition_gen_ln_default_dt',
|
||||||
|
], indirect=True)
|
||||||
|
def test_examples_fatfsgen(config: str, dut: Dut) -> None:
|
||||||
|
# Expects list of strings sequentially
|
||||||
|
def expect_all(msg_list: List[str], to: int) -> None:
|
||||||
|
for msg in msg_list:
|
||||||
|
dut.expect(msg, timeout=to)
|
||||||
|
|
||||||
|
# Expects prefix string followed by date in the format 'yyyy-mm-dd'
|
||||||
|
def expect_date(prefix: str, to: int) -> datetime:
|
||||||
|
expect_str = prefix + '(\\d+)-(\\d+)-(\\d+)'
|
||||||
|
match_ = dut.expect(re.compile(str.encode(expect_str)), timeout=to)
|
||||||
|
year_ = int(match_[1].decode())
|
||||||
|
month_ = int(match_[2].decode())
|
||||||
|
day_ = int(match_[3].decode())
|
||||||
|
return datetime(year_, month_, day_)
|
||||||
|
|
||||||
|
# Calculates absolute difference in days between date_reference and date_actual.
|
||||||
|
# Raises exception if difference exceeds tolerance
|
||||||
|
def evaluate_dates(date_reference: datetime, date_actual: datetime, days_tolerance: int) -> None:
|
||||||
|
td = date_actual - date_reference
|
||||||
|
if abs(td.days) > days_tolerance:
|
||||||
|
raise Exception(f'Too big date difference. Actual: {date_actual}, reference: {date_reference}, tolerance: {days_tolerance} day(s)')
|
||||||
|
|
||||||
|
# Expect timeout
|
||||||
|
timeout = 20
|
||||||
|
|
||||||
|
# We tolerate 30 days difference between actual file creation and date when test was executed.
|
||||||
|
tolerance = 30
|
||||||
|
filename_ln = 'sublongnames/testlongfilenames.txt'
|
||||||
|
filename_sn = 'sub/test.txt'
|
||||||
|
date_modified = datetime.today()
|
||||||
|
date_default = datetime(1980, 1, 1)
|
||||||
|
|
||||||
|
if config in ['test_read_write_partition_gen', 'test_read_write_partition_gen_default_dt']:
|
||||||
|
filename = filename_sn
|
||||||
|
filename_expected = f'/spiflash/{filename}'
|
||||||
|
date_ref = date_default if config == 'test_read_write_partition_gen_default_dt' else date_modified
|
||||||
|
expect_all(['example: Mounting FAT filesystem',
|
||||||
|
'example: Opening file',
|
||||||
|
'example: File written',
|
||||||
|
'example: Reading file',
|
||||||
|
'example: Read from file: \'This is written by the device\'',
|
||||||
|
'example: Reading file'], timeout)
|
||||||
|
date_act = expect_date(f'The file \'{filename_expected}\' was modified at date: ', timeout)
|
||||||
|
evaluate_dates(date_ref, date_act, tolerance)
|
||||||
|
expect_all(['example: Read from file: \'This is generated on the host\'',
|
||||||
|
'example: Unmounting FAT filesystem',
|
||||||
|
'example: Done'], timeout)
|
||||||
|
|
||||||
|
elif config in ['test_read_only_partition_gen', 'test_read_only_partition_gen_default_dt']:
|
||||||
|
filename = filename_sn
|
||||||
|
filename_expected = f'/spiflash/{filename}'
|
||||||
|
date_ref = date_default if config == 'test_read_only_partition_gen_default_dt' else date_modified
|
||||||
|
expect_all(['example: Mounting FAT filesystem',
|
||||||
|
'example: Reading file'], timeout)
|
||||||
|
date_act = expect_date(f'The file \'{filename_expected}\' was modified at date: ', timeout)
|
||||||
|
evaluate_dates(date_ref, date_act, tolerance)
|
||||||
|
expect_all(['example: Read from file: \'this is test\'',
|
||||||
|
'example: Unmounting FAT filesystem',
|
||||||
|
'example: Done'], timeout)
|
||||||
|
|
||||||
|
elif config in ['test_read_write_partition_gen_ln', 'test_read_write_partition_gen_ln_default_dt']:
|
||||||
|
filename = filename_ln
|
||||||
|
filename_expected = f'/spiflash/{filename}'
|
||||||
|
date_ref = date_default if config == 'test_read_write_partition_gen_ln_default_dt' else date_modified
|
||||||
|
expect_all(['example: Mounting FAT filesystem',
|
||||||
|
'example: Opening file',
|
||||||
|
'example: File written',
|
||||||
|
'example: Reading file',
|
||||||
|
'example: Read from file: \'This is written by the device\'',
|
||||||
|
'example: Reading file'], timeout)
|
||||||
|
date_act = expect_date(f'The file \'{filename_expected}\' was modified at date: ', timeout)
|
||||||
|
evaluate_dates(date_ref, date_act, tolerance)
|
||||||
|
expect_all(['example: Read from file: \'This is generated on the host; long name it has\'',
|
||||||
|
'example: Unmounting FAT filesystem',
|
||||||
|
'example: Done'], timeout)
|
||||||
|
|
||||||
|
elif config in ['test_read_only_partition_gen_ln', 'test_read_only_partition_gen_ln_default_dt']:
|
||||||
|
filename = filename_ln
|
||||||
|
filename_expected = f'/spiflash/{filename}'
|
||||||
|
date_ref = date_default if config == 'test_read_only_partition_gen_ln_default_dt' else date_modified
|
||||||
|
expect_all(['example: Mounting FAT filesystem',
|
||||||
|
'example: Reading file'], timeout)
|
||||||
|
date_act = expect_date(f'The file \'{filename_expected}\' was modified at date: ', timeout)
|
||||||
|
evaluate_dates(date_ref, date_act, tolerance)
|
||||||
|
expect_all(['example: Read from file: \'this is test; long name it has\'',
|
||||||
|
'example: Unmounting FAT filesystem',
|
||||||
|
'example: Done'], timeout)
|
@ -1,44 +0,0 @@
|
|||||||
import random
|
|
||||||
import re
|
|
||||||
import time
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
from tiny_test_fw import Utility
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_nvs_rw_blob(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('nvs_rw_blob', 'examples/storage/nvs_rw_blob')
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
def expect_start_msg(index):
|
|
||||||
dut.expect_all('Restart counter = {}'.format(index),
|
|
||||||
'Run time:',
|
|
||||||
timeout=10)
|
|
||||||
|
|
||||||
expect_start_msg(0)
|
|
||||||
dut.expect('Nothing saved yet!', timeout=5)
|
|
||||||
|
|
||||||
nvs_store = []
|
|
||||||
for i in range(1, 10):
|
|
||||||
time.sleep(random.uniform(0.1, 2)) # in order to randomize the runtimes stored in NVS
|
|
||||||
try:
|
|
||||||
# Pulling pin low using DTR
|
|
||||||
dut.port_inst.setDTR(True)
|
|
||||||
dut.expect('Restarting...', timeout=5) # the application waits for a second
|
|
||||||
finally:
|
|
||||||
dut.port_inst.setDTR(False)
|
|
||||||
|
|
||||||
expect_start_msg(i)
|
|
||||||
|
|
||||||
dut.expect_all(*nvs_store, timeout=10)
|
|
||||||
Utility.console_log('Received: {}'.format(', '.join(nvs_store)))
|
|
||||||
|
|
||||||
new_runtime = dut.expect(re.compile(r'{}: (\d+)'.format(i)), timeout=10)[0]
|
|
||||||
nvs_store.append('{}: {}'.format(i, new_runtime))
|
|
||||||
Utility.console_log('loop {} has finished with runtime {}'.format(i, new_runtime))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_nvs_rw_blob()
|
|
41
examples/storage/nvs_rw_blob/pytest_nvs_rw_blob.py
Normal file
41
examples/storage/nvs_rw_blob/pytest_nvs_rw_blob.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import random
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_examples_nvs_rw_blob(dut: Dut) -> None:
|
||||||
|
def expect_start_msg(index: int) -> None:
|
||||||
|
dut.expect('Restart counter = {}'.format(index), timeout=10)
|
||||||
|
dut.expect('Run time:', timeout=10)
|
||||||
|
|
||||||
|
expect_start_msg(0)
|
||||||
|
dut.expect('Nothing saved yet!', timeout=5)
|
||||||
|
nvs_store: List[str] = []
|
||||||
|
for i in range(1, 10):
|
||||||
|
time.sleep(random.uniform(0.1, 2)) # in order to randomize the runtimes stored in NVS
|
||||||
|
try:
|
||||||
|
# Pulling pin low using DTR
|
||||||
|
dut.serial.proc.setDTR(True)
|
||||||
|
dut.expect('Restarting...', timeout=5) # the application waits for a second
|
||||||
|
finally:
|
||||||
|
dut.serial.proc.setDTR(False)
|
||||||
|
|
||||||
|
expect_start_msg(i)
|
||||||
|
|
||||||
|
for store_item in nvs_store:
|
||||||
|
dut.expect(store_item.encode(), timeout=10)
|
||||||
|
|
||||||
|
logging.info('Received: {}'.format(', '.join(nvs_store)))
|
||||||
|
new_runtime = (dut.expect(re.compile(str.encode('{}: (\\d+)'.format(i))), timeout=10)[0]).decode()
|
||||||
|
nvs_store.append(new_runtime)
|
||||||
|
logging.info('loop {} has finished with runtime {}'.format(i, new_runtime))
|
@ -1,29 +0,0 @@
|
|||||||
import ttfw_idf
|
|
||||||
from tiny_test_fw import Utility
|
|
||||||
|
|
||||||
try:
|
|
||||||
from itertools import izip_longest as zip_longest
|
|
||||||
except ImportError:
|
|
||||||
# Python 3
|
|
||||||
from itertools import zip_longest
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_nvs_rw_value(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('nvs_rw_value', 'examples/storage/nvs_rw_value')
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
for i, counter_state in zip_longest(range(4), ('The value is not initialized yet!', ), fillvalue='Done'):
|
|
||||||
dut.expect_all('Opening Non-Volatile Storage (NVS) handle... Done',
|
|
||||||
'Reading restart counter from NVS ... {}'.format(counter_state),
|
|
||||||
'Restart counter = {}'.format(i) if i > 0 else '',
|
|
||||||
'Updating restart counter in NVS ... Done',
|
|
||||||
'Committing updates in NVS ... Done',
|
|
||||||
'Restarting in 10 seconds...',
|
|
||||||
timeout=20)
|
|
||||||
Utility.console_log('loop {} has finished'.format(i))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_nvs_rw_value()
|
|
21
examples/storage/nvs_rw_value/pytest_nvs_rw_value.py
Normal file
21
examples/storage/nvs_rw_value/pytest_nvs_rw_value.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from itertools import zip_longest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_examples_nvs_rw_value(dut: Dut) -> None:
|
||||||
|
for i, counter_state in zip_longest(range(4), ('The value is not initialized yet!',), fillvalue='Done'):
|
||||||
|
dut.expect('Opening Non-Volatile Storage \\(NVS\\) handle... Done', timeout=20)
|
||||||
|
dut.expect('Reading restart counter from NVS ... {}'.format(counter_state), timeout=20)
|
||||||
|
dut.expect('Restart counter = {}'.format(i) if i > 0 else '', timeout=20)
|
||||||
|
dut.expect('Updating restart counter in NVS ... Done', timeout=20)
|
||||||
|
dut.expect('Committing updates in NVS ... Done', timeout=20)
|
||||||
|
dut.expect('Restarting in 10 seconds...', timeout=20)
|
||||||
|
logging.info('loop {} has finished'.format(i))
|
@ -1,29 +0,0 @@
|
|||||||
import ttfw_idf
|
|
||||||
from tiny_test_fw import Utility
|
|
||||||
|
|
||||||
try:
|
|
||||||
from itertools import izip_longest as zip_longest
|
|
||||||
except ImportError:
|
|
||||||
# Python 3
|
|
||||||
from itertools import zip_longest
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_nvs_rw_value_cxx(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('nvs_rw_value_cxx', 'examples/storage/nvs_rw_value_cxx')
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
for i, counter_state in zip_longest(range(4), ('The value is not initialized yet!', ), fillvalue='Done'):
|
|
||||||
dut.expect_all('Opening Non-Volatile Storage (NVS) handle... Done',
|
|
||||||
'Reading restart counter from NVS ... {}'.format(counter_state),
|
|
||||||
'Restart counter = {}'.format(i) if i > 0 else '',
|
|
||||||
'Updating restart counter in NVS ... Done',
|
|
||||||
'Committing updates in NVS ... Done',
|
|
||||||
'Restarting in 10 seconds...',
|
|
||||||
timeout=20)
|
|
||||||
Utility.console_log('loop {} has finished'.format(i))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_nvs_rw_value_cxx()
|
|
21
examples/storage/nvs_rw_value_cxx/pytest_nvs_rw_value_cxx.py
Normal file
21
examples/storage/nvs_rw_value_cxx/pytest_nvs_rw_value_cxx.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from itertools import zip_longest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_examples_nvs_rw_value(dut: Dut) -> None:
|
||||||
|
for i, counter_state in zip_longest(range(4), ('The value is not initialized yet!',), fillvalue='Done'):
|
||||||
|
dut.expect('Opening Non-Volatile Storage \\(NVS\\) handle... Done', timeout=20)
|
||||||
|
dut.expect('Reading restart counter from NVS ... {}'.format(counter_state), timeout=20)
|
||||||
|
dut.expect('Restart counter = {}'.format(i) if i > 0 else '', timeout=20)
|
||||||
|
dut.expect('Updating restart counter in NVS ... Done', timeout=20)
|
||||||
|
dut.expect('Committing updates in NVS ... Done', timeout=20)
|
||||||
|
dut.expect('Restarting in 10 seconds...', timeout=20)
|
||||||
|
logging.info('loop {} has finished'.format(i))
|
@ -1,20 +1,24 @@
|
|||||||
import ttfw_idf
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
@pytest.mark.esp32
|
||||||
def test_examples_partition_find(env, extra_data):
|
@pytest.mark.esp32c3
|
||||||
|
def test_partition_find_example(dut: Dut) -> None:
|
||||||
|
def expect_partition(name: str, offset: int, size: int) -> None:
|
||||||
|
dut.expect(re.compile(str.encode("found partition '{}' at offset {:#x} with size {:#x}".format(name, offset, size))), timeout=5)
|
||||||
|
|
||||||
dut = env.get_dut('partition_find', 'examples/storage/partition_api/partition_find')
|
def expect_find_partition(_type: str, subtype: str, label: str, name: str, offset: int, size: int) -> None:
|
||||||
dut.start_app()
|
dut.expect(re.compile(str.encode('Find partition with type {}, subtype {}, label {}'.format(_type, subtype, label))), timeout=5)
|
||||||
|
|
||||||
def expect_partition(name, offset, size):
|
|
||||||
dut.expect("found partition '{}' at offset {:#x} with size {:#x}".format(name, offset, size), timeout=5)
|
|
||||||
|
|
||||||
def expect_find_partition(_type, subtype, label, name, offset, size):
|
|
||||||
dut.expect('Find partition with type {}, subtype {}, label {}'.format(_type, subtype, label), timeout=5)
|
|
||||||
expect_partition(name, offset, size)
|
expect_partition(name, offset, size)
|
||||||
|
|
||||||
dut.expect('----------------Find partitions---------------', timeout=20)
|
dut.expect('----------------Find partitions---------------', timeout=20)
|
||||||
|
|
||||||
expect_find_partition('ESP_PARTITION_TYPE_DATA', 'ESP_PARTITION_SUBTYPE_DATA_NVS', 'NULL',
|
expect_find_partition('ESP_PARTITION_TYPE_DATA', 'ESP_PARTITION_SUBTYPE_DATA_NVS', 'NULL',
|
||||||
'nvs', 0x9000, 0x6000)
|
'nvs', 0x9000, 0x6000)
|
||||||
expect_find_partition('ESP_PARTITION_TYPE_DATA', 'ESP_PARTITION_SUBTYPE_DATA_PHY', 'NULL',
|
expect_find_partition('ESP_PARTITION_TYPE_DATA', 'ESP_PARTITION_SUBTYPE_DATA_PHY', 'NULL',
|
||||||
@ -25,21 +29,20 @@ def test_examples_partition_find(env, extra_data):
|
|||||||
'storage1', 0x110000, 0x40000)
|
'storage1', 0x110000, 0x40000)
|
||||||
|
|
||||||
dut.expect('Find second FAT partition by specifying the label', timeout=5)
|
dut.expect('Find second FAT partition by specifying the label', timeout=5)
|
||||||
|
|
||||||
expect_find_partition('ESP_PARTITION_TYPE_DATA', 'ESP_PARTITION_SUBTYPE_DATA_FAT', 'storage2',
|
expect_find_partition('ESP_PARTITION_TYPE_DATA', 'ESP_PARTITION_SUBTYPE_DATA_FAT', 'storage2',
|
||||||
'storage2', 0x150000, 0x40000)
|
'storage2', 0x150000, 0x40000)
|
||||||
|
|
||||||
dut.expect_all('----------------Iterate through partitions---------------',
|
dut.expect('----------------Iterate through partitions---------------',timeout=5)
|
||||||
'Iterating through app partitions...', timeout=5)
|
dut.expect('Iterating through app partitions...', timeout=5)
|
||||||
|
|
||||||
expect_partition('factory', 0x10000, 0x100000)
|
expect_partition('factory', 0x10000, 0x100000)
|
||||||
|
|
||||||
dut.expect('Iterating through data partitions...', timeout=5)
|
dut.expect('Iterating through data partitions...', timeout=5)
|
||||||
|
|
||||||
expect_partition('nvs', 0x9000, 0x6000)
|
expect_partition('nvs', 0x9000, 0x6000)
|
||||||
expect_partition('phy_init', 0xf000, 0x1000)
|
expect_partition('phy_init', 0xf000, 0x1000)
|
||||||
expect_partition('storage1', 0x110000, 0x40000)
|
expect_partition('storage1', 0x110000, 0x40000)
|
||||||
expect_partition('storage2', 0x150000, 0x40000)
|
expect_partition('storage2', 0x150000, 0x40000)
|
||||||
|
|
||||||
dut.expect('Example end', timeout=5)
|
dut.expect('Example end', timeout=5)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_partition_find()
|
|
@ -1,23 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_partition_mmap(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('partition_mmap', 'examples/storage/partition_api/partition_mmap')
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
# ESP_ERROR_CHECK or assert will cause abort on error and "Example end" won't be received
|
|
||||||
dut.expect_all('Written sample data to partition: ESP-IDF Partition Memory Map Example',
|
|
||||||
re.compile(r'Mapped partition to data memory address \S+'),
|
|
||||||
'Read sample data from partition using mapped memory: ESP-IDF Partition Memory Map Example',
|
|
||||||
'Data matches',
|
|
||||||
'Unmapped partition from data memory',
|
|
||||||
'Example end',
|
|
||||||
timeout=20)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_partition_mmap()
|
|
@ -0,0 +1,22 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_partition_mmap_example(dut: Dut) -> None:
|
||||||
|
# ESP_ERROR_CHECK or assert will cause abort on error and "Example end" won't be received
|
||||||
|
message_list = (rb'Written sample data to partition: ESP-IDF Partition Memory Map Example',
|
||||||
|
rb'Mapped partition to data memory address \S+',
|
||||||
|
rb'Read sample data from partition using mapped memory: ESP-IDF Partition Memory Map Example',
|
||||||
|
rb'Data matches',
|
||||||
|
rb'Unmapped partition from data memory',
|
||||||
|
rb'Example end')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(re.compile(msg), timeout=20)
|
@ -1,19 +0,0 @@
|
|||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_partition_ops(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('partition_ops', 'examples/storage/partition_api/partition_ops')
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
# ESP_ERROR_CHECK or assert will cause abort on error and "Example end" won't be received
|
|
||||||
dut.expect_all('Written data: ESP-IDF Partition Operations Example (Read, Erase, Write)',
|
|
||||||
'Read data: ESP-IDF Partition Operations Example (Read, Erase, Write)',
|
|
||||||
'Erased data',
|
|
||||||
'Example end',
|
|
||||||
timeout=20)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_partition_ops()
|
|
@ -0,0 +1,20 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_partition_ops_example(dut: Dut) -> None:
|
||||||
|
# ESP_ERROR_CHECK or assert will cause abort on error and "Example end" won't be received
|
||||||
|
message_list = (rb'Written data: ESP-IDF Partition Operations Example \(Read, Erase, Write\)',
|
||||||
|
rb'Read data: ESP-IDF Partition Operations Example \(Read, Erase, Write\)',
|
||||||
|
rb'Erased data',
|
||||||
|
rb'Example end')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(re.compile(msg), timeout=20)
|
@ -1,36 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_parttool(env, extra_data):
|
|
||||||
dut = env.get_dut('parttool', 'examples/storage/parttool')
|
|
||||||
dut.start_app(False)
|
|
||||||
|
|
||||||
# Verify factory firmware
|
|
||||||
dut.expect('Partitions Tool Example')
|
|
||||||
dut.expect('Example end')
|
|
||||||
|
|
||||||
# Close connection to DUT
|
|
||||||
dut.receive_thread.exit()
|
|
||||||
dut.port_inst.close()
|
|
||||||
|
|
||||||
# Run the example python script
|
|
||||||
script_path = os.path.join(os.getenv('IDF_PATH'), 'examples', 'storage', 'parttool', 'parttool_example.py')
|
|
||||||
|
|
||||||
binary_path = ''
|
|
||||||
for flash_file in dut.app.flash_files:
|
|
||||||
if 'parttool.bin' in flash_file[1]:
|
|
||||||
binary_path = flash_file[1]
|
|
||||||
break
|
|
||||||
|
|
||||||
subprocess.check_call([sys.executable, script_path, '--binary', binary_path, '--port', dut.port])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_parttool()
|
|
28
examples/storage/parttool/pytest_parttool_example.py
Normal file
28
examples/storage/parttool/pytest_parttool_example.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_examples_parttool(dut: Dut) -> None:
|
||||||
|
# Verify factory firmware
|
||||||
|
dut.expect('Partitions Tool Example')
|
||||||
|
dut.expect('Example end')
|
||||||
|
|
||||||
|
# Close connection to DUT
|
||||||
|
dut.pexpect_proc.terminate()
|
||||||
|
dut.serial.stop_redirect_thread()
|
||||||
|
|
||||||
|
# Run the example python script
|
||||||
|
idf_path = os.getenv('IDF_PATH')
|
||||||
|
assert idf_path is not None
|
||||||
|
script_path = os.path.join(idf_path, 'examples', 'storage', 'parttool', 'parttool_example.py')
|
||||||
|
binary_path = os.path.join(dut.app.binary_path, 'parttool.bin')
|
||||||
|
subprocess.check_call([sys.executable, script_path, '--binary', binary_path, '--port', dut.serial.port])
|
37
examples/storage/sd_card/sdmmc/pytest_sdmmc_card_example.py
Normal file
37
examples/storage/sd_card/sdmmc/pytest_sdmmc_card_example.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.sdcard_sdmode
|
||||||
|
def test_examples_sd_card_sdmmc(dut: Dut) -> None:
|
||||||
|
dut.expect('example: Initializing SD card', timeout=20)
|
||||||
|
dut.expect('example: Using SDMMC peripheral', timeout=10)
|
||||||
|
|
||||||
|
# Provide enough time for possible SD card formatting
|
||||||
|
dut.expect('Filesystem mounted', timeout=60)
|
||||||
|
|
||||||
|
# These lines are matched separately because of ASCII color codes in the output
|
||||||
|
name = dut.expect(re.compile(rb'Name: (\w+)\r'), timeout=10).group(1).decode()
|
||||||
|
_type = dut.expect(re.compile(rb'Type: (\S+)'), timeout=10).group(1).decode()
|
||||||
|
speed = dut.expect(re.compile(rb'Speed: (\S+)'), timeout=10).group(1).decode()
|
||||||
|
size = dut.expect(re.compile(rb'Size: (\S+)'), timeout=10).group(1).decode()
|
||||||
|
|
||||||
|
logging.info('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
|
||||||
|
|
||||||
|
message_list = ('Opening file /sdcard/hello.txt',
|
||||||
|
'File written',
|
||||||
|
'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
|
||||||
|
'Reading file /sdcard/foo.txt',
|
||||||
|
"Read from file: 'Hello {}!'".format(name),
|
||||||
|
'Card unmounted')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(msg, timeout=10)
|
@ -1,36 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
from tiny_test_fw import Utility
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='UT_T1_SDMODE')
|
|
||||||
def test_examples_sd_card_sdmmc(env, extra_data): # type: (ttfw_idf.Env.Env, None ) -> None
|
|
||||||
|
|
||||||
dut = env.get_dut('sd_card', 'examples/storage/sd_card/sdmmc')
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect('example: Initializing SD card', timeout=20)
|
|
||||||
dut.expect('example: Using SDMMC peripheral', timeout=10)
|
|
||||||
|
|
||||||
# Provide enough time for possible SD card formatting
|
|
||||||
dut.expect('Filesystem mounted', timeout=60)
|
|
||||||
|
|
||||||
# These lines are matched separately because of ASCII color codes in the output
|
|
||||||
name = dut.expect(re.compile(r'Name: (\w+)\r'), timeout=10)[0]
|
|
||||||
_type = dut.expect(re.compile(r'Type: (\S+)'), timeout=10)[0]
|
|
||||||
speed = dut.expect(re.compile(r'Speed: (\S+)'), timeout=10)[0]
|
|
||||||
size = dut.expect(re.compile(r'Size: (\S+)'), timeout=10)[0]
|
|
||||||
|
|
||||||
Utility.console_log('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
|
|
||||||
|
|
||||||
dut.expect_all('Opening file /sdcard/hello.txt',
|
|
||||||
'File written',
|
|
||||||
'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
|
|
||||||
'Reading file /sdcard/foo.txt',
|
|
||||||
"Read from file: 'Hello {}!'".format(name),
|
|
||||||
'Card unmounted',
|
|
||||||
timeout=10)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_sd_card_sdmmc()
|
|
39
examples/storage/sd_card/sdspi/pytest_sdspi_card_example.py
Normal file
39
examples/storage/sd_card/sdspi/pytest_sdspi_card_example.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3 # no runner available at the moment
|
||||||
|
@pytest.mark.esp32s2
|
||||||
|
@pytest.mark.sdcard_spimode
|
||||||
|
def test_examples_sd_card_sdmmc(dut: Dut) -> None:
|
||||||
|
dut.expect('example: Initializing SD card', timeout=20)
|
||||||
|
dut.expect('example: Using SPI peripheral', timeout=20)
|
||||||
|
|
||||||
|
# Provide enough time for possible SD card formatting
|
||||||
|
dut.expect('Filesystem mounted', timeout=60)
|
||||||
|
|
||||||
|
# These lines are matched separately because of ASCII color codes in the output
|
||||||
|
name = dut.expect(re.compile(rb'Name: (\w+)\r'), timeout=20).group(1).decode()
|
||||||
|
_type = dut.expect(re.compile(rb'Type: (\S+)'), timeout=20).group(1).decode()
|
||||||
|
speed = dut.expect(re.compile(rb'Speed: (\S+)'), timeout=20).group(1).decode()
|
||||||
|
size = dut.expect(re.compile(rb'Size: (\S+)'), timeout=20).group(1).decode()
|
||||||
|
|
||||||
|
logging.info('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
|
||||||
|
|
||||||
|
message_list = ('Opening file /sdcard/hello.txt',
|
||||||
|
'File written',
|
||||||
|
'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
|
||||||
|
'Reading file /sdcard/foo.txt',
|
||||||
|
"Read from file: 'Hello {}!'".format(name),
|
||||||
|
'Card unmounted')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(msg, timeout=20)
|
@ -1,36 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
from tiny_test_fw import Utility
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='UT_T1_SPIMODE', target=['esp32', 'esp32s2', 'esp32c3'])
|
|
||||||
def test_examples_sd_card_sdspi(env, extra_data): # type: (ttfw_idf.Env.Env, None ) -> None
|
|
||||||
|
|
||||||
dut = env.get_dut('sd_card', 'examples/storage/sd_card/sdspi')
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect('example: Initializing SD card', timeout=20)
|
|
||||||
dut.expect('example: Using SPI peripheral', timeout=20)
|
|
||||||
|
|
||||||
# Provide enough time for possible SD card formatting
|
|
||||||
dut.expect('Filesystem mounted', timeout=60)
|
|
||||||
|
|
||||||
# These lines are matched separately because of ASCII color codes in the output
|
|
||||||
name = dut.expect(re.compile(r'Name: (\w+)\r'), timeout=20)[0]
|
|
||||||
_type = dut.expect(re.compile(r'Type: (\S+)'), timeout=20)[0]
|
|
||||||
speed = dut.expect(re.compile(r'Speed: (\S+)'), timeout=20)[0]
|
|
||||||
size = dut.expect(re.compile(r'Size: (\S+)'), timeout=20)[0]
|
|
||||||
|
|
||||||
Utility.console_log('Card {} {} {}MHz {} found'.format(name, _type, speed, size))
|
|
||||||
|
|
||||||
dut.expect_all('Opening file /sdcard/hello.txt',
|
|
||||||
'File written',
|
|
||||||
'Renaming file /sdcard/hello.txt to /sdcard/foo.txt',
|
|
||||||
'Reading file /sdcard/foo.txt',
|
|
||||||
"Read from file: 'Hello {}!'".format(name),
|
|
||||||
'Card unmounted',
|
|
||||||
timeout=20)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_sd_card_sdspi()
|
|
23
examples/storage/spiffs/pytest_spiffs_example.py
Normal file
23
examples/storage/spiffs/pytest_spiffs_example.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_examples_spiffs(dut: Dut) -> None:
|
||||||
|
message_list = (rb'example: Initializing SPIFFS',
|
||||||
|
rb'example: Partition size: total: \d+, used: \d+',
|
||||||
|
rb'example: Opening file',
|
||||||
|
rb'example: File written',
|
||||||
|
rb'example: Renaming file',
|
||||||
|
rb'example: Reading file',
|
||||||
|
rb'example: Read from file: \'Hello World!\'',
|
||||||
|
rb'example: SPIFFS unmounted')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(re.compile(msg), timeout=60)
|
@ -1,23 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_spiffs(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('spiffs', 'examples/storage/spiffs')
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect_all('example: Initializing SPIFFS',
|
|
||||||
re.compile(r'example: Partition size: total: \d+, used: \d+'),
|
|
||||||
'example: Opening file',
|
|
||||||
'example: File written',
|
|
||||||
'example: Renaming file',
|
|
||||||
'example: Reading file',
|
|
||||||
'example: Read from file: \'Hello World!\'',
|
|
||||||
'example: SPIFFS unmounted',
|
|
||||||
timeout=60)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_spiffs()
|
|
@ -1,17 +1,17 @@
|
|||||||
from __future__ import print_function
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import ttfw_idf
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
@pytest.mark.esp32
|
||||||
def test_examples_spiffsgen(env, extra_data):
|
@pytest.mark.esp32c3
|
||||||
|
def test_spiffsgen_example(dut: Dut) -> None:
|
||||||
# Test with default build configurations
|
# Test with default build configurations
|
||||||
dut = env.get_dut('spiffsgen', 'examples/storage/spiffsgen')
|
|
||||||
dut.start_app()
|
|
||||||
|
|
||||||
base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'spiffs_image')
|
base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'spiffs_image')
|
||||||
|
|
||||||
# Expect hello.txt is read successfully
|
# Expect hello.txt is read successfully
|
||||||
@ -22,7 +22,3 @@ def test_examples_spiffsgen(env, extra_data):
|
|||||||
with open(os.path.join(base_dir, 'sub', 'alice.txt'), 'rb') as alice_txt:
|
with open(os.path.join(base_dir, 'sub', 'alice.txt'), 'rb') as alice_txt:
|
||||||
alice_md5 = hashlib.md5(alice_txt.read()).hexdigest()
|
alice_md5 = hashlib.md5(alice_txt.read()).hexdigest()
|
||||||
dut.expect('Computed MD5 hash of alice.txt: ' + alice_md5)
|
dut.expect('Computed MD5 hash of alice.txt: ' + alice_md5)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_spiffsgen()
|
|
@ -0,0 +1,24 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.esp32
|
||||||
|
@pytest.mark.esp32c3
|
||||||
|
def test_wear_levelling_example(dut: Dut) -> None:
|
||||||
|
|
||||||
|
message_list = ('example: Mounting FAT filesystem',
|
||||||
|
'example: Opening file',
|
||||||
|
'example: File written',
|
||||||
|
'example: Reading file',
|
||||||
|
re.compile(str.encode('example: Read from file: \'written using ESP-IDF \\S+\'')),
|
||||||
|
'example: Unmounting FAT filesystem',
|
||||||
|
'example: Done')
|
||||||
|
|
||||||
|
for msg in message_list:
|
||||||
|
dut.expect(msg, timeout=20)
|
@ -1,22 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
import ttfw_idf
|
|
||||||
|
|
||||||
|
|
||||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
|
||||||
def test_examples_wear_levelling(env, extra_data):
|
|
||||||
|
|
||||||
dut = env.get_dut('wear_levelling', 'examples/storage/wear_levelling')
|
|
||||||
dut.start_app()
|
|
||||||
dut.expect_all('example: Mounting FAT filesystem',
|
|
||||||
'example: Opening file',
|
|
||||||
'example: File written',
|
|
||||||
'example: Reading file',
|
|
||||||
re.compile(r'example: Read from file: \'written using ESP-IDF \S+\''),
|
|
||||||
'example: Unmounting FAT filesystem',
|
|
||||||
'example: Done',
|
|
||||||
timeout=20)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_examples_wear_levelling()
|
|
@ -51,6 +51,9 @@ markers =
|
|||||||
wifi_high_traffic: wifi high traffic runners
|
wifi_high_traffic: wifi high traffic runners
|
||||||
wifi_wlan: wifi runner with a wireless NIC
|
wifi_wlan: wifi runner with a wireless NIC
|
||||||
xtal_26mhz: runner with 26MHz xtal on board
|
xtal_26mhz: runner with 26MHz xtal on board
|
||||||
|
external_flash: external flash memory connected via VSPI (FSPI)
|
||||||
|
sdcard_sdmode: sdcard running in SD mode
|
||||||
|
sdcard_spimode: sdcard running in SPI mode
|
||||||
|
|
||||||
# multi-dut markers
|
# multi-dut markers
|
||||||
multi_dut_generic: tests should be run on generic runners, at least have two duts connected.
|
multi_dut_generic: tests should be run on generic runners, at least have two duts connected.
|
||||||
|
Loading…
Reference in New Issue
Block a user