From patchwork Mon Mar 16 18:30:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2022 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=1773685890; bh=ZJZB+1xorS0ePm/jUp9nNaAKFIPLUtKcJG49J4VaYPg=; 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=v9A2Y9iVezzIO+6EKZrMTBDNRFsTb4sv6xo+ai+r5Xft9mcw7yWmphPShd8QZbX+y fZzKomOTieOgVBzqxAU2iNqTqEhm4i3IwuPdoOOE8HN/4ggSL/Gh+dqsnFfVKVL5ej ZrxcRwALrLVHTjW3ZFCF6+l7bR73z3kzdE5L4Cr2MnbaUSjCxR2BVS+vOEUk6PTVo4 soOMVTbCL/8lGgFp4EFjNXWJUD200M1X9o2Ged3gZLrbYa8kFxtYFAQrRO00i2uV2A q7BV3e9QVhvbZkci9SuMhPxs+xCre46NdZKqg8cytRuOxJxmY+qtKwSylnN1gn4FI6 17uw2ybcMrncg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 96C956A0B6 for ; Mon, 16 Mar 2026 12:31:30 -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 FwXdmRObNO0e for ; Mon, 16 Mar 2026 12:31:30 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685888; bh=ZJZB+1xorS0ePm/jUp9nNaAKFIPLUtKcJG49J4VaYPg=; 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=bSHEsgGOp4Qeq2uUZm/wRfqt5cMUMQkUOPkStJpcLGX3w0mS3TsPxrvi7D0WqfK80 8B31LgTNs489FVxKgT0LNOA5/OgdQ7Ej8gUhvYfPCc3ryJP2UpTeFYR72+YCcApPUs +lB64HSvRar6d3d/ljynzmTWPzybdoJTi2kITp8fj28W/uEBElh9RdVReihjbPpUs9 rsUmnd7PP//ByMy7RcOIc6Twzv1BUhcZOHKkogyCJozEdgCuhP6g318lAXQGajtIOf SENXFEzglJzWkxlgmbzvbZnZdGLRGavrtioldVEv2+TBZyHteljRzvoQs+PGN8sngT rYWwbiAe+DB+w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93ACF6A0BE for ; Mon, 16 Mar 2026 12:31:28 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685882; bh=IE+waU+nj5oo5PCB4DYcwQvXeyRGYj1tGt2ts4IHYvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICaY3rPWZSNHquL4zGExj4DzwPLKZVNEur4UQFT1GNNuNgTu3vgLgpSxW4tgscYA3 rgnbzlRyJwZGWErbCMyMje+hV/za0rbxBmFhspHfUrulKKeL3Qy9OVI558alroNqNO Z15L9eRor32bCOjtkqsyjPjkHtiW8n+EE+HXJBbEIuz3jQt+KkNoucE+gVYDUxw6xu vhsA4LRwd3LqLJC7nkK+HDcPb4SAk3Oz6EWZyZqZ5Is23N9wVoO5fH8JNdKJNfRjE1 socJb2N9HD9Ez3rIB9ya6oQDZ3mbY1ZFl+FGTD/GDEC9dQsj6g/XUDsK6EuAKUfrkh hMjgN3XDSBdhg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8BCCA6A09F; Mon, 16 Mar 2026 12:31:22 -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 hSgI5TAdPldG; Mon, 16 Mar 2026 12:31:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685880; bh=hWkd8UCy/Cg0n3zE92xZKZsIaWz814mAEiu5fWdT5Nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aO4XpTdbmpJYU/MAkMTF91Fuw0unn4hrwXuS3VIoP7QoXak41/eNuBWeMORgW/sLV GUrgCO/vtrzT4x/W78V6D/wZGyTPDfWGZroPB7xMpLHU7EDr2MYluhXsfa7hsbWZX2 GnBI4tl3XHqqPJx3jMYncuVTYrA1YFaWEO9spp3u6Clsbk4k5XIza1flEeM/Dv3VWE 5u3rI4WeM0MkV4uCfR9w7+O6ANeAXp5fe/bM5AsO2Mze1y9kcCvTu48fR89EjJwnXG JhkXJV8gxIxkPTqV+HZtYVAeRWJ+g+no4L7equU5x2Diwwr/DLEcnqfJGnsks4nBWw +z3UnOzUw3SGA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 14CC46A078; Mon, 16 Mar 2026 12:31:20 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:33 -0600 Message-ID: <20260316183050.3855921-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FQQJM6RLH2AYILFFPWP2CA3N6ESO3IOJ X-Message-ID-Hash: FQQJM6RLH2AYILFFPWP2CA3N6ESO3IOJ 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 10/17] test: py: Add --leak-check option to pytest 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 --leak-check flag to the pytest command line that passes -L to every ut invocation, enabling per-test heap-leak detection. Leaked allocations are printed with their address, size and caller backtrace. For example: test/py/test.py -B sandbox --leak-check -k dm_test_acpi_bgrt Signed-off-by: Simon Glass --- test/py/conftest.py | 3 +++ test/py/tests/test_ut.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 47a0d112e51..303a697d76a 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -106,6 +106,8 @@ def pytest_addoption(parser): help='Disable console timeout (useful for debugging)') parser.addoption('--no-full', default=False, action='store_true', help='Skip flat-tree tests (run live-tree only)') + parser.addoption('--leak-check', default=False, action='store_true', + help='Check for memory leaks around each unit test') parser.addoption('--malloc-dump', default=None, help='Write malloc dump to file on exit') @@ -364,6 +366,7 @@ def pytest_configure(config): ubconfig.allow_exceptions = config.getoption('allow_exceptions') ubconfig.no_timeout = config.getoption('no_timeout') ubconfig.no_full = config.getoption('no_full') + ubconfig.leak_check = config.getoption('leak_check') ubconfig.malloc_dump = config.getoption('malloc_dump') env_vars = ( diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index e64ccd407a0..21a948b4ac6 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -142,11 +142,13 @@ def test_ut(ubman, ut_subtest): execute command 'ut foo bar' """ + flags = '-L ' if ubman.config.leak_check else '' + if ut_subtest == 'hush hush_test_simple_dollar': # ut hush hush_test_simple_dollar prints "Unknown command" on purpose. with ubman.disable_check('unknown_command'): - output = ubman.run_command('ut ' + ut_subtest) + output = ubman.run_command(f'ut {flags}' + ut_subtest) assert 'Unknown command \'quux\' - try \'help\'' in output else: - output = ubman.run_command('ut ' + ut_subtest) + output = ubman.run_command(f'ut {flags}' + ut_subtest) assert output.endswith('failures: 0')