From patchwork Wed Dec 10 00:07:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 866 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=1765325329; bh=1bON2oYSSLHSnn9N5rbQHhvY8lPrncdfpBHIWinsgPg=; 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=s111+8wB4WobJErQpFpvlJXOOqbC0RrH1SFR2A8mncQSF+2SEFLcGgB1EblSQrX03 oQR+1bZKfO1Y4TlAcegrAbfjEcRrJXwW1bF50sA8TJPU8BwKh86dMezRVj0DfEnzGK 3nX8SgYavZNMBFG6Qr/f6/MmGtCbdoEGDX6/CuAlJD/08nspbZO8N7Iz1JUU3CKC+n PLztA0q7M8K/8WSy43L6a0dkTlUhESbWuvS+QQDodkkly7AD8Oox7NbfnqPPxB2AQX RiBfecMF6SWiJmiewVSY7lB2BcKEbeyKPmYd2yvWEHCy8Ssks82LkdnyrOxawXub0C 6NRnUdxuRSh1w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 524B5687A7 for ; Tue, 9 Dec 2025 17:08:49 -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 RBewbC6a8dGX for ; Tue, 9 Dec 2025 17:08:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325328; bh=1bON2oYSSLHSnn9N5rbQHhvY8lPrncdfpBHIWinsgPg=; 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=uSqVukyVNPpIm2Y+8VyVrTj8k8crId7VO9h06J8rhrpggNc5GBnu2LNm3o1kq8Kwu ZNccfVXoSCE2vfbg04112QLpVOzI+i7p3fQEZZYCen372Fg/GdC0Er5xmTgp/oWxnu kQUINMW66JbkT1dJ8+K8FCICYpL5yU03fbgjdlTY6qlKSb5YEpFnjyb5pzi3gu7foL eabw3wvyNdQayb7pkqFXWynWIjFJDpLeKq2x+0iugbUl8xLWBq1thb1yBF17M0/5/s WGskRAUdtZs7m4QNAjpKmlWbUDmwayL7qKl/f+4jlQvqeWMvwLjQ7+0imx9TNh+GT7 RPlNCmQXcENEQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EC7B0689EA for ; Tue, 9 Dec 2025 17:08:48 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325322; bh=EUx9prZPwsX1mN/vSWheiJuD+xdyAs01A/LquhD0mmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K1rJVdcnU7aH2EFcBgWz2pWGB71WdSbdmBNGa/Op87GQZK242gbs8YKYOro/FnkJM FwHADC+OizCro3RRzj7ZQ2DD6T7IH9ojacNeQWDqo8zDpkXJncJyQ8esGqUoMmFbTR pMbJIOR/4QFqiw8Vq3bnRx1+uoe19w3YTEP+6J+ZzXhfWeW5mIAc9XBZQCKNVtrdWI 2yzkx9xBOmsjb6FTA28kYjjvX2ZR7LccrLkxh18oaX2BqWtDYK8Ozc0KQ0CUoHBpjT cxSXojzAwG3BLRnj8c/hsaCQKYWfx6USuF1BifTLtxa0u+o9KatfwtgKignts0F8La En+X+B2mwPO7A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C59B768947; Tue, 9 Dec 2025 17:08:42 -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 vUb3Ht_v8Fwn; Tue, 9 Dec 2025 17:08:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325321; bh=1uW3gfYRdfoxufcJkN1x7b98/ijcFIFHYm6I2RzegT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oqeJFwJUrKpMotPhhnUlghG1BWf6Gcby0SNXgge0ZKGlHjo9hdohvCuxNQIYIww3o K8OOcBUsNqabVBRqwq/X12iJqi6JvPuxzJsSUqBeyzc0c1p2qdB3i+Pf94oa3O8bC/ NoBUv8eSvsAa3OS8upJ3oN1LhTK9cvH0zOC6Qr9gbywNgq5wwxwX+lKxLOIVsQfDwb gXONXP272d7gY9OmAGXdIQJKMfjD2qzJwSVVEi7SkDHWtrZtaSWbvM9XMmJRg+Hpsd kwc4tJQ8Pjvi88JK5Ep6zaUzZLaPHdWGlEmi20MCsuaWtIqh5g9or64zyqVMiOSgbW ObXCrogcNImtQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A24E7687A7; Tue, 9 Dec 2025 17:08:40 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 9 Dec 2025 17:07:00 -0700 Message-ID: <20251210000737.180797-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251210000737.180797-1-sjg@u-boot.org> References: <20251210000737.180797-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WKBSGOLPIWNAERMRSFNYDNM3JBF72OPV X-Message-ID-Hash: WKBSGOLPIWNAERMRSFNYDNM3JBF72OPV 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 09/35] test: Show the required size when console-record overflows 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 When the console-record buffer overflows, show both the current buffer size and the size needed. This helps the user know what value to set for CONFIG_CONSOLE_RECORD_OUT_SIZE. Add a console_out_ovf field to global_data to track the number of bytes that could not be written due to overflow. Co-developed-by: Claude Signed-off-by: Simon Glass --- common/console.c | 16 +++++++++++----- include/asm-generic/global_data.h | 14 ++++++++++++++ test/ut.c | 15 +++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/common/console.c b/common/console.c index c033d72486a..da1125cfa98 100644 --- a/common/console.c +++ b/common/console.c @@ -36,21 +36,26 @@ static void console_record_putc(const char c) { if (!(gd->flags & GD_FLG_RECORD)) return; - if (gd->console_out.start && - !membuf_putbyte((struct membuf *)&gd->console_out, c)) + if (gd->console_out.start && + !membuf_putbyte((struct membuf *)&gd->console_out, c)) { gd->flags |= GD_FLG_RECORD_OVF; + gd->console_out_ovf++; + } } static void console_record_puts(const char *s) { if (!(gd->flags & GD_FLG_RECORD)) return; - if (gd->console_out.start) { + if (gd->console_out.start) { int len = strlen(s); + int written; - if (membuf_put((struct membuf *)&gd->console_out, s, len) != - len) + written = membuf_put((struct membuf *)&gd->console_out, s, len); + if (written != len) { gd->flags |= GD_FLG_RECORD_OVF; + gd->console_out_ovf += len - written; + } } } @@ -893,6 +898,7 @@ void console_record_reset(void) membuf_purge((struct membuf *)&gd->console_out); membuf_purge((struct membuf *)&gd->console_in); gd->flags &= ~GD_FLG_RECORD_OVF; + gd->console_out_ovf = 0; } int console_record_reset_enable(void) diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index d91103dfe00..4a197a2c230 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -347,6 +347,12 @@ struct global_data { * This buffer is used to collect output during console recording. */ struct membuf console_out; + /** + * @console_out_ovf: overflow byte count for console recording + * + * Number of bytes that could not be written due to buffer overflow. + */ + int console_out_ovf; /** * @console_in: input buffer for console recording * @@ -589,6 +595,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE); #define gd_malloc_ptr() 0L #endif +#ifdef CONFIG_CONSOLE_RECORD +#define gd_console_out() (&gd->console_out) +#define gd_console_out_ovf() gd->console_out_ovf +#else +#define gd_console_out() NULL +#define gd_console_out_ovf() 0 +#endif + #if CONFIG_IS_ENABLED(UPL) #define gd_upl() gd->upl #define gd_set_upl(_val) gd->upl = (_val) diff --git a/test/ut.c b/test/ut.c index b4f2a8bf40f..94b09364687 100644 --- a/test/ut.c +++ b/test/ut.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #ifdef CONFIG_SANDBOX @@ -86,8 +87,18 @@ static int readline_check(struct unit_test_state *uts) ret = console_record_readline(uts->actual_str, sizeof(uts->actual_str)); if (ret == -ENOSPC) { - ut_fail(uts, __FILE__, __LINE__, __func__, - "Console record buffer too small - increase CONFIG_CONSOLE_RECORD_OUT_SIZE"); + if (IS_ENABLED(CONFIG_CONSOLE_RECORD)) { + int cur_size = membuf_size(gd_console_out()); + + ut_failf(uts, __FILE__, __LINE__, __func__, + "Console record buffer too small", + "CONFIG_CONSOLE_RECORD_OUT_SIZE=%#x, need %#x", + cur_size, cur_size + gd_console_out_ovf()); + } else { + ut_fail(uts, __FILE__, __LINE__, __func__, + "Console record buffer too small - increase " + "CONFIG_CONSOLE_RECORD_OUT_SIZE"); + } return ret; } else if (ret == -ENOENT) { strcpy(uts->actual_str, "");