xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/selftest/cases/bblayers.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#
2*4882a593Smuzhiyun# SPDX-License-Identifier: MIT
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun
5*4882a593Smuzhiyunimport os
6*4882a593Smuzhiyunimport re
7*4882a593Smuzhiyun
8*4882a593Smuzhiyunimport oeqa.utils.ftools as ftools
9*4882a593Smuzhiyunfrom oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars
10*4882a593Smuzhiyun
11*4882a593Smuzhiyunfrom oeqa.selftest.case import OESelftestTestCase
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunclass BitbakeLayers(OESelftestTestCase):
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun    def test_bitbakelayers_layerindexshowdepends(self):
16*4882a593Smuzhiyun        result = runCmd('bitbake-layers layerindex-show-depends meta-poky')
17*4882a593Smuzhiyun        find_in_contents = re.search("openembedded-core", result.output)
18*4882a593Smuzhiyun        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*4882a593Smuzhiyun
20*4882a593Smuzhiyun    def test_bitbakelayers_showcrossdepends(self):
21*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-cross-depends')
22*4882a593Smuzhiyun        self.assertIn('aspell', result.output)
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun    def test_bitbakelayers_showlayers(self):
25*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
26*4882a593Smuzhiyun        self.assertIn('meta-selftest', result.output)
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun    def test_bitbakelayers_showappends(self):
29*4882a593Smuzhiyun        recipe = "xcursor-transparent-theme"
30*4882a593Smuzhiyun        bb_file = self.get_recipe_basename(recipe)
31*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-appends')
32*4882a593Smuzhiyun        self.assertIn(bb_file, result.output)
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun    def test_bitbakelayers_showoverlayed(self):
35*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-overlayed')
36*4882a593Smuzhiyun        self.assertIn('aspell', result.output)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun    def test_bitbakelayers_flatten(self):
39*4882a593Smuzhiyun        recipe = "xcursor-transparent-theme"
40*4882a593Smuzhiyun        recipe_path = "recipes-graphics/xcursor-transparent-theme"
41*4882a593Smuzhiyun        recipe_file = self.get_recipe_basename(recipe)
42*4882a593Smuzhiyun        testoutdir = os.path.join(self.builddir, 'test_bitbakelayers_flatten')
43*4882a593Smuzhiyun        self.assertFalse(os.path.isdir(testoutdir), msg = "test_bitbakelayers_flatten should not exist at this point in time")
44*4882a593Smuzhiyun        self.track_for_cleanup(testoutdir)
45*4882a593Smuzhiyun        result = runCmd('bitbake-layers flatten %s' % testoutdir)
46*4882a593Smuzhiyun        bb_file = os.path.join(testoutdir, recipe_path, recipe_file)
47*4882a593Smuzhiyun        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*4882a593Smuzhiyun        contents = ftools.read_file(bb_file)
49*4882a593Smuzhiyun        find_in_contents = re.search("##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents)
50*4882a593Smuzhiyun        self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output)
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun    def test_bitbakelayers_add_remove(self):
53*4882a593Smuzhiyun        test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton')
54*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
55*4882a593Smuzhiyun        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*4882a593Smuzhiyun        result = runCmd('bitbake-layers add-layer %s' % test_layer)
57*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
58*4882a593Smuzhiyun        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*4882a593Smuzhiyun        result = runCmd('bitbake-layers remove-layer %s' % test_layer)
60*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
61*4882a593Smuzhiyun        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*4882a593Smuzhiyun        result = runCmd('bitbake-layers add-layer %s' % test_layer)
63*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
64*4882a593Smuzhiyun        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*4882a593Smuzhiyun        result = runCmd('bitbake-layers remove-layer */meta-skeleton')
66*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
67*4882a593Smuzhiyun        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*4882a593Smuzhiyun
69*4882a593Smuzhiyun    def test_bitbakelayers_showrecipes(self):
70*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-recipes')
71*4882a593Smuzhiyun        self.assertIn('aspell:', result.output)
72*4882a593Smuzhiyun        self.assertIn('mtd-utils:', result.output)
73*4882a593Smuzhiyun        self.assertIn('core-image-minimal:', result.output)
74*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-recipes mtd-utils')
75*4882a593Smuzhiyun        self.assertIn('mtd-utils:', result.output)
76*4882a593Smuzhiyun        self.assertNotIn('aspell:', result.output)
77*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-recipes -i image')
78*4882a593Smuzhiyun        self.assertIn('core-image-minimal', result.output)
79*4882a593Smuzhiyun        self.assertNotIn('mtd-utils:', result.output)
80*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig')
81*4882a593Smuzhiyun        self.assertIn('libproxy:', result.output)
82*4882a593Smuzhiyun        self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either
83*4882a593Smuzhiyun        self.assertNotIn('wget:', result.output) # doesn't inherit cmake
84*4882a593Smuzhiyun        self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig
85*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True)
86*4882a593Smuzhiyun        self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed')
87*4882a593Smuzhiyun        self.assertIn('ERROR:', result.output)
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun    def test_bitbakelayers_createlayer(self):
90*4882a593Smuzhiyun        priority = 10
91*4882a593Smuzhiyun        layername = 'test-bitbakelayer-layercreate'
92*4882a593Smuzhiyun        layerpath = os.path.join(self.builddir, layername)
93*4882a593Smuzhiyun        self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath)
94*4882a593Smuzhiyun        result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath))
95*4882a593Smuzhiyun        self.track_for_cleanup(layerpath)
96*4882a593Smuzhiyun        result = runCmd('bitbake-layers add-layer %s' % layerpath)
97*4882a593Smuzhiyun        self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath)
98*4882a593Smuzhiyun        result = runCmd('bitbake-layers show-layers')
99*4882a593Smuzhiyun        find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output)
100*4882a593Smuzhiyun        self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output))
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun        layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT']
103*4882a593Smuzhiyun        bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars])
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun        for v in layervars:
106*4882a593Smuzhiyun            varname = '%s_%s' % (v, layername)
107*4882a593Smuzhiyun            self.assertIsNotNone(bb_vars[varname], "%s not found" % varname)
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun        find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS'])
110*4882a593Smuzhiyun        self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername)
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun        self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority))
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun    def get_recipe_basename(self, recipe):
115*4882a593Smuzhiyun        recipe_file = ""
116*4882a593Smuzhiyun        result = runCmd("bitbake-layers show-recipes -f %s" % recipe)
117*4882a593Smuzhiyun        for line in result.output.splitlines():
118*4882a593Smuzhiyun            if recipe in line:
119*4882a593Smuzhiyun                recipe_file = line
120*4882a593Smuzhiyun                break
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun        self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
123*4882a593Smuzhiyun        return os.path.basename(recipe_file)
124