efi_loader: Disable ANSI output for tests
PATCH v2 1/1 efi_loader: Disable ANSI output for tests
We don't want ANSI escape-sequences 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 these characters not be sent.
Add a proper function comment while we are here, to encourage others.
---
Changes in v2:
- Use the term 'ANSI escape-sequences'
include/efi_loader.h | 21 ++++++++++++++++++++- lib/efi_loader/efi_console.c | 26 +++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-)
include/efi_loader.h +20 -1
@@ -532,8 +532,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 escape-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 escape-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);
lib/efi_loader/efi_console.c +17 -9
@@ -30,6 +30,17 @@ struct cout_mode {__maybe_unused static struct efi_object uart_obj; +/* +* suppress emission of ANSI escape-characters 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 ;
Signature · 4 lines
2.43.0 base-commit: c5a631df96de7421d10ee03dceed1b79db213026 branch: ansi2
Quoted 8 lines · Simon Glass
We don't want ANSI escape-sequences 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 these characters not be sent.
Add a proper function comment while we are here, to encourage others.
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Use the term 'ANSI escape-sequences'include/efi_loader.h | 21 ++++++++++++++++++++- lib/efi_loader/efi_console.c | 26 +++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-)
Since we keep coming back to this, here's the email where *why* there are ANSI escape sequences is explained along with Heinrich's suggestion of a fix for your concern:
https://lore.kernel.org/all/[email protected]/
I assume that this, rather than repeating and reposting this solution again is still what Heinrich prefers.
Signature · 1 line
Tom
Hi Tom,
Quoted 19 lines · Tom Rini
Quoted 8 lines · Simon Glass
We don't want ANSI escape-sequences 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 these characters not be sent.
Add a proper function comment while we are here, to encourage others.
Signed-off-by Simon Glass <[email protected]>Quoted 8 lines
---
Changes in v2:
- Use the term 'ANSI escape-sequences'include/efi_loader.h | 21 ++++++++++++++++++++- lib/efi_loader/efi_console.c | 26 +++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-)
Quoted 7 lines
Since we keep coming back to this, here's the email where *why* there are ANSI escape sequences is explained along with Heinrich's suggestion of a fix for your concern:
https://lore.kernel.org/all/[email protected]/I assume that this, rather than repeating and reposting this solution again is still what Heinrich prefers.
We discussed this and Heinrich pointed me to [1], which does a similar thing. So I believe he is OK with it now.
Regards,
Simon
[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/