cli: allow verbatim character entry with CTRL-v
cover cli: allow verbatim character entry with CTRL-v
Up to now the U-Boot console does not allow to add a control character to the line buffer. In Bash and Vim we can use CTRL-v for this purpose.
Add support for CTRL-v for verbatim entry of characters.
Heinrich Schuchardt (2):
cli: allow verbatim character entry with CTRL-v
test: verbatim character entry with CTRL-V
common/cli_readline.c | 38 ++++++++++- test/dm/Makefile | 2 +- test/dm/usb_console.c | 151 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 test/dm/usb_console.c
--
2.24.1
PATCH 1/2 cli: allow verbatim character entry with CTRL-v
Up to now the U-Boot console does not allow to add a control character to the line buffer. In Bash and Vim we can use CTRL-v for this purpose.
Add support for CTRL-v for verbatim entry of characters.
To keep things simple, while editing control characters are displayed as simple characters, e.g. ESC (0x1b) is displayed as [ and not as ^[.
--- common/cli_readline.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
common/cli_readline.c +35 -3
@@ -58,8 +58,6 @@ static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)* Author: Janghoon Lyu <[email protected]> */ -#define putnstr (str, n) printf("%.*s", (int)n, str) -#define CTL_CH (c) ((c) - 'a' + 1)#define CTL_BACKSPACE ('\b')#define DEL ((char)255)
@@ -83,6 +81,34 @@ static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */#define add_idx_minus_one () ((hist_add_idx == 0) ? hist_max : hist_add_idx-1) +/** +* putchar() - output single character +* +* Outputs single character. Control characters are converted, +* e.g. CTR-c is displayed as C. +*/ +static void putchar (char c) +{ +if (c <' ' ) + c +='@' ; +putc (c); +} + +/** +* putnstr() - output string buffer +* +* Outputs n characters for buffer str. Control characters are converted, e.g. +* CTRL-c is displayed as C. +* +* @str: string buffer +* @n: number of characters to print +*/ +static void putnstr (const char *str,size_t n) +{ +for (; n; --n) +putchar (*str++); +} +static void hist_init (void ) {int i;
@@ -385,7 +411,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,return -1 ;case CTL_CH ('f' ):if (num < eol_num) { -getcmd_putch (buf[num]); +putchar (buf[num]); num++; }break ;
@@ -419,6 +445,12 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,case CTL_CH ('o' ): insert = !insert;break ; +case CTL_CH ('v' ): +/* Add next character verbatim */ + ichar =getcmd_getch (); +cread_add_char (ichar, insert, &num, &eol_num, buf, + *len); +break ;case CTL_CH ('x' ):case CTL_CH ('u' ):BEGINNING_OF_LINE ();
--
2.24.1
PATCH 1/2 cli: allow verbatim character entry with CTRL-v
Quoted 6 lines · Heinrich Schuchardt
Up to now the U-Boot console does not allow to add a control character to the line buffer. In Bash and Vim we can use CTRL-v for this purpose.
Add support for CTRL-v for verbatim entry of characters.
Quoted 7 lines
To keep things simple, while editing control characters are displayed as simple characters, e.g. ESC (
0x1b) is displayed as [ and not as ^[.Signed-off-by Heinrich Schuchardt <[email protected]>--- common/cli_readline.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
PATCH 2/2 test: verbatim character entry with CTRL-V
In reply to Heinrich SchuchardtProvide a unit test checking that CTRL-V can be used to add control characters to the line buffer.
--- test/dm/Makefile | 2 +- test/dm/usb_console.c | 150 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 test/dm/usb_console.c
test/dm/Makefile +1 -1
@@ -51,7 +51,7 @@ obj-$(CONFIG_DM_SPI_FLASH) += sf.o obj-$(CONFIG_SMEM) += smem.o obj-$(CONFIG_DM_SPI) += spi.o obj-y += syscon.o -obj-$(CONFIG_DM_USB) += usb.o +obj-$(CONFIG_DM_USB) += usb.o usb_console.o obj-$(CONFIG_DM_PMIC) += pmic.o obj-$(CONFIG_DM_REGULATOR) += regulator.o obj-$(CONFIG_TIMER) += timer.o
test/dm/usb_console.c new file +150 -0
150 lines not on this page · raw message
--
2.24.1
PATCH 2/2 test: verbatim character entry with CTRL-V
Quoted 4 lines · Heinrich Schuchardt
Provide a unit test checking that CTRL-V can be used to add control characters to the line buffer.
Signed-off-by Heinrich Schuchardt <[email protected]>
I don't know why but this test, run when built with clang fails. A log is here: https://gitlab.denx.de/u-boot/u-boot/-/jobs/50540 but I saw it on Travis and Azure as well.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200124/b1dbbca3/attachment.sig>
PATCH 2/2 test: verbatim character entry with CTRL-V
Quoted 11 lines · Tom Rini
Quoted 4 lines · Heinrich Schuchardt
Provide a unit test checking that CTRL-V can be used to add control characters to the line buffer.
Signed-off-by Heinrich Schuchardt <[email protected]>I don't know why but this test, run when built with clang fails. A log is here: https://gitlab.denx.de/u-boot/u-boot/-/jobs/50540 but I saw it on Travis and Azure as well.
Hello Tom, hello Simon
when I clang U-Boot branch bisect-failure with in the Gitlab Docker image and run
./u-boot -d arch/sandbox/dts/test.dtb
ut dm usb_keyb
the test runs fine.
When I run
valgrind ./u-boot -d arch/sandbox/dts/test.dtb
usb start
ut dm usb_keyb
I see more than 100 use-after-free errors.
dm_test_destroy() calling uclass_destroy() seems to be the culprit.
@Simon:
Why would we destroy any uclass in ut dm that was in use before executing the command?
@Marek
Aren't usb_kbd_remove() and usb_kbd_deregister() essentially duplicate coding?
==149271== Invalid write of size 4
==149271== at 0x42CC04: usb_kbd_put_queue (usb_kbd.c:0) ==149271== by 0x42CC04: usb_kbd_translate (usb_kbd.c:255) ==149271== by 0x42C871: usb_kbd_irq_worker (usb_kbd.c:321) ==149271== by 0x42C7DF: usb_kbd_poll_for_event (usb_kbd.c:358) ==149271== by 0x42C7DF: usb_kbd_testc (usb_kbd.c:410) ==149271== by 0x42EF60: console_tstc (console.c:206) ==149271== by 0x50F302: dm_test_usb_keyb (usb.c:0) ==149271== by 0x4F17B4: dm_do_test (test-main.c:103) ==149271== by 0x4F1329: dm_test_main (test-main.c:180) ==149271== by 0x4F1329: do_ut_dm (test-main.c:210) ==149271== by 0x437A3B: cmd_call (command.c:576) ==149271== by 0x437A3B: cmd_process (command.c:631) ==149271== by 0x423DF2: run_pipe_real (cli_hush.c:1678) ==149271== by 0x423DF2: run_list_real (cli_hush.c:1876) ==149271== by 0x422FE2: run_list (cli_hush.c:2025) ==149271== by 0x422FE2: parse_stream_outer (cli_hush.c:3217) ==149271== by 0x423207: parse_file_outer (cli_hush.c:3300) ==149271== by 0x436EAA: cli_loop (cli.c:221) ==149271== Address 0xa681ca4 is 36 bytes inside a block of size 104 free'd ==149271== at 0x4C30D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==149271== by 0x42C6C9: usb_kbd_remove (usb_kbd.c:676) ==149271== by 0x442947: device_remove (device-remove.c:184) ==149271== by 0x442910: device_chld_remove (device-remove.c:52) ==149271== by 0x442910: device_remove (device-remove.c:175) ==149271== by 0x442910: device_chld_remove (device-remove.c:52) ==149271== by 0x442910: device_remove (device-remove.c:175) ==149271== by 0x442910: device_chld_remove (device-remove.c:52) ==149271== by 0x442910: device_remove (device-remove.c:175) ==149271== by 0x4415DC: uclass_destroy (uclass.c:121) ==149271== by 0x4F17DA: dm_test_destroy (test-main.c:72) ==149271== by 0x4F17DA: dm_do_test (test-main.c:107) ==149271== by 0x4F12CB: dm_test_main (test-main.c:169) ==149271== by 0x4F12CB: do_ut_dm (test-main.c:210) ==149271== by 0x437A3B: cmd_call (command.c:576) ==149271== by 0x437A3B: cmd_process (command.c:631) ==149271== by 0x423DF2: run_pipe_real (cli_hush.c:1678) ==149271== by 0x423DF2: run_list_real (cli_hush.c:1876) ==149271== by 0x422FE2: run_list (cli_hush.c:2025) ==149271== by 0x422FE2: parse_stream_outer (cli_hush.c:3217)
Best regards
Heinrich
PATCH 2/2 test: verbatim character entry with CTRL-V
Hi Heinrich,
Quoted 30 lines · Heinrich Schuchardt
Quoted 11 lines · Tom Rini
Quoted 4 lines · Heinrich Schuchardt
Provide a unit test checking that CTRL-V can be used to add control characters to the line buffer.
Signed-off-by Heinrich Schuchardt <[email protected]>I don't know why but this test, run when built with clang fails. A log is here: https://gitlab.denx.de/u-boot/u-boot/-/jobs/50540 but I saw it on Travis and Azure as well.
Hello Tom, hello Simon
when I clang U-Boot branch bisect-failure with in the Gitlab Docker image and run
./u-boot -d
arch/sandbox/dts/test.dtb
ut dmusb_keybthe test runs fine.
When I run
valgrind ./u-boot -d
arch/sandbox/dts/test.dtb
usb start
ut dmusb_keyb
Quoted 7 lines
I see more than 100 use-after-free errors.
dm_test_destroy()callinguclass_destroy()seems to be the culprit.@Simon:
Why would we destroy any uclass inut dmthat was in use before executing the command?
This is because the tests might require them to be in their initial state.
In general running a unit test along with other code is not safe.
I wonder if the situation has improved with the move to SDL2, but I'm not sure. [..]
Regards,
Simon