Skip to contentSkip to conversation

image-tests and sstate permissions testing

PATCH New Eilís 'pidge' Ní Fhlannagáin 1 participant 5 messages Feb 29, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

cover image-tests and sstate permissions testing

This patch series implements image-testing proof of concept and sstate permissions testing for self test. It fixes an issue in qemurunner due to changes in QEMUMonitorProtocol.cmd() and adds test png images to compare against for the image-testing.

Eilís 'pidge' Ní Fhlannagáin (4):
sstatetests.py: Add testing for correct sstate permissions qemurunner.py: Fix error on calls to run_monitor
image-tests: Add initial image test png files login.py: Proof of concept for screenshot testcases

 .../image-tests/core-image-sato-qemuarm.png   | Bin 0 -> 52405 bytes
 .../image-tests/core-image-sato-qemuarm64.png | Bin 0 -> 47505 bytes
 .../image-tests/core-image-sato-qemumips.png  | Bin 0 -> 46634 bytes
 .../core-image-sato-qemumips64.png            | Bin 0 -> 46053 bytes
 .../image-tests/core-image-sato-qemuppc.png   | Bin 0 -> 52232 bytes
 .../core-image-sato-qemuriscv64.png           | Bin 0 -> 38806 bytes
 .../image-tests/core-image-sato-qemux86.png   | Bin 0 -> 46548 bytes
 meta/lib/oeqa/runtime/cases/login.py          | 107 ++++++++++++++++++
 meta/lib/oeqa/selftest/cases/sstatetests.py   |  28 ++++-
 meta/lib/oeqa/utils/qemurunner.py             |   4 +-
 10 files changed, 136 insertions(+), 3 deletions(-)
 create mode 100644 meta/files/image-tests/core-image-sato-qemuarm.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemuarm64.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemumips.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemumips64.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemuppc.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemuriscv64.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemux86.png
 create mode 100644 meta/lib/oeqa/runtime/cases/login.py
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 sstatetests.py: Add testing for correct sstate permissions

This patch adds to run_test_sstate_creation so that it also tests that sstate directories don't accidentally pickup umask permissions from the user upon creation.

---
 meta/lib/oeqa/selftest/cases/sstatetests.py | 28 ++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/sstatetests.py +27 -1
index 56dfcdb0f39..c5581d52628 100644
@@ -79,7 +79,7 @@ class SStateBase(OESelftestTestCase):
                         result.append(f)
         return result
 
-    # Test sstate files creation and their location
+    # Test sstate files creation and their location and directory perms
     def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
         self.config_sstate(temp_sstate_location, [self.sstate_path])
 
@@ -88,6 +88,19 @@ class SStateBase(OESelftestTestCase):
         else:
             bitbake(['-ccleansstate'] + targets)
 
+        # We need to test that the env umask have does not effect sstate directory creation
+        # So, first, we'll get the current umask and set it to something we know incorrect
+        # See: sstate_task_postfunc for correct umask of os.umask(0o002)
+        import os
+        def current_umask():
+            current_umask = os.umask(0)
+            os.umask(current_umask)
+            return current_umask 
+
+        orig_umask = current_umask()
+        # Set it to a umask we know will be 'wrong'
+        os.umask(0o022)
+
         bitbake(targets)
         file_tracker = []
         results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
@@ -104,6 +117,19 @@ class SStateBase(OESelftestTestCase):
         else:
             self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker)))
 
+        # Now we'll walk the tree to check the mode and see if things are incorrect.
+        badperms = []
+        for root, dirs, files in os.walk(self.sstate_path):
+            for directory in dirs:
+                if str(oct(os.stat(os.path.join(root, directory)).st_mode & 0o777)) != "0o775":
+                    badperms.append(os.path.join(root, directory))
+
+        # Return to original umask
+        os.umask(orig_umask)
+
+        if should_pass:
+            self.assertTrue(badperms , msg="Found sstate directories with the wrong permissions: %s (found %s)" % (', '.join(map(str, targets)), str(badperms)))
+
     # Test the sstate files deletion part of the do_cleansstate task
     def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
         self.config_sstate(temp_sstate_location, [self.sstate_path])
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/4 qemurunner.py: Fix error on calls to run_monitor

In reply to Eilís 'pidge' Ní Fhlannagáin

A change in QEMUMonitorProtocol.cmd() requires that we either pass in kwargs instead of an argument dict or move to cmd_raw()

cmd() was renamed to cmd_raw() (and command() was renamed to cmd()) See:
https://github.com/qemu/qemu/commit/37274707f6f3868fae7e0055d9a703006fc142d0
https://github.com/qemu/qemu/commit/684750ab4f8a3ad69512b71532408be3ac2547d4

My concern with this patch is that I haven't seen this come up with utils/dump.py which also uses QemuMonitor's run_monitor. If it is occuring, this should fix issues there as well

---
 meta/lib/oeqa/utils/qemurunner.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +2 -2
index 277cd328484..cda43aad8c5 100644
@@ -650,9 +650,9 @@ class QemuRunner:
         if hasattr(self, 'qmp') and self.qmp:
             self.qmp.settimeout(timeout)
             if args is not None:
-                return self.qmp.cmd(command, args)
+                return self.qmp.cmd_raw(command, args)
             else:
-                return self.qmp.cmd(command)
+                return self.qmp.cmd_raw(command)
 
     def run_serial(self, command, raw=False, timeout=60):
         # Returns (status, output) where status is 1 on success and 0 on error
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/4 image-tests: Add initial image test png files

In reply to Eilís 'pidge' Ní Fhlannagáin

This is an initial commit of png's we can use to test qemu image testing against.

---
 .../image-tests/core-image-sato-qemuarm.png     | Bin 0 -> 52405 bytes
 .../image-tests/core-image-sato-qemuarm64.png   | Bin 0 -> 47505 bytes
 .../image-tests/core-image-sato-qemumips.png    | Bin 0 -> 46634 bytes
 .../image-tests/core-image-sato-qemumips64.png  | Bin 0 -> 46053 bytes
 .../image-tests/core-image-sato-qemuppc.png     | Bin 0 -> 52232 bytes
 .../image-tests/core-image-sato-qemuriscv64.png | Bin 0 -> 38806 bytes
 .../image-tests/core-image-sato-qemux86.png     | Bin 0 -> 46548 bytes
 7 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 meta/files/image-tests/core-image-sato-qemuarm.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemuarm64.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemumips.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemumips64.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemuppc.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemuriscv64.png
 create mode 100644 meta/files/image-tests/core-image-sato-qemux86.png
meta/files/image-tests/core-image-sato-qemuarm.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..43b069fdb7654bbb1691a91ec585c580801f41a1
GIT binary patch
meta/files/image-tests/core-image-sato-qemuarm64.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..007071ea951cacf85a2cb821336e00803a6eab51
GIT binary patch
meta/files/image-tests/core-image-sato-qemumips.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..9122038fe929924613bc6e62ee9438eb661dcdfc
GIT binary patch
meta/files/image-tests/core-image-sato-qemumips64.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4210d657bf466ea85010409aa200fd5604a2b798
GIT binary patch
meta/files/image-tests/core-image-sato-qemuppc.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..5b61c8e1c5bcc610272599efd4335a669c057b13
GIT binary patch
meta/files/image-tests/core-image-sato-qemuriscv64.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..3d872b2b1f8dbbd200fdd6fe92d2106ae3579d3d
GIT binary patch
meta/files/image-tests/core-image-sato-qemux86.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6a0c735f7488f0ed9b6f93fd044c4b21cb94a53c
GIT binary patch
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/4 login.py: Proof of concept for screenshot testcases

In reply to Eilís 'pidge' Ní Fhlannagáin

This takes the work rburton did on image screenshot testing and expands it.

Right now this works with most of the qemu based machines except for

- qemuppc64
- qemuarmv5
- qemuriscv32
- qemuloongarch64

See "Known Issues" further down.

This test takes a screendump of a qemu image, blanks out the clock and compares it to an image we have on record. If the diff is exact, the test passes. If not, it stores the image in build/failed-images and fails out.

In order to enable this test, you will need meta-openembedded/meta-oe in your bblayers.conf for imagemagick and the following in local.conf:

IMAGE_CLASSES += "testimage"
TEST_SUITES = "login"
TESTIMAGEDEPENDS:append:qemuall = " imagemagick-native:do_populate_sysroot "

Known Issues
------------

The main issue is that I've yet to find a gating factor that would allow me to tell when the qemu instance is fully up and rendered. I've tried a few tactics here, (dbus-wait, qmp) but for now a disgusting time.sleep(30) is there.

You can replicate this by running qemumips. The screen load takes forever, but you even see it on qemux86 where the Home and Workspace Switch icons will sometimes take a while to fully load.

Eventually I'm going to have to take multiple screenshots and compare them, but then you get into the issue where the question is, is the diff greater than 0 because it hasn't fully loaded or something is actually incorrect.

There are the issues I know about:

- runqemu qemuppc64 comes up blank.
- qemuarmv5 comes up with multiple heads but sending "head" to screendump. seems to create a png with a bad header.
- qemuriscv32 and qemuloongarch64 don't work with testimage apparently?
- qemumips64 is missing mouse icon.
- qemumips takes forever to render and is missing mouse icon.
- qemuarm and qemuppc return incorrect width
- All images have home and screen flipper icons not always rendered fully at first. The sleep seems to help this out some, depending on machine load.

---
 meta/lib/oeqa/runtime/cases/login.py | 107 +++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)
 create mode 100644 meta/lib/oeqa/runtime/cases/login.py
