diff options
| -rw-r--r-- | meta/lib/oeqa/selftest/sstate.py | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/sstate.py b/meta/lib/oeqa/selftest/sstate.py new file mode 100644 index 0000000000..98c1426791 --- /dev/null +++ b/meta/lib/oeqa/selftest/sstate.py | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | import datetime | ||
| 2 | import unittest | ||
| 3 | import os | ||
| 4 | import re | ||
| 5 | import shutil | ||
| 6 | |||
| 7 | import oeqa.utils.ftools as ftools | ||
| 8 | from oeqa.selftest.base import oeSelfTest | ||
| 9 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer | ||
| 10 | |||
| 11 | class SStateTests(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 | |||
| 54 | |||
| 55 | # Test sstate files creation and their location | ||
| 56 | def run_test_sstate_creation(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True, should_pass=True): | ||
| 57 | self.config_sstate(temp_sstate_location) | ||
| 58 | |||
| 59 | if self.temp_sstate_location: | ||
| 60 | bitbake(['-cclean'] + targets) | ||
| 61 | else: | ||
| 62 | bitbake(['-ccleansstate'] + targets) | ||
| 63 | |||
| 64 | bitbake(targets) | ||
| 65 | file_tracker = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific) | ||
| 66 | if should_pass: | ||
| 67 | self.assertTrue(file_tracker , msg="Could not find sstate files for: %s" % ', '.join(map(str, targets))) | ||
| 68 | else: | ||
| 69 | self.assertTrue(not file_tracker , msg="Found sstate files in the wrong place for: %s" % ', '.join(map(str, targets))) | ||
| 70 | |||
| 71 | def test_sstate_creation_distro_specific_pass(self): | ||
| 72 | self.run_test_sstate_creation(['binutils-cross', 'binutils-native'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) | ||
| 73 | |||
| 74 | def test_sstate_creation_distro_specific_fail(self): | ||
| 75 | self.run_test_sstate_creation(['binutils-cross', 'binutils-native'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True, should_pass=False) | ||
| 76 | |||
| 77 | def test_sstate_creation_distro_nonspecific_pass(self): | ||
| 78 | self.run_test_sstate_creation(['eglibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) | ||
| 79 | |||
| 80 | def test_sstate_creation_distro_nonspecific_fail(self): | ||
| 81 | self.run_test_sstate_creation(['eglibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True, should_pass=False) | ||
| 82 | |||
| 83 | |||
| 84 | # Test the sstate files deletion part of the do_cleansstate task | ||
| 85 | def run_test_cleansstate_task(self, targets, distro_specific=True, distro_nonspecific=True, temp_sstate_location=True): | ||
| 86 | self.config_sstate(temp_sstate_location) | ||
| 87 | |||
| 88 | bitbake(['-ccleansstate'] + targets) | ||
| 89 | |||
| 90 | bitbake(targets) | ||
| 91 | file_tracker_1 = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific) | ||
| 92 | self.assertTrue(file_tracker_1, msg="Could not find sstate files for: %s" % ', '.join(map(str, targets))) | ||
| 93 | |||
| 94 | bitbake(['-ccleansstate'] + targets) | ||
| 95 | file_tracker_2 = self.search_sstate('|'.join(map(str, targets)), distro_specific, distro_nonspecific) | ||
| 96 | self.assertTrue(not file_tracker_2) | ||
| 97 | |||
| 98 | def test_cleansstate_task_distro_specific_nonspecific(self): | ||
| 99 | self.run_test_cleansstate_task(['binutils-cross', 'binutils-native', 'eglibc-initial'], distro_specific=True, distro_nonspecific=True, temp_sstate_location=True) | ||
| 100 | |||
| 101 | def test_cleansstate_task_distro_nonspecific(self): | ||
| 102 | self.run_test_cleansstate_task(['eglibc-initial'], distro_specific=False, distro_nonspecific=True, temp_sstate_location=True) | ||
| 103 | |||
| 104 | def test_cleansstate_task_distro_specific(self): | ||
| 105 | self.run_test_cleansstate_task(['binutils-cross', 'binutils-native', 'eglibc-initial'], distro_specific=True, distro_nonspecific=False, temp_sstate_location=True) | ||
| 106 | |||
| 107 | |||
| 108 | # Test rebuilding of distro-specific sstate files | ||
| 109 | def run_test_rebuild_distro_specific_sstate(self, targets, temp_sstate_location=True): | ||
| 110 | self.config_sstate(temp_sstate_location) | ||
| 111 | |||
| 112 | bitbake(['-ccleansstate'] + targets) | ||
| 113 | |||
| 114 | bitbake(targets) | ||
| 115 | 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))) | ||
| 116 | file_tracker_1 = self.search_sstate('|'.join(map(str, targets)), distro_specific=True, distro_nonspecific=False) | ||
| 117 | self.assertTrue(len(file_tracker_1) > len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets))) | ||
| 118 | |||
| 119 | self.track_for_cleanup(self.distro_specific_sstate + "_old") | ||
| 120 | shutil.copytree(self.distro_specific_sstate, self.distro_specific_sstate + "_old") | ||
| 121 | shutil.rmtree(self.distro_specific_sstate) | ||
| 122 | |||
| 123 | bitbake(['-cclean'] + targets) | ||
| 124 | bitbake(targets) | ||
| 125 | file_tracker_2 = self.search_sstate('|'.join(map(str, targets)), distro_specific=True, distro_nonspecific=False) | ||
| 126 | self.assertTrue(len(file_tracker_2) > len(targets), msg = "Not all sstate files ware created for: %s" % ', '.join(map(str, targets))) | ||
| 127 | |||
| 128 | not_recreated = [x for x in file_tracker_1 if x not in file_tracker_2] | ||
| 129 | self.assertTrue(not_recreated == [], msg="The following sstate files ware not recreated: %s" % ', '.join(map(str, not_recreated))) | ||
| 130 | |||
| 131 | created_once = [x for x in file_tracker_2 if x not in file_tracker_1] | ||
| 132 | self.assertTrue(created_once == [], msg="The following sstate files ware created only in the second run: %s" % ', '.join(map(str, created_once))) | ||
| 133 | |||
| 134 | def test_rebuild_distro_specific_sstate_cross_native_targets(self): | ||
| 135 | self.run_test_rebuild_distro_specific_sstate(['binutils-cross', 'binutils-native'], temp_sstate_location=True) | ||
| 136 | |||
| 137 | def test_rebuild_distro_specific_sstate_cross_target(self): | ||
| 138 | self.run_test_rebuild_distro_specific_sstate(['binutils-cross'], temp_sstate_location=True) | ||
| 139 | |||
| 140 | def test_rebuild_distro_specific_sstate_native_target(self): | ||
| 141 | self.run_test_rebuild_distro_specific_sstate(['binutils-native'], temp_sstate_location=True) | ||
| 142 | |||
| 143 | |||
| 144 | # Test the sstate-cache-management script. Each element in the global_config list is used with the corresponding element in the target_config list | ||
| 145 | def run_test_sstate_cache_management_script(self, target, global_config=[''], target_config=['']): | ||
| 146 | self.assertTrue(global_config) | ||
| 147 | self.assertTrue(target_config) | ||
| 148 | self.assertTrue(len(global_config) == len(target_config), msg='Lists global_config and target_config should have the same number of elements') | ||
| 149 | self.config_sstate(temp_sstate_location=True, add_local_mirrors=[self.sstate_path]) | ||
| 150 | |||
| 151 | # If buildhistory is enabled, we need to disable version-going-backwards QA checks for this test. It may report errors otherwise. | ||
| 152 | if ('buildhistory' in get_bb_var('USER_CLASSES')) or ('buildhistory' in get_bb_var('INHERIT')): | ||
| 153 | remove_errors_config = 'ERROR_QA_remove = "version-going-backwards"' | ||
| 154 | self.append_config(remove_errors_config) | ||
| 155 | |||
| 156 | # For not this only checks if random sstate tasks are handled correctly as a group. | ||
| 157 | # In the future we should add control over what tasks we check for. | ||
| 158 | |||
| 159 | expected_remaining_sstate = [] | ||
| 160 | for idx in range(len(target_config)): | ||
| 161 | self.append_config(global_config[idx]) | ||
| 162 | self.append_recipeinc(target, target_config[idx]) | ||
| 163 | if target_config[idx] == target_config[-1]: | ||
| 164 | target_sstate_before_build = self.search_sstate(target) | ||
| 165 | bitbake("-cclean %s" % target) | ||
| 166 | result = bitbake(target, ignore_status=True) | ||
| 167 | if target_config[idx] == target_config[-1]: | ||
| 168 | target_sstate_after_build = self.search_sstate(target) | ||
| 169 | expected_remaining_sstate += [x for x in target_sstate_after_build if x not in target_sstate_before_build] | ||
| 170 | self.remove_config(global_config[idx]) | ||
| 171 | self.remove_recipeinc(target, target_config[idx]) | ||
| 172 | self.assertEqual(result.status, 0) | ||
| 173 | |||
| 174 | runCmd("sstate-cache-management.sh -y --cache-dir=%s --remove-duplicated" % self.sstate_path) | ||
| 175 | actual_remaining_sstate = self.search_sstate(target) | ||
| 176 | |||
| 177 | actual_not_expected = [x for x in actual_remaining_sstate if x not in expected_remaining_sstate] | ||
| 178 | self.assertFalse(actual_not_expected, msg="Files should have been removed but ware not: %s" % ', '.join(map(str, actual_not_expected))) | ||
| 179 | expected_not_actual = [x for x in expected_remaining_sstate if x not in actual_remaining_sstate] | ||
| 180 | self.assertFalse(expected_not_actual, msg="Extra files ware removed: %s" ', '.join(map(str, expected_not_actual))) | ||
| 181 | |||
| 182 | |||
| 183 | def test_sstate_cache_management_script_using_pr_1(self): | ||
| 184 | global_config = [] | ||
| 185 | target_config = [] | ||
| 186 | global_config.append('') | ||
| 187 | target_config.append('PR = "0"') | ||
| 188 | self.run_test_sstate_cache_management_script('m4', global_config, target_config) | ||
| 189 | |||
| 190 | def test_sstate_cache_management_script_using_pr_2(self): | ||
| 191 | global_config = [] | ||
| 192 | target_config = [] | ||
| 193 | global_config.append('') | ||
| 194 | target_config.append('PR = "0"') | ||
| 195 | global_config.append('') | ||
| 196 | target_config.append('PR = "1"') | ||
| 197 | self.run_test_sstate_cache_management_script('m4', global_config, target_config) | ||
| 198 | |||
| 199 | def test_sstate_cache_management_script_using_pr_3(self): | ||
| 200 | global_config = [] | ||
| 201 | target_config = [] | ||
| 202 | global_config.append('MACHINE = "qemux86-64"') | ||
| 203 | target_config.append('PR = "0"') | ||
| 204 | global_config.append(global_config[0]) | ||
| 205 | target_config.append('PR = "1"') | ||
| 206 | global_config.append('MACHINE = "qemux86"') | ||
| 207 | target_config.append('PR = "1"') | ||
| 208 | self.run_test_sstate_cache_management_script('m4', global_config, target_config) | ||
| 209 | |||
| 210 | def test_sstate_cache_management_script_using_machine(self): | ||
| 211 | global_config = [] | ||
| 212 | target_config = [] | ||
| 213 | global_config.append('MACHINE = "qemux86-64"') | ||
| 214 | target_config.append('') | ||
| 215 | global_config.append('MACHINE = "qemux86"') | ||
| 216 | target_config.append('') | ||
| 217 | self.run_test_sstate_cache_management_script('m4', global_config, target_config) | ||
| 218 | |||
| 219 | |||
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | |||
