Message ID | 20230331104025.1478393-5-ejo@pengutronix.de |
---|---|
State | New |
Headers | show |
Series | Add barebox bootloader support (and testing) | expand |
On Fri, 31 Mar 2023 at 12:40, Enrico Jorns <ejo@pengutronix.de> wrote:
> +re_vt100 = re.compile(r'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]')
This piece of 'magic' needs to be explained :) What does it define?
Alex
Hi Alex, Am Freitag, dem 31.03.2023 um 16:05 +0200 schrieb Alexander Kanavin: > On Fri, 31 Mar 2023 at 12:40, Enrico Jorns <ejo@pengutronix.de> wrote: > > +re_vt100 = re.compile(r'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]') > > This piece of 'magic' needs to be explained :) What does it define? this is actually 'stolen' from labgrid's implementation for barebox[1] or shell[2] drivers which have exactly the same needs: They need to remove the ansii (color) control codes from the strings in order to match the text only. The unprocessed barebox console prompt would 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. Regards, Enrico [1] https://github.com/labgrid-project/labgrid/blob/e05f530c22513cd775b4f84e28f6c8c920b95102/labgrid/driver/bareboxdriver.py#L44 [2] https://github.com/labgrid-project/labgrid/blob/5d3d5714976b37df0f9a9b769c581fe1f83ccbdc/labgrid/driver/shelldriver.py#L61 > Alex >
Right, but this information should be recorded in commit message, or the file itself. Alex On Mon, 3 Apr 2023 at 15:02, Enrico Jörns <ejo@pengutronix.de> wrote: > > Hi Alex, > > Am Freitag, dem 31.03.2023 um 16:05 +0200 schrieb Alexander Kanavin: > > On Fri, 31 Mar 2023 at 12:40, Enrico Jorns <ejo@pengutronix.de> wrote: > > > +re_vt100 = re.compile(r'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]') > > > > This piece of 'magic' needs to be explained :) What does it define? > > this is actually 'stolen' from labgrid's implementation for barebox[1] or shell[2] drivers which > have exactly the same needs: They need to remove the ansii (color) control codes from the strings in > order to match the text only. > > The unprocessed barebox console prompt would 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. > > > Regards, Enrico > > [1] https://github.com/labgrid-project/labgrid/blob/e05f530c22513cd775b4f84e28f6c8c920b95102/labgrid/driver/bareboxdriver.py#L44 > [2] https://github.com/labgrid-project/labgrid/blob/5d3d5714976b37df0f9a9b769c581fe1f83ccbdc/labgrid/driver/shelldriver.py#L61 > > > Alex > > > > -- > Pengutronix e.K. | Enrico Jörns | > Embedded Linux Consulting & Support | https://www.pengutronix.de/ | > Steuerwalder Str. 21 | Phone: +49-5121-206917-180 | > 31137 Hildesheim, Germany | Fax: +49-5121-206917-9 | >
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 05385763ac..95c9e6596c 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py @@ -30,6 +30,7 @@ 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))) +re_vt100 = re.compile(r'(\x1b\[|\x9b)[^@-_a-z]*[@-_a-z]|\x1b[@-_a-z]') class QemuRunner: @@ -662,7 +663,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. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> --- meta/lib/oeqa/utils/qemurunner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)