From patchwork Sun Dec 14 17:54:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 910 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=1765734972; bh=vFoH+csh8sBeIK57DAV71YjFwVv2/Xvm4GNQz9DiJbU=; 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=AuhbO4seq+kQvVAWKbP696fKZ2rTxRZ45IWVHxDegrwjn112Y55PM5+XjVqCNtMfj 31lKsWwcDrlXFMPZt1xSe+VYS5g/czNbmg5v5fmmRROOK/oPCtuZ6QxOkIn+HDwFZJ P7w6qaD64c8PYdJHTBl9tGIwwfHuF5kKpsksAP4YTwPieJKflSSEz+uCt1L19VuXFb 10Yuo31pkIESiQxxoIB1R0RnCGscyskzSpDFnvwlFZ/0aLXstbuv3oBWh5D0c+XIRq CqJUgLbs2AHHlptDWQUwXBX11cAK26Dfv2XYCI9x8klYHQGdZIMtPcnVwuCkgFq5Oy JThaDFP3lXv/A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8B05D68A91 for ; Sun, 14 Dec 2025 10:56:12 -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 k7oFsSIawQos for ; Sun, 14 Dec 2025 10:56:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734972; bh=vFoH+csh8sBeIK57DAV71YjFwVv2/Xvm4GNQz9DiJbU=; 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=AuhbO4seq+kQvVAWKbP696fKZ2rTxRZ45IWVHxDegrwjn112Y55PM5+XjVqCNtMfj 31lKsWwcDrlXFMPZt1xSe+VYS5g/czNbmg5v5fmmRROOK/oPCtuZ6QxOkIn+HDwFZJ P7w6qaD64c8PYdJHTBl9tGIwwfHuF5kKpsksAP4YTwPieJKflSSEz+uCt1L19VuXFb 10Yuo31pkIESiQxxoIB1R0RnCGscyskzSpDFnvwlFZ/0aLXstbuv3oBWh5D0c+XIRq CqJUgLbs2AHHlptDWQUwXBX11cAK26Dfv2XYCI9x8klYHQGdZIMtPcnVwuCkgFq5Oy JThaDFP3lXv/A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 79A5468A96 for ; Sun, 14 Dec 2025 10:56:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734970; bh=4R2AivVIASG9Q9dWQkEWz2NmwP7vWPsIV6GNJius5g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r+/AzZNy+Mn8f9NnufNVqEPBUC2nziK6Pmpx5MlTLmuamX6xpAWfF2XABY+rqPNmb bQ9QrTi+THUBodklx9J+gHbED1pgWbDyGTybzeu0AYWFvlx7iDi1sJ/Gwk+GR0j7Gf UDN0yJdp3EpkavkDHmnufWqZ13u/PenGR1y1DUoW5pSP4Q0q/T/1WH/r65dAR7fDzn mugpzuT0eoN6K7GpwG6AEjwz0pxEBCMNQdaOj4TKaLL6gz++P6CMFNUETwJPTQflOy adIrvPg6Fv4IqPRX4nEaaFJwRkwhopU98nNuF/hlqjo3gfT838F0WThjLVh9a5MFCt Ka1sLC6GG5Xww== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 777BD68A91; Sun, 14 Dec 2025 10:56:10 -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 1zfo0Z4Vc9_W; Sun, 14 Dec 2025 10:56:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765734966; bh=gucRtqFLiucsgrEfY9k3C96U4pZrf8xKv/JyivFQL50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MdLGJIGN8zmM1unQL9xnWMBWf9YC4l0yqOFJlgNX5vdqWG1LirqmNfKBUjxGjmRjd cXwJXaGTTLkMP84F5kP4aON/uPYmtVzd4R2B7rbAjdZjLzRm6upsNP6Hr8+kDSguAk I9NOABqUm88YPyPf3cD8LenBa2akFwP/dItUgeoc2Ic+QnEzzV6xAR7nFo/g78dbyS Peeb7tcz4bGXY0w09apvrkTyjD0NgCf//5ou7iLE5BtqJmlekG5UYYIIEE0aquHUN1 Z5dnqcDed/q667aCXet9XU+TEFmLXdE9mm08QRdgk8kqhejwEzBgrE5dYRDxuGlgsN gij0z1wJpwPVQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id AECE468A89; Sun, 14 Dec 2025 10:56:05 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 14 Dec 2025 10:54:39 -0700 Message-ID: <20251214175449.3799539-18-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: AFO6EQJXNBBLSDEOZEOGMLPU77TJIDTX X-Message-ID-Hash: AFO6EQJXNBBLSDEOZEOGMLPU77TJIDTX 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 17/21] test: Allow preserving console recording on failure 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 have a -R command option to prevent ut_fail() and ut_failf() from clearing GD_FLG_RECORD. This is useful when testing the test framework itself, where error messages need to be captured. Refactor ut_fail() and ut_failf() to call ut_unsilence_console() instead of duplicating the flag-clearing logic. Co-developed-by: Claude Signed-off-by: Simon Glass --- include/test/test.h | 2 ++ test/cmd_ut.c | 8 +++++++- test/ut.c | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/test/test.h b/include/test/test.h index 2facf5b3675..5ae90e39e00 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -96,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 + * @keep_record: Preserve console recording when ut_fail() is called * @priv: Private data for tests to use as needed */ struct unit_test_state { @@ -126,6 +127,7 @@ struct unit_test_state { struct ut_arg args[UT_MAX_ARGS]; int arg_count; bool arg_error; + bool keep_record; char priv[UT_PRIV_SIZE]; }; diff --git a/test/cmd_ut.c b/test/cmd_ut.c index adc96fcbcdc..6358f27a64f 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -252,6 +252,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) struct unit_test_state uts; bool show_suites = false; bool force_run = false; + bool keep_record = false; int runs_per_text = 1; struct suite *ste; char *name; @@ -276,6 +277,9 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (!strchr(test_insert, ':')) return CMD_RET_USAGE; break; + case 'R': + keep_record = true; + break; case 's': show_suites = true; break; @@ -288,6 +292,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_USAGE; ut_init_state(&uts); + uts.keep_record = keep_record; name = argv[0]; select_name = cmd_arg1(argc, argv); @@ -333,10 +338,11 @@ 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] [-R] [-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" + " -R Preserve console recording on test failure\n" " -s Show all suites with ut info\n" " Test suite to run (or comma-separated list)\n" " Specific test to run (optional)\n" diff --git a/test/ut.c b/test/ut.c index fe9a177ab53..0677e3fbee9 100644 --- a/test/ut.c +++ b/test/ut.c @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR; void ut_fail(struct unit_test_state *uts, const char *fname, int line, const char *func, const char *cond) { - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + ut_unsilence_console(uts); printf("%s:%d, %s(): %s\n", fname, line, func, cond); uts->cur.fail_count++; } @@ -33,7 +33,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, { va_list args; - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + ut_unsilence_console(uts); printf("%s:%d, %s(): %s: ", fname, line, func, cond); va_start(args, fmt); vprintf(fmt, args); @@ -286,7 +286,8 @@ void ut_silence_console(struct unit_test_state *uts) void ut_unsilence_console(struct unit_test_state *uts) { - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + if (!uts->keep_record) + gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); } void ut_set_skip_delays(struct unit_test_state *uts, bool skip_delays)