blob: 7d74833f61eab72d4c5a2f53b77744bd3ecf70e8 [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 re
7
8import oeqa.utils.ftools as ftools
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08009from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
11from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
13class BitbakeLayers(OESelftestTestCase):
14
Andrew Geisslerc926e172021-05-07 16:11:35 -050015 def test_bitbakelayers_layerindexshowdepends(self):
16 result = runCmd('bitbake-layers layerindex-show-depends meta-poky')
17 find_in_contents = re.search("openembedded-core", result.output)
18 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)
19
Brad Bishopd7bf8c12018-02-25 22:55:05 -050020 def test_bitbakelayers_showcrossdepends(self):
21 result = runCmd('bitbake-layers show-cross-depends')
Brad Bishop64c979e2019-11-04 13:55:29 -050022 self.assertIn('aspell', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 def test_bitbakelayers_showlayers(self):
25 result = runCmd('bitbake-layers show-layers')
Brad Bishop64c979e2019-11-04 13:55:29 -050026 self.assertIn('meta-selftest', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028 def test_bitbakelayers_showappends(self):
29 recipe = "xcursor-transparent-theme"
30 bb_file = self.get_recipe_basename(recipe)
31 result = runCmd('bitbake-layers show-appends')
Brad Bishop64c979e2019-11-04 13:55:29 -050032 self.assertIn(bb_file, result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 def test_bitbakelayers_showoverlayed(self):
35 result = runCmd('bitbake-layers show-overlayed')
Brad Bishop64c979e2019-11-04 13:55:29 -050036 self.assertIn('aspell', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038 def test_bitbakelayers_flatten(self):
39 recipe = "xcursor-transparent-theme"
40 recipe_path = "recipes-graphics/xcursor-transparent-theme"
41 recipe_file = self.get_recipe_basename(recipe)
42 testoutdir = os.path.join(self.builddir, 'test_bitbakelayers_flatten')
43 self.assertFalse(os.path.isdir(testoutdir), msg = "test_bitbakelayers_flatten should not exist at this point in time")
44 self.track_for_cleanup(testoutdir)
45 result = runCmd('bitbake-layers flatten %s' % testoutdir)
46 bb_file = os.path.join(testoutdir, recipe_path, recipe_file)
47 self.assertTrue(os.path.isfile(bb_file), msg = "Cannot find xcursor-transparent-theme_0.1.1.bb in the test_bitbakelayers_flatten local dir.")
48 contents = ftools.read_file(bb_file)
49 find_in_contents = re.search("##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents)
50 self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output)
51
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052 def test_bitbakelayers_add_remove(self):
53 test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton')
54 result = runCmd('bitbake-layers show-layers')
55 self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
56 result = runCmd('bitbake-layers add-layer %s' % test_layer)
57 result = runCmd('bitbake-layers show-layers')
58 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)
59 result = runCmd('bitbake-layers remove-layer %s' % test_layer)
60 result = runCmd('bitbake-layers show-layers')
61 self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output)
62 result = runCmd('bitbake-layers add-layer %s' % test_layer)
63 result = runCmd('bitbake-layers show-layers')
64 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)
65 result = runCmd('bitbake-layers remove-layer */meta-skeleton')
66 result = runCmd('bitbake-layers show-layers')
67 self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output)
68
Brad Bishopd7bf8c12018-02-25 22:55:05 -050069 def test_bitbakelayers_showrecipes(self):
70 result = runCmd('bitbake-layers show-recipes')
71 self.assertIn('aspell:', result.output)
72 self.assertIn('mtd-utils:', result.output)
73 self.assertIn('core-image-minimal:', result.output)
74 result = runCmd('bitbake-layers show-recipes mtd-utils')
75 self.assertIn('mtd-utils:', result.output)
76 self.assertNotIn('aspell:', result.output)
77 result = runCmd('bitbake-layers show-recipes -i image')
78 self.assertIn('core-image-minimal', result.output)
79 self.assertNotIn('mtd-utils:', result.output)
80 result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig')
81 self.assertIn('libproxy:', result.output)
82 self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either
83 self.assertNotIn('wget:', result.output) # doesn't inherit cmake
84 self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig
85 result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True)
86 self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed')
87 self.assertIn('ERROR:', result.output)
88
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080089 def test_bitbakelayers_createlayer(self):
90 priority = 10
91 layername = 'test-bitbakelayer-layercreate'
92 layerpath = os.path.join(self.builddir, layername)
93 self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath)
94 result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath))
95 self.track_for_cleanup(layerpath)
96 result = runCmd('bitbake-layers add-layer %s' % layerpath)
97 self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath)
98 result = runCmd('bitbake-layers show-layers')
99 find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output)
100 self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output))
101
102 layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT']
103 bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars])
104
105 for v in layervars:
106 varname = '%s_%s' % (v, layername)
107 self.assertIsNotNone(bb_vars[varname], "%s not found" % varname)
108
109 find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS'])
110 self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername)
111
112 self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority))
113
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500114 def get_recipe_basename(self, recipe):
115 recipe_file = ""
116 result = runCmd("bitbake-layers show-recipes -f %s" % recipe)
117 for line in result.output.splitlines():
118 if recipe in line:
119 recipe_file = line
120 break
121
122 self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
123 return os.path.basename(recipe_file)