From: Louis Rannou <lrannou@baylibre.com>
To: openembedded-core@lists.openembedded.org
Cc: khilman@baylibre.com, Louis Rannou <lrannou@baylibre.com>
Subject: [PATCH v4 1/2] oeqa/utils/qemurunner: change the serial runner
Date: Tue, 11 Apr 2023 17:05:02 +0200 [thread overview]
Message-ID: <20230411150503.2105880-2-lrannou@baylibre.com> (raw)
In-Reply-To: <20230411150503.2105880-1-lrannou@baylibre.com>
[YOCTO #15021]
Create a new runner run_serial_socket which usage matches the traditional ssh
runner. Its return status is 0 when the command succeeded or 0 when it
failed. If an error is encountered, it raises an Exception.
The previous serial runner is maintained and marked as deprecated.
Signed-off-by: Louis Rannou <lrannou@baylibre.com>
---
meta/lib/oeqa/targetcontrol.py | 3 ++
meta/lib/oeqa/utils/qemurunner.py | 57 +++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index d686fe07ec..3707883da7 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -206,6 +206,9 @@ class QemuTarget(BaseTarget):
def run_serial(self, command, timeout=60):
return self.runner.run_serial(command, timeout=timeout)
+ def run_serial_socket(self, command, timeout=60):
+ return self.runner.run_serial_socket(command, timeout=timeout)
+
class SimpleRemoteTarget(BaseTarget):
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 6734cee48d..7e1c7a7eac 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -637,6 +637,7 @@ class QemuRunner:
return self.qmp.cmd(command)
def run_serial(self, command, raw=False, timeout=60):
+ # Deprecated
# Returns (status, output) where status is 1 on success and 0 on error
# We assume target system have echo to get command status
@@ -688,6 +689,62 @@ class QemuRunner:
status = 1
return (status, str(data))
+ def run_serial_socket(self, command, raw=False, timeout=60):
+ # Returns (status, output) where status is 0 on success and a negative value on error.
+
+ # We assume target system have echo to get command status
+ if not raw:
+ command = "%s; echo $?\n" % command
+
+ data = ''
+ status = 0
+ self.server_socket.sendall(command.encode('utf-8'))
+ start = time.time()
+ end = start + timeout
+ while True:
+ now = time.time()
+ if now >= end:
+ data += "<<< run_serial_socket(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
+ break
+ try:
+ sread, _, _ = select.select([self.server_socket],[],[], end - now)
+ except InterruptedError:
+ continue
+ if sread:
+ # try to avoid reading single character at a time
+ time.sleep(0.1)
+ answer = self.server_socket.recv(1024)
+ if answer:
+ data += answer.decode('utf-8')
+ # Search the prompt to stop
+ if re.search(self.boot_patterns['search_cmd_finished'], data):
+ break
+ else:
+ if self.canexit:
+ return (1, "")
+ raise Exception("No data on serial console socket, connection closed?")
+
+ if not data:
+ raise Exception('serial run failed: no data')
+
+ if raw:
+ status = 0
+ else:
+ # Remove first line (command line) and last line (prompt)
+ data = data[data.find('$?\r\n')+4:data.rfind('\r\n')]
+ index = data.rfind('\r\n')
+ if index == -1:
+ data = ""
+ raise Exception('serial run failed: no result')
+ else:
+ status_cmd = data[index+2:]
+ data = data[:index]
+ try:
+ status = int(status_cmd)
+ except ValueError as e:
+ raise Exception('Could not convert to integer: {}'.format(str(e)))
+ return (status, str(data))
+
def _dump_host(self):
self.host_dumper.create_dir("qemu")
--
2.40.0
next prev parent reply other threads:[~2023-04-11 15:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 15:05 [PATCH v4 0/2] oeqa: Change the serial runner Louis Rannou
2023-04-11 15:05 ` Louis Rannou [this message]
2023-04-12 7:57 ` [OE-core] [PATCH v4 1/2] oeqa/utils/qemurunner: change " Luca Ceresoli
2023-04-18 7:31 ` Louis Rannou
2023-05-05 10:32 ` Ross Burton
2023-05-05 10:36 ` Ross Burton
2023-05-05 10:50 ` Richard Purdie
2023-05-09 12:22 ` Louis Rannou
2023-04-11 15:05 ` [PATCH v4 2/2] oeqa/selftest: change deprecated usage of run_serial Louis Rannou
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=20230411150503.2105880-2-lrannou@baylibre.com \
--to=lrannou@baylibre.com \
--cc=khilman@baylibre.com \
--cc=openembedded-core@lists.openembedded.org \
/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