[PATCH 2/7] tests/cooker: add a bitbake -b bbappend test
AdrianF <[email protected]>
| Newsgroups | org.openembedded.lists.bitbake-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Adrian Freihofer <[email protected]> The buildfile ("bitbake -b") mode had no test coverage at all. Add BuildFileTest.test_buildfile_applies_bbappends(), which writes a recipe plus a matching .bbappend to a temporary directory, points EXTRA_BBFILES at both and runs a task recording a variable the bbappend overrides. It uses the parse-tests BBPATH because that bitbake.conf already globs *.bbappend. Without the preceding fix the recipe's own default is recorded, i.e. -b dropped the bbappend silently. If the previous commit is reverted, this test faila with: AssertionError: 'no-bbappend' != 'bbappend-applied' - no-bbappend + bbappend-applied AI-Generated: Uses GitHub Copilot Signed-off-by: Adrian Freihofer <[email protected]> --- lib/bb/tests/cooker.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/bb/tests/cooker.py b/lib/bb/tests/cooker.py index 9e524ae34..76ec65540 100644 --- a/lib/bb/tests/cooker.py +++ b/lib/bb/tests/cooker.py @@ -8,6 +8,8 @@ import unittest import os +import subprocess +import tempfile import bb, bb.cooker import re import logging @@ -69,3 +71,53 @@ class CookerTest(unittest.TestCase): expected = [] self.assertEqual(log_handler.logdata, expected) + + +class BuildFileTest(unittest.TestCase): + """Tests for the buildfile ("bitbake -b") mode.""" + + # parse-tests BBPATH: minimal bitbake.conf whose BBFILES honours + # EXTRA_BBFILES and already includes *.bbappend + _parsetests = os.path.realpath(os.path.join(os.path.dirname(__file__), "parse-tests")) + + recipe = """\ +MARKER ??= "no-bbappend" +python do_marker() { + with open(d.expand("${TOPDIR}/marker.log"), "w") as f: + f.write(d.getVar("MARKER")) +} +addtask marker +""" + + bbappend = 'MARKER = "bbappend-applied"\n' + + def test_buildfile_applies_bbappends(self): + """bitbake -b must build the recipe with its bbappends applied. + + buildFileInternal() looks the appends up in self.collections[mc], which + on the -b path is only ever populated by matchFiles(). + """ + with tempfile.TemporaryDirectory(prefix="buildfilerecipes") as recipes, \ + tempfile.TemporaryDirectory(prefix="buildfiletest") as builddir: + recipe = os.path.join(recipes, "appendtest.bb") + with open(recipe, "w") as f: + f.write(self.recipe) + with open(os.path.join(recipes, "appendtest.bbappend"), "w") as f: + f.write(self.bbappend) + + env = os.environ.copy() + env["BBPATH"] = self._parsetests + env["BB_ENV_PASSTHROUGH_ADDITIONS"] = "TOPDIR EXTRA_BBFILES" + env["TOPDIR"] = builddir + env["EXTRA_BBFILES"] = "%s/*.bb %s/*.bbappend" % (recipes, recipes) + + cmd = ["bitbake", "-b", recipe, "-c", "marker"] + try: + subprocess.check_output(cmd, env=env, stderr=subprocess.STDOUT, + universal_newlines=True, cwd=builddir) + except subprocess.CalledProcessError as e: + self.fail("Command %s failed with %s" % (cmd, e.output)) + + with open(os.path.join(builddir, "marker.log")) as f: + self.assertEqual(f.read(), "bbappend-applied", + "bitbake -b did not apply the recipe's bbappend") -- 2.55.0