meta/lib/oeqa/runtime/cases/login.py new file +107 -0
new file mode 100644
index 00000000000..aea3bfc778e
@@ -0,0 +1,107 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+import subprocess
+from oeqa.runtime.case import OERuntimeTestCase
+import tempfile
+from oeqa.runtime.decorator.package import OEHasPackage
+
+### Status of qemu images.
+#   - runqemu qemuppc64 comes up blank. (skip)
+#   - qemuarmv5 comes up with multiple heads but sending "head" to screendump.
+#     seems to create a png with a bad header? (skip for now, but come back to fix)
+#   - qemuriscv32 and qemuloongarch64 doesn't work with testimage apparently? (skip)
+#   - qemumips64 is missing mouse icon.
+#   - qemumips takes forever to render and is missing mouse icon.
+#   - qemuarm and qemuppc are odd as they don't resize so we need to just set width.
+#   - All images have home and screen flipper icons not always rendered fully at first.
+#     the sleep seems to help this out some, depending on machine load.
+###
+
+class LoginTest(OERuntimeTestCase):
+    def test_screenshot(self):
+        if self.td.get('MACHINE') in ("qemuppc64", "qemuarmv5", "qemuriscv32", "qemuloongarch64"):
+            self.skipTest("{0} is not currently supported.".format(self.td.get('MACHINE')))
+
+        # Set DEBUG_CREATE_IMAGES to 1 in order to populate the image-test images directory.
+        DEBUG_CREATE_IMAGES="0"
+        # Store failed images so we can debug them.
+        failed_image_dir=self.td.get('TOPDIR') + "/failed-images/"
+
+        ###
+        # This is a really horrible way of doing this but I've not found the
+        # right event to determine "The system is loaded and screen is rendered"
+        #
+        # Using dbus-wait for matchbox is the wrong answer because while it
+        # ensures the system is up, it doesn't mean the screen is rendered.
+        #
+        # Checking the qmp socket doesn't work afaik either.
+        #
+        # One way to do this is to do compares of known good screendumps until
+        # we either get expected or close to expected or we time out. Part of the
+        # issue here with that is that there is a very fine difference in the
+        # diff between a screendump where the icons haven't loaded yet and
+        # one where they won't load. I'll look at that next, but, for now, this.
+        #
+        # Which is ugly and I hate it but it 'works' for various definitions of
+        # 'works'.
+        ###
+
+        import time
+        
+        # qemumips takes forever to render. We could probably get away with 20
+        # here were it not for that.
+        time.sleep(40)
+
+        with tempfile.NamedTemporaryFile(prefix="oeqa-screenshot-login", suffix=".png") as t:
+            ret = self.target.runner.run_monitor("screendump", args={"filename": t.name, "format":"png"})
+
+            # Find out size of image so we can determine where to blank out clock.
+            # qemuarm and qemuppc are odd as it doesn't resize the window and returns
+            # incorrect widths
+            if self.td.get('MACHINE')=="qemuarm" or self.td.get('MACHINE')=="qemuppc":
+                width="640"
+            else:
+                cmd = "identify.im7 -ping -format '%w' {0}".format(t.name)
+                width = subprocess.check_output(cmd, shell=True).decode()
+
+            rblank=int(float(width))
+            lblank=rblank-40
+
+            # Use the meta-oe version of convert, along with it's suffix. This blanks out the clock.
+            cmd = "convert.im7 {0} -fill white -draw 'rectangle {1},10 {2},22' {3}".format(t.name, str(rblank), str(lblank), t.name)
+            convert_out=subprocess.check_output(cmd, shell=True).decode()
+
+            if DEBUG_CREATE_IMAGES=="1":
+                # You probably aren't interested in this as it's just to create the images we compare against.
+                import shutil
+                shutil.copy2(t.name, "{0}/meta/files/image-tests/core-image-sato-{1}.png".format(self.td.get('COREBASE'), \
+                                                                                                 self.td.get('MACHINE')))
+                self.skipTest("Created a reference image for {0} and placed it in {1}/meta/files/image-tests/.".format(self.td.get('MACHINE'), self.td.get('COREBASE')))
+            else:
+                # Use the meta-oe version of compare, along with it's suffix.
+                cmd = "compare.im7 -metric MSE {0} {1}/meta/files/image-tests/core-image-sato-{2}.png /dev/null".format(t.name, \
+                                                                                                                        self.td.get('COREBASE'), \
+                                                                                                                        self.td.get('MACHINE'))
+                compare_out = subprocess.run(cmd, shell=True, capture_output=True, text=True)
+                diff=float(compare_out.stderr.replace("(", "").replace(")","").split()[1])
+                if diff > 0:
+                    from datetime import datetime
+                    import shutil
+                    import os
+                    try:
+                        os.mkdir(failed_image_dir)
+                    except FileExistsError:
+                        # directory exists
+                        pass
+                    # Keep a copy of the failed screenshot so we can see what happened.
+                    failedfile="{0}/failed-{1}-core-image-sato-{2}.png".format(failed_image_dir, \
+                                                                               datetime.timestamp(datetime.now()), \
+                                                                               self.td.get('MACHINE'))
+                    shutil.copy2(t.name, failedfile)
+                    self.fail("Screenshot diff is {0}. Failed image stored in {1}".format(str(diff), failedfile))
+                else:
+                    self.assertEqual(0, diff, "Screenshot diff is {0}.".format(str(diff)))
Signature · 1 line
2.34.1