* [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage
@ 2023-02-16 9:54 Louis Rannou
2023-02-16 9:54 ` [PATCH 2/2] oeqa/utils/qemurunner: remove deprecated usage of run_serial Louis Rannou
2023-02-16 22:31 ` [OE-core] [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Alexandre Belloni
0 siblings, 2 replies; 3+ messages in thread
From: Louis Rannou @ 2023-02-16 9:54 UTC (permalink / raw)
To: openembedded-core; +Cc: khilman, Louis Rannou
[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 | 42 ++++++++++++++++++++-----------
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index 1fdff82889..99fbcb5879 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -210,6 +210,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 c19164e6e7..c8fffd8fd1 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -618,7 +618,13 @@ 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
+ (status, output) = self.run_serial_socket(command, raw, timeout)
+ return (0 if status else 1, output)
+
+ 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:
@@ -632,7 +638,7 @@ class QemuRunner:
while True:
now = time.time()
if now >= end:
- data += "<<< run_serial(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
+ 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)
@@ -650,21 +656,27 @@ class QemuRunner:
return (1, "")
raise Exception("No data on serial console socket, connection closed?")
- if data:
- if raw:
- status = 1
+ if not data:
+ self.logger.error("serial run returned no data")
+ raise subprocess.SubprocessError('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 = ""
+ self.logger.error("serial run returned no result")
+ raise Exception('serial run failed: no result')
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:
- status_cmd = data
- data = ""
- else:
- status_cmd = data[index+2:]
- data = data[:index]
- if (status_cmd == "0"):
- status = 1
+ 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))
--
2.39.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] oeqa/utils/qemurunner: remove deprecated usage of run_serial
2023-02-16 9:54 [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Louis Rannou
@ 2023-02-16 9:54 ` Louis Rannou
2023-02-16 22:31 ` [OE-core] [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Louis Rannou @ 2023-02-16 9:54 UTC (permalink / raw)
To: openembedded-core; +Cc: khilman, Louis Rannou
change tests to use the new serial runner run_serial_socket instead of the
deprecated run_serial.
Signed-off-by: Louis Rannou <lrannou@baylibre.com>
---
meta/lib/oeqa/runtime/cases/_qemutiny.py | 2 +-
meta/lib/oeqa/selftest/cases/overlayfs.py | 20 ++++----
meta/lib/oeqa/selftest/cases/package.py | 4 +-
meta/lib/oeqa/selftest/cases/runqemu.py | 2 +-
meta/lib/oeqa/selftest/cases/runtime_test.py | 4 +-
meta/lib/oeqa/selftest/cases/wic.py | 50 ++++++++++----------
meta/lib/oeqa/utils/dump.py | 2 +-
7 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/meta/lib/oeqa/runtime/cases/_qemutiny.py b/meta/lib/oeqa/runtime/cases/_qemutiny.py
index 6886e36502..a6be56b6f6 100644
--- a/meta/lib/oeqa/runtime/cases/_qemutiny.py
+++ b/meta/lib/oeqa/runtime/cases/_qemutiny.py
@@ -7,6 +7,6 @@ from oeqa.runtime.case import OERuntimeTestCase
class QemuTinyTest(OERuntimeTestCase):
def test_boot_tiny(self):
- status, output = self.target.run_serial('uname -a')
+ status, output = self.target.run_serial_socket('uname -a')
msg = "Cannot detect poky tiny boot!"
self.assertTrue("yocto-tiny" in output, msg)
diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py b/meta/lib/oeqa/selftest/cases/overlayfs.py
index 96beb8b869..e5aece9f92 100644
--- a/meta/lib/oeqa/selftest/cases/overlayfs.py
+++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
@@ -180,20 +180,20 @@ EOT
with runqemu('core-image-minimal') as qemu:
# Check that application service started
- status, output = qemu.run_serial("systemctl status my-application")
+ status, output = qemu.run_serial_socket("systemctl status my-application")
self.assertTrue("active (exited)" in output, msg=output)
# Check that overlay mounts are dependencies of our application unit
- status, output = qemu.run_serial("systemctl list-dependencies my-application")
+ status, output = qemu.run_serial_socket("systemctl list-dependencies my-application")
self.assertTrue("overlayfs-user-overlays.service" in output, msg=output)
- status, output = qemu.run_serial("systemctl list-dependencies overlayfs-user-overlays")
+ status, output = qemu.run_serial_socket("systemctl list-dependencies overlayfs-user-overlays")
self.assertTrue("usr-share-another\\x2doverlay\\x2dmount.mount" in output, msg=output)
self.assertTrue("usr-share-my\\x2dapplication.mount" in output, msg=output)
# Check that we have /mnt/overlay fs mounted as tmpfs and
# /usr/share/my-application as an overlay (see overlayfs-user recipe)
- status, output = qemu.run_serial("/bin/mount -t tmpfs,overlay")
+ status, output = qemu.run_serial_socket("/bin/mount -t tmpfs,overlay")
line = getline_qemu(output, "on /mnt/overlay")
self.assertTrue(line and line.startswith("tmpfs"), msg=output)
@@ -372,7 +372,7 @@ OVERLAYFS_ETC_DEVICE = "/dev/sda3"
bitbake('core-image-minimal')
with runqemu('core-image-minimal', image_fstype='wic') as qemu:
- status, output = qemu.run_serial("/bin/mount")
+ status, output = qemu.run_serial_socket("/bin/mount")
line = getline_qemu(output, "upperdir=/data/overlay-etc/upper")
self.assertFalse(line, msg=output)
@@ -424,7 +424,7 @@ OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}"
testFile = "/etc/my-test-data"
with runqemu('core-image-minimal', image_fstype='wic', discard_writes=False) as qemu:
- status, output = qemu.run_serial("/bin/mount")
+ status, output = qemu.run_serial_socket("/bin/mount")
line = getline_qemu(output, "/dev/sda3")
self.assertTrue("/data" in output, msg=output)
@@ -432,14 +432,14 @@ OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "{OVERLAYFS_ETC_USE_ORIG_INIT_NAME}"
line = getline_qemu(output, "upperdir=/data/overlay-etc/upper")
self.assertTrue(line and line.startswith("/data/overlay-etc/upper on /etc type overlay"), msg=output)
- status, output = qemu.run_serial("touch " + testFile)
- status, output = qemu.run_serial("sync")
- status, output = qemu.run_serial("ls -1 " + testFile)
+ status, output = qemu.run_serial_socket("touch " + testFile)
+ status, output = qemu.run_serial_socket("sync")
+ status, output = qemu.run_serial_socket("ls -1 " + testFile)
line = getline_qemu(output, testFile)
self.assertTrue(line and line.startswith(testFile), msg=output)
# Check that file exists in /etc after reboot
with runqemu('core-image-minimal', image_fstype='wic') as qemu:
- status, output = qemu.run_serial("ls -1 " + testFile)
+ status, output = qemu.run_serial_socket("ls -1 " + testFile)
line = getline_qemu(output, testFile)
self.assertTrue(line and line.startswith(testFile), msg=output)
diff --git a/meta/lib/oeqa/selftest/cases/package.py b/meta/lib/oeqa/selftest/cases/package.py
index 51d835259e..897bfcf321 100644
--- a/meta/lib/oeqa/selftest/cases/package.py
+++ b/meta/lib/oeqa/selftest/cases/package.py
@@ -126,7 +126,7 @@ class PackageTests(OESelftestTestCase):
Check that gdb ``binary`` to read symbols from separated debug file
"""
self.logger.info("gdbtest %s" % binary)
- status, output = qemu.run_serial('/usr/bin/gdb.sh %s' % binary, timeout=60)
+ status, output = qemu.run_serial_socket('/usr/bin/gdb.sh %s' % binary, timeout=60)
for l in output.split('\n'):
# Check debugging symbols exists
if '(no debugging symbols found)' in l:
@@ -157,7 +157,7 @@ class PackageTests(OESelftestTestCase):
sysconfdir = get_bb_var('sysconfdir', 'selftest-chown')
def check_ownership(qemu, gid, uid, path):
self.logger.info("Check ownership of %s", path)
- status, output = qemu.run_serial(r'/bin/stat -c "%U %G" ' + path, timeout=60)
+ status, output = qemu.run_serial_socket(r'/bin/stat -c "%U %G" ' + path, timeout=60)
output = output.split(" ")
if output[0] != uid or output[1] != gid :
self.logger.error("Incrrect ownership %s [%s:%s]", path, output[0], output[1])
diff --git a/meta/lib/oeqa/selftest/cases/runqemu.py b/meta/lib/oeqa/selftest/cases/runqemu.py
index c1d277a095..7efbf6cbbd 100644
--- a/meta/lib/oeqa/selftest/cases/runqemu.py
+++ b/meta/lib/oeqa/selftest/cases/runqemu.py
@@ -169,7 +169,7 @@ class QemuTest(OESelftestTestCase):
# (such as the exception "Console connection closed unexpectedly")
# as qemu will disappear when we shut it down
qemu.runner.allowexit()
- qemu.run_serial("shutdown -h now")
+ qemu.run_serial_socket("shutdown -h now")
time_track = 0
try:
while True:
diff --git a/meta/lib/oeqa/selftest/cases/runtime_test.py b/meta/lib/oeqa/selftest/cases/runtime_test.py
index 858f12ec90..3ec845d6da 100644
--- a/meta/lib/oeqa/selftest/cases/runtime_test.py
+++ b/meta/lib/oeqa/selftest/cases/runtime_test.py
@@ -312,9 +312,9 @@ class Postinst(OESelftestTestCase):
with runqemu('core-image-minimal') as qemu:
# Make the test echo a string and search for that as
- # run_serial()'s status code is useless.'
+ # run_serial_socket()'s status code is useless.'
for filename in ("rootfs", "delayed-a", "delayed-b"):
- status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
+ status, output = qemu.run_serial_socket("test -f %s && echo found" % os.path.join(targettestdir, filename))
self.assertIn("found", output, "%s was not present on boot" % filename)
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index 49fb6fe52c..8442008d6b 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -850,12 +850,12 @@ class Wic2(WicTestCase):
with runqemu('wic-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' " \
"-e '/dev/root /|/dev/sda2 /' -e '/dev/sda3 /media' -e '/dev/sda4 /mnt'"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '4')
cmd = "grep UUID= /etc/fstab"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, 'UUID=2c71ef06-a81d-4735-9d3a-379b69c6bdba\t/media\text4\tdefaults\t0\t0')
@only_for_arch(['i586', 'i686', 'x86_64'])
@@ -870,8 +870,8 @@ class Wic2(WicTestCase):
with runqemu('core-image-minimal', ssh=False,
runqemuparams='nographic ovmf', image_fstype='wic') as qemu:
cmd = "grep sda. /proc/partitions |wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '3')
@staticmethod
@@ -1060,8 +1060,8 @@ class Wic2(WicTestCase):
with runqemu('core-image-minimal-mtdutils', ssh=False,
runqemuparams='nographic', image_fstype='wic') as qemu:
cmd = "grep sda. /proc/partitions |wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '2')
def _rawcopy_plugin(self, fstype):
@@ -1122,24 +1122,24 @@ class Wic2(WicTestCase):
runqemuparams='nographic', image_fstype='wic') as qemu:
# Check that we have ONLY two /dev/sda* partitions (/boot and /)
cmd = "grep sda. /proc/partitions | wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '2')
# Check that /dev/sda1 is /boot and that either /dev/root OR /dev/sda2 is /
cmd = "mount | grep '^/dev/' | cut -f1,3 -d ' ' | egrep -c -e '/dev/sda1 /boot' -e '/dev/root /|/dev/sda2 /'"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '2')
# Check that /boot has EFI bootx64.efi (required for EFI)
cmd = "ls /boot/EFI/BOOT/bootx64.efi | wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '1')
# Check that "BOOTABLE" flag is set on boot partition (required for PC-Bios)
- # Trailing "cat" seems to be required; otherwise run_serial() sends back echo of the input command
+ # Trailing "cat" seems to be required; otherwise run_serial_socket() sends back echo of the input command
cmd = "fdisk -l /dev/sda | grep /dev/sda1 | awk {print'$2'} | cat"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '*')
@only_for_arch(['i586', 'i686', 'x86_64'])
@@ -1185,18 +1185,18 @@ class Wic2(WicTestCase):
runqemuparams='nographic ovmf', image_fstype='wic') as qemu:
# Check that /boot has EFI bootx64.efi (required for EFI)
cmd = "ls /boot/EFI/BOOT/bootx64.efi | wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '1')
# Check that /boot has EFI/Linux/linux.efi (required for Unified Kernel Images auto detection)
cmd = "ls /boot/EFI/Linux/linux.efi | wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '1')
# Check that /boot doesn't have loader/entries/boot.conf (Unified Kernel Images are auto detected by the bootloader)
cmd = "ls /boot/loader/entries/boot.conf 2&>/dev/null | wc -l"
- status, output = qemu.run_serial(cmd)
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket(cmd)
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
self.assertEqual(output, '0')
def test_fs_types(self):
@@ -1333,8 +1333,8 @@ class Wic2(WicTestCase):
# Check if it boots in qemu
with runqemu('core-image-minimal', ssh=False, runqemuparams='nographic') as qemu:
cmd = "ls /etc/"
- status, output = qemu.run_serial('true')
- self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output))
+ status, output = qemu.run_serial_socket('true')
+ self.assertEqual(0, status, 'Failed to run command "%s": %s' % (cmd, output))
finally:
if os.path.exists(new_image_path):
os.unlink(new_image_path)
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py
index 95a79a571c..7e5cccb90c 100644
--- a/meta/lib/oeqa/utils/dump.py
+++ b/meta/lib/oeqa/utils/dump.py
@@ -103,7 +103,7 @@ class TargetDumper(BaseDumper):
for cmd in self.cmds:
# We can continue with the testing if serial commands fail
try:
- (status, output) = self.runner.run_serial(cmd)
+ (status, output) = self.runner.run_serial_socket(cmd)
self._write_dump(cmd.split()[0], output)
except:
print("Tried to dump info from target but "
--
2.39.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [OE-core] [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage
2023-02-16 9:54 [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Louis Rannou
2023-02-16 9:54 ` [PATCH 2/2] oeqa/utils/qemurunner: remove deprecated usage of run_serial Louis Rannou
@ 2023-02-16 22:31 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2023-02-16 22:31 UTC (permalink / raw)
To: Louis Rannou; +Cc: openembedded-core, khilman
I applied just this one, as the other one doesn't apply and most of the
builds failed with an error similar to this one;
2023-02-16 09:14:29,678 - oe-selftest - INFO - ======================================================================
2023-02-16 09:14:29,678 - oe-selftest - INFO - ERROR: overlayfs.OverlayFSEtcRunTimeTests.test_sbin_init_original (subunit.RemotedTestCase)
2023-02-16 09:14:29,679 - oe-selftest - INFO - ----------------------------------------------------------------------
2023-02-16 09:14:29,679 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
File "/home/pokybuild/yocto-worker/oe-selftest-debian/build/meta/lib/oeqa/core/decorator/__init__.py", line 35, in wrapped_f
return func(*args, **kwargs)
File "/home/pokybuild/yocto-worker/oe-selftest-debian/build/meta/lib/oeqa/selftest/cases/overlayfs.py", line 380, in test_sbin_init_original
self.run_sbin_init(True)
File "/home/pokybuild/yocto-worker/oe-selftest-debian/build/meta/lib/oeqa/selftest/cases/overlayfs.py", line 415, in run_sbin_init
status, output = qemu.run_serial("touch " + testFile)
File "/home/pokybuild/yocto-worker/oe-selftest-debian/build/meta/lib/oeqa/targetcontrol.py", line 211, in run_serial
return self.runner.run_serial(command, timeout=timeout)
File "/home/pokybuild/yocto-worker/oe-selftest-debian/build/meta/lib/oeqa/utils/qemurunner.py", line 642, in run_serial
(status, output) = self.run_serial_socket(command, raw, timeout)
File "/home/pokybuild/yocto-worker/oe-selftest-debian/build/meta/lib/oeqa/utils/qemurunner.py", line 693, in run_serial_socket
raise Exception('serial run failed: no result')
Exception: serial run failed: no result
On 16/02/2023 10:54:39+0100, Louis Rannou wrote:
> [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 | 42 ++++++++++++++++++++-----------
> 2 files changed, 30 insertions(+), 15 deletions(-)
>
> diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
> index 1fdff82889..99fbcb5879 100644
> --- a/meta/lib/oeqa/targetcontrol.py
> +++ b/meta/lib/oeqa/targetcontrol.py
> @@ -210,6 +210,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 c19164e6e7..c8fffd8fd1 100644
> --- a/meta/lib/oeqa/utils/qemurunner.py
> +++ b/meta/lib/oeqa/utils/qemurunner.py
> @@ -618,7 +618,13 @@ 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
> + (status, output) = self.run_serial_socket(command, raw, timeout)
> + return (0 if status else 1, output)
> +
> + 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:
> @@ -632,7 +638,7 @@ class QemuRunner:
> while True:
> now = time.time()
> if now >= end:
> - data += "<<< run_serial(): command timed out after %d seconds without output >>>\r\n\r\n" % timeout
> + 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)
> @@ -650,21 +656,27 @@ class QemuRunner:
> return (1, "")
> raise Exception("No data on serial console socket, connection closed?")
>
> - if data:
> - if raw:
> - status = 1
> + if not data:
> + self.logger.error("serial run returned no data")
> + raise subprocess.SubprocessError('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 = ""
> + self.logger.error("serial run returned no result")
> + raise Exception('serial run failed: no result')
> 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:
> - status_cmd = data
> - data = ""
> - else:
> - status_cmd = data[index+2:]
> - data = data[:index]
> - if (status_cmd == "0"):
> - status = 1
> + 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))
>
>
> --
> 2.39.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#177280): https://lists.openembedded.org/g/openembedded-core/message/177280
> Mute This Topic: https://lists.openembedded.org/mt/97002779/3617179
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alexandre.belloni@bootlin.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-16 22:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16 9:54 [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Louis Rannou
2023-02-16 9:54 ` [PATCH 2/2] oeqa/utils/qemurunner: remove deprecated usage of run_serial Louis Rannou
2023-02-16 22:31 ` [OE-core] [PATCH 1/2] oeqa/utils/qemurunner: change the serial runner usage Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox