blob: b0489483869c0aba3d1b5405047588074ba6d479 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import os
8import re
9
10import oeqa.utils.ftools as ftools
Patrick Williams92b42cb2022-09-03 06:53:57 -050011from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars, bitbake
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
13from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014
15class BitbakeLayers(OESelftestTestCase):
16
Andrew Geissler87f5cff2022-09-30 13:13:31 -050017 @classmethod
18 def setUpClass(cls):
19 super(BitbakeLayers, cls).setUpClass()
Patrick Williams92b42cb2022-09-03 06:53:57 -050020 bitbake("python3-jsonschema-native")
21 bitbake("-c addto_recipe_sysroot python3-jsonschema-native")
22
Andrew Geisslerc926e172021-05-07 16:11:35 -050023 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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028 def test_bitbakelayers_showcrossdepends(self):
29 result = runCmd('bitbake-layers show-cross-depends')
Brad Bishop64c979e2019-11-04 13:55:29 -050030 self.assertIn('aspell', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 def test_bitbakelayers_showlayers(self):
33 result = runCmd('bitbake-layers show-layers')
Brad Bishop64c979e2019-11-04 13:55:29 -050034 self.assertIn('meta-selftest', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036 def test_bitbakelayers_showappends(self):
37 recipe = "xcursor-transparent-theme"
38 bb_file = self.get_recipe_basename(recipe)
39 result = runCmd('bitbake-layers show-appends')
Brad Bishop64c979e2019-11-04 13:55:29 -050040 self.assertIn(bb_file, result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050041
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 def test_bitbakelayers_showoverlayed(self):
43 result = runCmd('bitbake-layers show-overlayed')
Brad Bishop64c979e2019-11-04 13:55:29 -050044 self.assertIn('aspell', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046 def test_bitbakelayers_flatten(self):
47 recipe = "xcursor-transparent-theme"
48 recipe_path = "recipes-graphics/xcursor-transparent-theme"
49 recipe_file = self.get_recipe_basename(recipe)
50 testoutdir = os.path.join(self.builddir, 'test_bitbakelayers_flatten')
51 self.assertFalse(os.path.isdir(testoutdir), msg = "test_bitbakelayers_flatten should not exist at this point in time")
52 self.track_for_cleanup(testoutdir)
53 result = runCmd('bitbake-layers flatten %s' % testoutdir)
54 bb_file = os.path.join(testoutdir, recipe_path, recipe_file)
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.")
56 contents = ftools.read_file(bb_file)
57 find_in_contents = re.search("##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents)
58 self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output)
59
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060 def test_bitbakelayers_add_remove(self):
61 test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton')
62 result = runCmd('bitbake-layers show-layers')
63 self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
64 result = runCmd('bitbake-layers add-layer %s' % test_layer)
65 result = runCmd('bitbake-layers show-layers')
66 self.assertIn('meta-skeleton', result.output, msg = "Something wrong happened. meta-skeleton layer was not added to conf/bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
67 result = runCmd('bitbake-layers remove-layer %s' % test_layer)
68 result = runCmd('bitbake-layers show-layers')
69 self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output)
70 result = runCmd('bitbake-layers add-layer %s' % test_layer)
71 result = runCmd('bitbake-layers show-layers')
72 self.assertIn('meta-skeleton', result.output, msg = "Something wrong happened. meta-skeleton layer was not added to conf/bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
73 result = runCmd('bitbake-layers remove-layer */meta-skeleton')
74 result = runCmd('bitbake-layers show-layers')
75 self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output)
76
Brad Bishopd7bf8c12018-02-25 22:55:05 -050077 def test_bitbakelayers_showrecipes(self):
78 result = runCmd('bitbake-layers show-recipes')
79 self.assertIn('aspell:', result.output)
80 self.assertIn('mtd-utils:', result.output)
81 self.assertIn('core-image-minimal:', result.output)
82 result = runCmd('bitbake-layers show-recipes mtd-utils')
83 self.assertIn('mtd-utils:', result.output)
84 self.assertNotIn('aspell:', result.output)
85 result = runCmd('bitbake-layers show-recipes -i image')
86 self.assertIn('core-image-minimal', result.output)
87 self.assertNotIn('mtd-utils:', result.output)
88 result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig')
89 self.assertIn('libproxy:', result.output)
90 self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either
91 self.assertNotIn('wget:', result.output) # doesn't inherit cmake
92 self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig
93 result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True)
94 self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed')
95 self.assertIn('ERROR:', result.output)
96
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080097 def test_bitbakelayers_createlayer(self):
98 priority = 10
99 layername = 'test-bitbakelayer-layercreate'
100 layerpath = os.path.join(self.builddir, layername)
101 self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath)
102 result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath))
103 self.track_for_cleanup(layerpath)
104 result = runCmd('bitbake-layers add-layer %s' % layerpath)
105 self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath)
106 result = runCmd('bitbake-layers show-layers')
107 find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output)
108 self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output))
109
110 layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT']
111 bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars])
112
113 for v in layervars:
114 varname = '%s_%s' % (v, layername)
115 self.assertIsNotNone(bb_vars[varname], "%s not found" % varname)
116
117 find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS'])
118 self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername)
119
120 self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority))
121
Patrick Williams92b42cb2022-09-03 06:53:57 -0500122 result = runCmd('bitbake-layers save-build-conf {} {}'.format(layerpath, "buildconf-1"))
123 for f in ('local.conf.sample', 'bblayers.conf.sample', 'conf-notes.txt'):
124 fullpath = os.path.join(layerpath, "conf", "templates", "buildconf-1", f)
125 self.assertTrue(os.path.exists(fullpath), "Template configuration file {} not found".format(fullpath))
126
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500127 def get_recipe_basename(self, recipe):
128 recipe_file = ""
129 result = runCmd("bitbake-layers show-recipes -f %s" % recipe)
130 for line in result.output.splitlines():
131 if recipe in line:
132 recipe_file = line
133 break
134
135 self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
136 return os.path.basename(recipe_file)
Patrick Williams92b42cb2022-09-03 06:53:57 -0500137
138 def validate_layersjson(self, json):
139 python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3')
140 jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema')
141 jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json')
142 result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema))
143
144 def test_validate_examplelayersjson(self):
145 json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json")
146 self.validate_layersjson(json)
147
148 def test_bitbakelayers_setup(self):
149 result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path))
150 jsonfile = os.path.join(self.testlayer_path, "setup-layers.json")
151 self.validate_layersjson(jsonfile)
152
153 # The revision-under-test may not necessarily be available on the remote server,
154 # so replace it with a revision that has a yocto-4.0 tag.
155 import json
156 with open(jsonfile) as f:
157 data = json.load(f)
158 for s in data['sources']:
159 data['sources'][s]['git-remote']['rev'] = '00cfdde791a0176c134f31e5a09eff725e75b905'
160 with open(jsonfile, 'w') as f:
161 json.dump(data, f)
162
163 testcheckoutdir = os.path.join(self.builddir, 'test-layer-checkout')
164 result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir))
165 # May not necessarily be named 'poky' or 'openembedded-core'
166 oecoredir = os.listdir(testcheckoutdir)[0]
167 testcheckoutfile = os.path.join(testcheckoutdir, oecoredir, "oe-init-build-env")
168 self.assertTrue(os.path.exists(testcheckoutfile), "File {} not found in test layer checkout".format(testcheckoutfile))