console: test: Allow tests to bypass the pager

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 <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-21 18:26:49 -06:00
parent d3d493c8a3
commit cad364dd79
4 changed files with 72 additions and 1 deletions

View File

@@ -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->test_bypass)
return s;
len = strlen(s);
@@ -117,6 +117,19 @@ const char *pager_next(struct pager *pag, bool use_pager, int key)
return str;
}
bool pager_set_test_bypass(struct pager *pag, bool bypass)
{
bool was_bypassed = false;
if (!pag)
return false;
was_bypassed = pag->test_bypass;
pag->test_bypass = bypass;
return was_bypassed;
}
void pager_uninit(struct pager *pag)
{
abuf_uninit(&pag->buf);

View File

@@ -64,6 +64,7 @@ enum pager_state {
* @nulch: pointer to where a nul character was written, NULL if none
* @oldch: old character that was at @nulch
* @state: current state of the pager state-machine
* @test_bypass: true if pager should behave as if in test mode (bypass all)
*/
struct pager {
int line_count;
@@ -74,6 +75,7 @@ struct pager {
char *nulch;
int oldch;
enum pager_state state;
bool test_bypass;
};
#if CONFIG_IS_ENABLED(CONSOLE_PAGER)
@@ -116,6 +118,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_test_bypass() - put the pager into test bypass mode
*
* This is used for tests. Test bypass mode stops the pager from doing
* anything to interrupt output, regardless of the current pager state.
*
* @pag: Pager to use, may be NULL in which case this function does nothing
* @bypass: true to put the pager in test bypass mode, false for normal
* Return: old value of the test bypass flag
*/
bool pager_set_test_bypass(struct pager *pag, bool bypass);
/**
* pager_uninit() - Uninit the pager
*
@@ -137,6 +151,11 @@ static inline const char *pager_next(struct pager *pag, bool use_pager, int ch)
return NULL;
}
static inline bool pager_set_test_bypass(struct pager *pag, bool bypass)
{
return true;
}
#endif
/**

View File

@@ -393,3 +393,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_test_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_test_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);

View File

@@ -14,6 +14,7 @@
#include <net.h>
#include <of_live.h>
#include <os.h>
#include <pager.h>
#include <spl.h>
#include <usb.h>
#include <dm/ofnode.h>
@@ -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_test_bypass(gd_pager(), true);
ret = ut_run_tests(uts, prefix, tests, count, select_name,
test_insert);
pager_set_test_bypass(gd_pager(), false);
/* Best efforts only...ignore errors */
if (has_dm_tests)