From: "Enrico Jörns" <ejo@pengutronix.de>
To: openembedded-core@lists.openembedded.org
Cc: yocto@pengutronix.de
Subject: [PATCH v4 4/7] oeqa/utils/qemurunner: support ignoring vt100 escape sequences
Date: Tue, 10 Sep 2024 09:20:03 +0200 [thread overview]
Message-ID: <20240910072006.3938401-5-ejo@pengutronix.de> (raw)
In-Reply-To: <20240910072006.3938401-1-ejo@pengutronix.de>
From: Enrico Jorns <ejo@pengutronix.de>
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 ANSI 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(-)
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index cda43aad8c..63fc6f6b53 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 ANSI (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]')
def getOutput(o):
import fcntl
@@ -681,7 +683,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
next prev parent reply other threads:[~2024-09-10 7:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 7:19 [PATCH v4 0/7] Add barebox bootloader support (and testing) Enrico Jörns
2024-09-10 7:20 ` [PATCH v4 1/7] barebox: add initial support Enrico Jörns
2024-09-10 8:33 ` [OE-core] " Alexander Kanavin
2024-09-10 8:41 ` Enrico Jörns
2024-09-10 7:20 ` [PATCH v4 2/7] barebox-tools: add initial barebox tools support Enrico Jörns
2024-09-10 8:37 ` [OE-core] " Alexander Kanavin
2024-09-10 8:45 ` Enrico Jörns
2024-09-10 8:49 ` Alexander Kanavin
2024-09-10 9:02 ` Enrico Jörns
2024-09-10 9:22 ` Alexander Kanavin
2024-09-10 9:32 ` Enrico Jörns
2024-09-10 7:20 ` [PATCH v4 3/7] barebox: set default BAREBOX_CONFIG for qemu machines Enrico Jörns
2024-09-10 7:20 ` Enrico Jörns [this message]
2024-09-10 7:20 ` [PATCH v4 5/7] oeqa: support passing custom boot patterns to runqemu Enrico Jörns
2024-09-10 7:20 ` [PATCH v4 6/7] oeqa/selftest/cases: add basic u-boot test Enrico Jörns
2024-09-10 7:20 ` [PATCH v4 7/7] oeqa/selftest/cases: add basic barebox tests Enrico Jörns
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240910072006.3938401-5-ejo@pengutronix.de \
--to=ejo@pengutronix.de \
--cc=openembedded-core@lists.openembedded.org \
--cc=yocto@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox