summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/sstatetests.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/selftest/sstatetests.py')
-rw-r--r--meta/lib/oeqa/selftest/sstatetests.py204
1 files changed, 204 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/sstatetests.py b/meta/lib/oeqa/selftest/sstatetests.py
new file mode 100644
index 0000000000..d578ddd489
--- /dev/null
+++ b/meta/lib/oeqa/selftest/sstatetests.py
@@ -0,0 +1,204 @@
1import datetime
2import unittest
3import os
4import re
5import shutil
6
7import oeqa.utils.ftools as ftools
8from oeqa.selftest.base import oeSelfTest
9from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer
10from oeqa.selftest.sstate import SStateBase
11from oeqa.utils.decorators import testcase
12
13class SStateTests(SStateBase):
14
15 # Test sstate files creation and their location
16 def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
17 self.config_sstate(temp_sstate_location)
18
19 if self.temp_sstate_location:
20 bitbake(['-cclean'] + targets)
21 else:
22 bitbake(['-ccleansstate'] + targets)
23
24 bitbake(targets)
25 file_tracker = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
26 if should_pass:
27 self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
28 else:
29 self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s" % ', '.join(map(str, targets)))
30
31 @testcase(975)
32 def test_sstate_creation_distro_specific_pass(self):
33 targetarch = get_bb_var('TUNE_ARCH')
34 self.run_test_sstate_creation(['binutils-cross-'+ targetarch, 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
35
36 @testcase(975)
37 def test_sstate_creation_distro_specific_fail(self):
38 targetarch = get_bb_var('TUNE_ARCH')
39 self.run_test_sstate_creation(['binutils-cross-'+ targetarch, 'binutils-native'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True, should_pass=False)
40
41 @testcase(976)
42 def test_sstate_creation_distro_nonspecific_pass(self):
43 self.run_test_sstate_creation(['glibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
44
45 @testcase(976)
46 def test_sstate_creation_distro_nonspecific_fail(self):
47 self.run_test_sstate_creation(['glibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False)
48
49
50 # Test the sstate files deletion part of the do_cleansstate task
51 def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
52 self.config_sstate(temp_sstate_location)
53
54 bitbake(['-ccleansstate'] + targets)
55
56 bitbake(targets)
57 tgz_created = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific, distro_nonspecific)
58 self.assertTrue(tgz_created, msg="Could not find sstate .tgz files for: %s" % ', '.join(map(str, targets)))
59
60 siginfo_created = self.search_sstate('|'.join(map(str, [s + '.*?\.siginfo$' for s in targets])), distro_specific, distro_nonspecific)
61 self.assertTrue(siginfo_created, msg="Could not find sstate .siginfo files for: %s" % ', '.join(map(str, targets)))
62
63 bitbake(['-ccleansstate'] + targets)
64 tgz_removed = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific, distro_nonspecific)
65 self.assertTrue(not tgz_removed, msg="do_cleansstate didn't remove .tgz sstate files for: %s" % ', '.join(map(str, targets)))
66
67 @testcase(977)
68 def test_cleansstate_task_distro_specific_nonspecific(self):
69 targetarch = get_bb_var('TUNE_ARCH')
70 self.run_test_cleansstate_task(['binutils-cross-' + targetarch, 'binutils-native', 'glibc-initial'], distro_specific=True, distro_nonspecific=True, temp_sstate_location=True)
71
72 @testcase(977)
73 def test_cleansstate_task_distro_nonspecific(self):
74 self.run_test_cleansstate_task(['glibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
75
76 @testcase(977)
77 def test_cleansstate_task_distro_specific(self):
78 targetarch = get_bb_var('TUNE_ARCH')
79 self.run_test_cleansstate_task(['binutils-cross-'+ targetarch, 'binutils-native', 'glibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
80
81
82 # Test rebuilding of distro-specific sstate files
83 def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True):
84 self.config_sstate(temp_sstate_location)
85
86 bitbake(['-ccleansstate'] + targets)
87
88 bitbake(targets)
89 self.assertTrue(self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=False, distro_nonspecific=True) == [], msg="Found distro non-specific sstate for: %s" % ', '.join(map(str, targets)))
90 file_tracker_1 = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=True, distro_nonspecific=False)
91 self.assertTrue(len(file_tracker_1) >= len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
92
93 self.track_for_cleanup(self.distro_specific_sstate + "_old")
94 shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old")
95 shutil.rmtree(self.distro_specific_sstate)
96
97 bitbake(['-cclean'] + targets)
98 bitbake(targets)
99 file_tracker_2 = self.search_sstate('|'.join(map(str, [s + '.*?\.tgz$' for s in targets])), distro_specific=True, distro_nonspecific=False)
100 self.assertTrue(len(file_tracker_2) >= len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
101
102 not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2]
103 self.assertTrue(not_recreated == [], msg="The following sstate files ware not recreated: %s" % ', '.join(map(str, not_recreated)))
104
105 created_once = [x for x in file_tracker_2 if x not in file_tracker_1]
106 self.assertTrue(created_once == [], msg="The following sstate files ware created only in the second run: %s" % ', '.join(map(str, created_once)))
107
108 @testcase(175)
109 def test_rebuild_distro_specific_sstate_cross_native_targets(self):
110 targetarch = get_bb_var('TUNE_ARCH')
111 self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + targetarch, 'binutils-native'], temp_sstate_location=True)
112
113 @testcase(175)
114 def test_rebuild_distro_specific_sstate_cross_target(self):
115 targetarch = get_bb_var('TUNE_ARCH')
116 self.run_test_rebuild_distro_specific_sstate(['binutils-cross-' + targetarch], temp_sstate_location=True)
117
118 @testcase(175)
119 def test_rebuild_distro_specific_sstate_native_target(self):
120 self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True)
121
122
123 # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list
124 # global_config elements are expected to not generate any sstate files that would be removed by sstate-cache-management.sh (such as changing the value of MACHINE)
125 def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=[''], ignore_patterns=[]):
126 self.assertTrue(global_config)
127 self.assertTrue(target_config)
128 self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements')
129 self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path])
130
131 # If buildhistory is enabled, we need to disable version-going-backwards QA checks for this test. It may report errors otherwise.
132 if ('buildhistory' in get_bb_var('USER_CLASSES')) or ('buildhistory' in get_bb_var('INHERIT')):
133 remove_errors_config = 'ERROR_QA_remove = "version-going-backwards"'
134 self.append_config(remove_errors_config)
135
136 # For not this only checks if random sstate tasks are handled correctly as a group.
137 # In the future we should add control over what tasks we check for.
138
139 sstate_archs_list = []
140 expected_remaining_sstate = []
141 for idx in range(len(target_config)):
142 self.append_config(global_config[idx])
143 self.append_recipeinc(target, target_config[idx])
144 sstate_arch = get_bb_var('SSTATE_PKGARCH', target)
145 if not sstate_arch in sstate_archs_list:
146 sstate_archs_list.append(sstate_arch)
147 if target_config[idx] == target_config[-1]:
148 target_sstate_before_build = self.search_sstate(target + '.*?\.tgz$')
149 bitbake("-cclean %s" % target)
150 result = bitbake(target, ignore_status=True)
151 if target_config[idx] == target_config[-1]:
152 target_sstate_after_build = self.search_sstate(target + '.*?\.tgz$')
153 expected_remaining_sstate += [x for x in target_sstate_after_build if x not in target_sstate_before_build if not any(pattern in x for pattern in ignore_patterns)]
154 self.remove_config(global_config[idx])
155 self.remove_recipeinc(target, target_config[idx])
156 self.assertEqual(result.status, 0)
157
158 runCmd("sstate-cache-management.sh -y --cache-dir=%s --remove-duplicated --extra-archs=%s" % (self.sstate_path, ','.join(map(str, sstate_archs_list))))
159 actual_remaining_sstate = [x for x in self.search_sstate(target + '.*?\.tgz$') if not any(pattern in x for pattern in ignore_patterns)]
160
161 actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate]
162 self.assertFalse(actual_not_expected, msg="Files should have been removed but ware not: %s" % ', '.join(map(str, actual_not_expected)))
163 expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate]
164 self.assertFalse(expected_not_actual, msg="Extra files ware removed: %s" ', '.join(map(str, expected_not_actual)))
165
166 @testcase(973)
167 def test_sstate_cache_management_script_using_pr_1(self):
168 global_config = []
169 target_config = []
170 global_config.append('')
171 target_config.append('PR = "0"')
172 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
173
174 @testcase(978)
175 def test_sstate_cache_management_script_using_pr_2(self):
176 global_config = []
177 target_config = []
178 global_config.append('')
179 target_config.append('PR = "0"')
180 global_config.append('')
181 target_config.append('PR = "1"')
182 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
183
184 @testcase(979)
185 def test_sstate_cache_management_script_using_pr_3(self):
186 global_config = []
187 target_config = []
188 global_config.append('MACHINE = "qemux86-64"')
189 target_config.append('PR = "0"')
190 global_config.append(global_config[0])
191 target_config.append('PR = "1"')
192 global_config.append('MACHINE = "qemux86"')
193 target_config.append('PR = "1"')
194 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])
195
196 @testcase(974)
197 def test_sstate_cache_management_script_using_machine(self):
198 global_config = []
199 target_config = []
200 global_config.append('MACHINE = "qemux86-64"')
201 target_config.append('')
202 global_config.append('MACHINE = "qemux86"')
203 target_config.append('')
204 self.run_test_sstate_cache_management_script('m4', global_config, target_config, ignore_patterns=['populate_lic'])