diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/bblayers.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/bblayers.py | 130 |
1 files changed, 127 insertions, 3 deletions
diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py index f131d9856c..695d17377d 100644 --- a/meta/lib/oeqa/selftest/cases/bblayers.py +++ b/meta/lib/oeqa/selftest/cases/bblayers.py | |||
@@ -1,4 +1,6 @@ | |||
1 | # | 1 | # |
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
2 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
3 | # | 5 | # |
4 | 6 | ||
@@ -6,12 +8,23 @@ import os | |||
6 | import re | 8 | import re |
7 | 9 | ||
8 | import oeqa.utils.ftools as ftools | 10 | import oeqa.utils.ftools as ftools |
9 | from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars | 11 | from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars, bitbake |
10 | 12 | ||
11 | from oeqa.selftest.case import OESelftestTestCase | 13 | from oeqa.selftest.case import OESelftestTestCase |
12 | 14 | ||
13 | class BitbakeLayers(OESelftestTestCase): | 15 | class BitbakeLayers(OESelftestTestCase): |
14 | 16 | ||
17 | @classmethod | ||
18 | def setUpClass(cls): | ||
19 | super(BitbakeLayers, cls).setUpClass() | ||
20 | bitbake("python3-jsonschema-native") | ||
21 | bitbake("-c addto_recipe_sysroot python3-jsonschema-native") | ||
22 | |||
23 | def test_bitbakelayers_layerindexshowdepends(self): | ||
24 | result = runCmd('bitbake-layers layerindex-show-depends meta-poky') | ||
25 | find_in_contents = re.search("openembedded-core", result.output) | ||
26 | self.assertTrue(find_in_contents, msg = "openembedded-core should have been listed at this step. bitbake-layers layerindex-show-depends meta-poky output: %s" % result.output) | ||
27 | |||
15 | def test_bitbakelayers_showcrossdepends(self): | 28 | def test_bitbakelayers_showcrossdepends(self): |
16 | result = runCmd('bitbake-layers show-cross-depends') | 29 | result = runCmd('bitbake-layers show-cross-depends') |
17 | self.assertIn('aspell', result.output) | 30 | self.assertIn('aspell', result.output) |
@@ -41,7 +54,7 @@ class BitbakeLayers(OESelftestTestCase): | |||
41 | bb_file = os.path.join(testoutdir, recipe_path, recipe_file) | 54 | bb_file = os.path.join(testoutdir, recipe_path, recipe_file) |
42 | self.assertTrue(os.path.isfile(bb_file), msg = "Cannot find xcursor-transparent-theme_0.1.1.bb in the test_bitbakelayers_flatten local dir.") | 55 | self.assertTrue(os.path.isfile(bb_file), msg = "Cannot find xcursor-transparent-theme_0.1.1.bb in the test_bitbakelayers_flatten local dir.") |
43 | contents = ftools.read_file(bb_file) | 56 | contents = ftools.read_file(bb_file) |
44 | find_in_contents = re.search("##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents) | 57 | find_in_contents = re.search(r"##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents) |
45 | self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output) | 58 | self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output) |
46 | 59 | ||
47 | def test_bitbakelayers_add_remove(self): | 60 | def test_bitbakelayers_add_remove(self): |
@@ -72,8 +85,9 @@ class BitbakeLayers(OESelftestTestCase): | |||
72 | result = runCmd('bitbake-layers show-recipes -i image') | 85 | result = runCmd('bitbake-layers show-recipes -i image') |
73 | self.assertIn('core-image-minimal', result.output) | 86 | self.assertIn('core-image-minimal', result.output) |
74 | self.assertNotIn('mtd-utils:', result.output) | 87 | self.assertNotIn('mtd-utils:', result.output) |
75 | result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig') | 88 | result = runCmd('bitbake-layers show-recipes -i meson,pkgconfig') |
76 | self.assertIn('libproxy:', result.output) | 89 | self.assertIn('libproxy:', result.output) |
90 | result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig') | ||
77 | self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either | 91 | self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either |
78 | self.assertNotIn('wget:', result.output) # doesn't inherit cmake | 92 | self.assertNotIn('wget:', result.output) # doesn't inherit cmake |
79 | self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig | 93 | self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig |
@@ -106,6 +120,11 @@ class BitbakeLayers(OESelftestTestCase): | |||
106 | 120 | ||
107 | self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority)) | 121 | self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority)) |
108 | 122 | ||
123 | result = runCmd('bitbake-layers save-build-conf {} {}'.format(layerpath, "buildconf-1")) | ||
124 | for f in ('local.conf.sample', 'bblayers.conf.sample', 'conf-summary.txt', 'conf-notes.txt'): | ||
125 | fullpath = os.path.join(layerpath, "conf", "templates", "buildconf-1", f) | ||
126 | self.assertTrue(os.path.exists(fullpath), "Template configuration file {} not found".format(fullpath)) | ||
127 | |||
109 | def get_recipe_basename(self, recipe): | 128 | def get_recipe_basename(self, recipe): |
110 | recipe_file = "" | 129 | recipe_file = "" |
111 | result = runCmd("bitbake-layers show-recipes -f %s" % recipe) | 130 | result = runCmd("bitbake-layers show-recipes -f %s" % recipe) |
@@ -116,3 +135,108 @@ class BitbakeLayers(OESelftestTestCase): | |||
116 | 135 | ||
117 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) | 136 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) |
118 | return os.path.basename(recipe_file) | 137 | return os.path.basename(recipe_file) |
138 | |||
139 | def validate_layersjson(self, json): | ||
140 | python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3') | ||
141 | jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema') | ||
142 | jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json') | ||
143 | result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema)) | ||
144 | |||
145 | def test_validate_examplelayersjson(self): | ||
146 | json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json") | ||
147 | self.validate_layersjson(json) | ||
148 | |||
149 | def test_bitbakelayers_setup(self): | ||
150 | result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path)) | ||
151 | jsonfile = os.path.join(self.testlayer_path, "setup-layers.json") | ||
152 | self.validate_layersjson(jsonfile) | ||
153 | |||
154 | # The revision-under-test may not necessarily be available on the remote server, | ||
155 | # so replace it with a revision that has a yocto-4.1 tag. | ||
156 | import json | ||
157 | with open(jsonfile) as f: | ||
158 | data = json.load(f) | ||
159 | for s in data['sources']: | ||
160 | data['sources'][s]['git-remote']['rev'] = '5200799866b92259e855051112520006e1aaaac0' | ||
161 | with open(jsonfile, 'w') as f: | ||
162 | json.dump(data, f) | ||
163 | |||
164 | testcheckoutdir = os.path.join(self.builddir, 'test-layer-checkout') | ||
165 | result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir)) | ||
166 | layers_json = os.path.join(testcheckoutdir, ".oe-layers.json") | ||
167 | self.assertTrue(os.path.exists(layers_json), "File {} not found in test layer checkout".format(layers_json)) | ||
168 | |||
169 | # As setup-layers checkout out an old revision of poky, there is no setup-build symlink, | ||
170 | # and we need to run oe-setup-build directly from the current poky tree under test | ||
171 | oe_setup_build = os.path.join(get_bb_var('COREBASE'), 'scripts/oe-setup-build') | ||
172 | oe_setup_build_l = os.path.join(testcheckoutdir, 'setup-build') | ||
173 | os.symlink(oe_setup_build,oe_setup_build_l) | ||
174 | |||
175 | cmd = '{} --layerlist {} list -v'.format(oe_setup_build_l, layers_json) | ||
176 | result = runCmd(cmd) | ||
177 | cond = "conf/templates/default" in result.output | ||
178 | self.assertTrue(cond, "Incorrect output from {}: {}".format(cmd, result.output)) | ||
179 | |||
180 | # rather than hardcode the build setup cmdline here, let's actually run what the tool suggests to the user | ||
181 | conf = None | ||
182 | if 'poky-default' in result.output: | ||
183 | conf = 'poky-default' | ||
184 | elif 'meta-default' in result.output: | ||
185 | conf = 'meta-default' | ||
186 | self.assertIsNotNone(conf, "Could not find the configuration to set up a build in the output: {}".format(result.output)) | ||
187 | |||
188 | cmd = '{} --layerlist {} setup -c {} --no-shell'.format(oe_setup_build_l, layers_json, conf) | ||
189 | result = runCmd(cmd) | ||
190 | |||
191 | def test_bitbakelayers_updatelayer(self): | ||
192 | result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path)) | ||
193 | jsonfile = os.path.join(self.testlayer_path, "setup-layers.json") | ||
194 | self.validate_layersjson(jsonfile) | ||
195 | |||
196 | import json | ||
197 | with open(jsonfile) as f: | ||
198 | data = json.load(f) | ||
199 | repos = [] | ||
200 | for s in data['sources']: | ||
201 | repos.append(s) | ||
202 | |||
203 | self.assertTrue(len(repos) > 1, "Not enough repositories available") | ||
204 | self.validate_layersjson(jsonfile) | ||
205 | |||
206 | test_ref_1 = 'ref_1' | ||
207 | test_ref_2 = 'ref_2' | ||
208 | |||
209 | # Create a new layers setup using custom references | ||
210 | result = runCmd('bitbake-layers create-layers-setup --use-custom-reference {first_repo}:{test_ref} --use-custom-reference {second_repo}:{test_ref} {path}' | ||
211 | .format(first_repo=repos[0], second_repo=repos[1], test_ref=test_ref_1, path=self.testlayer_path)) | ||
212 | self.validate_layersjson(jsonfile) | ||
213 | |||
214 | with open(jsonfile) as f: | ||
215 | data = json.load(f) | ||
216 | first_rev_1 = data['sources'][repos[0]]['git-remote']['rev'] | ||
217 | first_desc_1 = data['sources'][repos[0]]['git-remote']['describe'] | ||
218 | second_rev_1 = data['sources'][repos[1]]['git-remote']['rev'] | ||
219 | second_desc_1 = data['sources'][repos[1]]['git-remote']['describe'] | ||
220 | |||
221 | self.assertEqual(first_rev_1, test_ref_1, "Revision not set correctly: '{}'".format(first_rev_1)) | ||
222 | self.assertEqual(first_desc_1, '', "Describe not cleared: '{}'".format(first_desc_1)) | ||
223 | self.assertEqual(second_rev_1, test_ref_1, "Revision not set correctly: '{}'".format(second_rev_1)) | ||
224 | self.assertEqual(second_desc_1, '', "Describe not cleared: '{}'".format(second_desc_1)) | ||
225 | |||
226 | # Update one of the repositories in the layers setup using a different custom reference | ||
227 | # This should only update the selected repository, everything else should remain as is | ||
228 | result = runCmd('bitbake-layers create-layers-setup --update --use-custom-reference {first_repo}:{test_ref} {path}' | ||
229 | .format(first_repo=repos[0], test_ref=test_ref_2, path=self.testlayer_path)) | ||
230 | self.validate_layersjson(jsonfile) | ||
231 | |||
232 | with open(jsonfile) as f: | ||
233 | data = json.load(f) | ||
234 | first_rev_2 = data['sources'][repos[0]]['git-remote']['rev'] | ||
235 | first_desc_2 = data['sources'][repos[0]]['git-remote']['describe'] | ||
236 | second_rev_2 = data['sources'][repos[1]]['git-remote']['rev'] | ||
237 | second_desc_2 = data['sources'][repos[1]]['git-remote']['describe'] | ||
238 | |||
239 | self.assertEqual(first_rev_2, test_ref_2, "Revision not set correctly: '{}'".format(first_rev_2)) | ||
240 | self.assertEqual(first_desc_2, '', "Describe not cleared: '{}'".format(first_desc_2)) | ||
241 | self.assertEqual(second_rev_2, second_rev_1, "Revision should not be updated: '{}'".format(second_rev_2)) | ||
242 | self.assertEqual(second_desc_2, second_desc_1, "Describe should not be updated: '{}'".format(second_desc_2)) | ||