Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | import os |
| 6 | import re |
| 7 | |
| 8 | import oeqa.utils.ftools as ftools |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 9 | from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | |
| 11 | from oeqa.selftest.case import OESelftestTestCase |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | class BitbakeLayers(OESelftestTestCase): |
| 14 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 15 | def test_bitbakelayers_showcrossdepends(self): |
| 16 | result = runCmd('bitbake-layers show-cross-depends') |
| 17 | self.assertTrue('aspell' in result.output, msg = "No dependencies were shown. bitbake-layers show-cross-depends output: %s" % result.output) |
| 18 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | def test_bitbakelayers_showlayers(self): |
| 20 | result = runCmd('bitbake-layers show-layers') |
| 21 | self.assertTrue('meta-selftest' in result.output, msg = "No layers were shown. bitbake-layers show-layers output: %s" % result.output) |
| 22 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | 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') |
| 27 | self.assertTrue(bb_file in result.output, msg="%s file was not recognised. bitbake-layers show-appends output: %s" % (bb_file, result.output)) |
| 28 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | def test_bitbakelayers_showoverlayed(self): |
| 30 | result = runCmd('bitbake-layers show-overlayed') |
| 31 | self.assertTrue('aspell' in result.output, msg="aspell overlayed recipe was not recognised bitbake-layers show-overlayed %s" % result.output) |
| 32 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 33 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 47 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 84 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | 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) |