From patchwork Fri Aug 22 14:21: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: 113 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=1755872559; bh=phHs83ZtF7fEGS36hE8CxeRUZ0RRw0HBOGZESNaDFww=; 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=P4wchXtV1XXnyhvklc6exSBUWUQhKnao0IjTQt9D9HUIccS5jM6r9+aQc9o08DzS0 e04+NXr7aSaEe4YyP/+xX97Na8zayY9Yn9BBsw6RpP/83cuv6ow6T6TYU2xbf89C9s cVXODr8HlzLJTil0hbh/mDRSCvu/jzLvv1QyXWFMdOQl1kDTk9gzjfgI61B3+StZPV ib60X9whNUGTx/eZJmC9PzcWm4v7gpm3KU58brtNa/VI0ODFtTNAYJOqo+x7BqyHaV Zdz9bb806I4m43ldjH7Qx+HztbQ42Y0P5SxNJ8OoxHSHjk064z2yKHwfkiQQXbbYmv X8xHvdJvMx4RA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 02EB3675E3 for ; Fri, 22 Aug 2025 08:22:39 -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 PlqY4DH6iwNT for ; Fri, 22 Aug 2025 08:22:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872552; bh=phHs83ZtF7fEGS36hE8CxeRUZ0RRw0HBOGZESNaDFww=; 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=amWEQIcI2BWRmcp21TRq/8QtNEUfiJlZHjYwkxmB1XGLfrPdfCyHhDteDunWS7+8E f7HoAr4FklCZlR8v7YyZo5BSGdOaGc5LS+Hc42DfnydldKTTfSwQxP5jv4scsDQ248 fwsHu1wYfB4Ibl5BbRMqQhMrE8aQ0YZBwjMQomMtyj14OJBn3v22DaSN2QLPYlqp68 jxKPNSUuR63TJ1NCZBSjEe49MFHAafwcw33Kr0s6ExGZTJyHgdTunIeVeUmh/SSAvR TzDGVMjzJ42YidBMEDJQTRCCq80fEQCUrkVglaVkkp2FGYTJIlYHgtNm4ZmCSdFoIY FUsWSaj/HKOJg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D901D67718 for ; Fri, 22 Aug 2025 08:22:32 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755872551; bh=mwPkGNpJkHC8Ak6hwU0k+2xFSvozb3p4PbF/UtilklY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BgfTf6C8yLRONiEG9x9wFOohIsYHUSZBTMQUoC8GRi9yZ0IBW8W0qT2Q04bCxRxbh yb02kwP6nEv+v4tutclTZ1VAlcTZyB0+e7qyix2SIOYs99huDRABgTvo8hVzdCY6n+ I8GviiPQPJym6qvqZb4QWT0Em/AEHzGJLLTXsiZRRxJ/hja7UV3yiEny78E75WMaOu +yO9JftuSnZnWZJYUxt9pm7XjYNyUxBdOHFraPJRMpl8N/7z88DklPHeZ9Sf+vFnn1 Dy+A8WFBqBY2mufAYUKjbkzYqyJ6QePHmgCFaFHiIiv8z7g4JHHU7/w6CP0XPV4QNy pRQ+K3NA/rywQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 742C76771A; Fri, 22 Aug 2025 08:22:31 -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 R4uKZmnol_sS; 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=1755872547; bh=3ULt4ricpU0Am7nx/yMNGGV3IDNIhaFXwrnMC32mECc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=usn1TnVZ9Wg+fS0lpMKVS2dDGfKMY/wOAycX8zJ3NlLvbYdovJnqV8INkSN4nTifk LZvEVxJmhCT05MKMxyxbEBvCZUjWIBUIne8GaqLBX44yhfkoHjpgazs6+8nwjxhtL1 O+XX++KCam7lo7Ycf/1vDfVInAZXGUIwY6ZVTzg4b17JvaOlCQVfCfgfUDNHr6OBSO Qq/O+kx/Tjtv7SQKH30woQn/txS3T34OYHfXLJxsB/PVOcMw3v6ePl/goufyzj37LS 0nBDlO79KOyjR6+gHHHtt8A5wjut/3wVEby6hqCeJP86SAl0fDbqnQgQnSU59mDIQb 66teR1Qu3UclQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 237C3676C4; Fri, 22 Aug 2025 08:22:27 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 22 Aug 2025 08:21:39 -0600 Message-ID: <20250822142153.3404275-9-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: UATUFAJXNAKJWVD6D7FA2YEUPOH2K5NL X-Message-ID-Hash: UATUFAJXNAKJWVD6D7FA2YEUPOH2K5NL 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/16] console: Add a few more paging tests 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 Provide a test that the prompt is displayed and another that paging happens but does not appear in the recorded console-output. Signed-off-by: Simon Glass --- test/common/pager.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/test/common/pager.c b/test/common/pager.c index c1c2d40f648..792f5f24153 100644 --- a/test/common/pager.c +++ b/test/common/pager.c @@ -12,6 +12,9 @@ #include #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; /* Test basic pager init and cleanup */ static int pager_test_basic_init(struct unit_test_state *uts) @@ -465,3 +468,109 @@ static int pager_test_putc(struct unit_test_state *uts) return 0; } COMMON_TEST(pager_test_putc, 0); + +/* Test writing up to page limit then adding final newline */ +static int pager_test_limit_plus_newline(struct unit_test_state *uts) +{ + struct pager *pag; + const char *result; + + /* Init with page length of 3 lines */ + ut_assertok(pager_init(&pag, 3, 1024)); + + /* Write text that reaches exactly the page limit (2 newlines) */ + result = pager_post(pag, true, "Line 1\nLine 2"); + ut_assertnonnull(result); + ut_asserteq_str("Line 1\nLine 2", result); + ut_asserteq(1, pag->line_count); /* Should have 1 line counted */ + + /* Should be no more text yet - haven't hit limit */ + result = pager_next(pag, true, 0); + ut_assertnull(result); + + /* Now post a single newline - this should trigger the page limit */ + result = pager_post(pag, true, "\n"); + ut_assertnonnull(result); + /* + * Should get empty string since we hit the limit and the newline is + * consumed + */ + ut_asserteq_str("", result); + + /* Next call should return the pager prompt since we hit the limit */ + result = pager_next(pag, true, 0); + ut_assertnonnull(result); + ut_asserteq_str("\n: Press SPACE to continue", result); + + /* Press space to continue */ + result = pager_next(pag, true, ' '); + ut_assertnonnull(result); + ut_asserteq_str("\r \r", result); + + /* Should be no more text */ + result = pager_next(pag, true, 0); + ut_assertnull(result); + + pager_uninit(pag); + + return 0; +} +COMMON_TEST(pager_test_limit_plus_newline, 0); + +/* Test console integration - pager prompt appears in console output */ +static int pager_test_console(struct unit_test_state *uts) +{ + struct pager *pag, *orig_pag; + char line[100]; + int avail, ret; + + /* Save original pager */ + orig_pag = gd_pager(); + + /* Create our own pager for testing */ + ret = pager_init(&pag, 2, 1024); + if (ret) { + gd->pager = orig_pag; + return CMD_RET_FAILURE; + } + + /* Set up pager to be one away from limit (1 line already counted) */ + pag->line_count = 1; + + /* Assign our pager to the global data */ + gd->pager = pag; + + /* Trigger paging with a second newline */ + putc('\n'); + + /* Check if there's any console output available at all */ + avail = console_record_avail(); + + /* Restore original pager first */ + gd->pager = orig_pag; + pager_uninit(pag); + + /* Now check what we got */ + if (!avail) { + ut_reportf("No console output was recorded at all"); + return CMD_RET_FAILURE; + } + + /* Try to read the actual output */ + ret = console_record_readline(line, sizeof(line)); + if (ret < 0) { + ut_reportf("Failed to read first line, avail was %d", avail); + return CMD_RET_FAILURE; + } + + /* + * console recording does not see the pager prompt, so we should have + * just got a newline + */ + ut_asserteq_str("", line); + + ut_assert_console_end(); + + return 0; +} +COMMON_TEST(pager_test_console, UTF_CONSOLE);