diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-03-12 11:31:38 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-03-13 17:35:22 +0000 |
commit | 24206254147dc0c8e50d74d6693a5a4c36b369f0 (patch) | |
tree | 36811b5ebf21134502df6ee4939257eb0480657d | |
parent | a4c484b8cb2ec0eb82b8b0855532cadedb2fac97 (diff) | |
download | poky-24206254147dc0c8e50d74d6693a5a4c36b369f0.tar.gz |
oeqa/selftest/sstate: Move common code to base class
Move the other common shares test functions to the base class to
improve the code structure.
(From OE-Core rev: de3e6f85c5537a3571ffbe2326b73f2c2526bce2)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oeqa/selftest/cases/sstatetests.py | 197 |
1 files changed, 98 insertions, 99 deletions
diff --git a/meta/lib/oeqa/selftest/cases/sstatetests.py b/meta/lib/oeqa/selftest/cases/sstatetests.py index a6a688cc19..aedc35c262 100644 --- a/meta/lib/oeqa/selftest/cases/sstatetests.py +++ b/meta/lib/oeqa/selftest/cases/sstatetests.py | |||
@@ -71,47 +71,6 @@ class SStateBase(OESelftestTestCase): | |||
71 | result.append(f) | 71 | result.append(f) |
72 | return result | 72 | return result |
73 | 73 | ||
74 | |||
75 | class SStateTests(SStateBase): | ||
76 | def test_autorev_sstate_works(self): | ||
77 | # Test that a git repository which changes is correctly handled by SRCREV = ${AUTOREV} | ||
78 | # when PV does not contain SRCPV | ||
79 | |||
80 | tempdir = tempfile.mkdtemp(prefix='sstate_autorev') | ||
81 | tempdldir = tempfile.mkdtemp(prefix='sstate_autorev_dldir') | ||
82 | self.track_for_cleanup(tempdir) | ||
83 | self.track_for_cleanup(tempdldir) | ||
84 | create_temp_layer(tempdir, 'selftestrecipetool') | ||
85 | self.add_command_to_tearDown('bitbake-layers remove-layer %s' % tempdir) | ||
86 | self.append_config("DL_DIR = \"%s\"" % tempdldir) | ||
87 | runCmd('bitbake-layers add-layer %s' % tempdir) | ||
88 | |||
89 | # Use dbus-wait as a local git repo we can add a commit between two builds in | ||
90 | pn = 'dbus-wait' | ||
91 | srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517' | ||
92 | url = 'git://git.yoctoproject.org/dbus-wait' | ||
93 | result = runCmd('git clone %s noname' % url, cwd=tempdir) | ||
94 | srcdir = os.path.join(tempdir, 'noname') | ||
95 | result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir) | ||
96 | self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory') | ||
97 | |||
98 | recipefile = os.path.join(tempdir, "recipes-test", "dbus-wait-test", 'dbus-wait-test_git.bb') | ||
99 | os.makedirs(os.path.dirname(recipefile)) | ||
100 | srcuri = 'git://' + srcdir + ';protocol=file;branch=master' | ||
101 | result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri]) | ||
102 | self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output) | ||
103 | |||
104 | with open(recipefile, 'a') as f: | ||
105 | f.write('SRCREV = "${AUTOREV}"\n') | ||
106 | f.write('PV = "1.0"\n') | ||
107 | |||
108 | bitbake("dbus-wait-test -c fetch") | ||
109 | with open(os.path.join(srcdir, "bar.txt"), "w") as f: | ||
110 | f.write("foo") | ||
111 | result = runCmd('git add bar.txt; git commit -asm "add bar"', cwd=srcdir) | ||
112 | bitbake("dbus-wait-test -c unpack") | ||
113 | |||
114 | |||
115 | # Test sstate files creation and their location | 74 | # Test sstate files creation and their location |
116 | def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): | 75 | def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): |
117 | self.config_sstate(temp_sstate_location, [self.sstate_path]) | 76 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
@@ -137,18 +96,6 @@ class SStateTests(SStateBase): | |||
137 | else: | 96 | else: |
138 | self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker))) | 97 | self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s (found %s)" % (', '.join(map(str, targets)), str(file_tracker))) |
139 | 98 | ||
140 | def test_sstate_creation_distro_specific_pass(self): | ||
141 | self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) | ||
142 | |||
143 | def test_sstate_creation_distro_specific_fail(self): | ||
144 | 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) | ||
145 | |||
146 | def test_sstate_creation_distro_nonspecific_pass(self): | ||
147 | self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) | ||
148 | |||
149 | def test_sstate_creation_distro_nonspecific_fail(self): | ||
150 | self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False) | ||
151 | |||
152 | # Test the sstate files deletion part of the do_cleansstate task | 99 | # Test the sstate files deletion part of the do_cleansstate task |
153 | def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): | 100 | def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): |
154 | self.config_sstate(temp_sstate_location, [self.sstate_path]) | 101 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
@@ -166,20 +113,6 @@ class SStateTests(SStateBase): | |||
166 | archives_removed = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific, distro_nonspecific) | 113 | archives_removed = self.search_sstate('|'.join(map(str, [s + r'.*?\.tar.zst$' for s in targets])), distro_specific, distro_nonspecific) |
167 | self.assertTrue(not archives_removed, msg="do_cleansstate didn't remove .tar.zst sstate files for: %s (%s)" % (', '.join(map(str, targets)), str(archives_removed))) | 114 | self.assertTrue(not archives_removed, msg="do_cleansstate didn't remove .tar.zst sstate files for: %s (%s)" % (', '.join(map(str, targets)), str(archives_removed))) |
168 | 115 | ||
169 | def test_cleansstate_task_distro_specific_nonspecific(self): | ||
170 | targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native'] | ||
171 | targets.append('linux-libc-headers') | ||
172 | self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True) | ||
173 | |||
174 | def test_cleansstate_task_distro_nonspecific(self): | ||
175 | self.run_test_cleansstate_task(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) | ||
176 | |||
177 | def test_cleansstate_task_distro_specific(self): | ||
178 | targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native'] | ||
179 | targets.append('linux-libc-headers') | ||
180 | self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) | ||
181 | |||
182 | |||
183 | # Test rebuilding of distro-specific sstate files | 116 | # Test rebuilding of distro-specific sstate files |
184 | def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True): | 117 | def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True): |
185 | self.config_sstate(temp_sstate_location, [self.sstate_path]) | 118 | self.config_sstate(temp_sstate_location, [self.sstate_path]) |
@@ -212,6 +145,104 @@ class SStateTests(SStateBase): | |||
212 | created_once = [x for x in file_tracker_2 if x not in file_tracker_1] | 145 | created_once = [x for x in file_tracker_2 if x not in file_tracker_1] |
213 | self.assertTrue(created_once == [], msg="The following sstate files were created only in the second run: %s" % ', '.join(map(str, created_once))) | 146 | self.assertTrue(created_once == [], msg="The following sstate files were created only in the second run: %s" % ', '.join(map(str, created_once))) |
214 | 147 | ||
148 | def sstate_common_samesigs(self, configA, configB, allarch=False): | ||
149 | |||
150 | self.write_config(configA) | ||
151 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") | ||
152 | bitbake("world meta-toolchain -S none") | ||
153 | self.write_config(configB) | ||
154 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") | ||
155 | bitbake("world meta-toolchain -S none") | ||
156 | |||
157 | def get_files(d, result): | ||
158 | for root, dirs, files in os.walk(d): | ||
159 | for name in files: | ||
160 | if "meta-environment" in root or "cross-canadian" in root: | ||
161 | continue | ||
162 | if "do_build" not in name: | ||
163 | # 1.4.1+gitAUTOINC+302fca9f4c-r0.do_package_write_ipk.sigdata.f3a2a38697da743f0dbed8b56aafcf79 | ||
164 | (_, task, _, shash) = name.rsplit(".", 3) | ||
165 | result[os.path.join(os.path.basename(root), task)] = shash | ||
166 | |||
167 | files1 = {} | ||
168 | files2 = {} | ||
169 | subdirs = sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/*-nativesdk*-linux")) | ||
170 | if allarch: | ||
171 | subdirs.extend(sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/all-*-linux"))) | ||
172 | |||
173 | for subdir in subdirs: | ||
174 | nativesdkdir = os.path.basename(subdir) | ||
175 | get_files(self.topdir + "/tmp-sstatesamehash/stamps/" + nativesdkdir, files1) | ||
176 | get_files(self.topdir + "/tmp-sstatesamehash2/stamps/" + nativesdkdir, files2) | ||
177 | |||
178 | self.maxDiff = None | ||
179 | self.assertEqual(files1, files2) | ||
180 | |||
181 | class SStateTests(SStateBase): | ||
182 | def test_autorev_sstate_works(self): | ||
183 | # Test that a git repository which changes is correctly handled by SRCREV = ${AUTOREV} | ||
184 | # when PV does not contain SRCPV | ||
185 | |||
186 | tempdir = tempfile.mkdtemp(prefix='sstate_autorev') | ||
187 | tempdldir = tempfile.mkdtemp(prefix='sstate_autorev_dldir') | ||
188 | self.track_for_cleanup(tempdir) | ||
189 | self.track_for_cleanup(tempdldir) | ||
190 | create_temp_layer(tempdir, 'selftestrecipetool') | ||
191 | self.add_command_to_tearDown('bitbake-layers remove-layer %s' % tempdir) | ||
192 | self.append_config("DL_DIR = \"%s\"" % tempdldir) | ||
193 | runCmd('bitbake-layers add-layer %s' % tempdir) | ||
194 | |||
195 | # Use dbus-wait as a local git repo we can add a commit between two builds in | ||
196 | pn = 'dbus-wait' | ||
197 | srcrev = '6cc6077a36fe2648a5f993fe7c16c9632f946517' | ||
198 | url = 'git://git.yoctoproject.org/dbus-wait' | ||
199 | result = runCmd('git clone %s noname' % url, cwd=tempdir) | ||
200 | srcdir = os.path.join(tempdir, 'noname') | ||
201 | result = runCmd('git reset --hard %s' % srcrev, cwd=srcdir) | ||
202 | self.assertTrue(os.path.isfile(os.path.join(srcdir, 'configure.ac')), 'Unable to find configure script in source directory') | ||
203 | |||
204 | recipefile = os.path.join(tempdir, "recipes-test", "dbus-wait-test", 'dbus-wait-test_git.bb') | ||
205 | os.makedirs(os.path.dirname(recipefile)) | ||
206 | srcuri = 'git://' + srcdir + ';protocol=file;branch=master' | ||
207 | result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri]) | ||
208 | self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output) | ||
209 | |||
210 | with open(recipefile, 'a') as f: | ||
211 | f.write('SRCREV = "${AUTOREV}"\n') | ||
212 | f.write('PV = "1.0"\n') | ||
213 | |||
214 | bitbake("dbus-wait-test -c fetch") | ||
215 | with open(os.path.join(srcdir, "bar.txt"), "w") as f: | ||
216 | f.write("foo") | ||
217 | result = runCmd('git add bar.txt; git commit -asm "add bar"', cwd=srcdir) | ||
218 | bitbake("dbus-wait-test -c unpack") | ||
219 | |||
220 | def test_sstate_creation_distro_specific_pass(self): | ||
221 | self.run_test_sstate_creation(['binutils-cross-'+ self.tune_arch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) | ||
222 | |||
223 | def test_sstate_creation_distro_specific_fail(self): | ||
224 | 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) | ||
225 | |||
226 | def test_sstate_creation_distro_nonspecific_pass(self): | ||
227 | self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) | ||
228 | |||
229 | def test_sstate_creation_distro_nonspecific_fail(self): | ||
230 | self.run_test_sstate_creation(['linux-libc-headers'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False) | ||
231 | |||
232 | def test_cleansstate_task_distro_specific_nonspecific(self): | ||
233 | targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native'] | ||
234 | targets.append('linux-libc-headers') | ||
235 | self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True) | ||
236 | |||
237 | def test_cleansstate_task_distro_nonspecific(self): | ||
238 | self.run_test_cleansstate_task(['linux-libc-headers'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) | ||
239 | |||
240 | def test_cleansstate_task_distro_specific(self): | ||
241 | targets = ['binutils-cross-'+ self.tune_arch, 'binutils-native'] | ||
242 | targets.append('linux-libc-headers') | ||
243 | self.run_test_cleansstate_task(targets, distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) | ||
244 | |||
245 | |||
215 | def test_rebuild_distro_specific_sstate_cross_native_targets(self): | 246 | def test_rebuild_distro_specific_sstate_cross_native_targets(self): |
216 | self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch, 'binutils-native'], temp_sstate_location=True) | 247 | self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + self.tune_arch, 'binutils-native'], temp_sstate_location=True) |
217 | 248 | ||
@@ -433,38 +464,6 @@ BB_SIGNATURE_HANDLER = "OEBasicHash" | |||
433 | """ | 464 | """ |
434 | self.sstate_common_samesigs(configA, configB) | 465 | self.sstate_common_samesigs(configA, configB) |
435 | 466 | ||
436 | def sstate_common_samesigs(self, configA, configB, allarch=False): | ||
437 | |||
438 | self.write_config(configA) | ||
439 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") | ||
440 | bitbake("world meta-toolchain -S none") | ||
441 | self.write_config(configB) | ||
442 | self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") | ||
443 | bitbake("world meta-toolchain -S none") | ||
444 | |||
445 | def get_files(d, result): | ||
446 | for root, dirs, files in os.walk(d): | ||
447 | for name in files: | ||
448 | if "meta-environment" in root or "cross-canadian" in root: | ||
449 | continue | ||
450 | if "do_build" not in name: | ||
451 | # 1.4.1+gitAUTOINC+302fca9f4c-r0.do_package_write_ipk.sigdata.f3a2a38697da743f0dbed8b56aafcf79 | ||
452 | (_, task, _, shash) = name.rsplit(".", 3) | ||
453 | result[os.path.join(os.path.basename(root), task)] = shash | ||
454 | |||
455 | files1 = {} | ||
456 | files2 = {} | ||
457 | subdirs = sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/*-nativesdk*-linux")) | ||
458 | if allarch: | ||
459 | subdirs.extend(sorted(glob.glob(self.topdir + "/tmp-sstatesamehash/stamps/all-*-linux"))) | ||
460 | |||
461 | for subdir in subdirs: | ||
462 | nativesdkdir = os.path.basename(subdir) | ||
463 | get_files(self.topdir + "/tmp-sstatesamehash/stamps/" + nativesdkdir, files1) | ||
464 | get_files(self.topdir + "/tmp-sstatesamehash2/stamps/" + nativesdkdir, files2) | ||
465 | |||
466 | self.maxDiff = None | ||
467 | self.assertEqual(files1, files2) | ||
468 | 467 | ||
469 | def test_sstate_sametune_samesigs(self): | 468 | def test_sstate_sametune_samesigs(self): |
470 | """ | 469 | """ |