From patchwork Sun Dec 14 17:54:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 905 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=1765734952; bh=WuZAog6ipOxDEVt1dzXj4xyRcxrJJpiMfVkRDrQLRHM=; 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=TC8GFGIkQZ1ZECc4IVqokcD8CHvl2T0geATX7ZJCfT7ITGpvMu6aaRiKJF6kJu8la o3k7KCrLwYt5YK94JtbeRt20J9AJ5SCRQiu2B2uQku+gdAFYr9PAfDcU4o9FGx+vTM KarY7I5XoLYCCF31TP6NJZXKL6Rke+7iZ1G6S80fXakRaDvGkQk4DtMrcPp/GujBUC ldimy4jOXOCAp5PecrIgbSlsdrEK9Wm253SrAZgYeqcGsoTDU+LDmWZ0fqND6ci3qI 77ecm5bKveVzpJYuJ3wcbgd5p+C1PB8S6Lv9PFgbUtq+CF8m/tmUs3DTjR2KDIAZnM lp6eXiC8mYayA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D396E68AEA for ; Sun, 14 Dec 2025 10:55:52 -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 HPG6yFmqi-mT for ; Sun, 14 Dec 2025 10:55:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734952; bh=WuZAog6ipOxDEVt1dzXj4xyRcxrJJpiMfVkRDrQLRHM=; 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=TC8GFGIkQZ1ZECc4IVqokcD8CHvl2T0geATX7ZJCfT7ITGpvMu6aaRiKJF6kJu8la o3k7KCrLwYt5YK94JtbeRt20J9AJ5SCRQiu2B2uQku+gdAFYr9PAfDcU4o9FGx+vTM KarY7I5XoLYCCF31TP6NJZXKL6Rke+7iZ1G6S80fXakRaDvGkQk4DtMrcPp/GujBUC ldimy4jOXOCAp5PecrIgbSlsdrEK9Wm253SrAZgYeqcGsoTDU+LDmWZ0fqND6ci3qI 77ecm5bKveVzpJYuJ3wcbgd5p+C1PB8S6Lv9PFgbUtq+CF8m/tmUs3DTjR2KDIAZnM lp6eXiC8mYayA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C214768AC0 for ; Sun, 14 Dec 2025 10:55:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734950; bh=kwsUquihrUSZxl8fvvOBzJ2MydYOh1tAnW8T/D2u4gQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oGBLpVC7sa7w+AUbTis4BZfnyz00582lfd4kfUU6XOzKcUPOvslrLeNuMiBu31qev M9mF0W+gCh8FxvYPNqm2vAieK0cnr/gXSGKqswhwv9RS+DINOT36haVgp7Q83Wd/Ci VvGiY9XXAg22bJQlg7eH9ZXC5BYEUjl2vHCgxGSVHo6wrrWxL51dXrWRhJI/IKVwqt nYvFVrXoSu9mjuQj4h7NhSPfC3+0d9eiuY17gFHkwIdV6rsqcpuokNHivKBWzSOvXN Nr0uX203rThti1Ad0s911AyWfnBosm4SKePQu90+t4Of4rvT0QjKLmPXdxBo4WfSFW CgBdU3J6AI/lA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 80BDB68A84; Sun, 14 Dec 2025 10:55:50 -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 tqGv9TApfTZo; Sun, 14 Dec 2025 10:55:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734946; bh=D1UJvzitjqxgNMv62mrsG53M87plpI5zky5IQRJztWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBhANKvrLpzaxc89AunXlnL0DHEwHA4UDRRAm2FwbLTHpahVxiHt27k4GR0fAF0AH HB8KChxgukoXm9gGSkVJ8xHbZwhZ2r8EcB5W2o1+Tt2Zj8S4avhErGYucpRtTRAwwj OvSFzaKkrGStIf8BVjV7mYGxmhfcHN03Fvt/pogD4tu0RAS5F0WA0Kzoa9F+SkyWpx MrWp8ylwiwPXsOyV+YhuxvxVIR/4cwM5o7AkgXyfI4DIE4Q+A364EvgIaiCBaGNqN1 xFDGKmg8rnR7pKpAtANSrJ+XBrhlXr6liICgRmMMtb5WdKLoPhScWsIOBnm9xfM9aQ 8ttUhUkHzrBRg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 212BA68A89; Sun, 14 Dec 2025 10:55:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 14 Dec 2025 10:54:34 -0700 Message-ID: <20251214175449.3799539-13-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: PSSFVKLWQO5BYW537CIDERZ6J67QFZ7G X-Message-ID-Hash: PSSFVKLWQO5BYW537CIDERZ6J67QFZ7G 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 12/21] test: Add a macro to declare unit tests with arguments 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 UNIT_TEST_ARGS() macro to declare and register a test with inline argument definitions. The variadic arguments use struct ut_arg_def and a NULL terminator is added automatically to the list. Example usage: static int my_test(struct unit_test_state *uts) { ... } UNIT_TEST_ARGS(my_test, UTF_CONSOLE, my_suite, { "path", UT_ARG_STR }, { "count", UT_ARG_INT, UT_ARGF_OPTIONAL, { .vint = 10 } }); Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- include/test/test.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/test/test.h b/include/test/test.h index 5ead1200a40..cb0539e3bdd 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -47,6 +47,7 @@ enum ut_arg_type { * * @name: Name of the argument (points to ut_arg_def.name) * @type: Type of the argument + * @provided: true if value was provided on command line * @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) @@ -54,6 +55,7 @@ enum ut_arg_type { struct ut_arg { const char *name; enum ut_arg_type type; + bool provided; union { long vint; bool vbool; @@ -178,12 +180,14 @@ struct ut_arg_def { * @name: Name of test * @func: Function to call to perform test * @flags: Flags indicated pre-conditions for test + * @arg_defs: Argument definitions (NULL-terminated array), or NULL */ struct unit_test { const char *file; const char *name; int (*func)(struct unit_test_state *state); int flags; + const struct ut_arg_def *arg_defs; }; /** @@ -235,6 +239,33 @@ struct unit_test { .func = _name, \ } +/** + * UNIT_TEST_ARGS() - create unit test entry with inline argument definitions + * + * Like UNIT_TEST() but allows specifying argument definitions inline. + * The variadic arguments are struct ut_arg_def initializers. The NULL + * terminator is added automatically by the macro. + * + * Example: + * UNIT_TEST_ARGS(my_test, UTF_CONSOLE, my_suite, + * { "path", UT_ARG_STR }, + * { "count", UT_ARG_INT, UT_ARGF_OPTIONAL, { .vint = 10 } }); + * + * @_name: Test function name + * @_flags: Test flags (see enum ut_flags) + * @_suite: Test suite name + * @...: Argument definitions (struct ut_arg_def initializers) + */ +#define UNIT_TEST_ARGS(_name, _flags, _suite, ...) \ + static const struct ut_arg_def _name##_args[] = { __VA_ARGS__, { NULL } }; \ + ll_entry_declare(struct unit_test, _name, ut_ ## _suite) = { \ + .file = __FILE__, \ + .name = #_name, \ + .flags = _flags, \ + .func = _name, \ + .arg_defs = _name##_args, \ + } + /* Get the start of a list of unit tests for a particular suite */ #define UNIT_TEST_SUITE_START(_suite) \ ll_entry_start(struct unit_test, ut_ ## _suite)