From cf4c4257331f4b638333dcc6321a07dc2d511831 Mon Sep 17 00:00:00 2001 From: "sonika.rathi" Date: Thu, 30 Apr 2026 15:23:03 +0200 Subject: [PATCH] fix(fatfsgen): stabilize host read-flash after UART close in pytest --- .../fatfsgen/pytest_fatfsgen_example.py | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/test_apps/storage/fatfsgen/pytest_fatfsgen_example.py b/tools/test_apps/storage/fatfsgen/pytest_fatfsgen_example.py index e50bdc800ba..3f6ffffcc94 100644 --- a/tools/test_apps/storage/fatfsgen/pytest_fatfsgen_example.py +++ b/tools/test_apps/storage/fatfsgen/pytest_fatfsgen_example.py @@ -6,8 +6,9 @@ import shutil import sys import typing as t from datetime import datetime -from subprocess import run from subprocess import STDOUT +from subprocess import CalledProcessError +from subprocess import run from time import sleep import pytest @@ -177,12 +178,14 @@ def test_examples_fatfsgen(config: str, dut: Dut) -> None: expect('example: Mounting FAT filesystem') if not config_read_only: - expect_all([ - 'example: Opening file', - 'example: File written', - 'example: Reading file', - 'example: Read from file: ' + "'This is written by the device'", - ]) + expect_all( + [ + 'example: Opening file', + 'example: File written', + 'example: Reading file', + 'example: Read from file: ' + "'This is written by the device'", + ] + ) expect('example: Reading file') @@ -199,8 +202,18 @@ def test_examples_fatfsgen(config: str, dut: Dut) -> None: dut.serial.close() sleep(1) - target = ParttoolTarget(dut.serial.port, 1843200) - target.read_partition(PartitionName('storage'), 'temp.img') + # Host read-flash after closing the test UART can fail at very high baud (e.g. exit code 2 on + # 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: run(['python', fatfs_parser_path, '--long-name-support', 'temp.img'], stderr=STDOUT) else: