diff mbox series

[v2,3/8] tests/cooker: add a bitbake -b bbappend test

Message ID 20260816221507.155861-4-adrian.freihofer@siemens.com
State New
Headers show
Series cooker/tinfoil: fix -b bbappend handling and add single-task prepared-task API | expand

Commit Message

AdrianF Aug. 16, 2026, 10:14 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Add BuildFileTest.test_buildfile_applies_bbappends() to cover the
buildfile ("bitbake -b") mode, which had no test coverage at all.

The test writes a recipe plus a matching .bbappend into a temporary
directory, points EXTRA_BBFILES at both, and runs a task that records
the value of a variable the bbappend overrides. It then asserts the
bbappend's value was the one in effect.

It uses the parse-tests BBPATH rather than runqueue-tests because its
bitbake.conf already globs *.bbappend and the recipe needs no task
scaffolding beyond its own.

Without the preceding fix the recorded value is the recipe's default,
i.e. -b built the recipe with the bbappend silently dropped.

Built on _BitbakeSubprocessTestCase so the "bitbake -b" subprocess's
server is properly waited on before the TemporaryDirectory cleanup
runs.

AI-Generated: Uses GitHub Copilot

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 lib/bb/tests/cooker.py | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/tests/cooker.py b/lib/bb/tests/cooker.py
index c49375ed8..c32694cc5 100644
--- a/lib/bb/tests/cooker.py
+++ b/lib/bb/tests/cooker.py
@@ -119,3 +119,49 @@  class CookerTest(unittest.TestCase):
         expected = []
 
         self.assertEqual(log_handler.logdata, expected)
+
+
+class BuildFileTest(_BitbakeSubprocessTestCase):
+    """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, \
+             self._build_dir(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"]
+            self._run_subprocess(cmd, env, builddir)
+
+            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")