From patchwork Sun Dec 14 17:54:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 907 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=1765734959; bh=Z632tXGVlwt8eOeraTN8UISECp+J4y/x/+tAHjgvSi4=; 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=RXi2DHPMKneKx9IXGGhjQjwMN5RNCJYCS3+EVUG+9EG2Gp+GmuF9jNj8vtpMcmSg8 lR6og/cKlcP1ssK4Shui0aJ16q98q30SlBepOAb0z2ZHwP6+toqZQKTFdGM2o//Jx5 PCm5Vxki6cc/qrJUyW3R5RG6xDA4iEhwzJYPphww0u77uUmO/F9IkI17sAGFcdOnlH x0OlJ9vM6S1mRHtxkLGOFUBE9ID3OKJT8eD1B1NxZBX2DSIoCqgj3IG7exeVl+soWn 5AQVezz9nXPRj1kogLRSNkDHLNBgmhLblr4rdwUsRXvui11GYL2T6yZkSQQEaKz44t +7wmJE4lUyDhA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A311D68A92 for ; Sun, 14 Dec 2025 10:55:59 -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 U_S_-mS_QKvd for ; Sun, 14 Dec 2025 10:55:59 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734958; bh=Z632tXGVlwt8eOeraTN8UISECp+J4y/x/+tAHjgvSi4=; 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=uTg77ZyK40PbRYJG1ecFRj2v0v/8opAVcZbRHX8nlxixeew5Kr65sKoEV0d3qFy5q dN4wm57g+RSf6rzdO+2iCTuOaNTPryUl+gITycPvNeMNfjdQDYEuT/Qxi7WmYOc82Y Z5TgqwqltmeLFNncGHO75GmrCefgsipeKEALqY7ZvXkdmqRrfhl8j1u3l110ijhGV9 INIwODdl8avH0CKbx7P+fca7/rOxSUGd2yNbRdl0VnarfRXeDNws2xh+Anug/XcaKt g85IteVp1l53NFzz827w8q4ek/uYASSR3ZDEoGE0gXAEtxN+9ttK1fnq+qkxWN7H/U X8diVXYwlbC/g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 159E968A84 for ; Sun, 14 Dec 2025 10:55:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734956; bh=nsJpdnM1toGFl7UjcBtX5zqwQdrNvOVwkHPY6kToQvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QsZN54IJr4VHUxKRtlaYoF8B/sqA8CWeQx/mVYSSD5PfU2tXlIkXTHxnFBTQFKNFn ObWwt7CXcXQrzdi1FjU6a8SD33oZN3SVQqVCO9GIIjyQCJFdGkmuLvRsyrZUFlzA2k aENdKwqgh5imYKio7pkOBfQouLL1rVs8db6ERZAohtuDiGtcG2WbZaxjIGkJEimyh2 DsLJ9K9P3gYjlBNuxKdccns7r0S11UmdXlXmxSPWbQ1EKD0jJH8RfE/CiiVruUpE9p HXsB6fibQCVw95+lJVjCfCkiQD67KAK/ADPIj2yAB4TxoAkX3vgaFcUKQFpy4KZqTF zIaC2JVmAm70A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2451168A92; Sun, 14 Dec 2025 10:55:56 -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 6lzzNUw0DpCS; Sun, 14 Dec 2025 10:55:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734955; bh=G5zN5/q5fAf1MTwn+L1K/8YttPid2/EcxepHgyx9W7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d9PvaTJ5Sjy6MJS5n6A/Qju15yj51p2rXxHyAc4CcCQ/2FOMRUabBRScMBbDfNZE6 AOZ69gSM5K+SK62f1G+NLR+bTqpoMw26yW3fZQI1atN6Xg5ph95FfhjenXC+fC+ZLk /pd+zyoVMQnPCS4Rdd87qgtBt0+9ewxn5WAOFYszSdTLb+0MfinKJE7H3rqTscdgeH 7T3Y35lULSMR7uqja8z1JdYQDcazwZnj5v2HYXAQpr4ShvCWnV4/RJ95L5KBb3HP13 Tvo8KUEyywD+zhtDLXIHUrJzymXXFeFkQILPW/UeYCp9ebeQM0H8DM/ROyv5C+pQL/ Cr2OcpvoqTlpA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7401C68A89; Sun, 14 Dec 2025 10:55:55 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 14 Dec 2025 10:54:36 -0700 Message-ID: <20251214175449.3799539-15-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: FW5I3PCTENXTTDZJP76LZLY4SBMTWXRO X-Message-ID-Hash: FW5I3PCTENXTTDZJP76LZLY4SBMTWXRO 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 14/21] test: Enhance the ut command to pass test 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 Update the ut command to permit passing arguments to tests. Usage: ut -f fs test_name key1=value1 key2=value2 Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- doc/usage/cmd/ut.rst | 11 ++++++++++- test/cmd_ut.c | 29 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/doc/usage/cmd/ut.rst b/doc/usage/cmd/ut.rst index 1acf3126680..d8c3cbf496c 100644 --- a/doc/usage/cmd/ut.rst +++ b/doc/usage/cmd/ut.rst @@ -11,7 +11,7 @@ Synopsis :: - ut [-r] [-f] [-I:] [-r] [ | 'all' []] + ut [-r] [-f] [-I:] [ | all []] [...] ut [-s] info Description @@ -37,6 +37,11 @@ test causes another test to fail. If the one test fails, testing stops immediately. +args + Optional arguments to pass to the test, in `name=value` format. These are + used by tests declared with `UNIT_TEST_ARGS()` which define expected + argument names and types. + Typically the command is run on :ref:`arch/sandbox/sandbox:sandbox` since it includes a near-complete set of emulators, no code-size limits, many CONFIG options enabled and runs easily in CI without needing QEMU. It is also possible @@ -201,3 +206,7 @@ Run a selection of three suites:: Tests run: 10, 12 ms, average: 1 ms, failures: 0 Suites run: 3, total tests run: 37, 26 ms, average: 0 ms, failures: 0 Average test time: 0 ms, worst case 'mem' took 1 ms + +Run a test with arguments (used by tests declared with UNIT_TEST_ARGS):: + + => ut -f fs fs_test_ls_norun fs_type=ext4 fs_image=/tmp/img small=1MB.file diff --git a/test/cmd_ut.c b/test/cmd_ut.c index bad123a75fd..adc96fcbcdc 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -30,7 +30,7 @@ struct suite { static int do_ut_all(struct unit_test_state *uts, const char *select_name, int runs_per_test, bool force_run, - const char *test_insert); + const char *test_insert, int argc, char *const argv[]); static int do_ut_info(bool show_suites); @@ -122,7 +122,7 @@ static bool has_tests(struct suite *ste) /** run_suite() - Run a suite of tests */ static int run_suite(struct unit_test_state *uts, struct suite *ste, const char *select_name, int runs_per_test, bool force_run, - const char *test_insert) + const char *test_insert, int argc, char *const argv[]) { int n_ents = ste->end - ste->start; char prefix[30]; @@ -133,7 +133,7 @@ static int run_suite(struct unit_test_state *uts, struct suite *ste, ret = ut_run_list(uts, ste->name, prefix, ste->start, n_ents, select_name, runs_per_test, force_run, test_insert, - 0, NULL); + argc, argv); return ret; } @@ -169,7 +169,8 @@ static void update_stats(struct unit_test_state *uts, const struct suite *ste) } static int do_ut_all(struct unit_test_state *uts, const char *select_name, - int runs_per_test, bool force_run, const char *test_insert) + int runs_per_test, bool force_run, const char *test_insert, + int argc, char *const argv[]) { int i; int retval; @@ -181,7 +182,7 @@ static int do_ut_all(struct unit_test_state *uts, const char *select_name, if (has_tests(ste)) { printf("----Running %s tests----\n", ste->name); retval = run_suite(uts, ste, select_name, runs_per_test, - force_run, test_insert); + force_run, test_insert, argc, argv); if (!any_fail) any_fail = retval; update_stats(uts, ste); @@ -246,6 +247,8 @@ static struct suite *find_suite(const char *name) static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { const char *test_insert = NULL, *select_name; + int test_argc; + char *const *test_argv; struct unit_test_state uts; bool show_suites = false; bool force_run = false; @@ -287,9 +290,14 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) ut_init_state(&uts); name = argv[0]; select_name = cmd_arg1(argc, argv); + + /* Test arguments are after suite name and test name */ + test_argc = argc > 2 ? argc - 2 : 0; + test_argv = argc > 2 ? argv + 2 : NULL; + if (!strcmp(name, "all")) { ret = do_ut_all(&uts, select_name, runs_per_text, force_run, - test_insert); + test_insert, test_argc, test_argv); } else if (!strcmp(name, "info")) { ret = do_ut_info(show_suites); } else { @@ -308,7 +316,8 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } ret = run_suite(&uts, ste, select_name, runs_per_text, - force_run, test_insert); + force_run, test_insert, test_argc, + test_argv); if (!any_fail) any_fail = ret; update_stats(&uts, ste); @@ -324,12 +333,14 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } U_BOOT_LONGHELP(ut, - "[-rs] [-f] [-I:][] - run unit tests\n" + "[-rs] [-f] [-I:] [ [...]] - run unit tests\n" " -r Number of times to run each test\n" " -f Force 'manual' tests to run as well\n" " -I Test to run after other tests have run\n" " -s Show all suites with ut info\n" - " Comma-separated list of suites to run\n" + " Test suite to run (or comma-separated list)\n" + " Specific test to run (optional)\n" + " Test arguments as key=value pairs (optional)\n" "\n" "Options for :\n" "all - execute all enabled tests\n"