From patchwork Sat Mar 14 23:16:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1992 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530276; bh=Np1QRghToR0/QNcA+b5pIH0gO0bo6CrCceDcEDcq5EM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ihYe+xRii4q8IcDrjxrsjj+XAjrcCqP2wIUGMl2hpYM3lWI8xCohm777QZ3SevoRC cHisY88gvQ2HnUStrY0dkHqyfvkC37rSwL4V+EptuR3lcr1VouOBFF1O1iaJkOOXEc H7ycp43jfKTexrXLd1eBe3h3yNdFEcGgjeAUmsVNKqGbSCisRrTq2I74oOLvLTATwm RLWarPm6N0mUow3jAfuQHHBCFz1+gNib8W3M3wA2nUxWoxmR7vxSZyuQq4Ao/OSI9W XyCjXsOq/9ThwUq7Tq2hnBzMRd7p6rms931p5fP/BkPrc8zjSkKA0dYW8Uzz/SgNU/ kMVXpcXgW/+yw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 31C346A03D for ; Sat, 14 Mar 2026 17:17:56 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id uvlOzrf517lB for ; Sat, 14 Mar 2026 17:17:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530274; bh=Np1QRghToR0/QNcA+b5pIH0gO0bo6CrCceDcEDcq5EM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=W61UKCpMx6DgNkPIlYz1xwO9DICyUaEKrCfzAztnsTsy2dDISxZeyJ4DbYoZCX3bz KOTOQjy2L0U8UoQHvaCRvLBsquAon1wU9aSDT8ucLu07D1ctJCFANeWzmGik+d3y7q MMapVs0ogj6WRlTAcqVhZ0UOFvzfPNwoZudGRU8l2ztuV5wD3+s0c3ZV9dr1L+EPwn FmYPZJgEPUZEXuU+PgBzmEFCe528skODTbFkWKSrjC0qIX7PMdI98Nt4fDpfaKGFk1 XlYj3dBxi2Ls/IsS7B76/S36ediNbsq3mmn/VrlQXi0oNZHM8YpmLjjunJimQKqttK 9kv149uevixfQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EF0E36A053 for ; Sat, 14 Mar 2026 17:17:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530270; bh=F8gvVED2ZyjEdFZ5f8pAZ5UhDDQ9nTw1pONmCMKl+KI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g2TCgruD6BFKfn6HC+To+e1/Nxq++9mXn1FHv3wcNDlqxiG57Y2c3w3itVrKfPmZ8 bKr2KXRQFC0DPPqd3CwY9BSuLkCtBSeTjxrF911QLBOW00OHIj9ZhaYiKEXlvSGOy8 PjH6lo8m27XaYh/UTAmHIrWjOYZUfaMm7ES3rUPvI6gv26qqxdKa+CrfPYwo/Va8Lw XaAYrWVFs7ulrd7strT5I9SKenkQXYdfICqKBgcxZvBewJ11MvA1FLv9cEy2VeKN1Q 5J7Pvgs7vaC1+FnuM3n2eGRxoBBVFCx+5Mn+k/RRPlO2cnmyHz2eH4NmXarU2Yx3X7 9pPBvxhlrVEQw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 416716A057; Sat, 14 Mar 2026 17:17:50 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id S8JECGFKkk1y; Sat, 14 Mar 2026 17:17:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530267; bh=mBHzfWxCQ3inDr8mblE7vwNg93Wk9/Rjwn5Lxu1uAgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fa6eHHV7x8hdD0wdHIkhNYd0k+pBqcs9OET5GYnrB01zwh1BeNUnLMRSxmTnBC3oH vk86p1qW59vfqhcBzw1Ns8m+znFi2Iy7ZEYDYBoMQrwX0cTVxdT6r3tQgmLjawL5UF 7IAQjvATxFWqgUjAAbdfR8WM3IvWhceZfIyo4E82622KbBlFo0cr3JJjNxq9xaS8JW /zsXuepKiuyBN/IzgOiCu0Rn7HUPCtSLVykCLxoCwu+pIau+3b7mXKzsnPcpqWSwQG Cf9DbbT4/eOgmj8LZZmoO7bsv37xjNKKFBExwLJi6MIlA0vBI15dwQjN/DBfmPZyWd 9fglcSlqaU+lA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 221616A033; Sat, 14 Mar 2026 17:17:47 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sat, 14 Mar 2026 17:16:10 -0600 Message-ID: <20260314231618.338113-20-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260314231618.338113-1-sjg@u-boot.org> References: <20260314231618.338113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: R4Q4AFQAGAXLU7266T6HYHE4PP6HHXLB X-Message-ID-Hash: R4Q4AFQAGAXLU7266T6HYHE4PP6HHXLB X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 19/19] test: Save and restore bootstage record count in FIT tests List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a preserve_bootstage() context-manager helper in the pytest utils module, and use it in TestFitImage which runs bootm and is the main consumer of bootstage records. Also save and restore the bootstage record count in test_pre_run() and test_post_run() for ut tests which run multiple tests within a single 'ut' command invocation. Signed-off-by: Simon Glass --- include/test/test.h | 2 ++ test/py/tests/test_fit.py | 6 ++++++ test/py/utils.py | 18 ++++++++++++++++++ test/test-main.c | 5 +++++ 4 files changed, 31 insertions(+) diff --git a/include/test/test.h b/include/test/test.h index c3b251e2cd4..b81cab4d7a4 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -92,6 +92,7 @@ struct ut_arg { * @force_run: true to run tests marked with the UTF_MANUAL flag * @workers: Number of parallel workers, 0 if not sharding tests * @worker_id: ID of this worker (0 to workers-1) + * @old_bootstage_count: bootstage record count saved before each test * @old_bloblist: stores the old gd->bloblist pointer * @soft_fail: continue execution of the test even after it fails * @expect_str: Temporary string used to hold expected string value @@ -128,6 +129,7 @@ struct unit_test_state { bool force_run; int workers; int worker_id; + uint old_bootstage_count; void *old_bloblist; bool soft_fail; char expect_str[1024]; diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index ed18ff68825..6fb76196e16 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -140,6 +140,12 @@ class TestFitImage: - run code coverage to make sure we are testing all the code """ + @pytest.fixture(autouse=True) + def save_bootstage(self, ubman): + """Save and restore bootstage around each test.""" + with utils.preserve_bootstage(ubman): + yield + def make_fname(self, ubman, leaf): """Make a temporary filename diff --git a/test/py/utils.py b/test/py/utils.py index 083a3feddc2..9097f158496 100644 --- a/test/py/utils.py +++ b/test/py/utils.py @@ -14,8 +14,26 @@ import signal import sys import time import re +from contextlib import contextmanager import pytest +@contextmanager +def preserve_bootstage(ubman): + """Context manager to save and restore bootstage record count. + + Some commands (e.g. bootm) add bootstage records with unique IDs. These + accumulate across tests in a pytest session and can fill the bootstage + table. Use this around tests that trigger such commands. + + Args: + ubman (ConsoleBase): U-Boot console connection + """ + ubman.run_command('bootstage save') + try: + yield + finally: + ubman.run_command('bootstage restore') + def md5sum_data(data): """Calculate the MD5 hash of some data. diff --git a/test/test-main.c b/test/test-main.c index 5db35b59760..77223cfbcb7 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -7,6 +7,7 @@ #define LOG_CATEGORY LOGC_TEST #include +#include #include #include #include @@ -560,6 +561,8 @@ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test) gd_set_bloblist(NULL); } + uts->old_bootstage_count = bootstage_get_rec_count(); + if (!(test->flags & UTF_NO_SILENT)) ut_silence_console(uts); @@ -589,6 +592,8 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test) log_debug("restore bloblist %p\n", gd_bloblist()); } + bootstage_set_rec_count(uts->old_bootstage_count); + blkcache_free(); return 0;