diff options
| author | Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com> | 2024-02-29 12:05:04 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-03-07 17:27:51 +0000 |
| commit | 2b5903f51105715addbde13ac9811ae4eb142f10 (patch) | |
| tree | 0b2afbf6f4f081aa3e62b511881d57dd0b0dbd77 | |
| parent | 0bd3234676fc39e4cd687cbba56d4502a2b1d8a2 (diff) | |
| download | poky-2b5903f51105715addbde13ac9811ae4eb142f10.tar.gz | |
sstatetests.py: Add testing for correct sstate permissions
This patch adds to run_test_sstate_creation so that it also tests
that sstate directories don't accidentally pickup umask permissions
from the user upon creation.
[RP: Python style tweaking]
(From OE-Core rev: 7d6eb828e97ad3f27d94efdccd920fb2aef36743)
Signed-off-by: Eilís 'pidge' Ní Fhlannagáin <pidge@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/sstatetests.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/meta/lib/oeqa/selftest/cases/sstatetests.py b/meta/lib/oeqa/selftest/cases/sstatetests.py index 56dfcdb0f3..031c2266ac 100644 --- a/meta/lib/oeqa/selftest/cases/sstatetests.py +++ b/meta/lib/oeqa/selftest/cases/sstatetests.py | |||
| @@ -79,7 +79,7 @@ class SStateBase(OESelftestTestCase): | |||
| 79 | result.append(f) | 79 | result.append(f) |
| 80 | return result | 80 | return result |
| 81 | 81 | ||
| 82 | # Test sstate files creation and their location | 82 | # Test sstate files creation and their location and directory perms |
| 83 | def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): | 83 | def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): |
| 84 | self.config_sstate(temp_sstate_location, [self.sstate_path]) | 84 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
| 85 | 85 | ||
| @@ -88,6 +88,19 @@ class SStateBase(OESelftestTestCase): | |||
| 88 | else: | 88 | else: |
| 89 | bitbake(['-ccleansstate'] + targets) | 89 | bitbake(['-ccleansstate'] + targets) |
| 90 | 90 | ||
| 91 | # We need to test that the env umask have does not effect sstate directory creation | ||
| 92 | # So, first, we'll get the current umask and set it to something we know incorrect | ||
| 93 | # See: sstate_task_postfunc for correct umask of os.umask(0o002) | ||
| 94 | import os | ||
| 95 | def current_umask(): | ||
| 96 | current_umask = os.umask(0) | ||
| 97 | os.umask(current_umask) | ||
| 98 | return current_umask | ||
| 99 | |||
| 100 | orig_umask = current_umask() | ||
| 101 | # Set it to a umask we know will be 'wrong' | ||
| 102 | os.umask(0o022) | ||
| 103 | |||
| 91 | bitbake(targets) | 104 | bitbake(targets) |
| 92 | file_tracker = [] | 105 | file_tracker = [] |
| 93 | results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific) | 106 | results = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific) |
| @@ -104,6 +117,19 @@ class SStateBase(OESelftestTestCase): | |||
| 104 | else: | 117 | else: |
| 105 | self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker))) | 118 | self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker))) |
| 106 | 119 | ||
| 120 | # Now we'll walk the tree to check the mode and see if things are incorrect. | ||
| 121 | badperms = [] | ||
| 122 | for root, dirs, files in os.walk(self.sstate_path): | ||
| 123 | for directory in dirs: | ||
| 124 | if (os.stat(os.path.join(root, directory)).st_mode & 0o777) != 0o775: | ||
| 125 | badperms.append(os.path.join(root, directory)) | ||
| 126 | |||
| 127 | # Return to original umask | ||
| 128 | os.umask(orig_umask) | ||
| 129 | |||
| 130 | if should_pass: | ||
| 131 | self.assertTrue(badperms , msg="Found sstate directories with the wrong permissions: %s (found %s)" % (', '.join(map(str, targets)), str(badperms))) | ||
| 132 | |||
| 107 | # Test the sstate files deletion part of the do_cleansstate task | 133 | # Test the sstate files deletion part of the do_cleansstate task |
| 108 | def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): | 134 | def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): |
| 109 | self.config_sstate(temp_sstate_location, [self.sstate_path]) | 135 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
