blob: f131d9856c593f3e89638a1fb54d4f7c8dcf62e9 [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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015 def test_bitbakelayers_showcrossdepends(self):
16 result = runCmd('bitbake-layers show-cross-depends')
Brad Bishop64c979e2019-11-04 13:55:29 -050017 self.assertIn('aspell', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019 def test_bitbakelayers_showlayers(self):
20 result = runCmd('bitbake-layers show-layers')
Brad Bishop64c979e2019-11-04 13:55:29 -050021 self.assertIn('meta-selftest', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023 def test_bitbakelayers_showappends(self):
24 recipe = "xcursor-transparent-theme"
25 bb_file = self.get_recipe_basename(recipe)
26 result = runCmd('bitbake-layers show-appends')
Brad Bishop64c979e2019-11-04 13:55:29 -050027 self.assertIn(bb_file, result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 def test_bitbakelayers_showoverlayed(self):
30 result = runCmd('bitbake-layers show-overlayed')
Brad Bishop64c979e2019-11-04 13:55:29 -050031 self.assertIn('aspell', result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033 def test_bitbakelayers_flatten(self):
34 recipe = "xcursor-transparent-theme"
35 recipe_path = "recipes-graphics/xcursor-transparent-theme"
36 recipe_file = self.get_recipe_basename(recipe)
37 testoutdir = os.path.join(self.builddir, 'test_bitbakelayers_flatten')
38 self.assertFalse(os.path.isdir(testoutdir), msg = "test_bitbakelayers_flatten should not exist at this point in time")
39 self.track_for_cleanup(testoutdir)
40 result = runCmd('bitbake-layers flatten %s' % testoutdir)
41 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.")
43 contents = ftools.read_file(bb_file)
44 find_in_contents = re.search("##### 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)
46
Brad Bishopd7bf8c12018-02-25 22:55:05 -050047 def test_bitbakelayers_add_remove(self):
48 test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton')
49 result = runCmd('bitbake-layers show-layers')
50 self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output)
51 result = runCmd('bitbake-layers add-layer %s' % test_layer)
52 result = runCmd('bitbake-layers show-layers')
53 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)
54 result = runCmd('bitbake-layers remove-layer %s' % test_layer)
55 result = runCmd('bitbake-layers show-layers')
56 self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output)
57 result = runCmd('bitbake-layers add-layer %s' % test_layer)
58 result = runCmd('bitbake-layers show-layers')
59 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)
60 result = runCmd('bitbake-layers remove-layer */meta-skeleton')
61 result = runCmd('bitbake-layers show-layers')
62 self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output)
63
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064 def test_bitbakelayers_showrecipes(self):
65 result = runCmd('bitbake-layers show-recipes')
66 self.assertIn('aspell:', result.output)
67 self.assertIn('mtd-utils:', result.output)
68 self.assertIn('core-image-minimal:', result.output)
69 result = runCmd('bitbake-layers show-recipes mtd-utils')
70 self.assertIn('mtd-utils:', result.output)
71 self.assertNotIn('aspell:', result.output)
72 result = runCmd('bitbake-layers show-recipes -i image')
73 self.assertIn('core-image-minimal', result.output)
74 self.assertNotIn('mtd-utils:', result.output)
75 result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig')
76 self.assertIn('libproxy:', result.output)
77 self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either
78 self.assertNotIn('wget:', result.output) # doesn't inherit cmake
79 self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig
80 result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True)
81 self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed')
82 self.assertIn('ERROR:', result.output)
83
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084 def test_bitbakelayers_createlayer(self):
85 priority = 10
86 layername = 'test-bitbakelayer-layercreate'
87 layerpath = os.path.join(self.builddir, layername)
88 self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath)
89 result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath))
90 self.track_for_cleanup(layerpath)
91 result = runCmd('bitbake-layers add-layer %s' % layerpath)
92 self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath)
93 result = runCmd('bitbake-layers show-layers')
94 find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output)
95 self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output))
96
97 layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT']
98 bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars])
99
100 for v in layervars:
101 varname = '%s_%s' % (v, layername)
102 self.assertIsNotNone(bb_vars[varname], "%s not found" % varname)
103
104 find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS'])
105 self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername)
106
107 self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority))
108
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500109 def get_recipe_basename(self, recipe):
110 recipe_file = ""
111 result = runCmd("bitbake-layers show-recipes -f %s" % recipe)
112 for line in result.output.splitlines():
113 if recipe in line:
114 recipe_file = line
115 break
116
117 self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
118 return os.path.basename(recipe_file)