summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-27 09:41:33 +0200
committerSteve Sakoman <steve@sakoman.com>2025-07-04 07:50:16 -0700
commit5230e088bdaebc996f3c96a87232214a87880f2e (patch)
treebc67d0e18045f2347044c2e082d458b6eb949cbe
parent9c7e905fafc54899e2a1d8119c1e6a25b0c612a7 (diff)
downloadpoky-5230e088bdaebc996f3c96a87232214a87880f2e.tar.gz
oeqa/sstatetests: Improve/fix sstate creation tests
There are multiple problems with the sstate creation tests. They currently both execute twice, once to check one set of files, then another. We can do this together in one test which makes the code easier to follow. The common test function also has parameters which were always the same value, so those can be simplified. We can use the umask context manager from bb.utils to simplfy the umask code. The badperms test was actually broken, it was detecting bad permissions, then ignoring them. This patch fixes that regression too and allows the check to operate (relying on a separate fix to sstate umask handling). The result should be an easier to understand couple of test cases which should also function correctly and be more reliable. (From OE-Core rev: 4951d08046f66e905e6ab4bdd7af347c7ed14c64) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 5b9263040013199c5cb480125d5ca349f5d6dc55) Signed-off-by: Rasmus Villemoes <ravi@prevas.dk> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/lib/oeqa/selftest/cases/sstatetests.py78
1 files changed, 30 insertions, 48 deletions
diff --git a/meta/lib/oeqa/selftest/cases/sstatetests.py b/meta/lib/oeqa/selftest/cases/sstatetests.py
index 7231115a6b..08f94b168a 100644
--- a/meta/lib/oeqa/selftest/cases/sstatetests.py
+++ b/meta/lib/oeqa/selftest/cases/sstatetests.py
@@ -83,55 +83,43 @@ class SStateBase(OESelftestTestCase):
83 return result 83 return result
84 84
85 # Test sstate files creation and their location and directory perms 85 # Test sstate files creation and their location and directory perms
86 def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): 86 def run_test_sstate_creation(self, targets, hostdistro_specific):
87 self.config_sstate(temp_sstate_location, [self.sstate_path]) 87 self.config_sstate(True, [self.sstate_path])
88
89 bitbake(['-cclean'] + targets)
88 90
89 if self.temp_sstate_location:
90 bitbake(['-cclean'] + targets)
91 else:
92 bitbake(['-ccleansstate'] + targets)
93
94 # We need to test that the env umask have does not effect sstate directory creation
95 # So, first, we'll get the current umask and set it to something we know incorrect
96 # See: sstate_task_postfunc for correct umask of os.umask(0o002)
97 import os
98 def current_umask():
99 current_umask = os.umask(0)
100 os.umask(current_umask)
101 return current_umask
102
103 orig_umask = current_umask()
104 # Set it to a umask we know will be 'wrong' 91 # Set it to a umask we know will be 'wrong'
105 os.umask(0o022) 92 with bb.utils.umask(0o022):
93 bitbake(targets)
106 94
107 bitbake(targets) 95 # Distro specific files
108 file_tracker = [] 96 distro_specific_files = self.search_sstate('|'.join(map(str, targets)), True, False)
109 results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
110 if distro_nonspecific:
111 for r in results:
112 if r.endswith(("_populate_lic.tar.zst", "_populate_lic.tar.zst.siginfo", "_fetch.tar.zst.siginfo", "_unpack.tar.zst.siginfo", "_patch.tar.zst.siginfo")):
113 continue
114 file_tracker.append(r)
115 else:
116 file_tracker = results
117 97
118 if should_pass: 98 # Distro non-specific
119 self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets))) 99 distro_non_specific_files = []
100 results = self.search_sstate('|'.join(map(str, targets)), False, True)
101 for r in results:
102 if r.endswith(("_populate_lic.tar.zst", "_populate_lic.tar.zst.siginfo", "_fetch.tar.zst.siginfo", "_unpack.tar.zst.siginfo", "_patch.tar.zst.siginfo")):
103 continue
104 distro_non_specific_files.append(r)
105
106 if hostdistro_specific:
107 self.assertTrue(distro_specific_files , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
108 self.assertFalse(distro_non_specific_files, msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(distro_non_specific_files)))
120 else: 109 else:
121 self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker))) 110 self.assertTrue(distro_non_specific_files , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
111 self.assertFalse(distro_specific_files, msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(distro_specific_files)))
122 112
123 # Now we'll walk the tree to check the mode and see if things are incorrect. 113 # Now we'll walk the tree to check the mode and see if things are incorrect.
124 badperms = [] 114 badperms = []
125 for root, dirs, files in os.walk(self.sstate_path): 115 for root, dirs, files in os.walk(self.sstate_path):
126 for directory in dirs: 116 for directory in dirs:
127 if (os.stat(os.path.join(root, directory)).st_mode & 0o777) != 0o775: 117 mode = os.stat(os.path.join(root, directory)).st_mode & 0o777
128 badperms.append(os.path.join(root, directory)) 118 if mode != 0o775:
119 badperms.append("%s: %s vs %s" % (os.path.join(root, directory), mode, 0o775))
129 120
130 # Return to original umask 121 # Check badperms is empty
131 os.umask(orig_umask) 122 self.assertFalse(badperms , msg="Found sstate directories with the wrong permissions: %s (found %s)" % (', '.join(map(str, targets)), str(badperms)))
132
133 if should_pass:
134 self.assertTrue(badperms , msg="Found sstate directories with the wrong permissions: %s (found %s)" % (', '.join(map(str, targets)), str(badperms)))
135 123
136 # Test the sstate files deletion part of the do_cleansstate task 124 # Test the sstate files deletion part of the do_cleansstate task
137 def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): 125 def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
@@ -256,17 +244,11 @@ class SStateTests(SStateBase):
256 bitbake("dbus-wait-test -c unpack") 244 bitbake("dbus-wait-test -c unpack")
257 245
258class SStateCreation(SStateBase): 246class SStateCreation(SStateBase):
259 def test_sstate_creation_distro_specific_pass(self): 247 def test_sstate_creation_distro_specific(self):
260 self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) 248 self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], hostdistro_specific=True)
261
262 def test_sstate_creation_distro_specific_fail(self):
263 self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True, should_pass=False)
264
265 def test_sstate_creation_distro_nonspecific_pass(self):
266 self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
267 249
268 def test_sstate_creation_distro_nonspecific_fail(self): 250 def test_sstate_creation_distro_nonspecific(self):
269 self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False) 251 self.run_test_sstate_creation(['linux-libc-headers'], hostdistro_specific=False)
270 252
271class SStateCleanup(SStateBase): 253class SStateCleanup(SStateBase):
272 def test_cleansstate_task_distro_specific_nonspecific(self): 254 def test_cleansstate_task_distro_specific_nonspecific(self):