]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/blame - meta/lib/oeqa/runtime/cases/login.py
oeqa/runtime/login: Mask out the mouse panel icon for now
[thirdparty/openembedded/openembedded-core.git] / meta / lib / oeqa / runtime / cases / login.py
CommitLineData
dc7cefba
ENF
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
d09989b4 7import shutil
dc7cefba 8import subprocess
dc7cefba 9import tempfile
d09989b4
RP
10import time
11import os
12from datetime import datetime
13from oeqa.runtime.case import OERuntimeTestCase
dc7cefba
ENF
14from oeqa.runtime.decorator.package import OEHasPackage
15
16### Status of qemu images.
17# - runqemu qemuppc64 comes up blank. (skip)
18# - qemuarmv5 comes up with multiple heads but sending "head" to screendump.
19# seems to create a png with a bad header? (skip for now, but come back to fix)
20# - qemuriscv32 and qemuloongarch64 doesn't work with testimage apparently? (skip)
21# - qemumips64 is missing mouse icon.
22# - qemumips takes forever to render and is missing mouse icon.
23# - qemuarm and qemuppc are odd as they don't resize so we need to just set width.
24# - All images have home and screen flipper icons not always rendered fully at first.
25# the sleep seems to help this out some, depending on machine load.
26###
27
28class LoginTest(OERuntimeTestCase):
d09989b4 29 @OEHasPackage(['matchbox-desktop'])
dc7cefba
ENF
30 def test_screenshot(self):
31 if self.td.get('MACHINE') in ("qemuppc64", "qemuarmv5", "qemuriscv32", "qemuloongarch64"):
32 self.skipTest("{0} is not currently supported.".format(self.td.get('MACHINE')))
33
d09989b4
RP
34 pn = self.td.get('PN')
35
36 ourenv = os.environ.copy()
37 origpath = self.td.get("ORIGPATH")
38 if origpath:
39 ourenv['PATH'] = ourenv['PATH'] + ":" + origpath
40
41 for cmd in ["identify.im7", "convert.im7", "compare.im7"]:
42 try:
43 subprocess.check_output(["which", cmd], env=ourenv)
44 except subprocess.CalledProcessError:
45 self.skipTest("%s (from imagemagick) not available" % cmd)
46
47
48 # Store images so we can debug them if needed
49 saved_screenshots_dir = self.td.get('T') + "/saved-screenshots/"
dc7cefba
ENF
50
51 ###
52 # This is a really horrible way of doing this but I've not found the
53 # right event to determine "The system is loaded and screen is rendered"
54 #
55 # Using dbus-wait for matchbox is the wrong answer because while it
56 # ensures the system is up, it doesn't mean the screen is rendered.
57 #
58 # Checking the qmp socket doesn't work afaik either.
59 #
60 # One way to do this is to do compares of known good screendumps until
61 # we either get expected or close to expected or we time out. Part of the
62 # issue here with that is that there is a very fine difference in the
63 # diff between a screendump where the icons haven't loaded yet and
64 # one where they won't load. I'll look at that next, but, for now, this.
65 #
66 # Which is ugly and I hate it but it 'works' for various definitions of
67 # 'works'.
68 ###
69
dc7cefba
ENF
70 # qemumips takes forever to render. We could probably get away with 20
71 # here were it not for that.
72 time.sleep(40)
73
74 with tempfile.NamedTemporaryFile(prefix="oeqa-screenshot-login", suffix=".png") as t:
75 ret = self.target.runner.run_monitor("screendump", args={"filename": t.name, "format":"png"})
76
77 # Find out size of image so we can determine where to blank out clock.
78 # qemuarm and qemuppc are odd as it doesn't resize the window and returns
79 # incorrect widths
d09989b4
RP
80 if self.td.get('MACHINE') == "qemuarm" or self.td.get('MACHINE') == "qemuppc":
81 width = "640"
dc7cefba
ENF
82 else:
83 cmd = "identify.im7 -ping -format '%w' {0}".format(t.name)
d09989b4 84 width = subprocess.check_output(cmd, shell=True, env=ourenv).decode()
dc7cefba 85
d09989b4 86 rblank = int(float(width))
8ec02142 87 lblank = rblank-80
dc7cefba
ENF
88
89 # Use the meta-oe version of convert, along with it's suffix. This blanks out the clock.
8ec02142 90 cmd = "convert.im7 {0} -fill white -draw 'rectangle {1},4 {2},28' {3}".format(t.name, str(rblank), str(lblank), t.name)
d09989b4
RP
91 convert_out=subprocess.check_output(cmd, shell=True, env=ourenv).decode()
92
93
94 bb.utils.mkdirhier(saved_screenshots_dir)
95 savedfile = "{0}/saved-{1}-{2}-{3}.png".format(saved_screenshots_dir, \
96 datetime.timestamp(datetime.now()), \
97 pn, \
98 self.td.get('MACHINE'))
99 shutil.copy2(t.name, savedfile)
100
101 refimage = self.td.get('COREBASE') + "/meta/files/screenshot-tests/" + pn + "-" + self.td.get('MACHINE') +".png"
102 if not os.path.exists(refimage):
103 self.skipTest("No reference image for comparision (%s)" % refimage)
104
105 cmd = "compare.im7 -metric MSE {0} {1} /dev/null".format(t.name, refimage)
106 compare_out = subprocess.run(cmd, shell=True, capture_output=True, text=True, env=ourenv)
107 diff=float(compare_out.stderr.replace("(", "").replace(")","").split()[1])
108 if diff > 0:
109 # Keep a copy of the failed screenshot so we can see what happened.
110 self.fail("Screenshot diff is {0}. Failed image stored in {1}".format(str(diff), savedfile))
dc7cefba 111 else:
d09989b4 112 self.assertEqual(0, diff, "Screenshot diff is {0}.".format(str(diff)))