public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Quentin Schulz <quentin.schulz@cherry.de>
Cc: u-boot@lists.denx.de, Dmitrii Sharshakov <d3dx12.xx@gmail.com>,
	Andrew Soknacki <asoknacki@gmail.com>
Subject: Re: [PATCH v3] binman: elf: Check for ELF_TOOLS availability in is_valid
Date: Tue, 20 Jan 2026 11:55:04 -0600	[thread overview]
Message-ID: <20260120175504.GO3416603@bill-the-cat> (raw)
In-Reply-To: <80e83cf4-f559-4505-b12c-7696c11e18cf@cherry.de>

[-- Attachment #1: Type: text/plain, Size: 3379 bytes --]

On Tue, Jan 20, 2026 at 06:36:33PM +0100, Quentin Schulz wrote:
> Hi Tom,
> 
> On 1/20/26 4:47 PM, Tom Rini wrote:
> > From: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
> > 
> > Check if elftools package is available before running DecodeElf().
> > 
> > This clarifies the error message and adds the required test for
> > coverage.
> > 
> > Signed-off-by: Dmitrii Sharshakov <d3dx12.xx@gmail.com>
> > Signed-off-by: Andrew Soknacki <asoknacki@gmail.com>
> > Reviewed-by: Tom Rini <trini@konsulko.com>
> > [trini: Add the test provided by Andrew on IRC, to fix coverage]
> > Signed-off-by: Tom Rini <trini@konsulko.com>
> > ---
> > Changes in v3:
> > - Add the test, provided by Andrew, to address the coverage failure in
> >    CI
> > ---
> >   tools/binman/elf.py      |  2 ++
> >   tools/binman/elf_test.py | 12 ++++++++++++
> >   2 files changed, 14 insertions(+)
> > 
> > diff --git a/tools/binman/elf.py b/tools/binman/elf.py
> > index 6ac960e04196..899c84ad36d6 100644
> > --- a/tools/binman/elf.py
> > +++ b/tools/binman/elf.py
> > @@ -570,6 +570,8 @@ def is_valid(data):
> >       Returns:
> >           bool: True if a valid Elf file, False if not
> >       """
> > +    if not ELF_TOOLS:
> > +        raise ValueError("Python: No module named 'elftools'")
> >       try:
> >           DecodeElf(data, 0)
> >           return True
> > diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
> > index 5b1733928986..3ad0bf4c4b09 100644
> > --- a/tools/binman/elf_test.py
> > +++ b/tools/binman/elf_test.py
> > @@ -373,6 +373,18 @@ class TestElf(unittest.TestCase):
> >           self.assertEqual(True, elf.is_valid(data))
> >           self.assertEqual(False, elf.is_valid(data[4:]))
> > +    def test_is_valid_fail(self):
> > +        """Test calling is_valid() without elftools"""
> > +        old_val = elf.ELF_TOOLS
> > +        try:
> > +            elf.ELF_TOOLS = False
> > +            with self.assertRaises(ValueError) as e:
> > +                elf.is_valid(b'')
> > +            self.assertIn("Python: No module named 'elftools'",
> > +                      str(e.exception))
> > +        finally:
> > +            elf.ELF_TOOLS = old_val
> > +
> 
> I'm not sure this is a good idea. The issue is that you're modifying the
> variable from a python module. The check may be run by other tests at the
> same time in different threads and I think the tests will unnecessarily be
> skipped or fail?
> 
> I think we may want something like:
> 
> @unittest.mock.patch('binman.elf.ELF_TOOLS', False)
> def test_is_valid_fail(self):
> ?

It's following the same practice as all of the other tests however. I
might do a follow-up to try what you suggest, since learning about how
to fix this problem yesterday I realized that I can fix I think my "no
cover" in commit 66be03b7ee19 ("binman: blob_dtb: improve error message
when SPL is not found") correctly now, as I think it's the same kind of
failure.

Personally, I find the exercise as an example of testing for tests sake.
We didn't (and can't?) have a test that caught the real problem, which
is a lack of elftools giving a hard to understand error message. The
patch from Dmitrii fixes that real problem (re-use the test+raise logic
other functions do), but python testing requests a test for this new
failure.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-01-20 17:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-09 22:03 [PATCH v2] binman: elf: Check for ELF_TOOLS availability in is_valid Dmitrii Sharshakov
2026-01-09 22:31 ` Tom Rini
2026-01-20 15:47 ` [PATCH v3] " Tom Rini
2026-01-20 17:36   ` Quentin Schulz
2026-01-20 17:55     ` Tom Rini [this message]
2026-01-20 18:15       ` Quentin Schulz
2026-01-20 18:22         ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260120175504.GO3416603@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=asoknacki@gmail.com \
    --cc=d3dx12.xx@gmail.com \
    --cc=quentin.schulz@cherry.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox