diff options
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/login.py')
-rw-r--r-- | meta/lib/oeqa/runtime/cases/login.py | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/cases/login.py b/meta/lib/oeqa/runtime/cases/login.py new file mode 100644 index 0000000000..e1bc60d49b --- /dev/null +++ b/meta/lib/oeqa/runtime/cases/login.py | |||
@@ -0,0 +1,116 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
7 | import shutil | ||
8 | import subprocess | ||
9 | import tempfile | ||
10 | import time | ||
11 | import os | ||
12 | from datetime import datetime | ||
13 | from oeqa.runtime.case import OERuntimeTestCase | ||
14 | from 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 | |||
28 | class LoginTest(OERuntimeTestCase): | ||
29 | @OEHasPackage(['matchbox-desktop', 'dbus-wait']) | ||
30 | def test_screenshot(self): | ||
31 | if self.td.get('MACHINE') in ("qemuppc64", "qemuarmv5", "qemuriscv32", "qemuriscv64", "qemuloongarch64"): | ||
32 | self.skipTest("{0} is not currently supported.".format(self.td.get('MACHINE'))) | ||
33 | |||
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/" | ||
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 | # RP: if the signal is sent before we run this, it will never be seen and we'd timeout | ||
70 | #status, output = self.target.run('dbus-wait org.matchbox_project.desktop Loaded') | ||
71 | #if status != 0 or "Timeout" in output: | ||
72 | # self.fail('dbus-wait failed (%s, %s). This could mean that the image never loaded the matchbox desktop.' % (status, output)) | ||
73 | |||
74 | # Start taking screenshots every 2 seconds until diff=0 or timeout is 60 seconds | ||
75 | timeout = time.time() + 60 | ||
76 | diff = True | ||
77 | with tempfile.NamedTemporaryFile(prefix="oeqa-screenshot-login", suffix=".png") as t: | ||
78 | while diff != 0 and time.time() < timeout: | ||
79 | time.sleep(2) | ||
80 | ret = self.target.runner.run_monitor("screendump", args={"filename": t.name, "format":"png"}) | ||
81 | |||
82 | # Find out size of image so we can determine where to blank out clock. | ||
83 | # qemuarm and qemuppc are odd as it doesn't resize the window and returns | ||
84 | # incorrect widths | ||
85 | if self.td.get('MACHINE') == "qemuarm" or self.td.get('MACHINE') == "qemuppc": | ||
86 | width = "640" | ||
87 | else: | ||
88 | cmd = "identify.im7 -ping -format '%w' {0}".format(t.name) | ||
89 | width = subprocess.check_output(cmd, shell=True, env=ourenv).decode() | ||
90 | |||
91 | rblank = int(float(width)) | ||
92 | lblank = rblank-80 | ||
93 | |||
94 | # Use the meta-oe version of convert, along with it's suffix. This blanks out the clock. | ||
95 | cmd = "convert.im7 {0} -fill white -draw 'rectangle {1},4 {2},28' {3}".format(t.name, str(rblank), str(lblank), t.name) | ||
96 | convert_out=subprocess.check_output(cmd, shell=True, env=ourenv).decode() | ||
97 | |||
98 | bb.utils.mkdirhier(saved_screenshots_dir) | ||
99 | savedfile = "{0}/saved-{1}-{2}-{3}.png".format(saved_screenshots_dir, \ | ||
100 | datetime.timestamp(datetime.now()), \ | ||
101 | pn, \ | ||
102 | self.td.get('MACHINE')) | ||
103 | shutil.copy2(t.name, savedfile) | ||
104 | |||
105 | refimage = self.td.get('COREBASE') + "/meta/files/screenshot-tests/" + pn + "-" + self.td.get('MACHINE') +".png" | ||
106 | if not os.path.exists(refimage): | ||
107 | self.skipTest("No reference image for comparision (%s)" % refimage) | ||
108 | |||
109 | cmd = "compare.im7 -metric MSE {0} {1} /dev/null".format(t.name, refimage) | ||
110 | compare_out = subprocess.run(cmd, shell=True, capture_output=True, text=True, env=ourenv) | ||
111 | diff=float(compare_out.stderr.replace("(", "").replace(")","").split()[1]) | ||
112 | if diff > 0: | ||
113 | # Keep a copy of the failed screenshot so we can see what happened. | ||
114 | self.fail("Screenshot diff is {0}. Failed image stored in {1}".format(str(diff), savedfile)) | ||
115 | else: | ||
116 | self.assertEqual(0, diff, "Screenshot diff is {0}.".format(str(diff))) | ||