All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v6 08/12] efi_loader: Disable ANSI output for tests
Date: Fri, 27 Sep 2024 00:02:19 +0200	[thread overview]
Message-ID: <20240926220226.1265965-9-sjg@chromium.org> (raw)

We don't want ANSI characters written in tests since it is a pain to
check the output with ut_assert_nextline() et al.

Provide a way to tests to request that ANSI characters not be sent.

Add a proper function comment while we are here, to encourage others.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 include/efi_loader.h         | 21 ++++++++++++++++++++-
 lib/efi_loader/efi_console.c | 26 +++++++++++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index f84852e384f..82b90ee0f1d 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -531,8 +531,27 @@ efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
 efi_status_t efi_bootmgr_run(void *fdt);
 /* search the boot option index in BootOrder */
 bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
-/* Set up console modes */
+
+/**
+ * efi_setup_console_size() - update the mode table.
+ *
+ * By default the only mode available is 80x25. If the console has at least 50
+ * lines, enable mode 80x50. If we can query the console size and it is neither
+ * 80x25 nor 80x50, set it as an additional mode.
+ */
 void efi_setup_console_size(void);
+
+/**
+ * efi_console_set_ansi() - Set whether ANSI characters should be emitted
+ *
+ * These characters mess up tests which use ut_assert_nextline(). Call this
+ * function to tell efi_loader not to emit these characters when starting up the
+ * terminal
+ *
+ * @allow_ansi: Allow emitting ANSI characters
+ */
+void efi_console_set_ansi(bool allow_ansi);
+
 /* Set up load options from environment variable */
 efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
 				      u16 **load_options);
diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index cea50c748aa..569fc9199bc 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -30,6 +30,17 @@ struct cout_mode {
 
 __maybe_unused static struct efi_object uart_obj;
 
+/*
+ * suppress emission of ANSI codes for use by unit tests. Leave it as 0 for the
+ * default behaviour
+ */
+static bool no_ansi;
+
+void efi_console_set_ansi(bool allow_ansi)
+{
+	no_ansi = !allow_ansi;
+}
+
 static struct cout_mode efi_cout_modes[] = {
 	/* EFI Mode 0 is 80x25 and always present */
 	{
@@ -348,13 +359,6 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
 	return 0;
 }
 
-/**
- * efi_setup_console_size() - update the mode table.
- *
- * By default the only mode available is 80x25. If the console has at least 50
- * lines, enable mode 80x50. If we can query the console size and it is neither
- * 80x25 nor 80x50, set it as an additional mode.
- */
 void efi_setup_console_size(void)
 {
 	int rows = 25, cols = 80;
@@ -362,8 +366,12 @@ void efi_setup_console_size(void)
 
 	if (IS_ENABLED(CONFIG_VIDEO))
 		ret = query_vidconsole(&rows, &cols);
-	if (ret)
-		ret = query_console_serial(&rows, &cols);
+	if (ret) {
+		if (no_ansi)
+			ret = 0;
+		else
+			ret = query_console_serial(&rows, &cols);
+	}
 	if (ret)
 		return;
 
-- 
2.43.0


             reply	other threads:[~2024-09-26 22:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26 22:02 Simon Glass [this message]
2024-09-26 22:02 ` [PATCH v6 09/12] efi_loader: Add a test app Simon Glass
2024-09-27 13:50   ` Ilias Apalodimas
2024-09-27 16:50     ` Simon Glass
2024-09-30 12:00       ` Heinrich Schuchardt
2024-09-30 14:12         ` Simon Glass
2024-09-26 22:02 ` [PATCH v6 10/12] sandbox: virtio: Disable the sandbox virtio blk device Simon Glass
2024-09-27  0:22   ` Tom Rini
2024-09-26 22:02 ` [PATCH v6 11/12] test: efi: boot: Set up an image suitable for EFI testing Simon Glass
2024-09-26 22:02 ` [PATCH v6 12/12] test: efi: boot: Add a test for the efi bootmeth Simon Glass
2024-10-11 22:32   ` Tom Rini
2024-10-13 19:33     ` Simon Glass
2024-10-14  3:51       ` Tom Rini
2024-10-14  7:00         ` Heinrich Schuchardt
2024-10-14 14:32           ` Tom Rini
2024-10-14 19:13         ` Simon Glass
2024-10-14 21:11           ` Tom Rini
2024-10-15 10:19             ` Mark Kettenis
2024-10-15 11:36               ` Heinrich Schuchardt
2024-10-15 13:25                 ` Simon Glass
2024-10-15 14:16                   ` Tom Rini
  -- strict thread matches above, loose matches on Subject: below --
2024-09-26 21:59 [PATCH v6 00/12] efi: Add a test for EFI bootmeth Simon Glass
2024-09-26 21:59 ` [PATCH v6 08/12] efi_loader: Disable ANSI output for tests Simon Glass
2024-09-30 23:38   ` Heinrich Schuchardt
2024-10-01  0:24     ` Tom Rini
2024-10-01  2:34       ` Heinrich Schuchardt
2024-10-01 18:02         ` Tom Rini
2024-10-01 22:18           ` Heinrich Schuchardt
2024-10-01 23:14             ` Tom Rini
2024-10-11 22:16             ` Simon Glass
2024-10-11 22:28               ` Tom Rini
2024-10-13 19:33                 ` Simon Glass
2024-10-14  2:25                   ` Tom Rini
2024-10-14 19:13                     ` Simon Glass
2024-10-01  7:49       ` Peter Robinson
2024-10-01 14:28         ` Tom Rini
2024-10-11 22:18     ` Simon Glass
2024-10-11 22:54       ` Tom Rini
2024-10-11 23:45         ` Heinrich Schuchardt
2024-10-12  0:36           ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240926220226.1265965-9-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.