diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-03-05 18:00:10 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-03-07 17:27:51 +0000 |
commit | 4d161405d5fdf53e28a5a4f74a0c5c53ef14180e (patch) | |
tree | c5b413d9c7f460a78ed787a6735181402c5bf401 /meta/lib/oeqa/runtime | |
parent | b49d42ce90f0f910b6a4ec3a5ba26eccc543076c (diff) | |
download | poky-4d161405d5fdf53e28a5a4f74a0c5c53ef14180e.tar.gz |
oeqa/runtime/login: Various code improvements and fixes
* Allow tools to be found from the host PATH so that imagemagick from a buildtools
tarball/sdk can work
* Reformat the code to have imports at the start of the file and have more standard
formatting and whitespace
* Always save copies of the images, the space imapct is negligle compared to the
debug win
* Write the images to ${T}
* Use bb.utils.mkdirhier() instead of more complex code
* Restrict the tests to images containing matchbox-desktop
(From OE-Core rev: d09989b49517830297654e4d1d150aaa8723c41a)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/runtime')
-rw-r--r-- | meta/lib/oeqa/runtime/cases/login.py | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/meta/lib/oeqa/runtime/cases/login.py b/meta/lib/oeqa/runtime/cases/login.py index aea3bfc778..175a60c48c 100644 --- a/meta/lib/oeqa/runtime/cases/login.py +++ b/meta/lib/oeqa/runtime/cases/login.py | |||
@@ -4,9 +4,13 @@ | |||
4 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
5 | # | 5 | # |
6 | 6 | ||
7 | import shutil | ||
7 | import subprocess | 8 | import subprocess |
8 | from oeqa.runtime.case import OERuntimeTestCase | ||
9 | import tempfile | 9 | import tempfile |
10 | import time | ||
11 | import os | ||
12 | from datetime import datetime | ||
13 | from oeqa.runtime.case import OERuntimeTestCase | ||
10 | from oeqa.runtime.decorator.package import OEHasPackage | 14 | from oeqa.runtime.decorator.package import OEHasPackage |
11 | 15 | ||
12 | ### Status of qemu images. | 16 | ### Status of qemu images. |
@@ -22,14 +26,27 @@ from oeqa.runtime.decorator.package import OEHasPackage | |||
22 | ### | 26 | ### |
23 | 27 | ||
24 | class LoginTest(OERuntimeTestCase): | 28 | class LoginTest(OERuntimeTestCase): |
29 | @OEHasPackage(['matchbox-desktop']) | ||
25 | def test_screenshot(self): | 30 | def test_screenshot(self): |
26 | if self.td.get('MACHINE') in ("qemuppc64", "qemuarmv5", "qemuriscv32", "qemuloongarch64"): | 31 | if self.td.get('MACHINE') in ("qemuppc64", "qemuarmv5", "qemuriscv32", "qemuloongarch64"): |
27 | self.skipTest("{0} is not currently supported.".format(self.td.get('MACHINE'))) | 32 | self.skipTest("{0} is not currently supported.".format(self.td.get('MACHINE'))) |
28 | 33 | ||
29 | # Set DEBUG_CREATE_IMAGES to 1 in order to populate the image-test images directory. | 34 | pn = self.td.get('PN') |
30 | DEBUG_CREATE_IMAGES="0" | 35 | |
31 | # Store failed images so we can debug them. | 36 | ourenv = os.environ.copy() |
32 | failed_image_dir=self.td.get('TOPDIR') + "/failed-images/" | 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/" | ||
33 | 50 | ||
34 | ### | 51 | ### |
35 | # This is a really horrible way of doing this but I've not found the | 52 | # This is a really horrible way of doing this but I've not found the |
@@ -50,8 +67,6 @@ class LoginTest(OERuntimeTestCase): | |||
50 | # 'works'. | 67 | # 'works'. |
51 | ### | 68 | ### |
52 | 69 | ||
53 | import time | ||
54 | |||
55 | # qemumips takes forever to render. We could probably get away with 20 | 70 | # qemumips takes forever to render. We could probably get away with 20 |
56 | # here were it not for that. | 71 | # here were it not for that. |
57 | time.sleep(40) | 72 | time.sleep(40) |
@@ -62,46 +77,36 @@ class LoginTest(OERuntimeTestCase): | |||
62 | # Find out size of image so we can determine where to blank out clock. | 77 | # 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 | 78 | # qemuarm and qemuppc are odd as it doesn't resize the window and returns |
64 | # incorrect widths | 79 | # incorrect widths |
65 | if self.td.get('MACHINE')=="qemuarm" or self.td.get('MACHINE')=="qemuppc": | 80 | if self.td.get('MACHINE') == "qemuarm" or self.td.get('MACHINE') == "qemuppc": |
66 | width="640" | 81 | width = "640" |
67 | else: | 82 | else: |
68 | cmd = "identify.im7 -ping -format '%w' {0}".format(t.name) | 83 | cmd = "identify.im7 -ping -format '%w' {0}".format(t.name) |
69 | width = subprocess.check_output(cmd, shell=True).decode() | 84 | width = subprocess.check_output(cmd, shell=True, env=ourenv).decode() |
70 | 85 | ||
71 | rblank=int(float(width)) | 86 | rblank = int(float(width)) |
72 | lblank=rblank-40 | 87 | lblank = rblank-40 |
73 | 88 | ||
74 | # Use the meta-oe version of convert, along with it's suffix. This blanks out the clock. | 89 | # 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) | 90 | 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() | 91 | convert_out=subprocess.check_output(cmd, shell=True, env=ourenv).decode() |
77 | 92 | ||
78 | if DEBUG_CREATE_IMAGES=="1": | 93 | |
79 | # You probably aren't interested in this as it's just to create the images we compare against. | 94 | bb.utils.mkdirhier(saved_screenshots_dir) |
80 | import shutil | 95 | savedfile = "{0}/saved-{1}-{2}-{3}.png".format(saved_screenshots_dir, \ |
81 | shutil.copy2(t.name, "{0}/meta/files/image-tests/core-image-sato-{1}.png".format(self.td.get('COREBASE'), \ | 96 | datetime.timestamp(datetime.now()), \ |
82 | self.td.get('MACHINE'))) | 97 | pn, \ |
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'))) | 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)) | ||
84 | else: | 111 | else: |
85 | # Use the meta-oe version of compare, along with it's suffix. | 112 | self.assertEqual(0, diff, "Screenshot diff is {0}.".format(str(diff))) |
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))) | ||