xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/selftest/cases/bblayers.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#
2# SPDX-License-Identifier: MIT
3#
4
5import os
6import re
7
8import oeqa.utils.ftools as ftools
9from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars
10
11from oeqa.selftest.case import OESelftestTestCase
12
13class BitbakeLayers(OESelftestTestCase):
14
15    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
20    def test_bitbakelayers_showcrossdepends(self):
21        result = runCmd('bitbake-layers show-cross-depends')
22        self.assertIn('aspell', result.output)
23
24    def test_bitbakelayers_showlayers(self):
25        result = runCmd('bitbake-layers show-layers')
26        self.assertIn('meta-selftest', result.output)
27
28    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')
32        self.assertIn(bb_file, result.output)
33
34    def test_bitbakelayers_showoverlayed(self):
35        result = runCmd('bitbake-layers show-overlayed')
36        self.assertIn('aspell', result.output)
37
38    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
52    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
69    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
89    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
114    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)
124