From patchwork Fri Aug 22 14:21:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 112 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=1755872556; bh=uG1K8sQRAdg1MCl+czBEnVCZBbyYI4eDUP4yjZ7qUrY=; 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=abZzKL229Y7JUt4Pnzgw2P6hU5RB/rZ9oY+jE+W9YpG3FsWVNCYlqWn+LBJgH682X 81hBqMnRC+Q6xm7n6uFXHEa+eK/XvC2pADJ/DTSf7LtmWm1mp/bKnkepUACLrY2PHH OLVzAW5u9ITX6jZNXRbkh/53uP0aNTHj8+n5COtifhZ1qV+3puh604ZNLMENb+gmcB xR96CzIErM/3CY6a0SAoDs/sdETRHTnHG8GMyqNwB7JQmp/4WZSXWa4mi/Yyrxmlqc axUi8BWqXs/wufTyv1JPg2Z+XxzcH9G3t0Xyp2DeloY2M/SD5LKyP26TtJ87WWqbeD UweLVkHFkgV9g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4EA95674C7 for ; Fri, 22 Aug 2025 08:22:36 -0600 (MDT) 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 xkoO-fvmZ-67 for ; Fri, 22 Aug 2025 08:22:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872551; bh=uG1K8sQRAdg1MCl+czBEnVCZBbyYI4eDUP4yjZ7qUrY=; 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=aaJGgvwqp4yz8VV5LbzhbRjlHayo2TuNzxHhc6w4KtPPe5XxprSHNQzD8atIU9kV5 sW/jiGJRnfI/0W82Edf01KYOSZBSVcmh73eTaJw2KFYU5pWpTnGxNtX7YA0EZlyktx /EOv3m62wBKLSJ294TQOevZqQxaGUIzR6DQUfYPUKtTrI1fNrUQpk5Har9enfPivec lbNIvFQeuTnaX8+nD1wuwtBdUVAmFhsrGxzUuWLwM2Z3xpsSTQFlG+bGRpxveyVoKe 7pMYq0/sfnFfi1TiBGzXcubdXnddWXbef+VPO1i/J7z854eTxKXGJPuF5RnZRn6P1N XqoeNXZC1Zy1g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7C720676C4 for ; Fri, 22 Aug 2025 08:22:31 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872549; bh=ThuRXuZPpncXUKSbywChOq9u7FybVvvdhqrkubfwmSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YpTkjjBjouXIcL0sgyGhsj+Lu8u3a2BRoQ+HA+KLuj/hftJPhQ1Tj2TBtjFTqaUfy 4oJn5Wc9Osb92Cekk8RAAqI/uR5jmtUV/iqa0gQdde9lgEsuXcY/4BNU1poqPZJM5o xZGgMfrZ8HXli0mkv1q60ZGA/Aji9zZv1Wc6ooMIpgPVjQdkQnyDI+jAzS3CVm6qq2 AzrFiSKH/oiF3UWqV5XepqKGNm0aI+nfza8eBhsDL2k4795K/2O1CUFkDNWWnHFwd1 tRhr6k9+i1r/inH1R09wzJ2NDYJXJkJ4IaFL1sKuqJna9OOCh9cLLdjYb2JS5f5g49 Nrav/6FF9Wluw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 448A567712; Fri, 22 Aug 2025 08:22:29 -0600 (MDT) 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 oSzGxLvertG4; Fri, 22 Aug 2025 08:22:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872545; bh=ihyAgPMuUarEr89AjSs7yEJN28vCatspllQOtiKV+zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I3bM9VOL7Tem3A7+P2s0GFuD3pKS/zh4JlNBbf39AyWh0zAmhc40pGv8fAPpUMcJv 0tzsMBLChB0zyzP6hL0be9/+T2mVD0fP2fbtEeJgFiKuIKxPlB8Li10eeWZ+//Nqiv 28qIj/K5VGGHRaIgUQy5tJxdpG0Q0R+bwBKgHmaqlj2ftvV1r4gwOIwZTeNFd26QZp dKUDQnNKc48utBqQnnhiA/9v8OdvCZabDOkdQC0jB/D2OwnU7F9wdzDRBh2+zTWkXs q4/VrdcYAl1R+0vYfxEBtuLFmM0hlxgtoToUMqGIG03zKOWv1fHGLSL3LdVDZFq5xM aQeleVVnbAf8w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 62EC6676F1; Fri, 22 Aug 2025 08:22:25 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 22 Aug 2025 08:21:37 -0600 Message-ID: <20250822142153.3404275-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822142153.3404275-1-sjg@u-boot.org> References: <20250822142153.3404275-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: PKY4DEPDMFKQ2VYQT73EVT7UDP67BPMX X-Message-ID-Hash: PKY4DEPDMFKQ2VYQT73EVT7UDP67BPMX 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: Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 06/16] console: test: Allow tests to bypass the pager 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 We generally don't want the pager to be active when running tests, since U-Boot appears to hang forever. Perhaps we could detect when the tests are being run interactively and use the pager in that case. But for now, just bypass it. Co-developed-by: Claude Signed-off-by: Simon Glass --- common/pager.c | 20 +++++++++++++++++++- include/pager.h | 19 +++++++++++++++++++ test/common/pager.c | 36 ++++++++++++++++++++++++++++++++++++ test/test-main.c | 3 +++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/common/pager.c b/common/pager.c index 20aa8558654..a7ad77bea3b 100644 --- a/common/pager.c +++ b/common/pager.c @@ -19,7 +19,7 @@ const char *pager_post(struct pager *pag, bool use_pager, const char *s) struct membuf old; int ret, len; - if (!pag || !use_pager) + if (!pag || !use_pager || pag->state == PAGERST_TEST_BYPASS) return s; len = strlen(s); @@ -76,6 +76,8 @@ const char *pager_next(struct pager *pag, bool use_pager, int key) case PAGERST_CLEAR_PROMPT: pag->state = PAGERST_OK; break; + case PAGERST_TEST_BYPASS: + return NULL; } ret = membuf_getraw(&pag->mb, pag->buf.size - 1, false, &str); @@ -123,6 +125,22 @@ void pager_uninit(struct pager *pag) free(pag); } +bool pager_set_bypass(struct pager *pag, bool bypass) +{ + bool was_bypassed = false; + + if (!pag) + return false; + was_bypassed = pag->state == PAGERST_TEST_BYPASS; + + if (bypass) + pag->state = PAGERST_TEST_BYPASS; + else + pag->state = PAGERST_OK; + + return was_bypassed; +} + int pager_init(struct pager **pagp, int page_len, int buf_size) { struct pager *pag; diff --git a/include/pager.h b/include/pager.h index 7f7df690d7f..9bd99b5c959 100644 --- a/include/pager.h +++ b/include/pager.h @@ -26,12 +26,14 @@ * pager_next() will return a user prompt * @PAGERST_WAIT_USER: Waiting for the user to press a key * @PAGERST_CLEAR_PROMPT: Clearing the prompt ready for more output + * @PAGERST_TEST_BYPASS: Pager is being bypassed since tests are running */ enum pager_state { PAGERST_OK, PAGERST_AT_LIMIT, PAGERST_WAIT_USER, PAGERST_CLEAR_PROMPT, + PAGERST_TEST_BYPASS, }; /** @@ -109,6 +111,18 @@ const char *pager_post(struct pager *pag, bool use_pager, const char *s); */ const char *pager_next(struct pager *pag, bool use_pager, int ch); +/** + * pager_set_bypass() - put the pager into bypass mode + * + * This is used for tests. Bypass mode stops the pager from doing anything to + * interrupt output + * + * @pag: Pager to use, may be NULL in which case this function does nothing + * @bypass: true to put the pager in bypass mode, false to return to normal mode + * Return: old value of the bypass flag + */ +bool pager_set_bypass(struct pager *pag, bool bypass); + /** * pager_uninit() - Uninit the pager * @@ -130,6 +144,11 @@ static inline const char *pager_next(struct pager *pag, bool use_pager, int ch) return NULL; } +static inline bool pager_set_bypass(struct pager *pag, bool bypass) +{ + return true; +} + #endif /** diff --git a/test/common/pager.c b/test/common/pager.c index f72d0f40304..2512652ea01 100644 --- a/test/common/pager.c +++ b/test/common/pager.c @@ -389,3 +389,39 @@ static int pager_test_use_pager_param(struct unit_test_state *uts) return 0; } COMMON_TEST(pager_test_use_pager_param, 0); + +/* Test pager bypass mode */ +static int pager_test_bypass_mode(struct unit_test_state *uts) +{ + struct pager *pag; + const char *text = "This text should be returned directly"; + const char *result; + + /* Init with small page length to ensure paging would normally occur */ + ut_assertok(pager_init(&pag, 2, 1024)); + + /* Enable bypass mode */ + pager_set_bypass(pag, true); + + /* Post text - should get original string back directly */ + result = pager_post(pag, true, text); + ut_asserteq_ptr(text, result); /* Should be same pointer */ + + /* pager_next should return NULL in bypass mode */ + result = pager_next(pag, true, 0); + ut_assertnull(result); + + /* Disable bypass mode */ + pager_set_bypass(pag, false); + + /* Now pager should work normally */ + result = pager_post(pag, true, text); + ut_assertnonnull(result); + /* In normal mode, result should be different from original text */ + ut_assert(result != text); + + pager_uninit(pag); + + return 0; +} +COMMON_TEST(pager_test_bypass_mode, 0); diff --git a/test/test-main.c b/test/test-main.c index 8515a77fe42..4238bb196eb 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -747,8 +748,10 @@ int ut_run_list(struct unit_test_state *uts, const char *category, memcpy(uts->fdt_copy, gd->fdt_blob, uts->fdt_size); } uts->force_run = force_run; + pager_set_bypass(gd_pager(), true); ret = ut_run_tests(uts, prefix, tests, count, select_name, test_insert); + pager_set_bypass(gd_pager(), false); /* Best efforts only...ignore errors */ if (has_dm_tests)