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