Date
1 - 4 of 4
[PATCH v2 4/9] oeqa/utils/qemurunner: support ignoring vt100 escape sequences
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@...>
---
meta/lib/oeqa/utils/qemurunner.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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
--
2.39.2
escape sequences when matching strings.
Signed-off-by: Enrico Jorns <ejo@...>
---
meta/lib/oeqa/utils/qemurunner.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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
--
2.39.2
Hi Alex,
Am Freitag, dem 31.03.2023 um 16:05 +0200 schrieb Alexander Kanavin:
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
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 |
Am Freitag, dem 31.03.2023 um 16:05 +0200 schrieb Alexander Kanavin:
On Fri, 31 Mar 2023 at 12:40, Enrico Jorns <ejo@...> wrote:this is actually 'stolen' from labgrid's implementation for barebox[1] or shell[2] drivers which+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?
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 |
Alexander Kanavin
Right, but this information should be recorded in commit message, or
the file itself.
Alex
toggle quoted message
Show quoted text
the file itself.
Alex
On Mon, 3 Apr 2023 at 15:02, Enrico Jörns <ejo@...> 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@...> wrote:this is actually 'stolen' from labgrid's implementation for barebox[1] or shell[2] drivers which+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?
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#L61Alex--
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 |