blob: 606eaabcb0365cb962d3b56102fa6eddffd5cd35 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import os
6import glob
7from oeqa.utils.commands import bitbake, get_bb_vars
8from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009
10class Archiver(OESelftestTestCase):
11
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012 def test_archiver_allows_to_filter_on_recipe_name(self):
13 """
14 Summary: The archiver should offer the possibility to filter on the recipe. (#6929)
15 Expected: 1. Included recipe (busybox) should be included
16 2. Excluded recipe (zlib) should be excluded
17 Product: oe-core
18 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
19 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
20 """
21
22 include_recipe = 'busybox'
23 exclude_recipe = 'zlib'
24
25 features = 'INHERIT += "archiver"\n'
26 features += 'ARCHIVER_MODE[src] = "original"\n'
27 features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % include_recipe
28 features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % exclude_recipe
29 self.write_config(features)
30
31 bitbake('-c clean %s %s' % (include_recipe, exclude_recipe))
32 bitbake("-c deploy_archives %s %s" % (include_recipe, exclude_recipe))
33
34 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
35 src_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
36
37 # Check that include_recipe was included
38 included_present = len(glob.glob(src_path + '/%s-*' % include_recipe))
39 self.assertTrue(included_present, 'Recipe %s was not included.' % include_recipe)
40
41 # Check that exclude_recipe was excluded
42 excluded_present = len(glob.glob(src_path + '/%s-*' % exclude_recipe))
43 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % exclude_recipe)
44
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 def test_archiver_filters_by_type(self):
46 """
47 Summary: The archiver is documented to filter on the recipe type.
48 Expected: 1. included recipe type (target) should be included
49 2. other types should be excluded
50 Product: oe-core
51 Author: André Draszik <adraszik@tycoint.com>
52 """
53
54 target_recipe = 'initscripts'
55 native_recipe = 'zlib-native'
56
57 features = 'INHERIT += "archiver"\n'
58 features += 'ARCHIVER_MODE[src] = "original"\n'
59 features += 'COPYLEFT_RECIPE_TYPES = "target"\n'
60 self.write_config(features)
61
62 bitbake('-c clean %s %s' % (target_recipe, native_recipe))
63 bitbake("%s -c deploy_archives %s" % (target_recipe, native_recipe))
64
65 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS'])
66 src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
67 src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'])
68
69 # Check that target_recipe was included
70 included_present = len(glob.glob(src_path_target + '/%s-*' % target_recipe))
71 self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipe)
72
73 # Check that native_recipe was excluded
74 excluded_present = len(glob.glob(src_path_native + '/%s-*' % native_recipe))
75 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipe)
76
Brad Bishopd7bf8c12018-02-25 22:55:05 -050077 def test_archiver_filters_by_type_and_name(self):
78 """
79 Summary: Test that the archiver archives by recipe type, taking the
80 recipe name into account.
81 Expected: 1. included recipe type (target) should be included
82 2. other types should be excluded
83 3. recipe by name should be included / excluded,
84 overriding previous decision by type
85 Product: oe-core
86 Author: André Draszik <adraszik@tycoint.com>
87 """
88
89 target_recipes = [ 'initscripts', 'zlib' ]
90 native_recipes = [ 'update-rc.d-native', 'zlib-native' ]
91
92 features = 'INHERIT += "archiver"\n'
93 features += 'ARCHIVER_MODE[src] = "original"\n'
94 features += 'COPYLEFT_RECIPE_TYPES = "target"\n'
95 features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % native_recipes[1]
96 features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % target_recipes[1]
97 self.write_config(features)
98
99 bitbake('-c clean %s %s' % (' '.join(target_recipes), ' '.join(native_recipes)))
100 bitbake('-c deploy_archives %s %s' % (' '.join(target_recipes), ' '.join(native_recipes)))
101
102 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS'])
103 src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
104 src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'])
105
106 # Check that target_recipe[0] and native_recipes[1] were included
107 included_present = len(glob.glob(src_path_target + '/%s-*' % target_recipes[0]))
108 self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipes[0])
109
110 included_present = len(glob.glob(src_path_native + '/%s-*' % native_recipes[1]))
111 self.assertTrue(included_present, 'Recipe %s was not included.' % native_recipes[1])
112
113 # Check that native_recipes[0] and target_recipes[1] were excluded
114 excluded_present = len(glob.glob(src_path_native + '/%s-*' % native_recipes[0]))
115 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipes[0])
116
117 excluded_present = len(glob.glob(src_path_target + '/%s-*' % target_recipes[1]))
118 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % target_recipes[1])
Brad Bishop316dfdd2018-06-25 12:45:53 -0400119
120
121
122 def test_archiver_srpm_mode(self):
123 """
124 Test that in srpm mode, the added recipe dependencies at least exist/work [YOCTO #11121]
125 """
126
127 features = 'INHERIT += "archiver"\n'
128 features += 'ARCHIVER_MODE[srpm] = "1"\n'
129 self.write_config(features)
130
131 bitbake('-n core-image-sato')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500132
133 def _test_archiver_mode(self, mode, target_file_name, extra_config=None):
134 target = "selftest-ed"
135
136 features = 'INHERIT += "archiver"\n'
137 features += 'ARCHIVER_MODE[src] = "%s"\n' % (mode)
138 if extra_config:
139 features += extra_config
140 self.write_config(features)
141
142 bitbake('-c clean %s' % (target))
143 bitbake('-c deploy_archives %s' % (target))
144
145 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
146 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'], '%s-*' % (target))
147 glob_result = glob.glob(glob_str)
148 self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target))
149
150 archive_path = os.path.join(glob_result[0], target_file_name)
151 self.assertTrue(os.path.exists(archive_path), 'Missing archive file %s' % (target_file_name))
152
153 def test_archiver_mode_original(self):
154 """
155 Test that the archiver works with `ARCHIVER_MODE[src] = "original"`.
156 """
157
158 self._test_archiver_mode('original', 'ed-1.14.1.tar.lz')
159
160 def test_archiver_mode_patched(self):
161 """
162 Test that the archiver works with `ARCHIVER_MODE[src] = "patched"`.
163 """
164
165 self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-patched.tar.gz')
166
167 def test_archiver_mode_configured(self):
168 """
169 Test that the archiver works with `ARCHIVER_MODE[src] = "configured"`.
170 """
171
172 self._test_archiver_mode('configured', 'selftest-ed-1.14.1-r0-configured.tar.gz')
173
174 def test_archiver_mode_recipe(self):
175 """
176 Test that the archiver works with `ARCHIVER_MODE[recipe] = "1"`.
177 """
178
179 self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-recipe.tar.gz',
180 'ARCHIVER_MODE[recipe] = "1"\n')
181
182 def test_archiver_mode_diff(self):
183 """
184 Test that the archiver works with `ARCHIVER_MODE[diff] = "1"`.
185 Exclusions controlled by `ARCHIVER_MODE[diff-exclude]` are not yet tested.
186 """
187
188 self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-diff.gz',
189 'ARCHIVER_MODE[diff] = "1"\n')
190
191 def test_archiver_mode_dumpdata(self):
192 """
193 Test that the archiver works with `ARCHIVER_MODE[dumpdata] = "1"`.
194 """
195
196 self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-showdata.dump',
197 'ARCHIVER_MODE[dumpdata] = "1"\n')
198
199 def test_archiver_mode_mirror(self):
200 """
201 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`.
202 """
203
204 self._test_archiver_mode('mirror', 'ed-1.14.1.tar.lz',
205 'BB_GENERATE_MIRROR_TARBALLS = "1"\n')
206
207 def test_archiver_mode_mirror_excludes(self):
208 """
209 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"` and
210 correctly excludes an archive when its URL matches
211 `ARCHIVER_MIRROR_EXCLUDE`.
212 """
213
214 target='selftest-ed'
215 target_file_name = 'ed-1.14.1.tar.lz'
216
217 features = 'INHERIT += "archiver"\n'
218 features += 'ARCHIVER_MODE[src] = "mirror"\n'
219 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
220 features += 'ARCHIVER_MIRROR_EXCLUDE = "${GNU_MIRROR}"\n'
221 self.write_config(features)
222
223 bitbake('-c clean %s' % (target))
224 bitbake('-c deploy_archives %s' % (target))
225
226 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
227 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'], '%s-*' % (target))
228 glob_result = glob.glob(glob_str)
229 self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target))
230
231 archive_path = os.path.join(glob_result[0], target_file_name)
232 self.assertFalse(os.path.exists(archive_path), 'Failed to exclude archive file %s' % (target_file_name))
233
234 def test_archiver_mode_mirror_combined(self):
235 """
236 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`
237 and `ARCHIVER_MODE[mirror] = "combined"`. Archives for multiple recipes
238 should all end up in the 'mirror' directory.
239 """
240
241 features = 'INHERIT += "archiver"\n'
242 features += 'ARCHIVER_MODE[src] = "mirror"\n'
243 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
244 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
245 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
246 self.write_config(features)
247
248 for target in ['selftest-ed', 'selftest-hardlink']:
249 bitbake('-c clean %s' % (target))
250 bitbake('-c deploy_archives %s' % (target))
251
252 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
253 for target_file_name in ['ed-1.14.1.tar.lz', 'hello.c']:
254 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
255 glob_result = glob.glob(glob_str)
256 self.assertTrue(glob_result, 'Missing archive file %s' % (target_file_name))