[PATCH v2 4/9] oeqa/utils/qemurunner: support ignoring vt100 escape sequences

Enrico Jorns
2023-03-31T10:40:47Z

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(-)

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