Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import os |
| 8 | import re |
| 9 | |
| 10 | import oeqa.utils.ftools as ftools |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 11 | from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars, bitbake |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | from oeqa.selftest.case import OESelftestTestCase |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 14 | |
| 15 | class BitbakeLayers(OESelftestTestCase): |
| 16 | |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 17 | @classmethod |
| 18 | def setUpClass(cls): |
| 19 | super(BitbakeLayers, cls).setUpClass() |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 20 | bitbake("python3-jsonschema-native") |
| 21 | bitbake("-c addto_recipe_sysroot python3-jsonschema-native") |
| 22 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 23 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | def test_bitbakelayers_showcrossdepends(self): |
| 29 | result = runCmd('bitbake-layers show-cross-depends') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 30 | self.assertIn('aspell', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 32 | def test_bitbakelayers_showlayers(self): |
| 33 | result = runCmd('bitbake-layers show-layers') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 34 | self.assertIn('meta-selftest', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 35 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | 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 Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 40 | self.assertIn(bb_file, result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 41 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | def test_bitbakelayers_showoverlayed(self): |
| 43 | result = runCmd('bitbake-layers show-overlayed') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 44 | self.assertIn('aspell', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 45 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 46 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 60 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 77 | 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) |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 88 | result = runCmd('bitbake-layers show-recipes -i meson,pkgconfig') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 89 | self.assertIn('libproxy:', result.output) |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 90 | result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 91 | self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either |
| 92 | self.assertNotIn('wget:', result.output) # doesn't inherit cmake |
| 93 | self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig |
| 94 | result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True) |
| 95 | self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed') |
| 96 | self.assertIn('ERROR:', result.output) |
| 97 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 98 | def test_bitbakelayers_createlayer(self): |
| 99 | priority = 10 |
| 100 | layername = 'test-bitbakelayer-layercreate' |
| 101 | layerpath = os.path.join(self.builddir, layername) |
| 102 | self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath) |
| 103 | result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath)) |
| 104 | self.track_for_cleanup(layerpath) |
| 105 | result = runCmd('bitbake-layers add-layer %s' % layerpath) |
| 106 | self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath) |
| 107 | result = runCmd('bitbake-layers show-layers') |
| 108 | find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output) |
| 109 | self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output)) |
| 110 | |
| 111 | layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT'] |
| 112 | bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars]) |
| 113 | |
| 114 | for v in layervars: |
| 115 | varname = '%s_%s' % (v, layername) |
| 116 | self.assertIsNotNone(bb_vars[varname], "%s not found" % varname) |
| 117 | |
| 118 | find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS']) |
| 119 | self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername) |
| 120 | |
| 121 | self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority)) |
| 122 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 123 | result = runCmd('bitbake-layers save-build-conf {} {}'.format(layerpath, "buildconf-1")) |
| 124 | for f in ('local.conf.sample', 'bblayers.conf.sample', 'conf-notes.txt'): |
| 125 | fullpath = os.path.join(layerpath, "conf", "templates", "buildconf-1", f) |
| 126 | self.assertTrue(os.path.exists(fullpath), "Template configuration file {} not found".format(fullpath)) |
| 127 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 128 | def get_recipe_basename(self, recipe): |
| 129 | recipe_file = "" |
| 130 | result = runCmd("bitbake-layers show-recipes -f %s" % recipe) |
| 131 | for line in result.output.splitlines(): |
| 132 | if recipe in line: |
| 133 | recipe_file = line |
| 134 | break |
| 135 | |
| 136 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) |
| 137 | return os.path.basename(recipe_file) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 138 | |
| 139 | def validate_layersjson(self, json): |
| 140 | python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3') |
| 141 | jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema') |
| 142 | jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json') |
| 143 | result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema)) |
| 144 | |
| 145 | def test_validate_examplelayersjson(self): |
| 146 | json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json") |
| 147 | self.validate_layersjson(json) |
| 148 | |
| 149 | def test_bitbakelayers_setup(self): |
| 150 | result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path)) |
| 151 | jsonfile = os.path.join(self.testlayer_path, "setup-layers.json") |
| 152 | self.validate_layersjson(jsonfile) |
| 153 | |
| 154 | # The revision-under-test may not necessarily be available on the remote server, |
| 155 | # so replace it with a revision that has a yocto-4.0 tag. |
| 156 | import json |
| 157 | with open(jsonfile) as f: |
| 158 | data = json.load(f) |
| 159 | for s in data['sources']: |
| 160 | data['sources'][s]['git-remote']['rev'] = '00cfdde791a0176c134f31e5a09eff725e75b905' |
| 161 | with open(jsonfile, 'w') as f: |
| 162 | json.dump(data, f) |
| 163 | |
| 164 | testcheckoutdir = os.path.join(self.builddir, 'test-layer-checkout') |
| 165 | result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir)) |
| 166 | # May not necessarily be named 'poky' or 'openembedded-core' |
| 167 | oecoredir = os.listdir(testcheckoutdir)[0] |
| 168 | testcheckoutfile = os.path.join(testcheckoutdir, oecoredir, "oe-init-build-env") |
| 169 | self.assertTrue(os.path.exists(testcheckoutfile), "File {} not found in test layer checkout".format(testcheckoutfile)) |