mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(fatfsgen): stabilize host read-flash after UART close in pytest
This commit is contained in:
@@ -4,11 +4,12 @@ import os
|
|||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import typing as t
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from subprocess import run
|
|
||||||
from subprocess import STDOUT
|
from subprocess import STDOUT
|
||||||
|
from subprocess import CalledProcessError
|
||||||
|
from subprocess import run
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_embedded import Dut
|
from pytest_embedded import Dut
|
||||||
@@ -22,7 +23,7 @@ sys.path.append(parttool_dir)
|
|||||||
from parttool import PartitionName, ParttoolTarget # noqa E402 # pylint: disable=C0413
|
from parttool import PartitionName, ParttoolTarget # noqa E402 # pylint: disable=C0413
|
||||||
|
|
||||||
|
|
||||||
FileStructure = t.Dict[str, t.Union[t.Optional[str], 'FileStructure']]
|
FileStructure = dict[str, Union[str, None, 'FileStructure']] # noqa: UP007
|
||||||
|
|
||||||
|
|
||||||
class DirectoryStructureError(Exception):
|
class DirectoryStructureError(Exception):
|
||||||
@@ -69,7 +70,7 @@ def validate_directory_structure(base_path: str, expected_structure: FileStructu
|
|||||||
:raises DirectoryStructureError: If the structure or contents do not match.
|
:raises DirectoryStructureError: If the structure or contents do not match.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def normalize_case(items: t.List[str]) -> t.Dict[str, str]:
|
def normalize_case(items: list[str]) -> dict[str, str]:
|
||||||
return {item.lower(): item for item in items}
|
return {item.lower(): item for item in items}
|
||||||
|
|
||||||
def escape_output(text: str) -> str:
|
def escape_output(text: str) -> str:
|
||||||
@@ -93,7 +94,7 @@ def validate_directory_structure(base_path: str, expected_structure: FileStructu
|
|||||||
|
|
||||||
if isinstance(substructure, str): # Check file content
|
if isinstance(substructure, str): # Check file content
|
||||||
try:
|
try:
|
||||||
with open(full_path, 'r', encoding='utf-8') as file:
|
with open(full_path, encoding='utf-8') as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
if content != substructure:
|
if content != substructure:
|
||||||
raise ContentMismatchError(
|
raise ContentMismatchError(
|
||||||
@@ -141,7 +142,7 @@ def test_examples_fatfsgen(config: str, dut: Dut) -> None:
|
|||||||
dut.expect(msg, timeout=timeout)
|
dut.expect(msg, timeout=timeout)
|
||||||
|
|
||||||
# Expects list of strings sequentially
|
# Expects list of strings sequentially
|
||||||
def expect_all(msg_list: t.List[str], timeout: int = timeout) -> None:
|
def expect_all(msg_list: list[str], timeout: int = timeout) -> None:
|
||||||
for msg in msg_list:
|
for msg in msg_list:
|
||||||
expect(msg, timeout)
|
expect(msg, timeout)
|
||||||
|
|
||||||
@@ -177,12 +178,14 @@ def test_examples_fatfsgen(config: str, dut: Dut) -> None:
|
|||||||
expect('example: Mounting FAT filesystem')
|
expect('example: Mounting FAT filesystem')
|
||||||
|
|
||||||
if not config_read_only:
|
if not config_read_only:
|
||||||
expect_all([
|
expect_all(
|
||||||
'example: Opening file',
|
[
|
||||||
'example: File written',
|
'example: Opening file',
|
||||||
'example: Reading file',
|
'example: File written',
|
||||||
'example: Read from file: ' + "'This is written by the device'",
|
'example: Reading file',
|
||||||
])
|
'example: Read from file: ' + "'This is written by the device'",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
expect('example: Reading file')
|
expect('example: Reading file')
|
||||||
|
|
||||||
@@ -199,8 +202,18 @@ def test_examples_fatfsgen(config: str, dut: Dut) -> None:
|
|||||||
dut.serial.close()
|
dut.serial.close()
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
target = ParttoolTarget(dut.serial.port, 1843200)
|
# Host read-flash after closing the test UART can fail at very high baud (e.g. exit code 2 on
|
||||||
target.read_partition(PartitionName('storage'), 'temp.img')
|
# multi-Mbit reads). Use the same order of magnitude as post-stub flash programming (921600).
|
||||||
|
read_baud = 921600
|
||||||
|
for attempt in range(3):
|
||||||
|
try:
|
||||||
|
target = ParttoolTarget(dut.serial.port, read_baud)
|
||||||
|
target.read_partition(PartitionName('storage'), 'temp.img')
|
||||||
|
break
|
||||||
|
except CalledProcessError:
|
||||||
|
if attempt == 2:
|
||||||
|
raise
|
||||||
|
sleep(2)
|
||||||
if config_long_names:
|
if config_long_names:
|
||||||
run(['python', fatfs_parser_path, '--long-name-support', 'temp.img'], stderr=STDOUT)
|
run(['python', fatfs_parser_path, '--long-name-support', 'temp.img'], stderr=STDOUT)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user