Skip to contentSkip to conversation

oeqa/utils/qemurunner: change the serial runner usage

PATCH Superseded Louis Rannou 2 participants 3 messages Feb 16, 2023

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oeqa/utils/qemurunner: change the serial runner usage

[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.

---
 meta/lib/oeqa/targetcontrol.py    |  3 +++
 meta/lib/oeqa/utils/qemurunner.py | 42 ++++++++++++++++++++-----------
 2 files changed, 30 insertions(+), 15 deletions(-)
meta/lib/oeqa/targetcontrol.py +3 -0
index 1fdff82889..99fbcb5879 100644
@@ -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):
 
meta/lib/oeqa/utils/qemurunner.py +27 -15

62 lines not on this page · raw message

Signature · 1 line
2.39.1
#1 lore raw

PATCH 2/2 oeqa/utils/qemurunner: remove deprecated usage of run_serial

change tests to use the new serial runner run_serial_socket instead of the deprecated run_serial.

---
 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(-)
meta/lib/oeqa/runtime/cases/_qemutiny.py +1 -1
index 6886e36502..a6be56b6f6 100644
@@ -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)
meta/lib/oeqa/selftest/cases/overlayfs.py +10 -10
index 96beb8b869..e5aece9f92 100644
@@ -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)
meta/lib/oeqa/selftest/cases/package.py +2 -2
index 51d835259e..897bfcf321 100644
@@ -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])
meta/lib/oeqa/selftest/cases/runqemu.py +1 -1
index c1d277a095..7efbf6cbbd 100644
@@ -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:
meta/lib/oeqa/selftest/cases/runtime_test.py +2 -2
index 858f12ec90..3ec845d6da 100644
@@ -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)
 
 
meta/lib/oeqa/selftest/cases/wic.py +25 -25

103 lines not on this page · raw message

meta/lib/oeqa/utils/dump.py +1 -1
index 95a79a571c..7e5cccb90c 100644
@@ -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 "
Signature · 1 line
2.39.1
#2 lore raw
In reply to Louis Rannou

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

Quoted 110 lines · 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.

---
 meta/lib/oeqa/targetcontrol.py    |  3 +++
 meta/lib/oeqa/utils/qemurunner.py | 42 ++++++++++++++++++++-----------
 2 files changed, 30 insertions(+), 15 deletions(-)
meta/lib/oeqa/targetcontrol.py +3 -0
index 1fdff82889..99fbcb5879 100644
@@ -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):
 
meta/lib/oeqa/utils/qemurunner.py +27 -15
index c19164e6e7..c8fffd8fd1 100644
@@ -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))
 
 
Signature · 11 lines
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: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com