Message ID | 20230425184720.456896-5-ejo@pengutronix.de |
---|---|
State | New |
Headers | show |
Series | Add barebox bootloader support (and testing) | expand |
Hello Enrico, On Tue, 25 Apr 2023 20:47:15 +0200 Enrico Jörns <ejo@pengutronix.de> wrote: > If we talk to terminals that like colors, we need to ignore the vt100 > escape sequences when matching strings. > > An unprocessed barebox console prompt would e.g. look like: > > ESC[1;32mbarebox@ESC[1;36mARM QEMU virt64:/ESC[0m > > where we cannot match for something like "barebox@ARM QEMU virt64:/". > The same applies to colored Linux terminal output of course. > > The "\x1b\[" from the regex catches the standard start of ansii escape ^^^^^ I guess you mean "ansi" (single 'i'). I fixed that (and also converted to uppercase) while applying the patch for testing, no need to resend. > sequence while the rest catches the actual command code executed. > > Signed-off-by: Enrico Jorns <ejo@pengutronix.de> > --- > meta/lib/oeqa/utils/qemurunner.py | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py > index 6734cee48d..c3d8e9e815 100644 > --- a/meta/lib/oeqa/utils/qemurunner.py > +++ b/meta/lib/oeqa/utils/qemurunner.py > @@ -30,6 +30,8 @@ control_range = list(range(0,32))+list(range(127,160)) > control_chars = [chr(x) for x in control_range > if chr(x) not in string.printable] > re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) > +# Regex to remove the ansii (color) control codes from console strings in order to match the text only ^^^^^ Same here. Best regards, Luca
Hello Luca, Am Mittwoch, dem 26.04.2023 um 10:52 +0200 schrieb Luca Ceresoli: > Hello Enrico, > > On Tue, 25 Apr 2023 20:47:15 +0200 > Enrico Jörns <ejo@pengutronix.de> wrote: > > > If we talk to terminals that like colors, we need to ignore the vt100 > > escape sequences when matching strings. > > > > An unprocessed barebox console prompt would e.g. look like: > > > > ESC[1;32mbarebox@ESC[1;36mARM QEMU virt64:/ESC[0m > > > > where we cannot match for something like "barebox@ARM QEMU virt64:/". > > The same applies to colored Linux terminal output of course. > > > > The "\x1b\[" from the regex catches the standard start of ansii escape > ^^^^ > I guess you mean "ansi" (single 'i'). I fixed that (and also converted > to uppercase) while applying the patch for testing, no need to resend. indeed, seems as if a part of me had 'ascii' in mind and when writing this. ANSI is what I meant, yes. Thanks for fixing it at both places! Enrico > > sequence while the rest catches the actual command code executed. > > > > Signed-off-by: Enrico Jorns <ejo@pengutronix.de> > > --- > > meta/lib/oeqa/utils/qemurunner.py | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py > > index 6734cee48d..c3d8e9e815 100644 > > --- a/meta/lib/oeqa/utils/qemurunner.py > > +++ b/meta/lib/oeqa/utils/qemurunner.py > > @@ -30,6 +30,8 @@ control_range = list(range(0,32))+list(range(127,160)) > > control_chars = [chr(x) for x in control_range > > if chr(x) not in string.printable] > > re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) > > +# Regex to remove the ansii (color) control codes from console strings in order to match the > > text only > ^^^^^ > > Same here. > > Best regards, > Luca >
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 6734cee48d..c3d8e9e815 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py @@ -30,6 +30,8 @@ control_range = list(range(0,32))+list(range(127,160)) control_chars = [chr(x) for x in control_range if chr(x) not in string.printable] re_control_char = re.compile('[%s]' % re.escape("".join(control_chars))) +# Regex to remove the ansii (color) control codes from console strings in order to match the text only +re_vt100 = re.compile(r'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]') class QemuRunner: @@ -662,7 +664,7 @@ class QemuRunner: time.sleep(0.1) answer = self.server_socket.recv(1024) if answer: - data += answer.decode('utf-8') + data += re_vt100.sub("", answer.decode('utf-8')) # Search the prompt to stop if re.search(self.boot_patterns['search_cmd_finished'], data): break
If we talk to terminals that like colors, we need to ignore the vt100 escape sequences when matching strings. An unprocessed barebox console prompt would e.g. look like: ESC[1;32mbarebox@ESC[1;36mARM QEMU virt64:/ESC[0m where we cannot match for something like "barebox@ARM QEMU virt64:/". The same applies to colored Linux terminal output of course. The "\x1b\[" from the regex catches the standard start of ansii escape sequence while the rest catches the actual command code executed. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> --- meta/lib/oeqa/utils/qemurunner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)