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 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 17 | def setUpLocal(self): |
| 18 | bitbake("python3-jsonschema-native") |
| 19 | bitbake("-c addto_recipe_sysroot python3-jsonschema-native") |
| 20 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 21 | def test_bitbakelayers_layerindexshowdepends(self): |
| 22 | result = runCmd('bitbake-layers layerindex-show-depends meta-poky') |
| 23 | find_in_contents = re.search("openembedded-core", result.output) |
| 24 | 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) |
| 25 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | def test_bitbakelayers_showcrossdepends(self): |
| 27 | result = runCmd('bitbake-layers show-cross-depends') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 28 | self.assertIn('aspell', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | def test_bitbakelayers_showlayers(self): |
| 31 | result = runCmd('bitbake-layers show-layers') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 32 | self.assertIn('meta-selftest', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 33 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 34 | def test_bitbakelayers_showappends(self): |
| 35 | recipe = "xcursor-transparent-theme" |
| 36 | bb_file = self.get_recipe_basename(recipe) |
| 37 | result = runCmd('bitbake-layers show-appends') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 38 | self.assertIn(bb_file, result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 39 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 40 | def test_bitbakelayers_showoverlayed(self): |
| 41 | result = runCmd('bitbake-layers show-overlayed') |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 42 | self.assertIn('aspell', result.output) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 43 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | def test_bitbakelayers_flatten(self): |
| 45 | recipe = "xcursor-transparent-theme" |
| 46 | recipe_path = "recipes-graphics/xcursor-transparent-theme" |
| 47 | recipe_file = self.get_recipe_basename(recipe) |
| 48 | testoutdir = os.path.join(self.builddir, 'test_bitbakelayers_flatten') |
| 49 | self.assertFalse(os.path.isdir(testoutdir), msg = "test_bitbakelayers_flatten should not exist at this point in time") |
| 50 | self.track_for_cleanup(testoutdir) |
| 51 | result = runCmd('bitbake-layers flatten %s' % testoutdir) |
| 52 | bb_file = os.path.join(testoutdir, recipe_path, recipe_file) |
| 53 | self.assertTrue(os.path.isfile(bb_file), msg = "Cannot find xcursor-transparent-theme_0.1.1.bb in the test_bitbakelayers_flatten local dir.") |
| 54 | contents = ftools.read_file(bb_file) |
| 55 | find_in_contents = re.search("##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents) |
| 56 | self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output) |
| 57 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 58 | def test_bitbakelayers_add_remove(self): |
| 59 | test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton') |
| 60 | result = runCmd('bitbake-layers show-layers') |
| 61 | self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. 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 %s' % test_layer) |
| 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 | result = runCmd('bitbake-layers add-layer %s' % test_layer) |
| 69 | result = runCmd('bitbake-layers show-layers') |
| 70 | 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) |
| 71 | result = runCmd('bitbake-layers remove-layer */meta-skeleton') |
| 72 | result = runCmd('bitbake-layers show-layers') |
| 73 | self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output) |
| 74 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 75 | def test_bitbakelayers_showrecipes(self): |
| 76 | result = runCmd('bitbake-layers show-recipes') |
| 77 | self.assertIn('aspell:', result.output) |
| 78 | self.assertIn('mtd-utils:', result.output) |
| 79 | self.assertIn('core-image-minimal:', result.output) |
| 80 | result = runCmd('bitbake-layers show-recipes mtd-utils') |
| 81 | self.assertIn('mtd-utils:', result.output) |
| 82 | self.assertNotIn('aspell:', result.output) |
| 83 | result = runCmd('bitbake-layers show-recipes -i image') |
| 84 | self.assertIn('core-image-minimal', result.output) |
| 85 | self.assertNotIn('mtd-utils:', result.output) |
| 86 | result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig') |
| 87 | self.assertIn('libproxy:', result.output) |
| 88 | self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either |
| 89 | self.assertNotIn('wget:', result.output) # doesn't inherit cmake |
| 90 | self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig |
| 91 | result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True) |
| 92 | self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed') |
| 93 | self.assertIn('ERROR:', result.output) |
| 94 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 95 | def test_bitbakelayers_createlayer(self): |
| 96 | priority = 10 |
| 97 | layername = 'test-bitbakelayer-layercreate' |
| 98 | layerpath = os.path.join(self.builddir, layername) |
| 99 | self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath) |
| 100 | result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath)) |
| 101 | self.track_for_cleanup(layerpath) |
| 102 | result = runCmd('bitbake-layers add-layer %s' % layerpath) |
| 103 | self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath) |
| 104 | result = runCmd('bitbake-layers show-layers') |
| 105 | find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output) |
| 106 | self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output)) |
| 107 | |
| 108 | layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT'] |
| 109 | bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars]) |
| 110 | |
| 111 | for v in layervars: |
| 112 | varname = '%s_%s' % (v, layername) |
| 113 | self.assertIsNotNone(bb_vars[varname], "%s not found" % varname) |
| 114 | |
| 115 | find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS']) |
| 116 | self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername) |
| 117 | |
| 118 | self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority)) |
| 119 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 120 | result = runCmd('bitbake-layers save-build-conf {} {}'.format(layerpath, "buildconf-1")) |
| 121 | for f in ('local.conf.sample', 'bblayers.conf.sample', 'conf-notes.txt'): |
| 122 | fullpath = os.path.join(layerpath, "conf", "templates", "buildconf-1", f) |
| 123 | self.assertTrue(os.path.exists(fullpath), "Template configuration file {} not found".format(fullpath)) |
| 124 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 125 | def get_recipe_basename(self, recipe): |
| 126 | recipe_file = "" |
| 127 | result = runCmd("bitbake-layers show-recipes -f %s" % recipe) |
| 128 | for line in result.output.splitlines(): |
| 129 | if recipe in line: |
| 130 | recipe_file = line |
| 131 | break |
| 132 | |
| 133 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) |
| 134 | return os.path.basename(recipe_file) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 135 | |
| 136 | def validate_layersjson(self, json): |
| 137 | python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3') |
| 138 | jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema') |
| 139 | jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json') |
| 140 | result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema)) |
| 141 | |
| 142 | def test_validate_examplelayersjson(self): |
| 143 | json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json") |
| 144 | self.validate_layersjson(json) |
| 145 | |
| 146 | def test_bitbakelayers_setup(self): |
| 147 | result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path)) |
| 148 | jsonfile = os.path.join(self.testlayer_path, "setup-layers.json") |
| 149 | self.validate_layersjson(jsonfile) |
| 150 | |
| 151 | # The revision-under-test may not necessarily be available on the remote server, |
| 152 | # so replace it with a revision that has a yocto-4.0 tag. |
| 153 | import json |
| 154 | with open(jsonfile) as f: |
| 155 | data = json.load(f) |
| 156 | for s in data['sources']: |
| 157 | data['sources'][s]['git-remote']['rev'] = '00cfdde791a0176c134f31e5a09eff725e75b905' |
| 158 | with open(jsonfile, 'w') as f: |
| 159 | json.dump(data, f) |
| 160 | |
| 161 | testcheckoutdir = os.path.join(self.builddir, 'test-layer-checkout') |
| 162 | result = runCmd('{}/setup-layers --destdir {}'.format(self.testlayer_path, testcheckoutdir)) |
| 163 | # May not necessarily be named 'poky' or 'openembedded-core' |
| 164 | oecoredir = os.listdir(testcheckoutdir)[0] |
| 165 | testcheckoutfile = os.path.join(testcheckoutdir, oecoredir, "oe-init-build-env") |
| 166 | self.assertTrue(os.path.exists(testcheckoutfile), "File {} not found in test layer checkout".format(testcheckoutfile)) |