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