From patchwork Sun Dec 14 17:54:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 904 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=1765734947; bh=+C08RbliFRFoZd9tSUHcSiMa0ztwf8voksLf2JI+7Do=; 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=ThK8EURy7XMxkKugUdj4L57aIWZdynC/OLsrZMAIukI2ZKgpu0qFjF1ZhyC5Wuaq/ QUMt26H5JKUdmSLp0NMhSZoXarjDzzyjo9tzw8XLgrxQZQ7hb8oKbB8jI4OM4Z2mMo ChMhBB7AiElO/cdqAE7VLqfpsGx4IwtKz12hi2pSp485sNE4fpG4+KQSnOEQjy2O3r aaVEqTT7iG/4PccOUbQmQx5RHaUBE6dKVbHDlIy4xhT/7VwQBQBBD2OW058exe4532 jd5MImAj/BRDipyZBQv5b5kvqJTwL2a8wPoND7Gw3WR826jVMANjPLp2jrSndZ98vz sN9XGz+pmukDg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 70B3768B0B for ; Sun, 14 Dec 2025 10:55:47 -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 LPQeLY1bwxCq for ; Sun, 14 Dec 2025 10:55:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734947; bh=+C08RbliFRFoZd9tSUHcSiMa0ztwf8voksLf2JI+7Do=; 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=ThK8EURy7XMxkKugUdj4L57aIWZdynC/OLsrZMAIukI2ZKgpu0qFjF1ZhyC5Wuaq/ QUMt26H5JKUdmSLp0NMhSZoXarjDzzyjo9tzw8XLgrxQZQ7hb8oKbB8jI4OM4Z2mMo ChMhBB7AiElO/cdqAE7VLqfpsGx4IwtKz12hi2pSp485sNE4fpG4+KQSnOEQjy2O3r aaVEqTT7iG/4PccOUbQmQx5RHaUBE6dKVbHDlIy4xhT/7VwQBQBBD2OW058exe4532 jd5MImAj/BRDipyZBQv5b5kvqJTwL2a8wPoND7Gw3WR826jVMANjPLp2jrSndZ98vz sN9XGz+pmukDg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6062768ADC for ; Sun, 14 Dec 2025 10:55:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734945; bh=ix4VzLLcRF6GTV90xKu+e/tH0ZB7GojBW5yINCvoXmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NCvIxGtWxuGqpISAXtpVt32/Sci79e/kE2bpZu8UxoPC2KbVTJMnAsrfe2lQUaRvD 28rL0EDzDWEd0axD0XduPHDF7SNTj5hLHHZZavK9JUpzOd+lshyFQnJkTz+OmkkISz M1+FbnijLnAlANqaroOecckTp7rVt45ym2AtnDah1GXaDK9eeGID7kr94+U/MBU2pj bhqQYQwAITciAAygAhFCZQR+46eswBHRFyek/xguyuXVJhWitkyzBA9Yr1DOOB1Afj NmMv8BFR4jsUEdovx0UepqaF+x4erBH0j00E+7/7AfT6Opr1UL69jI5Ek2Zi5kEoED V7QQkaFSt9WfA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D2E0E68A84; Sun, 14 Dec 2025 10:55:45 -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 dIMeg8w9G-VH; Sun, 14 Dec 2025 10:55:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734941; bh=gxAsHmXmQnTaaLwyiqT/SGuN7m0vimyywapuYutudJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CFxQIy0kqNi64MYCMOKOQykXKAv2QAV21hcRE39Y0HL3n3VWsS/hxHSWNsfUHqW74 kQPJRk+P5ZVwrMJcpbv6TQ2/gWs34Ov/6J97sc/4k9vGnAzPUu9zWeIFzmS+ns278/ b4ELyc1bTXtGH4vTl7YsOJQa7KdtWdb9gZoi618swOTErFuHiIF+/kwCI/6nk//dMD VGrmxv3PRcUTVWlq/EaVhTC+COUSLyECsvjMGgTxrblWqoUmecvJn4fpkymmFCMIKB yT4eAc80FuTMrKS84PEJ/CWychuYT1L3xIE8mDIiQY31lCweWG/NRc3O1T51U1UYiq ZmCwjkg70pQew== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 72FFF68A89; Sun, 14 Dec 2025 10:55:41 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 14 Dec 2025 10:54:33 -0700 Message-ID: <20251214175449.3799539-12-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: HPLHC7TQ7WMNKLISIZGABVSUR32XEV44 X-Message-ID-Hash: HPLHC7TQ7WMNKLISIZGABVSUR32XEV44 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 Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/21] test: Add argument-type definitions 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 types for declaring and storing unit test arguments: - enum ut_arg_type: INT, BOOL, STR types - enum ut_arg_flags: OPTIONAL flag for non-required args - struct ut_arg_def: declares expected args with defaults - struct ut_arg: holds parsed argument values This prepares for passing key=value arguments to tests via the 'ut' command instead of needing to use environment variables. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- include/test/test.h | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/include/test/test.h b/include/test/test.h index 086fff1ca26..5ead1200a40 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -27,6 +27,40 @@ struct ut_stats { ulong duration_ms; }; +/** + * enum ut_arg_type - Type of a unit test argument + * + * @UT_ARG_INT: Integer argument (hex with 0x prefix, or decimal) -> vint + * @UT_ARG_BOOL: Boolean argument (0 or 1) -> vbool + * @UT_ARG_STR: String argument -> vstr + */ +enum ut_arg_type { + UT_ARG_INT, + UT_ARG_BOOL, + UT_ARG_STR, +}; + +/** + * struct ut_arg - Parsed unit test argument value + * + * Holds the parsed value of an argument after command-line processing. + * + * @name: Name of the argument (points to ut_arg_def.name) + * @type: Type of the argument + * @vint: Integer value (when type is UT_ARG_INT) + * @vbool: Boolean value (when type is UT_ARG_BOOL) + * @vstr: String value (when type is UT_ARG_STR, points into argv) + */ +struct ut_arg { + const char *name; + enum ut_arg_type type; + union { + long vint; + bool vbool; + const char *vstr; + }; +}; + /* * struct unit_test_state - Entire state of test system * @@ -107,6 +141,37 @@ enum ut_flags { UTF_UNINIT = BIT(14), /* test uninits a suite */ }; +/** + * enum ut_arg_flags - Flags for unit test arguments + * + * @UT_ARGF_OPTIONAL: Argument is optional; use default value if not provided + */ +enum ut_arg_flags { + UT_ARGF_OPTIONAL = BIT(0), +}; + +/** + * struct ut_arg_def - Definition of a unit test argument + * + * Declares an expected argument for a test, including its name, type, + * whether it is optional, and its default value. + * + * @name: Name of the argument (used in key=value matching) + * @type: Type of the argument (int, bool, or string) + * @flags: Argument flags (e.g., UT_ARGF_OPTIONAL) + * @def: Default value (used when argument is optional and not provided) + */ +struct ut_arg_def { + const char *name; + enum ut_arg_type type; + int flags; + union { + long vint; + bool vbool; + const char *vstr; + } def; +}; + /** * struct unit_test - Information about a unit test *