Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | import os |
| 2 | import re |
| 3 | |
| 4 | import oeqa.utils.ftools as ftools |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | from oeqa.utils.commands import runCmd, get_bb_var, get_bb_vars |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6 | |
| 7 | from oeqa.selftest.case import OESelftestTestCase |
| 8 | from oeqa.core.decorator.oeid import OETestID |
| 9 | |
| 10 | class BitbakeLayers(OESelftestTestCase): |
| 11 | |
| 12 | @OETestID(756) |
| 13 | def test_bitbakelayers_showcrossdepends(self): |
| 14 | result = runCmd('bitbake-layers show-cross-depends') |
| 15 | self.assertTrue('aspell' in result.output, msg = "No dependencies were shown. bitbake-layers show-cross-depends output: %s" % result.output) |
| 16 | |
| 17 | @OETestID(83) |
| 18 | def test_bitbakelayers_showlayers(self): |
| 19 | result = runCmd('bitbake-layers show-layers') |
| 20 | self.assertTrue('meta-selftest' in result.output, msg = "No layers were shown. bitbake-layers show-layers output: %s" % result.output) |
| 21 | |
| 22 | @OETestID(93) |
| 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 | |
| 29 | @OETestID(90) |
| 30 | def test_bitbakelayers_showoverlayed(self): |
| 31 | result = runCmd('bitbake-layers show-overlayed') |
| 32 | self.assertTrue('aspell' in result.output, msg="aspell overlayed recipe was not recognised bitbake-layers show-overlayed %s" % result.output) |
| 33 | |
| 34 | @OETestID(95) |
| 35 | def test_bitbakelayers_flatten(self): |
| 36 | recipe = "xcursor-transparent-theme" |
| 37 | recipe_path = "recipes-graphics/xcursor-transparent-theme" |
| 38 | recipe_file = self.get_recipe_basename(recipe) |
| 39 | testoutdir = os.path.join(self.builddir, 'test_bitbakelayers_flatten') |
| 40 | self.assertFalse(os.path.isdir(testoutdir), msg = "test_bitbakelayers_flatten should not exist at this point in time") |
| 41 | self.track_for_cleanup(testoutdir) |
| 42 | result = runCmd('bitbake-layers flatten %s' % testoutdir) |
| 43 | bb_file = os.path.join(testoutdir, recipe_path, recipe_file) |
| 44 | self.assertTrue(os.path.isfile(bb_file), msg = "Cannot find xcursor-transparent-theme_0.1.1.bb in the test_bitbakelayers_flatten local dir.") |
| 45 | contents = ftools.read_file(bb_file) |
| 46 | find_in_contents = re.search("##### bbappended from meta-selftest #####\n(.*\n)*include test_recipe.inc", contents) |
| 47 | self.assertTrue(find_in_contents, msg = "Flattening layers did not work. bitbake-layers flatten output: %s" % result.output) |
| 48 | |
| 49 | @OETestID(1195) |
| 50 | def test_bitbakelayers_add_remove(self): |
| 51 | test_layer = os.path.join(get_bb_var('COREBASE'), 'meta-skeleton') |
| 52 | result = runCmd('bitbake-layers show-layers') |
| 53 | self.assertNotIn('meta-skeleton', result.output, "This test cannot run with meta-skeleton in bblayers.conf. bitbake-layers show-layers output: %s" % result.output) |
| 54 | result = runCmd('bitbake-layers add-layer %s' % test_layer) |
| 55 | result = runCmd('bitbake-layers show-layers') |
| 56 | 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) |
| 57 | result = runCmd('bitbake-layers remove-layer %s' % test_layer) |
| 58 | result = runCmd('bitbake-layers show-layers') |
| 59 | self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output) |
| 60 | result = runCmd('bitbake-layers add-layer %s' % test_layer) |
| 61 | result = runCmd('bitbake-layers show-layers') |
| 62 | 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) |
| 63 | result = runCmd('bitbake-layers remove-layer */meta-skeleton') |
| 64 | result = runCmd('bitbake-layers show-layers') |
| 65 | self.assertNotIn('meta-skeleton', result.output, msg = "meta-skeleton should have been removed at this step. bitbake-layers show-layers output: %s" % result.output) |
| 66 | |
| 67 | @OETestID(1384) |
| 68 | def test_bitbakelayers_showrecipes(self): |
| 69 | result = runCmd('bitbake-layers show-recipes') |
| 70 | self.assertIn('aspell:', result.output) |
| 71 | self.assertIn('mtd-utils:', result.output) |
| 72 | self.assertIn('core-image-minimal:', result.output) |
| 73 | result = runCmd('bitbake-layers show-recipes mtd-utils') |
| 74 | self.assertIn('mtd-utils:', result.output) |
| 75 | self.assertNotIn('aspell:', result.output) |
| 76 | result = runCmd('bitbake-layers show-recipes -i image') |
| 77 | self.assertIn('core-image-minimal', result.output) |
| 78 | self.assertNotIn('mtd-utils:', result.output) |
| 79 | result = runCmd('bitbake-layers show-recipes -i cmake,pkgconfig') |
| 80 | self.assertIn('libproxy:', result.output) |
| 81 | self.assertNotIn('mtd-utils:', result.output) # doesn't inherit either |
| 82 | self.assertNotIn('wget:', result.output) # doesn't inherit cmake |
| 83 | self.assertNotIn('waffle:', result.output) # doesn't inherit pkgconfig |
| 84 | result = runCmd('bitbake-layers show-recipes -i nonexistentclass', ignore_status=True) |
| 85 | self.assertNotEqual(result.status, 0, 'bitbake-layers show-recipes -i nonexistentclass should have failed') |
| 86 | self.assertIn('ERROR:', result.output) |
| 87 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 88 | def test_bitbakelayers_createlayer(self): |
| 89 | priority = 10 |
| 90 | layername = 'test-bitbakelayer-layercreate' |
| 91 | layerpath = os.path.join(self.builddir, layername) |
| 92 | self.assertFalse(os.path.exists(layerpath), '%s should not exist at this point in time' % layerpath) |
| 93 | result = runCmd('bitbake-layers create-layer --priority=%d %s' % (priority, layerpath)) |
| 94 | self.track_for_cleanup(layerpath) |
| 95 | result = runCmd('bitbake-layers add-layer %s' % layerpath) |
| 96 | self.add_command_to_tearDown('bitbake-layers remove-layer %s' % layerpath) |
| 97 | result = runCmd('bitbake-layers show-layers') |
| 98 | find_in_contents = re.search(re.escape(layername) + r'\s+' + re.escape(layerpath) + r'\s+' + re.escape(str(priority)), result.output) |
| 99 | self.assertTrue(find_in_contents, "%s not found in layers\n%s" % (layername, result.output)) |
| 100 | |
| 101 | layervars = ['BBFILE_PRIORITY', 'BBFILE_PATTERN', 'LAYERDEPENDS', 'LAYERSERIES_COMPAT'] |
| 102 | bb_vars = get_bb_vars(['BBFILE_COLLECTIONS'] + ['%s_%s' % (v, layername) for v in layervars]) |
| 103 | |
| 104 | for v in layervars: |
| 105 | varname = '%s_%s' % (v, layername) |
| 106 | self.assertIsNotNone(bb_vars[varname], "%s not found" % varname) |
| 107 | |
| 108 | find_in_contents = re.search(r'(^|\s)' + re.escape(layername) + r'($|\s)', bb_vars['BBFILE_COLLECTIONS']) |
| 109 | self.assertTrue(find_in_contents, "%s not in BBFILE_COLLECTIONS" % layername) |
| 110 | |
| 111 | self.assertEqual(bb_vars['BBFILE_PRIORITY_%s' % layername], str(priority), 'BBFILE_PRIORITY_%s != %d' % (layername, priority)) |
| 112 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 113 | def get_recipe_basename(self, recipe): |
| 114 | recipe_file = "" |
| 115 | result = runCmd("bitbake-layers show-recipes -f %s" % recipe) |
| 116 | for line in result.output.splitlines(): |
| 117 | if recipe in line: |
| 118 | recipe_file = line |
| 119 | break |
| 120 | |
| 121 | self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe) |
| 122 | return os.path.basename(recipe_file) |