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.py227
1 files changed, 227 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..a0489fe4f1
--- /dev/null
+++ b/meta/lib/oeqa/selftest/sstatetests.py
@@ -0,0 +1,227 @@
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
10
11class SStateBase(oeSelfTest):
12
13 def setUpLocal(self):
14 self.temp_sstate_location = None
15 self.sstate_path = get_bb_var('SSTATE_DIR')
16 self.distro = get_bb_var('NATIVELSBSTRING')
17 self.distro_specific_sstate = os.path.join(self.sstate_path, self.distro)
18
19 # Creates a special sstate configuration with the option to add sstate mirrors
20 def config_sstate(self, temp_sstate_location=False, add_local_mirrors=[]):
21 self.temp_sstate_location = temp_sstate_location
22
23 if self.temp_sstate_location:
24 temp_sstate_path = os.path.join(self.builddir, "temp_sstate_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
25 config_temp_sstate = "SSTATE_DIR = \"%s\"" % temp_sstate_path
26 self.append_config(config_temp_sstate)
27 self.track_for_cleanup(temp_sstate_path)
28 self.sstate_path = get_bb_var('SSTATE_DIR')
29 self.distro = get_bb_var('NATIVELSBSTRING')
30 self.distro_specific_sstate = os.path.join(self.sstate_path, self.distro)
31
32 if add_local_mirrors:
33 config_set_sstate_if_not_set = 'SSTATE_MIRRORS ?= ""'
34 self.append_config(config_set_sstate_if_not_set)
35 for local_mirror in add_local_mirrors:
36 self.assertFalse(os.path.join(local_mirror) == os.path.join(self.sstate_path), msg='Cannot add the current sstate path as a sstate mirror')
37 config_sstate_mirror = "SSTATE_MIRRORS += \"file://.* file:///%s/PATH\"" % local_mirror
38 self.append_config(config_sstate_mirror)
39
40 # Returns a list containing sstate files
41 def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True):
42 result = []
43 for root, dirs, files in os.walk(self.sstate_path):
44 if distro_specific and re.search("%s/[a-z0-9]{2}$" % self.distro, root):
45 for f in files:
46 if re.search(filename_regex, f):
47 result.append(f)
48 if distro_nonspecific and re.search("%s/[a-z0-9]{2}$" % self.sstate_path, root):
49 for f in files:
50 if re.search(filename_regex, f):
51 result.append(f)
52 return result
53
54class SStateTests(SStateBase):
55
56 # Test sstate files creation and their location
57 def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True):
58 self.config_sstate(temp_sstate_location)
59
60 if self.temp_sstate_location:
61 bitbake(['-cclean'] + targets)
62 else:
63 bitbake(['-ccleansstate'] + targets)
64
65 bitbake(targets)
66 file_tracker = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
67 if should_pass:
68 self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
69 else:
70 self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s" % ', '.join(map(str, targets)))
71
72 def test_sstate_creation_distro_specific_pass(self):
73 self.run_test_sstate_creation(['binutils-cross', 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
74
75 def test_sstate_creation_distro_specific_fail(self):
76 self.run_test_sstate_creation(['binutils-cross', 'binutils-native'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True, should_pass=False)
77
78 def test_sstate_creation_distro_nonspecific_pass(self):
79 self.run_test_sstate_creation(['eglibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
80
81 def test_sstate_creation_distro_nonspecific_fail(self):
82 self.run_test_sstate_creation(['eglibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False)
83
84
85 # Test the sstate files deletion part of the do_cleansstate task
86 def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True):
87 self.config_sstate(temp_sstate_location)
88
89 bitbake(['-ccleansstate'] + targets)
90
91 bitbake(targets)
92 file_tracker_1 = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
93 self.assertTrue(file_tracker_1, msg="Could not find sstate files for: %s" % ', '.join(map(str, targets)))
94
95 bitbake(['-ccleansstate'] + targets)
96 file_tracker_2 = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific)
97 self.assertTrue(not file_tracker_2)
98
99 def test_cleansstate_task_distro_specific_nonspecific(self):
100 self.run_test_cleansstate_task(['binutils-cross', 'binutils-native', 'eglibc-initial'], distro_specific=True, distro_nonspecific=True, temp_sstate_location=True)
101
102 def test_cleansstate_task_distro_nonspecific(self):
103 self.run_test_cleansstate_task(['eglibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True)
104
105 def test_cleansstate_task_distro_specific(self):
106 self.run_test_cleansstate_task(['binutils-cross', 'binutils-native', 'eglibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True)
107
108
109 # Test rebuilding of distro-specific sstate files
110 def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True):
111 self.config_sstate(temp_sstate_location)
112
113 bitbake(['-ccleansstate'] + targets)
114
115 bitbake(targets)
116 self.assertTrue(self.search_sstate('|'.join(map(str, targets)), distro_specific=False, distro_nonspecific=True) == [], msg="Found distro non-specific sstate for: %s" % ', '.join(map(str, targets)))
117 file_tracker_1 = self.search_sstate('|'.join(map(str, targets)), distro_specific=True, distro_nonspecific=False)
118 self.assertTrue(len(file_tracker_1) > len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
119
120 self.track_for_cleanup(self.distro_specific_sstate + "_old")
121 shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old")
122 shutil.rmtree(self.distro_specific_sstate)
123
124 bitbake(['-cclean'] + targets)
125 bitbake(targets)
126 file_tracker_2 = self.search_sstate('|'.join(map(str, targets)), distro_specific=True, distro_nonspecific=False)
127 self.assertTrue(len(file_tracker_2) > len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets)))
128
129 not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2]
130 self.assertTrue(not_recreated == [], msg="The following sstate files ware not recreated: %s" % ', '.join(map(str, not_recreated)))
131
132 created_once = [x for x in file_tracker_2 if x not in file_tracker_1]
133 self.assertTrue(created_once == [], msg="The following sstate files ware created only in the second run: %s" % ', '.join(map(str, created_once)))
134
135 def test_rebuild_distro_specific_sstate_cross_native_targets(self):
136 self.run_test_rebuild_distro_specific_sstate(['binutils-cross', 'binutils-native'], temp_sstate_location=True)
137
138 def test_rebuild_distro_specific_sstate_cross_target(self):
139 self.run_test_rebuild_distro_specific_sstate(['binutils-cross'], temp_sstate_location=True)
140
141 def test_rebuild_distro_specific_sstate_native_target(self):
142 self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True)
143
144
145 # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list
146 def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=['']):
147 self.assertTrue(global_config)
148 self.assertTrue(target_config)
149 self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements')
150 self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path])
151
152 # If buildhistory is enabled, we need to disable version-going-backwards QA checks for this test. It may report errors otherwise.
153 if ('buildhistory' in get_bb_var('USER_CLASSES')) or ('buildhistory' in get_bb_var('INHERIT')):
154 remove_errors_config = 'ERROR_QA_remove = "version-going-backwards"'
155 self.append_config(remove_errors_config)
156
157 # For not this only checks if random sstate tasks are handled correctly as a group.
158 # In the future we should add control over what tasks we check for.
159
160 expected_remaining_sstate = []
161 for idx in range(len(target_config)):
162 self.append_config(global_config[idx])
163 self.append_recipeinc(target, target_config[idx])
164 if target_config[idx] == target_config[-1]:
165 target_sstate_before_build = self.search_sstate(target)
166 bitbake("-cclean %s" % target)
167 result = bitbake(target, ignore_status=True)
168 if target_config[idx] == target_config[-1]:
169 target_sstate_after_build = self.search_sstate(target)
170 expected_remaining_sstate += [x for x in target_sstate_after_build if x not in target_sstate_before_build]
171 self.remove_config(global_config[idx])
172 self.remove_recipeinc(target, target_config[idx])
173 self.assertEqual(result.status, 0)
174
175 runCmd("sstate-cache-management.sh -y --cache-dir=%s --remove-duplicated" % self.sstate_path)
176 actual_remaining_sstate = self.search_sstate(target)
177
178 actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate]
179 self.assertFalse(actual_not_expected, msg="Files should have been removed but ware not: %s" % ', '.join(map(str, actual_not_expected)))
180 expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate]
181 self.assertFalse(expected_not_actual, msg="Extra files ware removed: %s" ', '.join(map(str, expected_not_actual)))
182
183
184 def test_sstate_cache_management_script_using_pr_1(self):
185 global_config = []
186 target_config = []
187 global_config.append('')
188 target_config.append('PR = "0"')
189 self.run_test_sstate_cache_management_script('m4', global_config, target_config)
190
191 def test_sstate_cache_management_script_using_pr_2(self):
192 global_config = []
193 target_config = []
194 global_config.append('')
195 target_config.append('PR = "0"')
196 global_config.append('')
197 target_config.append('PR = "1"')
198 self.run_test_sstate_cache_management_script('m4', global_config, target_config)
199
200 def test_sstate_cache_management_script_using_pr_3(self):
201 global_config = []
202 target_config = []
203 global_config.append('MACHINE = "qemux86-64"')
204 target_config.append('PR = "0"')
205 global_config.append(global_config[0])
206 target_config.append('PR = "1"')
207 global_config.append('MACHINE = "qemux86"')
208 target_config.append('PR = "1"')
209 self.run_test_sstate_cache_management_script('m4', global_config, target_config)
210
211 def test_sstate_cache_management_script_using_machine(self):
212 global_config = []
213 target_config = []
214 global_config.append('MACHINE = "qemux86-64"')
215 target_config.append('')
216 global_config.append('MACHINE = "qemux86"')
217 target_config.append('')
218 self.run_test_sstate_cache_management_script('m4', global_config, target_config)
219
220
221
222
223
224
225
226
227