diff mbox series

[2/2] runqueue: Verify mcdepends are valid

Message ID 1737687019-22232-2-git-send-email-mark.hatle@kernel.crashing.org
State New
Headers show
Series [1/2] runqueue: add 'default' mc translation to mcdepends | expand

Commit Message

Mark Hatle Jan. 24, 2025, 2:50 a.m. UTC
From: Mark Hatle <mark.hatle@amd.com>

In order to avoid a potentially confusing backtrace, check that the mcdepend
is valid when we add it.

Add a test case to ensure invalid configurations are caught and trigger an
error.

Signed-off-by: Mark Hatle <mark.hatle@amd.com>
Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
---
 bitbake/lib/bb/runqueue.py                        | 2 ++
 bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb | 2 ++
 bitbake/lib/bb/tests/runqueue.py                  | 9 +++++++++
 3 files changed, 13 insertions(+)
 create mode 100644 bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb

Comments

Richard Purdie Jan. 25, 2025, 9:04 a.m. UTC | #1
On Thu, 2025-01-23 at 20:50 -0600, Mark Hatle via lists.openembedded.org wrote:
> From: Mark Hatle <mark.hatle@amd.com>
> 
> In order to avoid a potentially confusing backtrace, check that the mcdepend
> is valid when we add it.
> 
> Add a test case to ensure invalid configurations are caught and trigger an
> error.
> 
> Signed-off-by: Mark Hatle <mark.hatle@amd.com>
> Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
> ---
>  bitbake/lib/bb/runqueue.py                        | 2 ++
>  bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb | 2 ++
>  bitbake/lib/bb/tests/runqueue.py                  | 9 +++++++++
>  3 files changed, 13 insertions(+)
>  create mode 100644 bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb
> 
> diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py
> index f941749b0d..90f606469b 100644
> --- a/bitbake/lib/bb/runqueue.py
> +++ b/bitbake/lib/bb/runqueue.py
> @@ -734,6 +734,8 @@ class RunQueueData:
>                  if mc == frommc:
>                      fn = taskData[mcdep].build_targets[pn][0]
>                      newdep = '%s:%s' % (fn,deptask)
> +                    if newdep not in taskData[mcdep].taskentries:
> +                        bb.fatal("Task mcdepends on non-existent task %s" % (newdep))
>                      taskData[mc].taskentries[tid].tdepends.append(newdep)
>  
>          for mc in taskData:
> diff --git a/bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb b/bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb
> new file mode 100644
> index 0000000000..3c7dca0257
> --- /dev/null
> +++ b/bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb
> @@ -0,0 +1,2 @@
> +do_build[mcdepends] = "mc::mc-1:h1:do_invalid"
> +
> diff --git a/bitbake/lib/bb/tests/runqueue.py b/bitbake/lib/bb/tests/runqueue.py
> index cea2ca13fe..4662efbf55 100644
> --- a/bitbake/lib/bb/tests/runqueue.py
> +++ b/bitbake/lib/bb/tests/runqueue.py
> @@ -321,6 +321,15 @@ class RunQueueTests(unittest.TestCase):
>                         ["mc_2:i1:%s" % t for t in self.alltasks]
>              self.assertEqual(set(tasks), set(expected))
>  
> +            # Check what happens with an invalid task depednency
> +            passed = False
> +            try:
> +                self.run_bitbakecmd(["bitbake", "j1"], tempdir, "", extraenv=extraenv, cleanup=True)
> +            except AssertionError as e:
> +                print("Expected failure: %s" % e)
> +                passed = True
> +            self.assertEqual(True, passed)
> +
>              self.shutdown(tempdir)
>  
>      def test_hashserv_single(self):


Firstly, I *really* appreciate people adding tests, its great to see so
thanks for that.

The test needs a few tweaks, just to follow best practice.

Basically you can use assertRaises() to test it raises an exception and
we should really check that it says "Command.*failed" and "mcdepends on
non-existent task.*do_invalid".

https://www.geeksforgeeks.org/test-if-a-function-throws-an-exception-in-python/

Another option would be to have a new parameter to run_bitbakecmd which
just makes it return the failure output.

Cheers,

Richard
diff mbox series

Patch

diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py
index f941749b0d..90f606469b 100644
--- a/bitbake/lib/bb/runqueue.py
+++ b/bitbake/lib/bb/runqueue.py
@@ -734,6 +734,8 @@  class RunQueueData:
                 if mc == frommc:
                     fn = taskData[mcdep].build_targets[pn][0]
                     newdep = '%s:%s' % (fn,deptask)
+                    if newdep not in taskData[mcdep].taskentries:
+                        bb.fatal("Task mcdepends on non-existent task %s" % (newdep))
                     taskData[mc].taskentries[tid].tdepends.append(newdep)
 
         for mc in taskData:
diff --git a/bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb b/bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb
new file mode 100644
index 0000000000..3c7dca0257
--- /dev/null
+++ b/bitbake/lib/bb/tests/runqueue-tests/recipes/j1.bb
@@ -0,0 +1,2 @@ 
+do_build[mcdepends] = "mc::mc-1:h1:do_invalid"
+
diff --git a/bitbake/lib/bb/tests/runqueue.py b/bitbake/lib/bb/tests/runqueue.py
index cea2ca13fe..4662efbf55 100644
--- a/bitbake/lib/bb/tests/runqueue.py
+++ b/bitbake/lib/bb/tests/runqueue.py
@@ -321,6 +321,15 @@  class RunQueueTests(unittest.TestCase):
                        ["mc_2:i1:%s" % t for t in self.alltasks]
             self.assertEqual(set(tasks), set(expected))
 
+            # Check what happens with an invalid task depednency
+            passed = False
+            try:
+                self.run_bitbakecmd(["bitbake", "j1"], tempdir, "", extraenv=extraenv, cleanup=True)
+            except AssertionError as e:
+                print("Expected failure: %s" % e)
+                passed = True
+            self.assertEqual(True, passed)
+
             self.shutdown(tempdir)
 
     def test_hashserv_single(self):