From patchwork Sun Dec 14 17:54:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 909 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=1765734968; bh=KBDeXJrXl/rz3yUTmBiRMPCah2aXIEpxYdTm6yIeEgk=; 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=D17ytoCw4cf3xkJo/11xdnd3q8sZyc+pLUpadqPUh2aqnvimahxDgvn2/7dtA1LY/ iwqbzNZF0zp3OljZe3gBcmRTqZlj9KyxOEYw2XzF98OxGZS8v7JYH21dc/SoxXiIBT giwOyY4wiSwZi8fv9nSRpxiWPFpaX9o3FVHwhrcePtFetIl9NzTf5awIvDw/9z5ag6 nelIE7I1dgaY4NfbHIepoDMn93L3Nqn0XDGgPuxK5tJCktl5uXJau4AHLTx3qvMooX gBo5BVmmaoo72HmCFlUmBIXagxmnY+tivc/1RONu7WNFn7IU27UT3g2Dc1ODNLtDLF T2Nk3j0yf0zig== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1246168ADF for ; Sun, 14 Dec 2025 10:56:08 -0700 (MST) 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 MYf8aEVTdApn for ; Sun, 14 Dec 2025 10:56:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734968; bh=KBDeXJrXl/rz3yUTmBiRMPCah2aXIEpxYdTm6yIeEgk=; 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=D17ytoCw4cf3xkJo/11xdnd3q8sZyc+pLUpadqPUh2aqnvimahxDgvn2/7dtA1LY/ iwqbzNZF0zp3OljZe3gBcmRTqZlj9KyxOEYw2XzF98OxGZS8v7JYH21dc/SoxXiIBT giwOyY4wiSwZi8fv9nSRpxiWPFpaX9o3FVHwhrcePtFetIl9NzTf5awIvDw/9z5ag6 nelIE7I1dgaY4NfbHIepoDMn93L3Nqn0XDGgPuxK5tJCktl5uXJau4AHLTx3qvMooX gBo5BVmmaoo72HmCFlUmBIXagxmnY+tivc/1RONu7WNFn7IU27UT3g2Dc1ODNLtDLF T2Nk3j0yf0zig== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 010EE68A92 for ; Sun, 14 Dec 2025 10:56:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734966; bh=Hkb5D380grelXrbUtYk+0vzURG7EHF+krdai609dgWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upHIUOFZ7gRVivoRP2eW/6V+UA/BVpZFh65wDUIyx1H18YhBGXtyNlnPRS1qYiyh/ eLI1XgpPQyH0EAnXu0sHaX1uS1x6o8f7aozN4+wA6e9PpudyE0URMNg+Poam8/v1J3 wen5Lup0DxJU+fzcLskHtK6RF6cqdZhv7Go+v6DIJ9GXwrVMoopzDgQb/5hvssCqP9 ThY8sVNyJ286ALrmOE9ImqBmvPOIIt/N/h0ofbMYzH1yXIJBf9e3XzmlzAQhHOz3J9 SJvauDijhOrZohbr013HGuSjWoAREgIg5eCKBqq9HfMtdYiGe6wbw7czBohLYU5vhM WUayuF2ukp12Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F40CD68A92; Sun, 14 Dec 2025 10:56:05 -0700 (MST) 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 4VzixJhw8HDU; Sun, 14 Dec 2025 10:56:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734961; bh=Zh09Q4c87syBNRrze7xWGyCss3cMdMIwYlLgW230AZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CnaqltO52jI7VVkXvvBurHxzfCbp1izAmeQ/dUtTAMROv3gPBvsOFUx4mgeGOa+3R gObp0ShR88j3DkwZQoD+osJUzQJX0p8zGAymgCaf8AWQMhmdojrq7lJbNBwNO0i9ja /PsGF7gpQKHwXsWnIgsvw0v2jNmb5iAAU26Up1d2J7dxNCgh4gPC5YccJbOdUQ5dfX 2KGcZgez6vuqXq9lGCn7wnBy+wdjjumHRiCZwemsc5Y3oKiD/Nqxe6IbEAfWxtujzY wcq3EvjK9yJHRh2PtTMtMfo197XhylTEZQWExjaIRVmL1zg0in9QatO+KiRJZ/OGOw +oKa0bEoYSZCQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 114A268A84; Sun, 14 Dec 2025 10:56:01 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 14 Dec 2025 10:54:38 -0700 Message-ID: <20251214175449.3799539-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251214175449.3799539-1-sjg@u-boot.org> References: <20251214175449.3799539-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BTFTTXPPWGMP5JSHQZ3SINQZI4HQ555M X-Message-ID-Hash: BTFTTXPPWGMP5JSHQZ3SINQZI4HQ555M 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: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 16/21] test: Add a private buffer for 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 priv[] buffer to struct unit_test_state that tests can use for their own data. This avoids the need to allocate memory or use global variables for test-specific state. Co-developed-by: Claude Signed-off-by: Simon Glass --- doc/develop/tests_writing.rst | 14 ++++++++++++++ include/test/test.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/doc/develop/tests_writing.rst b/doc/develop/tests_writing.rst index 41612a9e21b..6842533e2c6 100644 --- a/doc/develop/tests_writing.rst +++ b/doc/develop/tests_writing.rst @@ -486,6 +486,20 @@ ut_check_delta(last) Return the change in free memory since ``last`` was obtained from ``ut_check_free()``. A positive value means more memory has been allocated. +Private buffer +~~~~~~~~~~~~~~ + +Each test has access to a private buffer ``uts->priv`` (256 bytes) for temporary +data. This avoids the need to allocate memory or use global variables:: + + static int my_test(struct unit_test_state *uts) + { + snprintf(uts->priv, sizeof(uts->priv), "/%s", filename); + /* use uts->priv as a path string */ + + return 0; + } + Writing Python tests -------------------- diff --git a/include/test/test.h b/include/test/test.h index 15ed8b37890..2facf5b3675 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -10,6 +10,7 @@ #include #define UT_MAX_ARGS 8 +#define UT_PRIV_SIZE 256 /** * struct ut_stats - Statistics about tests run @@ -95,6 +96,7 @@ struct ut_arg { * @args: Parsed argument values for current test * @arg_count: Number of parsed arguments * @arg_error: Set if ut_str/int/bool() detects a type mismatch + * @priv: Private data for tests to use as needed */ struct unit_test_state { struct ut_stats cur; @@ -124,6 +126,7 @@ struct unit_test_state { struct ut_arg args[UT_MAX_ARGS]; int arg_count; bool arg_error; + char priv[UT_PRIV_SIZE]; }; /* Test flags for each test */